• Post Reply Bookmark Topic Watch Topic
  • New Topic

Client State Between Two Web Apps  RSS feed

 
Qand Davaatsedev
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a J2EE app with 2 WAR's and one SFSB to store a client state. When I create the SBSB in one web app I need to get it's reference in another web app.
According to the EJB 1.1 spec the only way to do that is:
handle.getEJBObject().
Now a problem appears how to pass this handle from one web app to another.
Any ideas?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it be feasible to serialize the handle into a temp directory and refer to it by a random generated id? For example, "...foobar.jsp&mysfsb=aAGadwGasdGasG" would tell the other webapp that it should deserialize the handle from a file called "/tmp/aAGadwGasdGasG" (if I remember correctly, the system's temporary directory is a standard Java system property...).
 
Qand Davaatsedev
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have to serialize handle why not just serialize my client state object and eliminate SFSB at all?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have to serialize handle why not just serialize my client state object and eliminate SFSB at all?

If that's possible then by all means do it. It'll be a lot easier than trying to move the state information between two webapps in the backend (if you're able to serialize in general, that is).
 
Qand Davaatsedev
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, serialization is always possible, but Sun recommends to store client state in stateful session bean. I would like to follow best practices but I don't know how.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. Are the two webapps running on the same J2EE server? If they are, you could try doing something like this:
- Put a class called "SessionSharing" somewhere so that it is loaded by the system classloader
- When you want to have a shared SFSB instance, give a reference to the SessionSharing class by calling (public static void) SessionSharing.add("foobar", myEjbRef)
- Give "foobar", the key, somehow to the other webapp so that it knows to make a call to SessionSharing.get("foobar")
That way you should be able to share the EJB object reference between two webapps on the same J2EE server. There could be some problems though with concurrent access so you could consider giving instances of some kind of a synchronized proxy class instead of the actual EJB reference object (the proxy would make sure that only one thread invokes the SFSB at a time).
I don't know whether this would really work. Let me know how it worked out for you.
 
Qand Davaatsedev
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lasse,
Yes my two web apps are parts of the same J2EE application (which contains 2 WAR and 1 EJB-JAR file).
My associate just implemented your solution and it works. The question is: why not to pass real client state this way (what she actually has done).
I don't believe Sun would really approve this practice.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My associate just implemented your solution and it works.

Happy to hear that.
The question is: why not to pass real client state this way (what she actually has done).

That is quite possible. If you don't see any problem with it, go for it. My suggestion is to do whichever seems more simple.
I don't believe Sun would really approve this practice.

I don't think so either. I wonder if Sun could come up with a better solution...
 
James Ward
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yours is a case of two wars in the same j2ee container...
If all u have is a one j2ee container, why even bother with a sfsb... overkill..
The solution the sun suggests is for this case (distributed) :
- There are more than one J2EE Container.
- There is a ear (same) in each J2EE Container.
- There is a web/jsp (or more than one) server in front of EJB containers.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!