On 03/11/2009 08:13, Imad Hachem wrote:
Dear Chris / Pid,

Issue has been solved after setting both hashmap&  QueryCryptUser
objects to the Session as below:

        static HashMap userSessionMapArray = new HashMap();
        SecretKey b =  KeyGenerator.getInstance("DESede").generateKey();
        QueryCryptUser  qcu = new QueryCryptUser(sessionID, b);
        userSessionMapArray.put(sessionID, qcu);

request.getSession().setAttribute("userSessionMapArray",userSessionMapAr
ray;
request.getSession().setAttribute("qcu", qcu);

Thanks for your help

I still don't understand why the HashMap is marked static - I don't see that it will do anything - try removing that and seeing if it works.

I also don't understand, if you're adding the QueryCryptUser to the session, and it contains the SecretKey 'b' already, why do you need the HashMap?

It doesn't contain other users session ids does it?


p


Imad Hachem | Asst.Product Development Manager
e-Banking Department
Path Solutions
Tel: +961 1 697444 ext. 222
Fax: +961 1 696744
www.path-solutions.com



Disclaimer
[The information contained in this e-mail message and any attached files
are confidential information and intended solely for the use of the
individual or entity to whom they are addressed. This transmission may
contain information that is privileged, confidential or exempt from
disclosure under applicable law. If you have received this e-mail in
error, please notify the sender immediately and delete all copies. If
you are not the intended recipient, any disclosure, copying,
distribution, or use of the information contained herein is STRICTLY
PROHIBITED. Path Solutions accepts no responsibility for any errors,
omissions, computer viruses and other defects.]




-----Original Message-----
From: Imad Hachem
Sent: Tuesday, November 03, 2009 12:21 PM
To: 'Tomcat Users List'
Subject: RE: MISC; After one Tomcat Cluster node shutdown Session
Replication working but a Hashmap object is getting empty

Dear Chris,

<distributable/>  has been set in my Web application web.xml and I have
set as well the<Context distributable="true">  in the context.xml of
both Tomcat Nodes but still not able to replicate my haspmap.

Please find below QueryCryptUser.java source code:


package com.guhesan.querycrypt.beans;

import java.util.HashMap;

import javax.crypto.SecretKey;


public class QueryCryptUser implements java.io.Serializable
{
        private String sessionID = "";
        private HashMap md5Keys = new HashMap();
        private SecretKey secretKey = null;
        /**
         * @return Returns the md5Keys.
         */
        public HashMap getMd5Keys()
        {
                return md5Keys;
        }
        /**
         * @param md5Keys The md5Keys to set.
         */
        public void setMd5Keys(HashMap md5Keys)
        {
                this.md5Keys = md5Keys;
        }
        /**
         * @return Returns the sessionID.
         */
        public String getSessionID()
        {
                return sessionID;
        }
        /**
         * @param sessionID The sessionID to set.
         */
        public void setSessionID(String sessionID)
        {
                this.sessionID = sessionID;
        }
        
        public void addToMD5Map(String md5, byte[] encryptedStr)
        {
                this.md5Keys.put(md5, encryptedStr);
        }
        
        public byte[] getByKey(String md5key)
        {
                return (byte[]) this.md5Keys.get(md5key);
        }
        /**
         * @return Returns the secretKey.
         */
        public SecretKey getSecretKey()
        {
                return secretKey;
        }
        /**
         * @param secretKey The secretKey to set.
         */
        public void setSecretKey(SecretKey secretKey)
        {
                this.secretKey = secretKey;
        }
        
        public QueryCryptUser(String sessionid, SecretKey key)
        {
                super();
                // TODO Auto-generated constructor stub
                secretKey = key;
                sessionID = sessionid;
        }
        
        
}


Imad Hachem | Asst.Product Development Manager
e-Banking Department
Path Solutions
Tel: +961 1 697444 ext. 222
Fax: +961 1 696744
www.path-solutions.com



Disclaimer
[The information contained in this e-mail message and any attached files
are confidential information and intended solely for the use of the
individual or entity to whom they are addressed. This transmission may
contain information that is privileged, confidential or exempt from
disclosure under applicable law. If you have received this e-mail in
error, please notify the sender immediately and delete all copies. If
you are not the intended recipient, any disclosure, copying,
distribution, or use of the information contained herein is STRICTLY
PROHIBITED. Path Solutions accepts no responsibility for any errors,
omissions, computer viruses and other defects.]




-----Original Message-----
From: Christopher Schultz [mailto:ch...@christopherschultz.net]
Sent: Monday, November 02, 2009 10:24 PM
To: Tomcat Users List
Subject: Re: MISC; After one Tomcat Cluster node shutdown Session
Replication working but a Hashmap object is getting empty

-----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


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



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

Reply via email to