Since you have to specify the url during deployment for the JNDI ENC, how do you deal with dynamic query strings for a web page?
Furthermore, can one use the HttpURLConnection.getInputStream() method since Enterprise JavaBeans are restricted from performing certain operations such as setting the stream handler factory used by the URL class? If not, how can you retrieve the contents?
I'm not sure what you mean by a dynamic query string for a web page. Can you please elaborate?
Also, to help you with the 2nd question (HttpURLConnection), I've always used servlets for performing Http requests, and had the servlets delegate to the EJB components. Have you considered that alternative?
I've got this page that displays dynamic contents based on the query strings. And I want to implement an EJB that can fetch the contents of this page based on the query strings input by the user at another page and do some formatting to the contents.
Here is what I want to do:
I've written a servlet to accept the query strings. The servlet will pass the inputs to an EJB that opens a connection to the URL, set the query strings, fetch the dynamic contents, and format it. An alternative is to have everything done by the servlet but this function is expected to be used quite heavily. The problems lay in setting the query strings and fetching the contents. How can you do it in an EJB?
If I understand you correctly, you've got a web browser that's sending parameters down to a servlet, and your servlet wants to load and format information stored in a database dynamically based upon the parameters sent from the browser. You then want to spit this formatted data back out to the browser. Is that correct?
If this is the case then have you considered using the EJB bean to read the data out of the database, pass it back to the servlet, and have the servlet write it back out to the browser?
You've got everything right except for the part about getting data from the database. Some of the data are coming from other web servers where I do not have total access to. Therefore, using an HttpURLConnection is the easiest way that does not require tampering with other web servers.
Why do you want an EJB to handle these presentation related issues? Infact I an not even sure that it is aloud. Aren't EJB's restricted from performing SocketCommunications ? I think the type of work you trying to do is in the domain of Servlets (Presentation Logic), whereas EJB's should be used for business logic.
What I would recommend doing is having a program fetch the contents of your "foreign" URL and write them to a file on your local drive (use CRON or something). Now your servlets can just access that file (MUCH FASTER than waiting to connect to other servers).
The fetching program is exactly what I'm trying to write in EJB. Yes, EJB is restricted to use socket communication but you can obtain a URLConnection using JNDI ENC.