Hi,
As per the EJB Specifications, we are not allowed to use "java.io" package.
I need to execute a servlet existing on a different Server through a stateless session bean.
I am planning to do this by opening a HttpURLConnection and getting the InputStream from the connection established.
Am I violating the EJB spec? What are the inherent problems in the same? Any workarounds?
TIA,
Prasad
Discussions
EJB programming & troubleshooting: Using HttpURLConnection inside Stateless Session Bean
-
Using HttpURLConnection inside Stateless Session Bean (3 messages)
- Posted by: Prasad S
- Posted on: May 14 2002 23:38 EDT
Threaded Messages (3)
- Using HttpURLConnection inside Stateless Session Bean by Randy Poznan on May 15 2002 11:47 EDT
- Using HttpURLConnection inside Stateless Session Bean by Gal Binyamini on May 15 2002 12:28 EDT
- Using HttpURLConnection inside Stateless Session Bean by Prasad S on May 15 2002 11:04 EDT
- Using HttpURLConnection inside Stateless Session Bean by Gal Binyamini on May 15 2002 12:28 EDT
-
Using HttpURLConnection inside Stateless Session Bean[ Go to top ]
- Posted by: Randy Poznan
- Posted on: May 15 2002 11:47 EDT
- in response to Prasad S
Did you try writing a utility class that calls the URL and does post/get and returns a String result or custom Response object? You should be able to call a class like that. Wrap java.io.* Exceptions.
-
Using HttpURLConnection inside Stateless Session Bean[ Go to top ]
- Posted by: Gal Binyamini
- Posted on: May 15 2002 12:28 EDT
- in response to Randy Poznan
Prasad,
The EJB specification is a great resource, but you *have* to read it with caution and notice the details if you are going to use it. The EJB spec sais:
"An enterprise bean must not use the java.io package to attempt to access files and directories in the file system."
This restriction is ment to ensure an enterprise bean does not become dependent on the particular box it is running on, because the App server may load it on several different boxes. It does *not* mean that you are not allowed to use java.io at all.
An enterprise bean is allowed to connect to a remote host, and therefore openning an HTTP connection is allowed.
Randy,
This is a common mistake. The EJB specification does not seperate an enterprise bean and the classes that it uses. Utility classes are subject to all the normal restrictions that are put on enterprise beans. The restrictions are on the *runtime environment*, not the bean's class.
Gal -
Using HttpURLConnection inside Stateless Session Bean[ Go to top ]
- Posted by: Prasad S
- Posted on: May 15 2002 23:04 EDT
- in response to Gal Binyamini
Thanks for the clarification!!