类 HttpSessionHandshakeInterceptor
- java.lang.Object
- org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor
- 所有已实现的接口:
HandshakeInterceptor
public class HttpSessionHandshakeInterceptor extends Object implements HandshakeInterceptor
An interceptor to copy information from the HTTP session to the "handshake attributes" map to made available viaWebSocketSession.getAttributes()
.Copies a subset or all HTTP session attributes and/or the HTTP session id under the key
HTTP_SESSION_ID_ATTR_NAME
.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
字段概要
字段 修饰符和类型 字段 说明 static String
HTTP_SESSION_ID_ATTR_NAME
The name of the attribute under which the HTTP session id is exposed whencopyHttpSessionId
is "true".
构造器概要
构造器 构造器 说明 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.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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 keyHTTP_SESSION_ID_ATTR_NAME
.void
setCreateSession(boolean createSession)
Whether to allow the HTTP session to be created while accessing it.
字段详细资料
HTTP_SESSION_ID_ATTR_NAME
public static final String HTTP_SESSION_ID_ATTR_NAME
The name of the attribute under which the HTTP session id is exposed whencopyHttpSessionId
is "true".- 另请参阅:
- 常量字段值
构造器详细资料
HttpSessionHandshakeInterceptor
public HttpSessionHandshakeInterceptor()
Default constructor for copying all HTTP session attributes and the HTTP session id.
HttpSessionHandshakeInterceptor
public HttpSessionHandshakeInterceptor(Collection<String> attributeNames)
Constructor for copying specific HTTP session attributes and the HTTP session id.- 参数:
attributeNames
- session attributes to copy- 另请参阅:
setCopyAllAttributes(boolean)
,setCopyHttpSessionId(boolean)
方法详细资料
getAttributeNames
public Collection<String> getAttributeNames()
Return the configured attribute names to copy (read-only).
setCopyAllAttributes
public void setCopyAllAttributes(boolean copyAllAttributes)
Whether to copy all attributes from the HTTP session. If set to "true", any explicitly configured attribute names are ignored.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 attributes
isCopyAllAttributes
public boolean isCopyAllAttributes()
Whether to copy all HTTP session attributes.
setCopyHttpSessionId
public void setCopyHttpSessionId(boolean copyHttpSessionId)
Whether the HTTP session id should be copied to the handshake attributes under the keyHTTP_SESSION_ID_ATTR_NAME
.By default this is "true".
- 参数:
copyHttpSessionId
- whether to copy the HTTP session id.
isCopyHttpSessionId
public boolean isCopyHttpSessionId()
Whether to copy the HTTP session id to the handshake attributes.
setCreateSession
public void setCreateSession(boolean createSession)
Whether to allow the HTTP session to be created while accessing it.By default set to
false
.
isCreateSession
public boolean isCreateSession()
Whether the HTTP session is allowed to be created.
beforeHandshake
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String,Object> attributes) throws Exception
从接口复制的说明:HandshakeInterceptor
Invoked before the handshake is processed.- 指定者:
beforeHandshake
在接口中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.- 返回:
- whether to proceed with the handshake (
true
) or abort (false
) - 抛出:
Exception
afterHandshake
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, @Nullable Exception ex)
从接口复制的说明:HandshakeInterceptor
Invoked after the handshake is done. The response status and headers indicate the results of the handshake, i.e. whether it was successful or not.- 指定者:
afterHandshake
在接口中HandshakeInterceptor
- 参数:
request
- the current requestresponse
- the current responsewsHandler
- the target WebSocket handlerex
- an exception raised during the handshake, ornull
if none