Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -43,8 +43,6 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*/
|
||||
public abstract class AbstractWebSocketClient implements WebSocketClient {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private static final Set<String> specialHeaders = new HashSet<String>();
|
||||
|
||||
static {
|
||||
@@ -60,11 +58,14 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
||||
}
|
||||
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
@Override
|
||||
public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
|
||||
String uriTemplate, Object... uriVars) {
|
||||
|
||||
Assert.notNull(uriTemplate, "uriTemplate must not be null");
|
||||
Assert.notNull(uriTemplate, "'uriTemplate' must not be null");
|
||||
URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri();
|
||||
return doHandshake(webSocketHandler, null, uri);
|
||||
}
|
||||
@@ -73,7 +74,7 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
||||
public final ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
|
||||
WebSocketHttpHeaders headers, URI uri) {
|
||||
|
||||
Assert.notNull(webSocketHandler, "webSocketHandler must not be null");
|
||||
Assert.notNull(webSocketHandler, "WebSocketHandler must not be null");
|
||||
assertUri(uri);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -89,25 +90,26 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
||||
}
|
||||
}
|
||||
|
||||
List<String> subProtocols = ((headers != null) && (headers.getSecWebSocketProtocol() != null)) ?
|
||||
headers.getSecWebSocketProtocol() : Collections.<String>emptyList();
|
||||
List<String> subProtocols = (headers != null && headers.getSecWebSocketProtocol() != null ?
|
||||
headers.getSecWebSocketProtocol() : Collections.<String>emptyList());
|
||||
|
||||
List<WebSocketExtension> extensions = ((headers != null) && (headers.getSecWebSocketExtensions() != null)) ?
|
||||
headers.getSecWebSocketExtensions() : Collections.<WebSocketExtension>emptyList();
|
||||
List<WebSocketExtension> extensions = (headers != null && headers.getSecWebSocketExtensions() != null ?
|
||||
headers.getSecWebSocketExtensions() : Collections.<WebSocketExtension>emptyList());
|
||||
|
||||
return doHandshakeInternal(webSocketHandler, headersToUse, uri, subProtocols, extensions,
|
||||
Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
protected void assertUri(URI uri) {
|
||||
Assert.notNull(uri, "uri must not be null");
|
||||
Assert.notNull(uri, "URI must not be null");
|
||||
String scheme = uri.getScheme();
|
||||
Assert.isTrue(scheme != null && ("ws".equals(scheme) || "wss".equals(scheme)), "Invalid scheme: " + scheme);
|
||||
if (!"ws".equals(scheme) && !"wss".equals(scheme)) {
|
||||
throw new IllegalArgumentException("Invalid scheme: " + scheme);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
@@ -116,7 +118,6 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
||||
* @param extensions requested WebSocket extensions, or an empty list
|
||||
* @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,
|
||||
|
||||
Reference in New Issue
Block a user