> From: "Atanu Neogi" <[EMAIL PROTECTED]>
> Sent: Friday, May 13, 2005 10:38 AM

> Hi,
>    a.    What is the best way to share a HttpSession between web
> applications running on a single Tomcat instance ? That Tomcat instance is
> not a cluster node and clustering has not been enabled.
>
>   b. What is the best way to share other java Object information (without
> using common persistence storage ) in memory between web applications? Are
> the add-on cache modules like JBoss cache etc. only solution?

The problem is that the webapps have their own distinct classloader
hierarchies, so that's one thing that makes sharing objects across webapps
difficult. Recall that an objects Class is based not just on the actual
Class it uses, but the Classloader for the class as well. Thus if you have
the an object of ClassX that's loaded by the classloader for WebappA, and
another object of ClassX loaded by WebappB, and in WebappA you try:

ClassX myObject = (ClassX)getObjectFromWebappB();

That will fail with a class cast exception, because WebappA.ClassX !=
WebappB.ClassX.

Using a "clustering" style caching solution helps remedy this by serializing
the objects, which breaks a lot of those dependencies, but is obviously
expensive.

One thing you can do, however, is move any classes that you want to share
across webapps out into the common/lib or common/classes directories. Those
classes are all shared across webapps, so they can safely be used back and
forth between them, since they share the Common classloader.

As for sharing HttpSessions, I don't think you can do that directly, as each
webapp will have their own unique session. You'll need to have some other
means to identify the user outside of the sessionid (like, say, their login
name if they authenticate, or an arbitrary domain level cookie that you
create on the fly if it doesn't exist yet).

Then you use that credential to access shared information stored in a Cache
that's loaded from the Common classloader.

Regards,

Will Hartung
([EMAIL PROTECTED])


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to