Rename handshakeAttributes to just attributes
Issue: SPR-11566
This commit is contained in:
parent
1fa4a7d34f
commit
48b62e80d5
|
@ -50,11 +50,15 @@ public interface WebSocketSession {
|
|||
HttpHeaders getHandshakeHeaders();
|
||||
|
||||
/**
|
||||
* Handshake request specific attributes.
|
||||
* To add attributes to a server-side WebSocket session see
|
||||
* {@link org.springframework.web.socket.server.HandshakeInterceptor}.
|
||||
* Return the map with attributes associated with the WebSocket session.
|
||||
*
|
||||
* <p>When the WebSocketSession is created, on the server side, the map can be
|
||||
* through a {@link org.springframework.web.socket.server.HandshakeInterceptor}.
|
||||
* On the client side, the map can be populated by passing attributes to the
|
||||
* {@link org.springframework.web.socket.client.WebSocketClient} handshake
|
||||
* methods.
|
||||
*/
|
||||
Map<String, Object> getHandshakeAttributes();
|
||||
Map<String, Object> getAttributes();
|
||||
|
||||
/**
|
||||
* Return a {@link java.security.Principal} instance containing the name of the
|
||||
|
|
|
@ -43,22 +43,22 @@ public abstract class AbstractWebSocketSession<T> implements NativeWebSocketSess
|
|||
|
||||
private T nativeSession;
|
||||
|
||||
private final Map<String, Object> handshakeAttributes;
|
||||
private final Map<String, Object> attributes;
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* @param handshakeAttributes attributes from the HTTP handshake to make available
|
||||
* through the WebSocket session
|
||||
* Create a new instance and associate the given attributes with it.
|
||||
*
|
||||
* @param attributes attributes from the HTTP handshake to associate with the WebSocket session
|
||||
*/
|
||||
public AbstractWebSocketSession(Map<String, Object> handshakeAttributes) {
|
||||
this.handshakeAttributes = handshakeAttributes;
|
||||
public AbstractWebSocketSession(Map<String, Object> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getHandshakeAttributes() {
|
||||
return this.handshakeAttributes;
|
||||
public Map<String, Object> getAttributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,24 +56,21 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
|
|||
/**
|
||||
* Create a new {@link JettyWebSocketSession} instance.
|
||||
*
|
||||
* @param handshakeAttributes attributes from the HTTP handshake to make available
|
||||
* through the WebSocket session
|
||||
* @param attributes attributes from the HTTP handshake to associate with the WebSocket session
|
||||
*/
|
||||
public JettyWebSocketSession(Map<String, Object> handshakeAttributes) {
|
||||
this(handshakeAttributes, null);
|
||||
public JettyWebSocketSession(Map<String, Object> attributes) {
|
||||
this(attributes, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link JettyWebSocketSession} instance associated with the given user.
|
||||
*
|
||||
* @param handshakeAttributes attributes from the HTTP handshake to make available
|
||||
* through the WebSocket session
|
||||
* @param user the user associated with the session; can be left
|
||||
* {@code null} in which case, we'll fallback on the user available via
|
||||
* {@link org.eclipse.jetty.websocket.api.Session#getUpgradeRequest()}
|
||||
* @param attributes attributes from the HTTP handshake to associate with the WebSocket session
|
||||
* @param user the user associated with the session; if {@code null} we'll fallback on the user
|
||||
* available via {@link org.eclipse.jetty.websocket.api.Session#getUpgradeRequest()}
|
||||
*/
|
||||
public JettyWebSocketSession(Map<String, Object> handshakeAttributes, Principal user) {
|
||||
super(handshakeAttributes);
|
||||
public JettyWebSocketSession(Map<String, Object> attributes, Principal user) {
|
||||
super(attributes);
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,32 +63,31 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
|
|||
* Class constructor.
|
||||
*
|
||||
* @param headers the headers of the handshake request
|
||||
* @param handshakeAttributes attributes from the HTTP handshake to make available
|
||||
* through the WebSocket session
|
||||
* @param attributes attributes from the HTTP handshake to associate with the WebSocket session
|
||||
* @param localAddress the address on which the request was received
|
||||
* @param remoteAddress the address of the remote client
|
||||
*/
|
||||
public StandardWebSocketSession(HttpHeaders headers, Map<String, Object> handshakeAttributes,
|
||||
public StandardWebSocketSession(HttpHeaders headers, Map<String, Object> attributes,
|
||||
InetSocketAddress localAddress, InetSocketAddress remoteAddress) {
|
||||
|
||||
this(headers, handshakeAttributes, localAddress, remoteAddress, null);
|
||||
this(headers, attributes, localAddress, remoteAddress, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor that associates a user with the WebSocket session.
|
||||
*
|
||||
* @param headers the headers of the handshake request
|
||||
* @param handshakeAttributes attributes from the HTTP handshake to make available
|
||||
* through the WebSocket session
|
||||
* @param attributes attributes from the HTTP handshake to associate with the WebSocket session
|
||||
* @param localAddress the address on which the request was received
|
||||
* @param remoteAddress the address of the remote client
|
||||
* @param user the user associated with the session; can be left
|
||||
* {@code null} in which case, we'll fallback on the user available via
|
||||
* @param user the user associated with the session; if {@code null} we'll
|
||||
* fallback on the user available in the underlying WebSocket session
|
||||
*/
|
||||
public StandardWebSocketSession(HttpHeaders headers, Map<String, Object> handshakeAttributes,
|
||||
public StandardWebSocketSession(HttpHeaders headers, Map<String, Object> attributes,
|
||||
InetSocketAddress localAddress, InetSocketAddress remoteAddress, Principal user) {
|
||||
|
||||
super(handshakeAttributes);
|
||||
super(attributes);
|
||||
|
||||
headers = (headers != null) ? headers : new HttpHeaders();
|
||||
this.handshakeHeaders = HttpHeaders.readOnlyHttpHeaders(headers);
|
||||
this.localAddress = localAddress;
|
||||
|
@ -96,6 +95,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
|
|||
this.user = user;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
checkNativeSessionInitialized();
|
||||
|
|
|
@ -103,18 +103,20 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
|||
|
||||
/**
|
||||
* Perform the actual handshake to establish a connection to the server.
|
||||
*
|
||||
* @param webSocketHandler the client-side handler for WebSocket messages
|
||||
* @param headers HTTP headers to use for the handshake, with unwanted (forbidden)
|
||||
* headers filtered out, never {@code null}
|
||||
* @param uri the target URI for the handshake, never {@code null}
|
||||
* @param subProtocols requested sub-protocols, or an empty list
|
||||
* @param extensions requested WebSocket extensions, or an empty list
|
||||
* @param handshakeAttributes attributes to make available via
|
||||
* {@link WebSocketSession#getHandshakeAttributes()}; currently always an empty map.
|
||||
* @param attributes attributes to associate with the WebSocketSession, i.e. via
|
||||
* {@link WebSocketSession#getAttributes()}; currently always an empty map.
|
||||
*
|
||||
* @return the established WebSocket session wrapped in a ListenableFuture.
|
||||
*/
|
||||
protected abstract ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
|
||||
HttpHeaders headers, URI uri, List<String> subProtocols, List<WebSocketExtension> extensions,
|
||||
Map<String, Object> handshakeAttributes);
|
||||
Map<String, Object> attributes);
|
||||
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Sma
|
|||
@Override
|
||||
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler,
|
||||
HttpHeaders headers, final URI uri, List<String> protocols,
|
||||
List<WebSocketExtension> extensions, Map<String, Object> handshakeAttributes) {
|
||||
List<WebSocketExtension> extensions, Map<String, Object> attributes) {
|
||||
|
||||
final ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
request.setSubProtocols(protocols);
|
||||
|
@ -186,7 +186,7 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Sma
|
|||
}
|
||||
|
||||
Principal user = getUser();
|
||||
final JettyWebSocketSession wsSession = new JettyWebSocketSession(handshakeAttributes, user);
|
||||
final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
|
||||
final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);
|
||||
|
||||
Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {
|
||||
|
|
|
@ -104,14 +104,14 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
|
|||
@Override
|
||||
protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
|
||||
HttpHeaders headers, final URI uri, List<String> protocols,
|
||||
List<WebSocketExtension> extensions, Map<String, Object> handshakeAttributes) {
|
||||
List<WebSocketExtension> extensions, Map<String, Object> attributes) {
|
||||
|
||||
int port = getPort(uri);
|
||||
InetSocketAddress localAddress = new InetSocketAddress(getLocalHost(), port);
|
||||
InetSocketAddress remoteAddress = new InetSocketAddress(uri.getHost(), port);
|
||||
|
||||
final StandardWebSocketSession session = new StandardWebSocketSession(headers,
|
||||
handshakeAttributes, localAddress, remoteAddress);
|
||||
attributes, localAddress, remoteAddress);
|
||||
|
||||
final ClientEndpointConfig.Builder configBuidler = ClientEndpointConfig.Builder.create();
|
||||
configBuidler.configurator(new StandardWebSocketClientConfigurator(headers));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -40,8 +40,8 @@ public interface HandshakeInterceptor {
|
|||
* @param request the current request
|
||||
* @param response the current response
|
||||
* @param wsHandler the target WebSocket handler
|
||||
* @param attributes attributes to make available via
|
||||
* {@link WebSocketSession#getHandshakeAttributes()}
|
||||
* @param attributes attributes from the HTTP handshake to associate with the
|
||||
* WebSocket session, i.e. via {@link WebSocketSession#getAttributes()}
|
||||
* @return whether to proceed with the handshake {@code true} or abort {@code false}
|
||||
*/
|
||||
boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.springframework.web.socket.server.HandshakeInterceptor;
|
|||
|
||||
/**
|
||||
* An interceptor to copy HTTP session attributes into the map of "handshake attributes"
|
||||
* made available through {@link WebSocketSession#getHandshakeAttributes()}.
|
||||
* made available through {@link WebSocketSession#getAttributes()}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
|
|
|
@ -269,7 +269,7 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
|
|||
}
|
||||
|
||||
private SockJsSession createSockJsSession(String sessionId, SockJsSessionFactory sessionFactory,
|
||||
WebSocketHandler handler, Map<String, Object> handshakeAttributes) {
|
||||
WebSocketHandler handler, Map<String, Object> attributes) {
|
||||
|
||||
synchronized (this.sessions) {
|
||||
SockJsSession session = this.sessions.get(sessionId);
|
||||
|
@ -283,7 +283,7 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
|
|||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Creating new session with session id \"" + sessionId + "\"");
|
||||
}
|
||||
session = sessionFactory.createSession(sessionId, handler, handshakeAttributes);
|
||||
session = sessionFactory.createSession(sessionId, handler, attributes);
|
||||
this.sessions.put(sessionId, session);
|
||||
return session;
|
||||
}
|
||||
|
|
|
@ -72,9 +72,9 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
|
|||
|
||||
|
||||
public AbstractHttpSockJsSession(String id, SockJsServiceConfig config,
|
||||
WebSocketHandler wsHandler, Map<String, Object> handshakeAttributes) {
|
||||
WebSocketHandler wsHandler, Map<String, Object> attributes) {
|
||||
|
||||
super(id, config, wsHandler, handshakeAttributes);
|
||||
super(id, config, wsHandler, attributes);
|
||||
this.messageCache = new ArrayBlockingQueue<String>(config.getHttpMessageCacheSize());
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ public abstract class AbstractSockJsSession implements SockJsSession {
|
|||
|
||||
private final WebSocketHandler handler;
|
||||
|
||||
private final Map<String, Object> handshakeAttributes;
|
||||
private final Map<String, Object> attributes;
|
||||
|
||||
private State state = State.NEW;
|
||||
|
||||
|
@ -105,12 +105,15 @@ public abstract class AbstractSockJsSession implements SockJsSession {
|
|||
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param id the session ID
|
||||
* @param config SockJS service configuration options
|
||||
* @param handler the recipient of SockJS messages
|
||||
* @param attributes attributes from the HTTP handshake to associate with the WebSocket session
|
||||
*/
|
||||
public AbstractSockJsSession(String id, SockJsServiceConfig config,
|
||||
WebSocketHandler handler, Map<String, Object> handshakeAttributes) {
|
||||
public AbstractSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler,
|
||||
Map<String, Object> attributes) {
|
||||
|
||||
Assert.notNull(id, "SessionId must not be null");
|
||||
Assert.notNull(config, "SockJsConfig must not be null");
|
||||
|
@ -119,7 +122,7 @@ public abstract class AbstractSockJsSession implements SockJsSession {
|
|||
this.id = id;
|
||||
this.config = config;
|
||||
this.handler = handler;
|
||||
this.handshakeAttributes = handshakeAttributes;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
|
||||
|
@ -133,8 +136,8 @@ public abstract class AbstractSockJsSession implements SockJsSession {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getHandshakeAttributes() {
|
||||
return this.handshakeAttributes;
|
||||
public Map<String, Object> getAttributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
|
|
|
@ -95,12 +95,12 @@ public class TestWebSocketSession implements WebSocketSession {
|
|||
this.headers = headers;
|
||||
}
|
||||
|
||||
public void setHandshakeAttributes(Map<String, Object> attributes) {
|
||||
public void setAttributes(Map<String, Object> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getHandshakeAttributes() {
|
||||
public Map<String, Object> getAttributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue