我是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());
请帮忙。