diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java index 77e5984cb6..b860602c39 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java @@ -43,7 +43,9 @@ public interface WebSocketSession extends Closeable { /** * Return the URI used to open the WebSocket connection. + * ({@code null} on the client side). */ + @Nullable URI getUri(); /** diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java index d437015588..61348da16e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java @@ -103,7 +103,7 @@ public class JettyWebSocketSession extends AbstractWebSocketSession { @Override public URI getUri() { - Assert.state(this.uri != null, "WebSocket session is not yet initialized"); + checkNativeSessionInitialized(); return this.uri; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java index dbd4143522..31944ded6e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java @@ -118,7 +118,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession @Override public URI getUri() { - Assert.state(this.uri != null, "WebSocket session is not yet initialized"); + checkNativeSessionInitialized(); return this.uri; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java index a03944dc19..f597462464 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java @@ -79,7 +79,8 @@ public class XhrClientSockJsSession extends AbstractClientSockJsSession { @Override public InetSocketAddress getRemoteAddress() { - return new InetSocketAddress(getUri().getHost(), getUri().getPort()); + URI uri = getUri(); + return (uri != null ? new InetSocketAddress(uri.getHost(), uri.getPort()) : null); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java index 5f6d96944d..77a41a6a58 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java @@ -127,8 +127,8 @@ public abstract class AbstractSockJsSession implements SockJsSession { public AbstractSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler, @Nullable Map attributes) { - Assert.notNull(id, "SessionId must not be null"); - Assert.notNull(config, "SockJsConfig must not be null"); + Assert.notNull(id, "Session id must not be null"); + Assert.notNull(config, "SockJsServiceConfig must not be null"); Assert.notNull(handler, "WebSocketHandler must not be null"); this.id = id;