Thanks Tim, your suggestion works. Here is the changed code

        Enumeration sessionAttributes = session.getAttributeNames();
      ArrayList list = new ArrayList();
        while(sessionAttributes.hasMoreElements()) {
                String name = (String) sessionAttributes.nextElement();
                if ((name.compareTo("userSession") != 0) &&
                    (name.compareTo("style") != 0) &&
                    (name.compareTo("moduleID") != 0) &&
                    (name.compareTo("listNavigatorMap") != 0))
                        list.add(name);
                }
        }
        Iterator iList = list.iterator();
        while(iList.hasNext()) {
                session.removeAttribute((String) iList.next());
        }

Imran
-----Original Message-----
From: Tim Funk [mailto:[EMAIL PROTECTED]
Sent: Saturday, July 19, 2003 5:48 AM
To: Tomcat Users List
Subject: Re: How to clean objects in user's session


Older versions of tomcat have their Enumeration from
session.getAttributeNames() backed by an Iterator. So if a change is made
you
get the ConcurrentModificationException. I know tomcat 5 does not have this
problem but I don't know about tomcat4. Since your using 4.1.24 - I am
guessing the change was not backported.

The easiest solution is to call invalidate - but this also usually logs the
user out too so it may not be acceptable. Once a session is invalidated - it
can't be used anymore for getting and setting stuff.

The alternative is clone/copy the Enumeration (probably the hard way by an
extra iteration) - then iterate through the copied version. The copied
version has no relation to the list so you can clear its atributes without
the exception.

-Tim



Imran Balkhi wrote:
> Hello,
>
> Our application is divided into multiple vertical views (ie, multiple
> company). User can work in only one vertical slice at a time (ie, abc
> company). Currently users have to logout and login again to change the
> vertical. There is a business requirement to provide ability to switch
> verticals without the need to logout and relogin. Here are my options.
>
>
> 1) invalidate the session object and create a new session. I am not sure
> if this is possible with logout and relogin routine. We are using our own
> authentication.
>
> 2) remove vertical specific objects from user's session. This option
> seems to be less intrusive on users. However, I am not able to remove
> objects Here is the test code
>
> if((userPreference.getCurrentCompanyId() > 0) &&
>     userPreference.getCurrentCompanyId() != companyId){
>       Enumeration sessionAttributes = session.getAttributeNames();
>       while(sessionAttributes.hasMoreElements()) {
>               String name = (String) sessionAttributes.nextElement();
>               if ((name.compareTo("userSession") != 0) &&  //exclude vertical
> independent objects
>                   (name.compareTo("style") != 0) &&
>                   (name.compareTo("moduleID") != 0) &&
>                   (name.compareTo("listNavigatorMap") != 0))
>                       logger.debug ("Name :  " + name);
>                       session.removeAttribute(name);
>               }
>       }
> }
>
> I am getting ConcurrentModificationException, detials are in attached
file.
>
> Can any one point out what am I doing wrong or let me know if there are
> better ways to get to goal.
>
> Thanks,
> Imran
>
>
>


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




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

Reply via email to