This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!

Jack Tauson

Ranch Hand
+ Follow
since Mar 27, 2014
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jack Tauson

Paul Clapham wrote:
So here's where JMS might come into the picture: you set up another server, outside the web application. .



Thanks Paul.When you say the above,did you mean a complete new server? I mean, I am on RHEL server and my webapp is deployed on the tomcat installed on RHEL. Did you mean to have a complete new RHEL server setup just for this?

If this is not an option, do you think I could use MOM like ActiveMQ on the Tomcat or any other preference? Thanks again !

Paul Clapham wrote:

Jack Tauson wrote:If I understood the definition of component properly, I have two components above, one is the client side code and another is the webservice code which is communicating with the Oracle database and getting me JSON data.



That's what I thought. So you already have the client side sending messages (via a web service) to the server side. In which case I can't understand why you want to bring in JMS, whose purpose is also to send messages.



Actually, what I am trying to figure out using JMS is the following:

Since, my SQL query is going to take long time when a user clicks on the download button, whether I could schedule this process in the JMS queue so that user interaction with other parts of the UI won't be blocked and possibly, when the SQL is finished, I could send a message to the user (via email) stating that the Query has finished or something similar?
I've my front end written using HTML/CSS/Javascript. Front end is communicating with the backend(Oracle database) using Java Webservices (Spring boot app).

Situation #1:
User clicks on the `Download` button, using Ajax call, I call my Java webservice, java webservice returns the data in JSON format, I display this data in the UI in tabular format.

Situation #2:
Since the amount of data to be returned is going to be huge, when a user clicks on the download button,I am expecting that the query could take hours or maybe a day to finish. Once the query is finished,I would like to upload the data returned from the webservice in a file at some location on the (RHEL)server so that when user comes back, he/she can click the `Download` button and download the file with huge data in whatever format it was saved (CSV, Excel etc)


Questions:

1) I was reading in another Stack overflow post  here (https://stackoverflow.com/questions/13752984/html5-file-api-downloading-file-from-server-and-saving-it-in-sandbox ) that saving file using FileSystemAPI on Firefox isn't supported. I am wondering if this is even a good solution based on the situation #2 described above?

2)If a webservice keeps on running for a day, isn't it going to time out in few hours? I've a feeling that the approach I've mentioned in Situation #2 above isn't an efficient one.

3) Is there something else that can be done in a more efficient manner to accomplish my task? Probably, some scheduling at database point of view?

4) In Situation #2, since the query is going to take long time, I am also planning to change the display of `Download` button to something "Come Back again". In this scenario, how would I determine that a particular query is going to take long time?


3 days ago

Paul Clapham wrote:

Jack Tauson wrote:If I understood the definition of component properly, I have two components above, one is the client side code and another is the webservice code which is communicating with the Oracle database and getting me JSON data.



That's what I thought. So you already have the client side sending messages (via a web service) to the server side. In which case I can't understand why you want to bring in JMS, whose purpose is also to send messages.



Ok. So if I understood correctly, you are considering "calling a web service to get the JSON data" as "client side sending messages (via a web service) to the server side".I'll ask a fresh question w/o using JMS terminology so that this thread could be considered as closed.

Paul Clapham wrote:

Jack Tauson wrote:Also, JMS can't be used for scheduling a SQL query which is going to take one day or two,right?



Well, remember that the purpose of JMS is to send messages asynchronously between software components. So certainly you could use JMS to send a message to a component which, when it receives a message, will run the query.

And certainly you could use JMS to send another message to that component to ask whether the query is finished yet. And perhaps you could also, given a suitable configuration, have that component send a message back to the other component to say Yes or No.

It isn't clear from your description what components exist on your proposed system which might support that architecture. If you were hoping that the client side of your web application would be the component which communicates via JMS to the component which runs the query, then that's unlikely to work except in very specialized situations. Perhaps the server side of the web application could be that component, but I got the impression that the client side was supposed to be getting the information about whether the query was complete or not. If that's the case then I don't see the point of using JMS on the server side.




I am not sure if we should call this a component or not. But please correct me if something looks illogical in my explanation below as far as components are concerned:

In my spring boot app, I have my client side code as well (HTML,CSS,Javascript), and Spring based webservices related Java code. My client side code communicates with this spring based webservices and these webservices runs and gets me the data from the Oracle database in JSON format and I display
that in my UI. The way I deploy this app on my RHEL server is, I export this app in WAR from my Eclipse and then deployed it on the Apache Tomcat on RHEL server.

If I understood the definition of component properly, I have two components above, one is the client side code and another is the webservice code which is communicating with the Oracle database and getting me JSON data.

1) So, you mean to say that it would be difficult to get information regarding when the query is finished on the client side using JMS?

2) Can the query which is triggered via webservice be scheduled using JMS when a user clicks on a button in the UI? I mean let's say the webservice is going to take one or two days to finish because the query is going to take long, I am wondering if this thing can be scheduled using JMS?

Jack Tauson wrote:

Ron McLeod wrote:JMS is an interface to a message queue which provides an loosely-coupled asynchronous mechanism for communications between applications or software components.  Providers (senders) place messages in a queue, and consumers (receivers) take messages from the queue.  JMS doesn't perform any kind of calculations/computing, and does not itself support SMTP (email) or HTTP (browser) protocols.

I don't see it can help with providing the user an hint at the amount of time it will take to complete the upload the file, or provide an indication of the progress of the upload.

Probably the best approach would be to solve this with client-side scripting, using a framework/library such as jQuery or Bootstrap.



Thank you for your valuable inputs. Do you think that JMS could be useful in the context of my situation discussed above, provided that I am handling the upload of the file using jQuery or Bootstrap? I am trying to understand how it could communicate between applications internally, maybe in my scenario.



Also, JMS can't be used for scheduling a SQL query which is going to take one day or two,right?

Ron McLeod wrote:JMS is an interface to a message queue which provides an loosely-coupled asynchronous mechanism for communications between applications or software components.  Providers (senders) place messages in a queue, and consumers (receivers) take messages from the queue.  JMS doesn't perform any kind of calculations/computing, and does not itself support SMTP (email) or HTTP (browser) protocols.

I don't see it can help with providing the user an hint at the amount of time it will take to complete the upload the file, or provide an indication of the progress of the upload.

Probably the best approach would be to solve this with client-side scripting, using a framework/library such as jQuery or Bootstrap.



Thank you for your valuable inputs. Do you think that JMS could be useful in the context of my situation discussed above, provided that I am handling the upload of the file using jQuery or Bootstrap? I am trying to understand how it could communicate between applications internally, maybe in my scenario.

Ron McLeod wrote:

Jack Tauson wrote:.. I say download, I mean  transferring from client (browser) to server.


Ok - that is normally referred to as upload.

Jack Tauson wrote:Please let me know if I can answer more questions.


What are you hoping that JMS will do in this scenario/use-case?



So, when a user hits the download button, since the download is going to take long time, how JMS will come into play in this scenario. I am trying to understand this. I was hoping that there would be some pre computing step within JMS and that will send message to the user letting them know how long it's going to
take for download? Secondly, how does messages reach user, via email or via browser, UI?

Ron McLeod wrote:It's not clear what are you hoping that JMS will do in this scenario/use-case.

Also, when you say download, do you mean transferring from client (browser?) to server, or server to client?



Yes, when I say download, I mean  transferring from client (browser) to server.  Please let me know if I can answer more questions. Thanks
I haven't used JMS before and hence trying to understand its usage in the following scenario.

I've a springboot webapp. It's WAR is deployed on the RHEL server. Client side is HTML,CSS and JavaScript.

Scenario Description:

There is a download button on the UI. When a user clicks on it, I might want it to save it in CSV or XSLS format on the RHEL server. The problem is that this download could take one or two days starting from the time user hits download button. In this scenario, I might want to display the user a message that they would need to come back after 1 day or whenever that download completes so that they could see the downloaded results.I am planning to display these downloaded results on the UI once the download is finished and file is saved somewhere on the RHEL server.


1) In order to use JMS here, do I need to setup ActiveMQ on the tomcat 8 server that I am using on the RHEL server?

2) How can I use it with my spring boot application with my web service that I am already using ?

2) How JMS messaging works, is it going to send messages via email to the user? If yes, then, do I need to have SMTP configured on my RHEL server which could be used by JMS?

3) Since the download is going to take long time, is there something in the JMS that would precompute the time in advance so that user would see the message as soon as a button is clicked? I mean is user going to see how long it is going to take OR the sole purpose of sending a message to the user after the process is completed is to avoid this per-computing step?

4)I guess saving the huge file in CSV or XSLS format once the download is completed has nothing to do with JMS, right? I mean, JMS won't have any functionality to handle these things, right?

Let me know if I can answer qny question. Thanks !
1 week ago

Dave Tolls wrote:Not off the top of my head, but there must be something on github or similar.
Do a search on Java ResultSet to JSON, or something like that.



Great. I used the JSONArray approach to convert the Resultset into a JSON as mentioned here :

https://stackoverflow.com/questions/6514876/most-efficient-conversion-of-resultset-to-json


And I don't even need to deal with using Reflection API stuff for generating getter and setter methods at runtime. Were you also referring to something similar package ? Also, any problems with the above approach?
1 month ago

Dave Tolls wrote:I'd be surprised if there wasn't already some package that can do this for you.



Could you please suggest which package would suit best based on the problem description given above? Thanks !
1 month ago

Tim Holloway wrote:I'm not sure, but I think that Junilu was expecting that you had ready-made class definitions and you just wanted to construct instances of those classes and have your generic code populate their values. Like ORMs do and JAXB does. For example, the Apache Digester.

That's not trivial, but there are things to make it easier. You can use the Apache beanutils to leverage Java's introspection services. All the cool apps do that - Tomcat's configuration compiler, popular JPA implementations, and so forth.

However, if you're hoping to build up a custom class field by field on the fly, that's much messier. Aside from everything else, Java's internal security mechanisms deliberately discourage rogue apps from "sabotaging" internal class structure,

The Map option is much easier. Basically, you construct a Map<String, Object>, then iterate the metadata of the resultset. For each returned column, put() a name/value pair into the Map, where the name is the column name and the value is the object returned by doing a "get" value for that column from the ResultSet.




Thanks for elaborating. I would like to clarify more on what I am looking for :

Let's take a look at the DAO implementation (GetSQLDaoImpl) of the interface (GetSQLDAO) as shown in my first post above

Inside the EmployeeList class, I've the getter and setters defined, which I am making use of in the try block, as shown below :


Using ResultSetMetaData interface, I was able to get the column names and the type of column in the following manner :



Now, inside the above try block, inside while(rsNew.next()){} , depending upon the column name and type (VARCHAR2 or DATE or NUMBER),

1) I was thinking of creating setter and getter methods inside the EmployeeList class (if this sounds like a good approach and not a messier approach). But I am still finding it difficult to understand, how would I be defining
something like empList.setEmpName(rs.getString("EMPNAME")); or empList.setEmpId(rs.getInt("EMPID")); dynamically.

Please let me know if I can answer more questions. Thanks !

 
1 month ago

Junilu Lacar wrote:Why would you name an object "EmployeeList" if it only represents one employee?

There are several ways to go about this but here are the main problems you have:

1. Figuring out which columns are included in the query and the order they will be in
2. Mapping the query columns to the appropriate setter() method on the object

For #1, you'll need metadata or you'll need to parse the text between "SELECT" and "FROM" of the query

For #2, for maximum flexibility, you'll have to use the Reflection API. Another option, although more tedious, would be to specify a "mapper" object for each query. That means you would potentially have to define as many mapper objects as you have queries. A mapper object will essentially have for its main logic whatever code you have in your while (rs.next()) loop.



Thanks. #1 : I was able to get the name of columns using ResultSetMetaData interface.


For #2:

Could you please elaborate on a) Reflection API usage here  and the b) mapper object technique you mentioned.

                 
1 month ago

Tim Holloway wrote:While Junilu has a point (EmployeeListItem would be a better name), there are basically 2 ways to do that. One is really brutal and that's to construct a Class completely in Java code using the Class meta-methods and their friends and relatives. The other is to construct Java source code (well, you could construct raw bytecodes, but that's harder to debug). and run the code through the Java compiler, then use a classloader to cause the current runtime to adopt this new class.

OR you could simply forget about making custom classes and return a Map, which is what most people do. It's a lot less work.



Could you please elaborate on this OR you could simply forget about making custom classes and return a Map, which is what most people do. It's a lot less work?
1 month ago