Mark ListenableFuture as deprecated for removal
Closes gh-33808
This commit is contained in:
@@ -118,7 +118,8 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
||||
* @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(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
protected org.springframework.util.concurrent.ListenableFuture<WebSocketSession> doHandshakeInternal(
|
||||
WebSocketHandler webSocketHandler, HttpHeaders headers, URI uri, List<String> subProtocols,
|
||||
List<WebSocketExtension> extensions, Map<String, Object> attributes) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -44,9 +44,11 @@ public interface WebSocketClient {
|
||||
* @return a future that completes when the session is available
|
||||
* @deprecated as of 6.0, in favor of {@link #execute(WebSocketHandler, String, Object...)}
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
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));
|
||||
}
|
||||
@@ -71,9 +73,11 @@ public interface WebSocketClient {
|
||||
* @return a future that completes when the session is available
|
||||
* @deprecated as of 6.0, in favor of {@link #execute(WebSocketHandler, WebSocketHttpHeaders, URI)}
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -237,7 +237,8 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
* @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(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
|
||||
String url, StompSessionHandler handler, Object... uriVars) {
|
||||
|
||||
@@ -270,7 +271,8 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
* @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(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
|
||||
String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
|
||||
StompSessionHandler handler, Object... uriVariables) {
|
||||
@@ -309,7 +311,8 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
* @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(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
|
||||
String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
|
||||
@Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {
|
||||
@@ -350,7 +353,8 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
||||
* @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(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
|
||||
URI url, @Nullable WebSocketHttpHeaders handshakeHeaders,
|
||||
@Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -67,11 +67,13 @@ public abstract class AbstractClientSockJsSession implements WebSocketSession {
|
||||
@Nullable
|
||||
private volatile CloseStatus closeStatus;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code AbstractClientSockJsSession}.
|
||||
* @deprecated as of 6.0, in favor of {@link #AbstractClientSockJsSession(TransportRequest, WebSocketHandler, CompletableFuture)}
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
protected AbstractClientSockJsSession(TransportRequest request, WebSocketHandler handler,
|
||||
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture) {
|
||||
this(request, handler, connectFuture.completable());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -108,10 +108,12 @@ public abstract class AbstractXhrTransport implements XhrTransport {
|
||||
return connectFuture;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
protected void connectInternal(TransportRequest request, WebSocketHandler handler,
|
||||
URI receiveUrl, HttpHeaders handshakeHeaders, XhrClientSockJsSession session,
|
||||
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture) {
|
||||
|
||||
throw new UnsupportedOperationException("connectInternal has been deprecated in favor of connectInternal");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -146,7 +146,8 @@ class DefaultTransportRequest implements TransportRequest {
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public void connect(WebSocketHandler handler,
|
||||
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> future) {
|
||||
|
||||
@@ -207,7 +208,7 @@ class DefaultTransportRequest implements TransportRequest {
|
||||
* to connect. Also implements {@code Runnable} to handle a scheduled timeout
|
||||
* callback.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings("removal")
|
||||
private class ListenableConnectCallback implements
|
||||
org.springframework.util.concurrent.ListenableFutureCallback<WebSocketSession>, Runnable {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -45,9 +45,11 @@ public interface Transport {
|
||||
* @return a future to indicate success or failure to connect
|
||||
* @deprecated as of 6.0, in favor of {@link #connectAsync(TransportRequest, WebSocketHandler)}
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
default org.springframework.util.concurrent.ListenableFuture<WebSocketSession> connect(
|
||||
TransportRequest request, WebSocketHandler webSocketHandler) {
|
||||
|
||||
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
|
||||
connectAsync(request, webSocketHandler));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -42,11 +42,13 @@ public class WebSocketClientSockJsSession extends AbstractClientSockJsSession im
|
||||
@Nullable
|
||||
private WebSocketSession webSocketSession;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code WebSocketClientSockJsSession}.
|
||||
* @deprecated as of 6.0, in favor of {@link #WebSocketClientSockJsSession(TransportRequest, WebSocketHandler, CompletableFuture)}
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public WebSocketClientSockJsSession(TransportRequest request, WebSocketHandler handler,
|
||||
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture) {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -54,12 +54,14 @@ public class XhrClientSockJsSession extends AbstractClientSockJsSession {
|
||||
|
||||
private int binaryMessageSizeLimit = -1;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code XhrClientSockJsSession}.
|
||||
* @deprecated as of 6.0, in favor of
|
||||
* {@link #XhrClientSockJsSession(TransportRequest, WebSocketHandler, XhrTransport, CompletableFuture)}
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
@Deprecated(since = "6.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public XhrClientSockJsSession(
|
||||
TransportRequest request, WebSocketHandler handler, XhrTransport transport,
|
||||
org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -57,38 +57,34 @@ class StandardWebSocketClientTests {
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void getLocalAddress() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
WebSocketSession session = this.wsClient.execute(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertThat(session.getLocalAddress()).isNotNull();
|
||||
assertThat(session.getLocalAddress().getPort()).isEqualTo(80);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void getLocalAddressWss() throws Exception {
|
||||
URI uri = URI.create("wss://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
WebSocketSession session = this.wsClient.execute(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertThat(session.getLocalAddress()).isNotNull();
|
||||
assertThat(session.getLocalAddress().getPort()).isEqualTo(443);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void getLocalAddressNoScheme() {
|
||||
URI uri = URI.create("localhost/abc");
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.wsClient.doHandshake(this.wsHandler, this.headers, uri));
|
||||
this.wsClient.execute(this.wsHandler, this.headers, uri));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void getRemoteAddress() throws Exception {
|
||||
URI uri = URI.create("wss://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
WebSocketSession session = this.wsClient.execute(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertThat(session.getRemoteAddress()).isNotNull();
|
||||
assertThat(session.getRemoteAddress().getHostName()).isEqualTo("localhost");
|
||||
@@ -96,27 +92,25 @@ class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void handshakeHeaders() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
List<String> protocols = Collections.singletonList("abc");
|
||||
this.headers.setSecWebSocketProtocol(protocols);
|
||||
this.headers.add("foo", "bar");
|
||||
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
WebSocketSession session = this.wsClient.execute(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertThat(session.getHandshakeHeaders()).hasSize(1);
|
||||
assertThat(session.getHandshakeHeaders().getFirst("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void clientEndpointConfig() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
List<String> protocols = Collections.singletonList("abc");
|
||||
this.headers.setSecWebSocketProtocol(protocols);
|
||||
|
||||
this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
this.wsClient.execute(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
ArgumentCaptor<ClientEndpointConfig> captor = ArgumentCaptor.forClass(ClientEndpointConfig.class);
|
||||
verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class));
|
||||
@@ -126,13 +120,12 @@ class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void clientEndpointConfigWithUserProperties() throws Exception {
|
||||
Map<String,Object> userProperties = Collections.singletonMap("foo", "bar");
|
||||
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
this.wsClient.setUserProperties(userProperties);
|
||||
this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
this.wsClient.execute(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
ArgumentCaptor<ClientEndpointConfig> captor = ArgumentCaptor.forClass(ClientEndpointConfig.class);
|
||||
verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class));
|
||||
@@ -142,12 +135,11 @@ class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void standardWebSocketClientConfiguratorInsertsHandshakeHeaders() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
this.headers.add("foo", "bar");
|
||||
|
||||
this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
this.wsClient.execute(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
ArgumentCaptor<ClientEndpointConfig> captor = ArgumentCaptor.forClass(ClientEndpointConfig.class);
|
||||
verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class));
|
||||
@@ -159,11 +151,10 @@ class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void taskExecutor() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
this.wsClient.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
WebSocketSession session = this.wsClient.execute(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertThat(session).isNotNull();
|
||||
}
|
||||
|
||||
@@ -209,24 +209,16 @@ abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void infoRequestFailure() throws Exception {
|
||||
TestClientHandler handler = new TestClientHandler();
|
||||
this.testFilter.sendErrorMap.put("/info", 500);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
initSockJsClient(createWebSocketTransport());
|
||||
this.sockJsClient.doHandshake(handler, this.baseUrl + "/echo").addCallback(
|
||||
new org.springframework.util.concurrent.ListenableFutureCallback<>() {
|
||||
@Override
|
||||
public void onSuccess(WebSocketSession result) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable ex) {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
);
|
||||
this.sockJsClient.execute(handler, this.baseUrl + "/echo").whenComplete((result, ex) -> {
|
||||
if (ex != null) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
assertThat(latch.await(5000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
}
|
||||
|
||||
@@ -245,14 +237,13 @@ abstract class AbstractSockJsIntegrationTests {
|
||||
|
||||
@Test
|
||||
@Timeout(5)
|
||||
@SuppressWarnings("deprecation")
|
||||
void fallbackAfterConnectTimeout() throws Exception {
|
||||
TestClientHandler clientHandler = new TestClientHandler();
|
||||
this.testFilter.sleepDelayMap.put("/xhr_streaming", 10000L);
|
||||
this.testFilter.sendErrorMap.put("/xhr_streaming", 503);
|
||||
initSockJsClient(createXhrTransport());
|
||||
// this.sockJsClient.setConnectTimeoutScheduler(this.wac.getBean(ThreadPoolTaskScheduler.class));
|
||||
WebSocketSession clientSession = sockJsClient.doHandshake(clientHandler, this.baseUrl + "/echo").get();
|
||||
WebSocketSession clientSession = sockJsClient.execute(clientHandler, this.baseUrl + "/echo").get();
|
||||
assertThat(clientSession.getClass()).as("Fallback didn't occur").isEqualTo(XhrClientSockJsSession.class);
|
||||
TextMessage message = new TextMessage("message1");
|
||||
clientSession.sendMessage(message);
|
||||
@@ -261,7 +252,6 @@ abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void testEcho(int messageCount, Transport transport, WebSocketHttpHeaders headers) throws Exception {
|
||||
List<TextMessage> messages = new ArrayList<>();
|
||||
for (int i = 0; i < messageCount; i++) {
|
||||
@@ -270,7 +260,7 @@ abstract class AbstractSockJsIntegrationTests {
|
||||
TestClientHandler handler = new TestClientHandler();
|
||||
initSockJsClient(transport);
|
||||
URI url = URI.create(this.baseUrl + "/echo");
|
||||
WebSocketSession session = this.sockJsClient.doHandshake(handler, headers, url).get();
|
||||
WebSocketSession session = this.sockJsClient.execute(handler, headers, url).get();
|
||||
for (TextMessage message : messages) {
|
||||
session.sendMessage(message);
|
||||
}
|
||||
@@ -282,13 +272,10 @@ abstract class AbstractSockJsIntegrationTests {
|
||||
session.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void testReceiveOneMessage(Transport transport, WebSocketHttpHeaders headers)
|
||||
throws Exception {
|
||||
|
||||
private void testReceiveOneMessage(Transport transport, WebSocketHttpHeaders headers) throws Exception {
|
||||
TestClientHandler clientHandler = new TestClientHandler();
|
||||
initSockJsClient(transport);
|
||||
this.sockJsClient.doHandshake(clientHandler, headers, URI.create(this.baseUrl + "/test")).get();
|
||||
this.sockJsClient.execute(clientHandler, headers, URI.create(this.baseUrl + "/test")).get();
|
||||
TestServerHandler serverHandler = this.wac.getBean(TestServerHandler.class);
|
||||
|
||||
assertThat(clientHandler.session).as("afterConnectionEstablished should have been called").isNotNull();
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
||||
@@ -129,26 +130,17 @@ class RestTemplateXhrTransportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectFailure() {
|
||||
final HttpServerErrorException expected = new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
RestOperations restTemplate = mock();
|
||||
given(restTemplate.execute(any(), eq(HttpMethod.POST), any(), any())).willThrow(expected);
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
connect(restTemplate).addCallback(
|
||||
new org.springframework.util.concurrent.ListenableFutureCallback<>() {
|
||||
@Override
|
||||
public void onSuccess(WebSocketSession result) {
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable ex) {
|
||||
if (ex == expected) {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
connect(restTemplate).whenComplete((result, ex) -> {
|
||||
if (ex == expected) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
verifyNoMoreInteractions(this.webSocketHandler);
|
||||
}
|
||||
|
||||
@@ -178,16 +170,11 @@ class RestTemplateXhrTransportTests {
|
||||
verify(response).close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private org.springframework.util.concurrent.ListenableFuture<WebSocketSession> connect(
|
||||
ClientHttpResponse... responses) {
|
||||
private CompletableFuture<WebSocketSession> connect(ClientHttpResponse... responses) {
|
||||
return connect(new TestRestTemplate(responses));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private org.springframework.util.concurrent.ListenableFuture<WebSocketSession> connect(
|
||||
RestOperations restTemplate, ClientHttpResponse... responses) {
|
||||
|
||||
private CompletableFuture<WebSocketSession> connect(RestOperations restTemplate) {
|
||||
RestTemplateXhrTransport transport = new RestTemplateXhrTransport(restTemplate);
|
||||
transport.setTaskExecutor(new SyncTaskExecutor());
|
||||
|
||||
@@ -197,7 +184,7 @@ class RestTemplateXhrTransportTests {
|
||||
TransportRequest request = new DefaultTransportRequest(urlInfo, headers, headers,
|
||||
transport, TransportType.XHR, CODEC);
|
||||
|
||||
return transport.connect(request, this.webSocketHandler);
|
||||
return transport.connectAsync(request, this.webSocketHandler);
|
||||
}
|
||||
|
||||
private ClientHttpResponse response(HttpStatus status, String body) throws IOException {
|
||||
@@ -218,7 +205,6 @@ class RestTemplateXhrTransportTests {
|
||||
|
||||
private Queue<ClientHttpResponse> responses = new LinkedBlockingDeque<>();
|
||||
|
||||
|
||||
private TestRestTemplate(ClientHttpResponse... responses) {
|
||||
this.responses.addAll(Arrays.asList(responses));
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.web.socket.sockjs.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -50,17 +51,15 @@ class SockJsClientTests {
|
||||
|
||||
private static final WebSocketHandler handler = mock();
|
||||
|
||||
|
||||
private final InfoReceiver infoReceiver = mock();
|
||||
|
||||
private final TestTransport webSocketTransport = new TestTransport("WebSocketTestTransport");
|
||||
|
||||
private final XhrTestTransport xhrTransport = new XhrTestTransport("XhrTestTransport");
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private org.springframework.util.concurrent.ListenableFutureCallback<WebSocketSession> connectCallback = mock();
|
||||
private final BiConsumer<WebSocketSession, Throwable> connectCallback = mock();
|
||||
|
||||
private SockJsClient sockJsClient = new SockJsClient(List.of(this.webSocketTransport, this.xhrTransport));
|
||||
private final SockJsClient sockJsClient = new SockJsClient(List.of(this.webSocketTransport, this.xhrTransport));
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -69,40 +68,36 @@ class SockJsClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectWebSocket() {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
this.sockJsClient.execute(handler, URL).whenComplete(this.connectCallback);
|
||||
assertThat(this.webSocketTransport.invoked()).isTrue();
|
||||
WebSocketSession session = mock();
|
||||
this.webSocketTransport.getConnectCallback().accept(session, null);
|
||||
verify(this.connectCallback).onSuccess(session);
|
||||
verify(this.connectCallback).accept(session, null);
|
||||
verifyNoMoreInteractions(this.connectCallback);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectWebSocketDisabled() {
|
||||
setupInfoRequest(false);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
this.sockJsClient.execute(handler, URL);
|
||||
assertThat(this.webSocketTransport.invoked()).isFalse();
|
||||
assertThat(this.xhrTransport.invoked()).isTrue();
|
||||
assertThat(this.xhrTransport.getRequest().getTransportUrl().toString()).endsWith("xhr_streaming");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectXhrStreamingDisabled() {
|
||||
setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
this.sockJsClient.execute(handler, URL).whenComplete(this.connectCallback);
|
||||
assertThat(this.webSocketTransport.invoked()).isFalse();
|
||||
assertThat(this.xhrTransport.invoked()).isTrue();
|
||||
assertThat(this.xhrTransport.getRequest().getTransportUrl().toString()).endsWith("xhr");
|
||||
}
|
||||
|
||||
@Test // SPR-13254
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectWithHandshakeHeaders() {
|
||||
ArgumentCaptor<HttpHeaders> headersCaptor = setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
@@ -110,7 +105,7 @@ class SockJsClientTests {
|
||||
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
|
||||
headers.set("foo", "bar");
|
||||
headers.set("auth", "123");
|
||||
this.sockJsClient.doHandshake(handler, headers, URI.create(URL)).addCallback(this.connectCallback);
|
||||
this.sockJsClient.execute(handler, headers, URI.create(URL)).whenComplete(this.connectCallback);
|
||||
|
||||
HttpHeaders httpHeaders = headersCaptor.getValue();
|
||||
assertThat(httpHeaders).hasSize(2);
|
||||
@@ -124,7 +119,6 @@ class SockJsClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() {
|
||||
ArgumentCaptor<HttpHeaders> headersCaptor = setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
@@ -133,7 +127,7 @@ class SockJsClientTests {
|
||||
headers.set("foo", "bar");
|
||||
headers.set("auth", "123");
|
||||
this.sockJsClient.setHttpHeaderNames("auth");
|
||||
this.sockJsClient.doHandshake(handler, headers, URI.create(URL)).addCallback(this.connectCallback);
|
||||
this.sockJsClient.execute(handler, headers, URI.create(URL)).whenComplete(this.connectCallback);
|
||||
|
||||
assertThat(headersCaptor.getValue()).hasSize(1);
|
||||
assertThat(headersCaptor.getValue().getFirst("auth")).isEqualTo("123");
|
||||
@@ -142,30 +136,27 @@ class SockJsClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectSockJsInfo() {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
this.sockJsClient.execute(handler, URL);
|
||||
verify(this.infoReceiver, times(1)).executeInfoRequest(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectSockJsInfoCached() {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
this.sockJsClient.execute(handler, URL);
|
||||
this.sockJsClient.execute(handler, URL);
|
||||
this.sockJsClient.execute(handler, URL);
|
||||
verify(this.infoReceiver, times(1)).executeInfoRequest(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectInfoRequestFailure() {
|
||||
HttpServerErrorException exception = new HttpServerErrorException(HttpStatus.SERVICE_UNAVAILABLE);
|
||||
given(this.infoReceiver.executeInfoRequest(any(), any())).willThrow(exception);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
verify(this.connectCallback).onFailure(exception);
|
||||
this.sockJsClient.execute(handler, URL).whenComplete(this.connectCallback);
|
||||
verify(this.connectCallback).accept(null, exception);
|
||||
assertThat(this.webSocketTransport.invoked()).isFalse();
|
||||
assertThat(this.xhrTransport.invoked()).isFalse();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user