Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB Handles  RSS feed

 
ipog
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The process of saving the handle for EJBObject through Object streams doesn't work out. The same works fine for EJBHome handle. Any valid reasons?
Any solution? Im getting null ptr exception due to some JVRM protocol.......
 
Rufus BugleWeed
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bartender ( err bouncer ) is going to complain
about your user id...
I don't think you want to even try to serialize
the EJBObject. The container assigns your beans
to the EJBObject. At any unknown time your bean
can be passivated or pooled and sometime later
come back to life with a different EJBObject.
Why do you want to serialize the EJBObject?
 
ipog
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An EJB Handle is a long lived proxy for an EJBObject. If for some reason you disconnect from the EJB Container,you can use the handle to reconnect to the EJBObject later.
For that reason, I need to save the handle to a flat file for later use.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi "ipog",
We have a naming policy here at JavaRanch where all publicly displayed names take the form, "Firstname Surname". Could you please edit your profile to bring it into line?
Thanks in advance...
As for your question, which J2EE server are you using? You should just be able to serializable the handle reference with no problems. Perhaps it's worth pasting the code that persists the reference for us to look at.
Cheers
Simon (aka the bouncer)
 
ipog
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im using weblogic 6.1
here's the code
serializing...
*********
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.T3InitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
InitialContext ctx = new InitialContext(ht);
System.out.println("..................Getting the JNDI of the bean");
StatefulSessionSampleHome home = (StatefulSessionSampleHome)ctx.lookup(strStatefulJNDI);
System.out.println("................. Getting the Remote Reference");
StatefulSessionSample remote;
remote = home.create();
System.out.println("................. Setting the Name");
remote.setName("IPOG");
System.out.println("run session client1 for getting the Name");
//HomeHandle myHandle = home.getHomeHandle();
javax.ejb.Handle myHandle = remote.getHandle();
//STORE IT IN FILE
ObjectOutputStream obj = new ObjectOutputStream(new FileOutputStream("passivated.txt"));
obj.writeObject(myHandle);
obj.flush();
obj.close();
********
*****
deserializing...
***
ObjectInputStream obj = new ObjectInputStream(new FileInputStream("passivated.txt"));
Handle myHandle = (Handle)obj.readObject();
StatefulSessionSample remote = (StatefulSessionSample)javax.rmi.PortableRemoteObject.narrow(myHandle.getEJBObject(),StatefulSessionSample.class);
System.out.println("NAME:"+remote.getName());
***
i get this error...

java.lang.NullPointerException
at weblogic.rjvm.Protocol.getDefaultProtocol(Protocol.java:106)
at weblogic.rjvm.JVMID.<init>(JVMID.java:768)
at java.io.ObjectInputStream.allocateNewObject(Native Method)
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1201)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
at weblogic.rmi.internal.BasicRemoteRef.readExternal(BasicRemoteRef.java:316)
at weblogic.rmi.internal.LeasedRemoteRef.readExternal(LeasedRemoteRef.java:40)
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1212)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
at java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2262)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519)
at weblogic.rmi.internal.StubInfo.readObject(StubInfo.java:73)
at java.lang.reflect.Method.invoke(Native Method)
at java.io.ObjectInputStream.invokeObjectReader(ObjectInputStream.java:2213)
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1410)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
at weblogic.ejb20.internal.HandleImpl.readExternal(HandleImpl.java:89)
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1212)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
at enterprisebeans.SessionClient1.main(SessionClient1.java:29)

And finally as regards the name, I'm not interested in editing my profile.
thanks in advance
 
Laudney Ren
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you get the Home, you should use java.rmi.portable.narrow() method, not just direct casting
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ipog, I'm sorry you aren't interested in changing your name to meet the requirements you agreed to when you registered. We aren't interested in seeing you on the ranch if you don't want to abide by the ranch rules. Your account has been closed.
[ June 01, 2002: Message edited by: Thomas Paul ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!