-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Imad,

On 11/2/2009 12:33 PM, Imad Hachem wrote:
> You are right about the case of Tomcat Node non shutdown, HashMap is not
> replicated correctly to the other node.

Okay, good (sort of). If it was only failing on one-node shutdown, it
would be much messier to track this down. Instead, this one attribute
(or perhaps more) are simply failing to replicate properly.

> Note that I am saving a secretKey (javax.crypto.SecretKey) as a VALUE
> for the sessionid KEY stored in the HashMap.

Do you have <distributable/> set in your web.xml? If not, you should
enable this. Doing so should cause an IllegalArgumentException to be
thrown if you try to put something into the session that isn't Serializable.

Note that the above statement only apples to values explicitly stored in
the session. This, for instance, will cause an error:

HttpSession session = request.getSession(true);
session.put("someKey", new NonSerializableClass());

...while this will not:

HttpSession session = request.getSession(true);
HashMap map = new HashMap();
map.put("someOtherKey", new NonSerializableClass());
session.put("someKey", map);

so, you have to be careful that the full object trees you put into your
session are serializable in their entirety. You could write a filter
that checks all this if you wanted to.

> How can I make sure that this secretKey or all HaspMap data are
> serializable?

Well, javax.crypto.SecretKey is not itself required to be serializable,
but one of its implementations, SecretKeySpec, /is/ marked as
Serializable. Any idea what kind of object you actually have?

> Note I am using the below code to store in the HashMap:
> 
>       static HashMap userSessionMapArray = new HashMap();
>       SecretKey       b =
> KeyGenerator.getInstance("DESede").generateKey();
>       QueryCryptUser  qcu = new QueryCryptUser(sessionID, b);
>       userSessionMapArray.put(sessionID, qcu);
> 
> 
> Note that I have tried to create the "QueryCryptUser" Class to
> implements java.io.Serializable but still facing the same problem and
> HashMap not replicated to the 2nd Node.

Well, would you be comfortable putting the key text itself into the
session? The key text itself should just be a byte[] which you could
convert to char[] in a number of ways if you'd like to make it (human)
readable.

I agree with Pid's question: why is the array static? ...and what it is
static to?

Clearly, your QueryCryptUser object needs to be Serializable, so you
should really focus on that, I think. You can encapsulate the logic to
serialize your SecretKey object within your QueryCryptUser class.

Can you post some or all of the QueryCryptUser class code?

Are you getting any errors in your log files when these objects are
serialized? It might help alot to see what the JVM is refusing to serialize.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrvP/kACgkQ9CaO5/Lv0PDKEwCgr2zMyPXLl0teiHA4KhJwTh7g
pVgAmgLKL5nT+ksy7xyeekvIT/ujJmNR
=zM1q
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to