Add flag whether to create HTTP session

Issue: SPR-12840
This commit is contained in:
Rossen Stoyanchev 2015-03-26 17:28:26 -04:00
parent ae3417133b
commit 73d6d30951
1 changed files with 19 additions and 1 deletions

View File

@ -54,6 +54,8 @@ public class HttpSessionHandshakeInterceptor implements HandshakeInterceptor {
private boolean copyHttpSessionId = true;
private boolean createSession;
/**
* Default constructor for copying all HTTP session attributes and the HTTP
@ -121,6 +123,22 @@ public class HttpSessionHandshakeInterceptor implements HandshakeInterceptor {
return this.copyHttpSessionId;
}
/**
* Whether to allow the HTTP session to be created while accessing it.
* <p>By default set to {@code false}.
* @see javax.servlet.http.HttpServletRequest#getSession(boolean)
*/
public void setCreateSession(boolean createSession) {
this.createSession = createSession;
}
/**
* Whether the HTTP session is allowed to be created.
*/
public boolean isCreateSession() {
return this.createSession;
}
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
@ -145,7 +163,7 @@ public class HttpSessionHandshakeInterceptor implements HandshakeInterceptor {
private HttpSession getSession(ServerHttpRequest request) {
if (request instanceof ServletServerHttpRequest) {
ServletServerHttpRequest serverRequest = (ServletServerHttpRequest) request;
return serverRequest.getServletRequest().getSession(false);
return serverRequest.getServletRequest().getSession(isCreateSession());
}
return null;
}