Browse Source

Rename handshakeAttributes to just attributes

Issue: SPR-11566
pull/441/merge
Rossen Stoyanchev 12 years ago
parent
commit
48b62e80d5
  1. 12
      spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java
  2. 16
      spring-websocket/src/main/java/org/springframework/web/socket/adapter/AbstractWebSocketSession.java
  3. 19
      spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java
  4. 20
      spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java
  5. 8
      spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java
  6. 4
      spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java
  7. 4
      spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java
  8. 6
      spring-websocket/src/main/java/org/springframework/web/socket/server/HandshakeInterceptor.java
  9. 2
      spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java
  10. 4
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java
  11. 4
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java
  12. 15
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java
  13. 4
      spring-websocket/src/test/java/org/springframework/web/socket/handler/TestWebSocketSession.java

12
spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java

@ -50,11 +50,15 @@ public interface WebSocketSession {
HttpHeaders getHandshakeHeaders(); HttpHeaders getHandshakeHeaders();
/** /**
* Handshake request specific attributes. * Return the map with attributes associated with the WebSocket session.
* To add attributes to a server-side WebSocket session see *
* {@link org.springframework.web.socket.server.HandshakeInterceptor}. * <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 * Return a {@link java.security.Principal} instance containing the name of the

16
spring-websocket/src/main/java/org/springframework/web/socket/adapter/AbstractWebSocketSession.java

@ -43,22 +43,22 @@ public abstract class AbstractWebSocketSession<T> implements NativeWebSocketSess
private T nativeSession; private T nativeSession;
private final Map<String, Object> handshakeAttributes; private final Map<String, Object> attributes;
/** /**
* Class constructor * Create a new instance and associate the given attributes with it.
* @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 AbstractWebSocketSession(Map<String, Object> handshakeAttributes) { public AbstractWebSocketSession(Map<String, Object> attributes) {
this.handshakeAttributes = handshakeAttributes; this.attributes = attributes;
} }
@Override @Override
public Map<String, Object> getHandshakeAttributes() { public Map<String, Object> getAttributes() {
return this.handshakeAttributes; return this.attributes;
} }
@Override @Override

19
spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java

@ -56,24 +56,21 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
/** /**
* Create a new {@link JettyWebSocketSession} instance. * Create a new {@link JettyWebSocketSession} instance.
* *
* @param handshakeAttributes attributes from the HTTP handshake to make available * @param attributes attributes from the HTTP handshake to associate with the WebSocket session
* through the WebSocket session
*/ */
public JettyWebSocketSession(Map<String, Object> handshakeAttributes) { public JettyWebSocketSession(Map<String, Object> attributes) {
this(handshakeAttributes, null); this(attributes, null);
} }
/** /**
* Create a new {@link JettyWebSocketSession} instance associated with the given user. * Create a new {@link JettyWebSocketSession} instance associated with the given user.
* *
* @param handshakeAttributes attributes from the HTTP handshake to make available * @param attributes attributes from the HTTP handshake to associate with the WebSocket session
* through the WebSocket session * @param user the user associated with the session; if {@code null} we'll fallback on the user
* @param user the user associated with the session; can be left * available via {@link org.eclipse.jetty.websocket.api.Session#getUpgradeRequest()}
* {@code null} in which case, we'll fallback on the user available via
* {@link org.eclipse.jetty.websocket.api.Session#getUpgradeRequest()}
*/ */
public JettyWebSocketSession(Map<String, Object> handshakeAttributes, Principal user) { public JettyWebSocketSession(Map<String, Object> attributes, Principal user) {
super(handshakeAttributes); super(attributes);
this.user = user; this.user = user;
} }

20
spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java

@ -63,32 +63,31 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
* Class constructor. * Class constructor.
* *
* @param headers the headers of the handshake request * @param headers the headers of the handshake request
* @param handshakeAttributes attributes from the HTTP handshake to make available * @param attributes attributes from the HTTP handshake to associate with the WebSocket session
* through the WebSocket session
* @param localAddress the address on which the request was received * @param localAddress the address on which the request was received
* @param remoteAddress the address of the remote client * @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) { 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. * Class constructor that associates a user with the WebSocket session.
* *
* @param headers the headers of the handshake request * @param headers the headers of the handshake request
* @param handshakeAttributes attributes from the HTTP handshake to make available * @param attributes attributes from the HTTP handshake to associate with the WebSocket session
* through the WebSocket session
* @param localAddress the address on which the request was received * @param localAddress the address on which the request was received
* @param remoteAddress the address of the remote client * @param remoteAddress the address of the remote client
* @param user the user associated with the session; can be left * @param user the user associated with the session; if {@code null} we'll
* {@code null} in which case, we'll fallback on the user available via * 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) { InetSocketAddress localAddress, InetSocketAddress remoteAddress, Principal user) {
super(handshakeAttributes); super(attributes);
headers = (headers != null) ? headers : new HttpHeaders(); headers = (headers != null) ? headers : new HttpHeaders();
this.handshakeHeaders = HttpHeaders.readOnlyHttpHeaders(headers); this.handshakeHeaders = HttpHeaders.readOnlyHttpHeaders(headers);
this.localAddress = localAddress; this.localAddress = localAddress;
@ -96,6 +95,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
this.user = user; this.user = user;
} }
@Override @Override
public String getId() { public String getId() {
checkNativeSessionInitialized(); checkNativeSessionInitialized();

8
spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java

@ -103,18 +103,20 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
/** /**
* Perform the actual handshake to establish a connection to the server. * Perform the actual handshake to establish a connection to the server.
*
* @param webSocketHandler the client-side handler for WebSocket messages * @param webSocketHandler the client-side handler for WebSocket messages
* @param headers HTTP headers to use for the handshake, with unwanted (forbidden) * @param headers HTTP headers to use for the handshake, with unwanted (forbidden)
* headers filtered out, never {@code null} * headers filtered out, never {@code null}
* @param uri the target URI for the handshake, never {@code null} * @param uri the target URI for the handshake, never {@code null}
* @param subProtocols requested sub-protocols, or an empty list * @param subProtocols requested sub-protocols, or an empty list
* @param extensions requested WebSocket extensions, or an empty list * @param extensions requested WebSocket extensions, or an empty list
* @param handshakeAttributes attributes to make available via * @param attributes attributes to associate with the WebSocketSession, i.e. via
* {@link WebSocketSession#getHandshakeAttributes()}; currently always an empty map. * {@link WebSocketSession#getAttributes()}; currently always an empty map.
*
* @return the established WebSocket session wrapped in a ListenableFuture. * @return the established WebSocket session wrapped in a ListenableFuture.
*/ */
protected abstract ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler, protected abstract ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
HttpHeaders headers, URI uri, List<String> subProtocols, List<WebSocketExtension> extensions, HttpHeaders headers, URI uri, List<String> subProtocols, List<WebSocketExtension> extensions,
Map<String, Object> handshakeAttributes); Map<String, Object> attributes);
} }

4
spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java

@ -172,7 +172,7 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Sma
@Override @Override
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler, public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler,
HttpHeaders headers, final URI uri, List<String> protocols, 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(); final ClientUpgradeRequest request = new ClientUpgradeRequest();
request.setSubProtocols(protocols); request.setSubProtocols(protocols);
@ -186,7 +186,7 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Sma
} }
Principal user = getUser(); Principal user = getUser();
final JettyWebSocketSession wsSession = new JettyWebSocketSession(handshakeAttributes, user); final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession); final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);
Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() { Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {

4
spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java

@ -104,14 +104,14 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
@Override @Override
protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler, protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
HttpHeaders headers, final URI uri, List<String> protocols, 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); int port = getPort(uri);
InetSocketAddress localAddress = new InetSocketAddress(getLocalHost(), port); InetSocketAddress localAddress = new InetSocketAddress(getLocalHost(), port);
InetSocketAddress remoteAddress = new InetSocketAddress(uri.getHost(), port); InetSocketAddress remoteAddress = new InetSocketAddress(uri.getHost(), port);
final StandardWebSocketSession session = new StandardWebSocketSession(headers, final StandardWebSocketSession session = new StandardWebSocketSession(headers,
handshakeAttributes, localAddress, remoteAddress); attributes, localAddress, remoteAddress);
final ClientEndpointConfig.Builder configBuidler = ClientEndpointConfig.Builder.create(); final ClientEndpointConfig.Builder configBuidler = ClientEndpointConfig.Builder.create();
configBuidler.configurator(new StandardWebSocketClientConfigurator(headers)); configBuidler.configurator(new StandardWebSocketClientConfigurator(headers));

6
spring-websocket/src/main/java/org/springframework/web/socket/server/HandshakeInterceptor.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 request the current request
* @param response the current response * @param response the current response
* @param wsHandler the target WebSocket handler * @param wsHandler the target WebSocket handler
* @param attributes attributes to make available via * @param attributes attributes from the HTTP handshake to associate with the
* {@link WebSocketSession#getHandshakeAttributes()} * WebSocket session, i.e. via {@link WebSocketSession#getAttributes()}
* @return whether to proceed with the handshake {@code true} or abort {@code false} * @return whether to proceed with the handshake {@code true} or abort {@code false}
*/ */
boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,

2
spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java

@ -34,7 +34,7 @@ import org.springframework.web.socket.server.HandshakeInterceptor;
/** /**
* An interceptor to copy HTTP session attributes into the map of "handshake attributes" * 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 * @author Rossen Stoyanchev
* @since 4.0 * @since 4.0

4
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java

@ -269,7 +269,7 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
} }
private SockJsSession createSockJsSession(String sessionId, SockJsSessionFactory sessionFactory, private SockJsSession createSockJsSession(String sessionId, SockJsSessionFactory sessionFactory,
WebSocketHandler handler, Map<String, Object> handshakeAttributes) { WebSocketHandler handler, Map<String, Object> attributes) {
synchronized (this.sessions) { synchronized (this.sessions) {
SockJsSession session = this.sessions.get(sessionId); SockJsSession session = this.sessions.get(sessionId);
@ -283,7 +283,7 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Creating new session with session id \"" + sessionId + "\""); 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); this.sessions.put(sessionId, session);
return session; return session;
} }

4
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java

@ -72,9 +72,9 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
public AbstractHttpSockJsSession(String id, SockJsServiceConfig config, 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()); this.messageCache = new ArrayBlockingQueue<String>(config.getHttpMessageCacheSize());
} }

15
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java

@ -93,7 +93,7 @@ public abstract class AbstractSockJsSession implements SockJsSession {
private final WebSocketHandler handler; private final WebSocketHandler handler;
private final Map<String, Object> handshakeAttributes; private final Map<String, Object> attributes;
private State state = State.NEW; 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 id the session ID
* @param config SockJS service configuration options * @param config SockJS service configuration options
* @param handler the recipient of SockJS messages * @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, public AbstractSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler,
WebSocketHandler handler, Map<String, Object> handshakeAttributes) { Map<String, Object> attributes) {
Assert.notNull(id, "SessionId must not be null"); Assert.notNull(id, "SessionId must not be null");
Assert.notNull(config, "SockJsConfig 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.id = id;
this.config = config; this.config = config;
this.handler = handler; this.handler = handler;
this.handshakeAttributes = handshakeAttributes; this.attributes = attributes;
} }
@ -133,8 +136,8 @@ public abstract class AbstractSockJsSession implements SockJsSession {
} }
@Override @Override
public Map<String, Object> getHandshakeAttributes() { public Map<String, Object> getAttributes() {
return this.handshakeAttributes; return this.attributes;
} }
public boolean isNew() { public boolean isNew() {

4
spring-websocket/src/test/java/org/springframework/web/socket/handler/TestWebSocketSession.java

@ -95,12 +95,12 @@ public class TestWebSocketSession implements WebSocketSession {
this.headers = headers; this.headers = headers;
} }
public void setHandshakeAttributes(Map<String, Object> attributes) { public void setAttributes(Map<String, Object> attributes) {
this.attributes = attributes; this.attributes = attributes;
} }
@Override @Override
public Map<String, Object> getHandshakeAttributes() { public Map<String, Object> getAttributes() {
return this.attributes; return this.attributes;
} }

Loading…
Cancel
Save