2015-07-20 124 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,请尽快启动它们,然后再将任何内容输出回给用户。 鉴于我们无法阅读课程的其余部分,因此难以进一步提供帮助。如果可能,请使用您正在使用的响应方法编辑您的问题。

相关问题