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]
RE: How to clean objects in user's session
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]
How to clean objects in user's session
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 htmlheadtitleApache Tomcat/4.1.24 - Error report/titleSTYLE!--H1{font-family : sans-serif,Arial,Tahoma;color : white;background-color : #0086b2;} H3{font-family : sans-serif,Arial,Tahoma;color : white;background-color : #0086b2;} BODY{font-family : sans-serif,Arial,Tahoma;color : black;background-color : white;} B{color : white;background-color : #0086b2;} HR{color : #0086b2;} --/STYLE /headbodyh1HTTP Status 500 - /h1HR size=1 noshadepbtype/b Exception report/ppbmessage/b u/u/ppbdescription/b uThe server encountered an internal error () that prevented it from fulfilling this request./u/ppbexception/b preorg.apache.jasper.JasperException at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)