WebSocketSession.getUri() may return null

Issue: SPR-15721
This commit is contained in:
Juergen Hoeller 2017-06-30 20:56:21 +02:00
parent 930f0f1760
commit 9afce23845
5 changed files with 8 additions and 5 deletions

View File

@ -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();
/**

View File

@ -103,7 +103,7 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
@Override
public URI getUri() {
Assert.state(this.uri != null, "WebSocket session is not yet initialized");
checkNativeSessionInitialized();
return this.uri;
}

View File

@ -118,7 +118,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
@Override
public URI getUri() {
Assert.state(this.uri != null, "WebSocket session is not yet initialized");
checkNativeSessionInitialized();
return this.uri;
}

View File

@ -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

View File

@ -127,8 +127,8 @@ public abstract class AbstractSockJsSession implements SockJsSession {
public AbstractSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler,
@Nullable Map<String, Object> 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;