我是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());
請幫忙。