2

I am facing a strange issue and am not able to find out the root cause. Here is the problem statement.

I have one tapestry page with a logout button. When I click on the logout button, the code below is executed and I get the exception.

// method which called onclick of logout button. 
@OnEvent(value = EventConstants.ACTION, component = "tlogout")
public Object logout()
{
    request.getSession(false).invalidate();
    return "Login";
}

Exception is:

INFO  | net.awl.tapestry5.kawwa.services.KawwaModule.TabLocator | 2011-01-05 14:33:23,321
   > Checking for any UPDATES

INFO  | net.awl.bfi.websuite.services.AppModule.TimingFilter | 2011-01-05 14:33:23,352
   > Request time: 31 ms

ERROR | org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/WebSuiteMoreaTapestry].[default] | 2011-01-05 14:33:23,352
   > Servlet.service() for servlet default threw exception

java.lang.IllegalStateException: Cannot create a session after the response has been committed
    at org.apache.catalina.connector.Request.doGetSession(Request.java:2221)
    at org.apache.catalina.connector.Request.getSession(Request.java:2031)
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:832)
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:843)
    at net.atos.xa.rm.jaas.openejb.web.RMOpenEJBFilter.doFilter(RMOpenEJBFilter.java:89)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.openejb.tomcat.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Thread.java:595)

Guys any idea? Regards,
Mahendra

4
  • As your method does not appear in the stack trace, it seems to execute fine, but net.atos.xa.rm.jaas.openejb.web.RMOpenEJBFilter is trying to use/create a session after you have invalidated it, which fails. Does the exception happen on the same request as the logout, or is it after the redirect to the login page?
    – Henning
    Jan 5, 2011 at 16:03
  • Henning i think it is for the same request as the logout. because i tried to put system.out.print in @SetupRender method of Login page but it didn't print anything on console. Next point is that i checked <code>net.atos.xa.rm.jaas.openejb.web.RMOpenEJBFilter</code> doFilter method and found that it is getting some attributes from session and that's why i am getting error. but it is an filter, so it is going to be called after each request/response. so does it means that i can not invalidated the session? Jan 5, 2011 at 18:08
  • a filter can do it's work before or after the request is processed. perhaps you need to notify openejb that the session is invalidated. i would have a look at it's source code, docs etc. i don't think this is a tapestry issue. tagging incase openejb people have ideas.
    – pstanton
    Jan 5, 2011 at 21:52
  • yes this is because of the RMOpenEJBFilter. Can we bypass the Filter for a selected request/response without modifying the Filter source code? Jan 6, 2011 at 5:49

2 Answers 2

1

Thanks for your time and your comments! With some good discussion I finally found the solution and are sharing it with you.

In my case request/response coming through RMOpenEJBFilter. So, when I invalidated the session in my code then it crashed in RMOpenEJBFilter because its internal code process on session.

So here is my solution.

  1. I created one Filter named as LogOutFilter.
  2. in WEB.XML I put it before RMOpenEJBFilter (for the purpose of Filter Chaining).
  3. in my logout code i am setting one variable in session

request.getSession(false).setAttribute("InvalidateSession", true);

  1. so when I click on the logout button it sets the session attribute, then goes to the RMOpenEJBFilter where it process the request (till the time session is not invalidated). Now control goes to the LogOutFilter where I made a check to invalidate the session.

if (httpRequest.getSession(false) != null && httpRequest.getSession(false).getAttribute("InvalidateSession") != null) { httpRequest.getSession(false).invalidate(); }

And now it's working fine.

Hope my solution is good enough to be accepted.

Feel free to contact me for any clarification.

Regards,
Mahendra Athneria
Mumbai, India

2
  • i'm sure that would work, however i'd expect openejb would have a way of avoiding the situation...
    – pstanton
    Jan 6, 2011 at 18:16
  • yes you are right. but that is not in my control thats why i have created my own filter to sort out the problem. Jan 7, 2011 at 11:16
0

i think u don't need filter. just add following action for logout.

@OnEvent("Logout")
    private Object onActionFromLogout() {
        Session session = requestGlobals.getRequest().getSession(false);
        if (session != null) {
            session.invalidate();
        }

        return Login.class;
    } 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.