public class HttpSessionHandshakeInterceptor extends java.lang.Object implements HandshakeInterceptor
WebSocketSession.getAttributes()
.
Copies a subset or all HTTP session attributes and/or the HTTP session id
under the key HTTP_SESSION_ID_ATTR_NAME
.
Modifier and Type | Field and Description |
---|---|
private java.util.Collection<java.lang.String> |
attributeNames |
private boolean |
copyAllAttributes |
private boolean |
copyHttpSessionId |
private boolean |
createSession |
static java.lang.String |
HTTP_SESSION_ID_ATTR_NAME
The name of the attribute under which the HTTP session id is exposed when
copyHttpSessionId is "true". |
Constructor and Description |
---|
HttpSessionHandshakeInterceptor()
Default constructor for copying all HTTP session attributes and the HTTP
session id.
|
HttpSessionHandshakeInterceptor(java.util.Collection<java.lang.String> attributeNames)
Constructor for copying specific HTTP session attributes and the HTTP
session id.
|
Modifier and Type | Method and Description |
---|---|
void |
afterHandshake(ServerHttpRequest request,
ServerHttpResponse response,
WebSocketHandler wsHandler,
java.lang.Exception ex)
Invoked after the handshake is done.
|
boolean |
beforeHandshake(ServerHttpRequest request,
ServerHttpResponse response,
WebSocketHandler wsHandler,
java.util.Map<java.lang.String,java.lang.Object> attributes)
Invoked before the handshake is processed.
|
java.util.Collection<java.lang.String> |
getAttributeNames()
Return the configured attribute names to copy (read-only).
|
private HttpSession |
getSession(ServerHttpRequest request) |
boolean |
isCopyAllAttributes()
Whether to copy all HTTP session attributes.
|
boolean |
isCopyHttpSessionId()
Whether to copy the HTTP session id to the handshake attributes.
|
boolean |
isCreateSession()
Whether the HTTP session is allowed to be created.
|
void |
setCopyAllAttributes(boolean copyAllAttributes)
Whether to copy all attributes from the HTTP session.
|
void |
setCopyHttpSessionId(boolean copyHttpSessionId)
Whether the HTTP session id should be copied to the handshake attributes
under the key
HTTP_SESSION_ID_ATTR_NAME . |
void |
setCreateSession(boolean createSession)
Whether to allow the HTTP session to be created while accessing it.
|
public static final java.lang.String HTTP_SESSION_ID_ATTR_NAME
copyHttpSessionId
is "true".private final java.util.Collection<java.lang.String> attributeNames
private boolean copyAllAttributes
private boolean copyHttpSessionId
private boolean createSession
public HttpSessionHandshakeInterceptor()
public HttpSessionHandshakeInterceptor(java.util.Collection<java.lang.String> attributeNames)
attributeNames
- session attributes to copysetCopyAllAttributes(boolean)
,
setCopyHttpSessionId(boolean)
public java.util.Collection<java.lang.String> getAttributeNames()
public void setCopyAllAttributes(boolean copyAllAttributes)
By default this is set to either "true" or "false" depending on which constructor was used (default or with attribute names respectively).
copyAllAttributes
- whether to copy all attributespublic boolean isCopyAllAttributes()
public void setCopyHttpSessionId(boolean copyHttpSessionId)
HTTP_SESSION_ID_ATTR_NAME
.
By default this is "true".
copyHttpSessionId
- whether to copy the HTTP session id.public boolean isCopyHttpSessionId()
public void setCreateSession(boolean createSession)
By default set to false
.
javax.servlet.http.HttpServletRequest#getSession(boolean)
public boolean isCreateSession()
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, java.util.Map<java.lang.String,java.lang.Object> attributes) throws java.lang.Exception
HandshakeInterceptor
beforeHandshake
in interface HandshakeInterceptor
request
- the current requestresponse
- the current responsewsHandler
- the target WebSocket handlerattributes
- attributes from the HTTP handshake to associate with the WebSocket
session; the provided attributes are copied, the original map is not used.true
) or abort (false
)java.lang.Exception
private HttpSession getSession(ServerHttpRequest request)
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, java.lang.Exception ex)
HandshakeInterceptor
afterHandshake
in interface HandshakeInterceptor
request
- the current requestresponse
- the current responsewsHandler
- the target WebSocket handlerex
- an exception raised during the handshake, or null
if none