Tapestry5 注销异常

发布于 2024-10-10 13:39:41 字数 2669 浏览 2 评论 0原文

我面临一个奇怪的问题,无法找出根本原因。这是问题陈述。

我有一张带有注销按钮的挂毯页面。当我单击注销按钮时,将执行下面的代码并收到异常。

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

例外的是:

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)

大家有什么想法吗? 问候,
马亨德拉

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痞味浪人 2024-10-17 13:39:41

感谢您的时间和评论!经过一番讨论,我终于找到了解决方案并与您分享。

就我而言,请求/响应通过 RMOpenEJBFilter 进行。因此,当我在代码中使会话无效时,它会在 RMOpenEJBFilter 中崩溃,因为其内部代码在会话上进行处理。

这是我的解决方案。

  1. 我创建了一个名为 LogOutFilter 的过滤器。
  2. 在 WEB.XML 中,我将其放在 RMOpenEJBFilter 之前(出于过滤器链接的目的)。
  3. 在我的注销代码中,我在会话中设置一个变量

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

  1. 因此,当我单击注销按钮时,它会设置会话属性,然后继续到 RMOpenEJBFilter 处理请求(直到会话未失效)。现在控制权转到 LogOutFilter ,我在其中进行了检查以使会话无效。

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

现在它工作正常

希望我的解决方案足够好,能够被接受。

如需任何说明,请随时与我联系。

问候,
Mahendra Athneria
印度孟买

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

江南月 2024-10-17 13:39:41

我认为你不需要过滤器。只需添加以下注销操作即可。

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

        return Login.class;
    } 

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;
    } 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文