Clean up warnings and polishing

This commit is contained in:
Sam Brannen
2022-07-31 14:14:56 +03:00
parent 9d1e9703ae
commit e4395f2f8b
55 changed files with 412 additions and 396 deletions

View File

@@ -18,7 +18,6 @@ package org.springframework.web.socket.client;
import java.net.URI;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -30,7 +29,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.socket.WebSocketExtension;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketHttpHeaders;
@@ -45,19 +43,16 @@ import org.springframework.web.util.UriComponentsBuilder;
*/
public abstract class AbstractWebSocketClient implements WebSocketClient {
private static final Set<String> specialHeaders = new HashSet<>();
static {
specialHeaders.add("cache-control");
specialHeaders.add("connection");
specialHeaders.add("host");
specialHeaders.add("sec-websocket-extensions");
specialHeaders.add("sec-websocket-key");
specialHeaders.add("sec-websocket-protocol");
specialHeaders.add("sec-websocket-version");
specialHeaders.add("pragma");
specialHeaders.add("upgrade");
}
private static final Set<String> specialHeaders = Set.of(
"cache-control",
"connection",
"host",
"sec-websocket-extensions",
"sec-websocket-key",
"sec-websocket-protocol",
"sec-websocket-version",
"pragma",
"upgrade");
protected final Log logger = LogFactory.getLog(getClass());
@@ -119,13 +114,14 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
* @param extensions requested WebSocket extensions, or an empty list
* @param attributes the 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.
* @return the established WebSocket session wrapped in a {@code ListenableFuture}.
* @deprecated as of 6.0, in favor of {@link #executeInternal(WebSocketHandler, HttpHeaders, URI, List, List, Map)}
*/
@Deprecated
protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
HttpHeaders headers, URI uri, List<String> subProtocols, List<WebSocketExtension> extensions,
Map<String, Object> attributes) {
protected org.springframework.util.concurrent.ListenableFuture<WebSocketSession> doHandshakeInternal(
WebSocketHandler webSocketHandler, HttpHeaders headers, URI uri, List<String> subProtocols,
List<WebSocketExtension> extensions, Map<String, Object> attributes) {
throw new UnsupportedOperationException("doHandshakeInternal is deprecated in favor of executeInternal");
}
@@ -138,8 +134,8 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
* @param subProtocols requested sub-protocols, or an empty list
* @param extensions requested WebSocket extensions, or an empty list
* @param attributes the 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.
* {@link WebSocketSession#getAttributes()}; currently always an empty map
* @return the established WebSocket session wrapped in a {@code CompletableFuture}.
*/
protected abstract CompletableFuture<WebSocketSession> executeInternal(WebSocketHandler webSocketHandler,
HttpHeaders headers, URI uri, List<String> subProtocols, List<WebSocketExtension> extensions,

View File

@@ -20,8 +20,6 @@ import java.net.URI;
import java.util.concurrent.CompletableFuture;
import org.springframework.lang.Nullable;
import org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketHttpHeaders;
import org.springframework.web.socket.WebSocketSession;
@@ -47,9 +45,10 @@ public interface WebSocketClient {
* @deprecated as of 6.0, in favor of {@link #execute(WebSocketHandler, String, Object...)}
*/
@Deprecated
default ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
String uriTemplate, Object... uriVariables) {
return new CompletableToListenableFutureAdapter<>(execute(webSocketHandler, uriTemplate, uriVariables));
default org.springframework.util.concurrent.ListenableFuture<WebSocketSession> doHandshake(
WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
execute(webSocketHandler, uriTemplate, uriVariables));
}
/**
@@ -73,9 +72,10 @@ public interface WebSocketClient {
* @deprecated as of 6.0, in favor of {@link #execute(WebSocketHandler, WebSocketHttpHeaders, URI)}
*/
@Deprecated
default ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
@Nullable WebSocketHttpHeaders headers, URI uri) {
return new CompletableToListenableFutureAdapter<>(execute(webSocketHandler, headers, uri));
default org.springframework.util.concurrent.ListenableFuture<WebSocketSession> doHandshake(
WebSocketHandler webSocketHandler, @Nullable WebSocketHttpHeaders headers, URI uri) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
execute(webSocketHandler, headers, uri));
}
/**

View File

@@ -30,10 +30,8 @@ import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.springframework.context.Lifecycle;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.concurrent.FutureUtils;
@@ -84,8 +82,8 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Lif
/**
* Set an {@link AsyncListenableTaskExecutor} to use when opening connections.
* If this property is set to {@code null}, calls to any of the
* Set an {@link AsyncTaskExecutor} to use when opening connections.
* <p>If this property is set to {@code null}, calls to any of the
* {@code doHandshake} methods will block until the connection is established.
* <p>By default an instance of {@code SimpleAsyncTaskExecutor} is used.
*/
@@ -94,7 +92,7 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Lif
}
/**
* Return the configured {@link TaskExecutor}.
* Return the configured {@link AsyncTaskExecutor}.
*/
@Nullable
public AsyncTaskExecutor getTaskExecutor() {

View File

@@ -36,10 +36,8 @@ import jakarta.websocket.Extension;
import jakarta.websocket.HandshakeResponse;
import jakarta.websocket.WebSocketContainer;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -109,8 +107,8 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
}
/**
* Set an {@link AsyncListenableTaskExecutor} to use when opening connections.
* If this property is set to {@code null}, calls to any of the
* Set an {@link AsyncTaskExecutor} to use when opening connections.
* <p>If this property is set to {@code null}, calls to any of the
* {@code doHandshake} methods will block until the connection is established.
* <p>By default, an instance of {@code SimpleAsyncTaskExecutor} is used.
*/
@@ -119,7 +117,7 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
}
/**
* Return the configured {@link TaskExecutor}.
* Return the configured {@link AsyncTaskExecutor}.
*/
@Nullable
public AsyncTaskExecutor getTaskExecutor() {

View File

@@ -49,8 +49,6 @@ import org.springframework.messaging.tcp.TcpConnectionHandler;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.socket.BinaryMessage;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
@@ -210,12 +208,15 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* @param url the url to connect to
* @param handler the session handler
* @param uriVars the URI variables to expand into the URL
* @return a ListenableFuture for access to the session when ready for use
* @return a {@code ListenableFuture} for access to the session when ready for use
* @deprecated as of 6.0, in favor of {@link #connectAsync(String, StompSessionHandler, Object...)}
*/
@Deprecated
public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) {
return new CompletableToListenableFutureAdapter<>(connectAsync(url, handler, uriVars));
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
String url, StompSessionHandler handler, Object... uriVars) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(url, handler, uriVars));
}
/**
@@ -240,14 +241,15 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* @param handshakeHeaders the headers for the WebSocket handshake
* @param handler the session handler
* @param uriVariables the URI variables to expand into the URL
* @return a ListenableFuture for access to the session when ready for use
* @return a {@code ListenableFuture} for access to the session when ready for use
* @deprecated as of 6.0, in favor of {@link #connectAsync(String, WebSocketHttpHeaders, StompSessionHandler, Object...)}
*/
@Deprecated
public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
StompSessionHandler handler, Object... uriVariables) {
return new CompletableToListenableFutureAdapter<>(
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(url, handshakeHeaders, null, handler, uriVariables));
}
@@ -259,7 +261,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* @param handshakeHeaders the headers for the WebSocket handshake
* @param handler the session handler
* @param uriVariables the URI variables to expand into the URL
* @return a ListenableFuture for access to the session when ready for use
* @return a {@code ListenableFuture} for access to the session when ready for use
* @since 6.0
*/
public CompletableFuture<StompSession> connectAsync(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
@@ -278,14 +280,15 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* @param connectHeaders headers for the STOMP CONNECT frame
* @param handler the session handler
* @param uriVariables the URI variables to expand into the URL
* @return a ListenableFuture for access to the session when ready for use
* @return a {@code ListenableFuture} for access to the session when ready for use
* @deprecated as of 6.0, in favor of {@link #connectAsync(String, WebSocketHttpHeaders, StompHeaders, StompSessionHandler, Object...)}
*/
@Deprecated
public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
@Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {
return new CompletableToListenableFutureAdapter<>(
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(url, handshakeHeaders, connectHeaders, handler, uriVariables));
}
@@ -318,14 +321,15 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* @param handshakeHeaders the headers for the WebSocket handshake
* @param connectHeaders headers for the STOMP CONNECT frame
* @param sessionHandler the STOMP session handler
* @return a ListenableFuture for access to the session when ready for use
* @return a {@code ListenableFuture} for access to the session when ready for use
* @deprecated as of 6.0, in favor of {@link #connectAsync(URI, WebSocketHttpHeaders, StompHeaders, StompSessionHandler)}
*/
@Deprecated
public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders,
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
URI url, @Nullable WebSocketHttpHeaders handshakeHeaders,
@Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) {
return new CompletableToListenableFutureAdapter<>(
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(url, handshakeHeaders, connectHeaders, sessionHandler));
}

View File

@@ -29,7 +29,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.SettableListenableFuture;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketHandler;
@@ -40,9 +39,11 @@ import org.springframework.web.socket.sockjs.frame.SockJsMessageCodec;
/**
* Base class for SockJS client implementations of {@link WebSocketSession}.
* Provides processing of incoming SockJS message frames and delegates lifecycle
*
* <p>Provides processing of incoming SockJS message frames and delegates lifecycle
* events and messages to the (application) {@link WebSocketHandler}.
* Sub-classes implement actual send as well as disconnect logic.
*
* <p>Subclasses implement actual send as well as disconnect logic.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
@@ -72,7 +73,7 @@ public abstract class AbstractClientSockJsSession implements WebSocketSession {
*/
@Deprecated
protected AbstractClientSockJsSession(TransportRequest request, WebSocketHandler handler,
SettableListenableFuture<WebSocketSession> connectFuture) {
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture) {
this(request, handler, connectFuture.completable());
}

View File

@@ -29,7 +29,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.util.concurrent.SettableListenableFuture;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketHandler;
@@ -112,7 +111,7 @@ public abstract class AbstractXhrTransport implements XhrTransport {
@Deprecated
protected void connectInternal(TransportRequest request, WebSocketHandler handler,
URI receiveUrl, HttpHeaders handshakeHeaders, XhrClientSockJsSession session,
SettableListenableFuture<WebSocketSession> connectFuture) {
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture) {
throw new UnsupportedOperationException("connectInternal has been deprecated in favor of connectInternal");
}

View File

@@ -33,8 +33,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.ListenableFutureCallback;
import org.springframework.util.concurrent.SettableListenableFuture;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.sockjs.SockJsTransportFailureException;
@@ -149,7 +147,9 @@ class DefaultTransportRequest implements TransportRequest {
@Deprecated
public void connect(WebSocketHandler handler, SettableListenableFuture<WebSocketSession> future) {
public void connect(WebSocketHandler handler,
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> future) {
if (logger.isTraceEnabled()) {
logger.trace("Starting " + this);
}
@@ -208,15 +208,17 @@ class DefaultTransportRequest implements TransportRequest {
* callback.
*/
@SuppressWarnings("deprecation")
private class ListenableConnectCallback implements ListenableFutureCallback<WebSocketSession>, Runnable {
private class ListenableConnectCallback implements
org.springframework.util.concurrent.ListenableFutureCallback<WebSocketSession>, Runnable {
private final WebSocketHandler handler;
private final SettableListenableFuture<WebSocketSession> future;
private final org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> future;
private final AtomicBoolean handled = new AtomicBoolean();
public ListenableConnectCallback(WebSocketHandler handler, SettableListenableFuture<WebSocketSession> future) {
public ListenableConnectCallback(WebSocketHandler handler,
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> future) {
this.handler = handler;
this.future = future;
}

View File

@@ -19,8 +19,6 @@ package org.springframework.web.socket.sockjs.client;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.sockjs.transport.TransportType;
@@ -34,29 +32,31 @@ import org.springframework.web.socket.sockjs.transport.TransportType;
public interface Transport {
/**
* Return the SockJS transport types that this transport can be used for.
* In particular since from a client perspective there is no difference
* Get the SockJS transport types that this transport can be used for.
* <p>In particular since from a client perspective there is no difference
* between XHR and XHR streaming, an {@code XhrTransport} could do both.
*/
List<TransportType> getTransportTypes();
/**
* Connect the transport.
* @param request the transport request.
* @param webSocketHandler the application handler to delegate lifecycle events to.
* @return a future to indicate success or failure to connect.
* @param request the transport request
* @param webSocketHandler the application handler to delegate lifecycle events to
* @return a future to indicate success or failure to connect
* @deprecated as of 6.0, in favor of {@link #connectAsync(TransportRequest, WebSocketHandler)}
*/
@Deprecated
default ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler webSocketHandler) {
return new CompletableToListenableFutureAdapter<>(connectAsync(request, webSocketHandler));
default org.springframework.util.concurrent.ListenableFuture<WebSocketSession> connect(
TransportRequest request, WebSocketHandler webSocketHandler) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(request, webSocketHandler));
}
/**
* Connect the transport.
* @param request the transport request.
* @param webSocketHandler the application handler to delegate lifecycle events to.
* @return a future to indicate success or failure to connect.
* @param request the transport request
* @param webSocketHandler the application handler to delegate lifecycle events to
* @return a future to indicate success or failure to connect
* @since 6.0
*/
CompletableFuture<WebSocketSession> connectAsync(TransportRequest request, WebSocketHandler webSocketHandler);

View File

@@ -23,7 +23,6 @@ import java.util.concurrent.CompletableFuture;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.SettableListenableFuture;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketExtension;
@@ -49,7 +48,7 @@ public class WebSocketClientSockJsSession extends AbstractClientSockJsSession im
*/
@Deprecated
public WebSocketClientSockJsSession(TransportRequest request, WebSocketHandler handler,
SettableListenableFuture<WebSocketSession> connectFuture) {
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture) {
super(request, handler, connectFuture);
}

View File

@@ -25,7 +25,6 @@ import java.util.concurrent.CompletableFuture;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.SettableListenableFuture;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketExtension;
@@ -56,11 +55,13 @@ public class XhrClientSockJsSession extends AbstractClientSockJsSession {
/**
* Create a new {@code XhrClientSockJsSession}.
* @deprecated as of 6.0, in favor of {@link #XhrClientSockJsSession(TransportRequest, WebSocketHandler, XhrTransport, CompletableFuture)}
* @deprecated as of 6.0, in favor of
* {@link #XhrClientSockJsSession(TransportRequest, WebSocketHandler, XhrTransport, CompletableFuture)}
*/
@Deprecated
public XhrClientSockJsSession(TransportRequest request, WebSocketHandler handler,
XhrTransport transport, SettableListenableFuture<WebSocketSession> connectFuture) {
public XhrClientSockJsSession(
TransportRequest request, WebSocketHandler handler, XhrTransport transport,
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture) {
super(request, handler, connectFuture);
Assert.notNull(transport, "XhrTransport is required");
@@ -72,6 +73,10 @@ public class XhrClientSockJsSession extends AbstractClientSockJsSession {
this.sendUrl = request.getSockJsUrlInfo().getTransportUrl(TransportType.XHR_SEND);
}
/**
* Create a new {@code XhrClientSockJsSession}.
* @since 6.0
*/
public XhrClientSockJsSession(TransportRequest request, WebSocketHandler handler,
XhrTransport transport, CompletableFuture<WebSocketSession> connectFuture) {