2015-07-20 121 views
2

我是Rest-API的新手,並試圖找出會話驗證。對於我的應用程序,我有會話和會話超時的概念。如果用戶會話無效或超時,那麼我正在檢查會話並返回錯誤消息。代碼如下所示。Rest-API中的會話驗證[java.lang.IllegalStateException:在提交響應後無法創建會話]

@GET 
@Path("/getScreenDetails") 
@Produces(MediaType.APPLICATION_JSON) 
public Response getScreenDetails(@BeanParam RequestBean requestBean) { 

    HttpSession currentSession = (HttpSession) InitialiseHelper 
      .getSessionMap().get(
        requestBean.getRequest().getSession().getId()); 
    if (currentSession == null) { 
     // user has not logged in needs to throw and error. 
     String errorMessage = "Invalid session "; 
     return ResponseHelper.getErrorResponse(103, errorMessage, 
       AAConstants.HTTP_UNAUTHORIZED_401); 
    } 
    //Do operations: 
    } 

但是我卻越來越

[java.lang.IllegalStateException: Cannot create a session after the response has been committed]

與根源

java.lang.IllegalStateException: Cannot create a session after the response has been committed error.

,我發現了錯誤IllegalStateException異常在第一線。

HttpSession currentSession = (HttpSession) InitialiseHelper 
      .getSessionMap().get(
        requestBean.getRequest().getSession().getId()); 

請幫忙。

回答

0

通常,當內容已發送給請求者時,您無法啓動會話。

這意味着如果您打算使用Session,請儘快啓動它們,然後再將任何內容輸出回給用戶。 鑑於我們無法閱讀課程的其餘部分,因此難以進一步提供幫助。如果可能,請使用您正在使用的響應方法編輯您的問題。

相關問題