This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes EJB Handle from HttpSession Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "EJB Handle from HttpSession" Watch "EJB Handle from HttpSession" New topic
Author

EJB Handle from HttpSession

Shawn Clark
Greenhorn

Joined: Aug 03, 2004
Posts: 7
I have searched around and haven't found any good documented code on how to set and then retrieve EJB handles through the HttpSession. Most of the stuff I have read so far is more discussions between if people should be using HttpSession and when to use that compared to using a SFSB. We have already decided on the design of our application and we are going to be using the SFSB to store state for a user. This allows us the freedom from moving our view from a web page to some other application at any time without having to re-code all the session stuff that might have been stored in a HttpSession. So please don't start up another discussion on using HttpSession over SFSB and the like.

The problem I am having is in my servlet. I am able to store the handle to the EJBs remote reference in the HttpSession. I am then able to get that handle from the HttpSession on a subsequent call to the servlet. The error occurs when I am trying to do a synopsisHandle.getEJBObject() where synopsisHandle is a Handle that I got from the HttpSession. The error that I get is:



This error leads me to believe that somewhere in the Handle object there is a reference to a JNDI name of 'SyNOPsisEJB' which would be right but I am getting a reference to the 'SyNOPsisEJB' by first doing a RMI call to another machine. Here is the code that gets the initial SyNOPsisEJB remote reference:



The last line is where I set the EJB handle in the HttpSession. Now the code that retrieves the handle is as follows:



The line of "synopsis = (SyNOPsisEJB) javax.rmi.PortableRemoteObject.narrow(synopsisHandle.getEJBObject(), SyNOPsisEJB.class);" is line 131 in the TOP.java code that is being referenced by the error message.

What am I doing wrong? Should I still be needing to make a connection to the SyNOPsisEJBHome when trying to connect to the same SFSB? Any and all suggestions are welcome as I am at a loss right now.

--
Shawn Clark
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382


The last line is where I set the EJB handle in the HttpSession. Now the code that retrieves the handle is as follows:



What am I doing wrong? Should I still be needing to make a connection to the SyNOPsisEJBHome when trying to connect to the same SFSB? Any and all suggestions are welcome as I am at a loss right now.

--
Shawn Clark[/qb]<hr></blockquote>

synopsisHandle.getEJBObject() returns the reference to you ejb's remote interface, not the home interface. So, you don't have to do PortableRemoteObject.narrow(synopsisHandle.getEJBObject(), SyNOPsisEJB.class).

You have already done the PortableRemoteObject.narrow() on the home interface before creating the remote interface. Don something like this:

[ August 03, 2004: Message edited by: Sadanand Murthy ]

Ever Existing, Ever Conscious, Ever-new Bliss
Shawn Clark
Greenhorn

Joined: Aug 03, 2004
Posts: 7
I was wondering that as well but I did try the code without the narrow as well. I originally had that line as:

synopsis = (SyNOPsisEJB) synopsisHandle.getEJBObject();

Both cases cause it to give the EJBHome error.

Any onther suggestions?
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Originally posted by Shawn Clark:
I was wondering that as well but I did try the code without the narrow as well. I originally had that line as:

synopsis = (SyNOPsisEJB) synopsisHandle.getEJBObject();

Both cases cause it to give the EJBHome error.

Any onther suggestions?


I have none. In my case, I have a java request handler class that the servlet uses & the ejb handle is a field in the request handler class. The servlet save the request handler in the httpsession which essentially serializes every non-transient field in the request handler object. I do handle.getEJBObject() in the request handler class and it has worked for me. You may want to post this question in the EJB forum or the Oracle/OAS forum.
Ade Barkah
Ranch Hand

Joined: Mar 17, 2004
Posts: 65
If you try to immediately get the object back from the handle (within the same request) does it also fail? Or does it only fail between different HTTP request in the same session?

Eg.:

synopsis = synopsisEJBHome.create();
synopsisHandle = synopsis.getHandle();
synopsis = (SyNOPsisEJB)synopsisHandle.getEJBObject(); // fails?

-Ade Barkah
[ August 05, 2004: Message edited by: Ade Barkah ]

-Ade<br /><a href="http://www.barkah.org" target="_blank" rel="nofollow">www.barkah.org</a>
Shawn Clark
Greenhorn

Joined: Aug 03, 2004
Posts: 7
Tried doing what you suggested and the same error occured. Here was the new modified code:



The log file had this in it:



and the error message was:



As you can see the log file shows that it made it to line 145 in the code but didn't make it to line 147 which is the final log message of the EJB object being retrieved properly. The stack trace shows that it errored on line 146 of the TOP.java when trying to do the getEJBObject().

So if I can't even get it back during the same request then what is happening? I am wondering if it might be something that is Oracle OC4J specific or if it is a J2EE problem.

Any other troubleshooting suggestions or assistance?

--
Shawn Clark
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Originally posted by Shawn Clark:
So if I can't even get it back during the same request then what is happening? I am wondering if it might be something that is Oracle OC4J specific or if it is a J2EE problem.

Any other troubleshooting suggestions or assistance?

--
Shawn Clark


I doubt it is a problem with J2EE specs. This certainly works for me on weblogic 6.1. I'd suspect that this would be a problem with oracle app server. Perhaps they have a service pack/patch that is missing on your computer.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: EJB Handle from HttpSession
 
Similar Threads
Oracle 9iAS Query
JMS with 9ias
JMS server refusing connection
Version conflict
Oracle 9iAS Query