2014-02-20 122 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上發佈。 –