2014-02-20 70 views
4

似乎我已经遇到了XPages中的SessionListener实现。侦听器在创建会话时将输出打印到日志中,因此我知道它已正确注册。但是,它在注销时不会调用sessionDestroyed。是否有任何特殊的URL重定向我需要执行以使Domino/XPage会话在注销时立即销毁?正如你所看到的,我已经尝试清除范围,并清除尝试启动sessionDestroyed方法的cookie。请注意,当重新启动http服务器任务时,sessionDestroyed不会被调用,所以看起来会话可能会一直存在,直到处于非活动状态超时。SessionListener sessionDestroyed not called

开发服务器是:9.0.1(64位Win7上本地运行) 运行基于会话验证单个服务器(注:我试过了基本身份验证,同样的问题)

注销程序法(SSJS称为):

public static void logout(){ 


    String url = XSPUtils.externalContext().getRequestContextPath() + "?logout&redirectto=" + externalContext().getRequestContextPath(); 
    XSPUtils.getRequest().getSession(false).invalidate(); 

    //wipe out the cookies 
    for(Cookie cookie : getCookies()){ 
     cookie.setValue(""); 
     cookie.setPath("/"); 
     cookie.setMaxAge(0); 
     XSPUtils.getResponse().addCookie(cookie); 
    } 

    try { 
     XSPUtils.externalContext().redirect(url); 
    } catch (IOException e) { 
     logger.log(Level.SEVERE,null,e); 
    } 
} 

简单的会话监听器:

public class MySessionListener implements SessionListener { 

public void sessionCreated(ApplicationEx arg0, HttpSessionEvent event) { 
    System.out.println("***sessionCreated***"); 

} 

public void sessionDestroyed(ApplicationEx arg0, HttpSessionEvent event) { 
    System.out.println("***sessionDestroyed***"); 
} 

}

+0

这是否有帮助? http://stackoverflow.com/a/11183463/785061 –

+0

感谢您的反馈。在我对这个问题的研究中,我确实找到了这篇文章。我的问题不是会话创建或注册监听器(sessionCreated正在触发)。在使HttpSession失效并执行注销重定向之后,必须处理sessionDestroy。该方法将不会触发,直到我重新启动http和/或如果我等待超时。 –

+0

您是否试过[ExtLib注销控制](http://notesin9.com/index.php/2012/03/09/notesin9-049-xpages-login-and-logout/)? – stwissel

回答

5

我们正在考虑将传统http stack“?logout”行为与XPages运行时会话管理层耦合。目前,基于会话超时到期和/或HTTP堆栈重新启动,会话被丢弃。如果您想强制删除会话并调用SessionListener.sessionDestroyed,请参考以下XSP片段 - 这同样适用于移植到Java:

<xp:button value="Logout" id="button2"> 
    <xp:eventHandler event="onclick" submit="true" 
     refreshMode="complete"> 
     <xp:this.action> 
      <![CDATA[#{javascript: 
       // things we need... 
       var externalContext = facesContext.getExternalContext(); 
       var request = externalContext.getRequest(); 
       var response = externalContext.getResponse(); 
       var currentContext = com.ibm.domino.xsp.module.nsf.NotesContext.getCurrent(); 
       var session = request.getSession(false); 
       var sessionId = session.getId(); 

       // flush the cookies and invalidate the HTTP session... 
       for(var cookie in request.getCookies()){ 
        cookie.setValue(""); 
        cookie.setPath("/"); 
        cookie.setMaxAge(0); 
        response.addCookie(cookie); 
       } 
       session.invalidate(); 

       // now nuke the XSP session from RAM, then jump to logout... 
       currentContext.getModule().removeSession(sessionId); 
       externalContext.redirect("http://foo/bar.nsf?logout"); 
      }]]> 
     </xp:this.action> 
    </xp:eventHandler> 
</xp:button> 
+0

将你的ssjs片段移植到我的注销java方法中,我的监听器现在正在注销时被调用。谢谢!你也应该在XSnippets上发布。 –