public class HttpSessionHandshakeInterceptor extends 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 |
---|---|
static 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(Collection<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,
Exception ex)
Invoked after the handshake is done.
|
boolean |
beforeHandshake(ServerHttpRequest request,
ServerHttpResponse response,
WebSocketHandler wsHandler,
Map<String,Object> attributes)
Invoked before the handshake is processed.
|
Collection<String> |
getAttributeNames()
Return the configured attribute names to copy (read-only).
|
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 String HTTP_SESSION_ID_ATTR_NAME
copyHttpSessionId
is "true".public HttpSessionHandshakeInterceptor()
public HttpSessionHandshakeInterceptor(Collection<String> attributeNames)
attributeNames
- session attributes to copysetCopyAllAttributes(boolean)
,
setCopyHttpSessionId(boolean)
public Collection<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
.
HttpServletRequest.getSession(boolean)
public boolean isCreateSession()
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String,Object> attributes) throws Exception
HandshakeInterceptor
beforeHandshake
in interface HandshakeInterceptor
request
- the current requestresponse
- the current responsewsHandler
- the target WebSocket handlerattributes
- the 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
)Exception
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, @Nullable 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