Browse Source

Mark ListenableFuture as deprecated for removal

Closes gh-33808
pull/33827/head
Juergen Hoeller 1 year ago
parent
commit
9e3371ef07
  1. 4
      spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java
  2. 4
      spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleThreadPoolTaskExecutor.java
  3. 2
      spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java
  4. 15
      spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java
  5. 2
      spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java
  6. 9
      spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java
  7. 9
      spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java
  8. 2
      spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java
  9. 2
      spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java
  10. 6
      spring-context/src/test/java/example/scannable/AutowiredQualifierFooService.java
  11. 6
      spring-context/src/test/java/example/scannable/FooServiceImpl.java
  12. 6
      spring-context/src/test/java/example/scannable/ScopedProxyTestBean.java
  13. 2
      spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java
  14. 8
      spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncResultTests.java
  15. 18
      spring-core/src/main/java/org/springframework/core/task/AsyncListenableTaskExecutor.java
  16. 2
      spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java
  17. 4
      spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java
  18. 5
      spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java
  19. 4
      spring-core/src/main/java/org/springframework/util/concurrent/FailureCallback.java
  20. 8
      spring-core/src/main/java/org/springframework/util/concurrent/ListenableFuture.java
  21. 5
      spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureAdapter.java
  22. 5
      spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallback.java
  23. 5
      spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java
  24. 5
      spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureTask.java
  25. 1
      spring-core/src/main/java/org/springframework/util/concurrent/MonoToListenableFutureAdapter.java
  26. 5
      spring-core/src/main/java/org/springframework/util/concurrent/SettableListenableFuture.java
  27. 4
      spring-core/src/main/java/org/springframework/util/concurrent/SuccessCallback.java
  28. 2
      spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java
  29. 2
      spring-core/src/test/java/org/springframework/util/concurrent/MonoToListenableFutureAdapterTests.java
  30. 4
      spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java
  31. 6
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java
  32. 16
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ListenableFutureReturnValueHandler.java
  33. 2
      spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java
  34. 5
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ConnectionHandlingStompSession.java
  35. 10
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java
  36. 5
      spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpConnection.java
  37. 16
      spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java
  38. 2
      spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java
  39. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java
  40. 8
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java
  41. 3
      spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java
  42. 10
      spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java
  43. 12
      spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java
  44. 6
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java
  45. 6
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractXhrTransport.java
  46. 7
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java
  47. 6
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/Transport.java
  48. 6
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java
  49. 6
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java
  50. 29
      spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java
  51. 31
      spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java
  52. 32
      spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java
  53. 39
      spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java

4
spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java

@ -1,5 +1,5 @@ @@ -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.
@ -281,8 +281,8 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { @@ -281,8 +281,8 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
* @param returnType the declared return type (potentially a {@link Future} variant)
* @return the execution result (potentially a corresponding {@link Future} handle)
*/
@SuppressWarnings("removal")
@Nullable
@SuppressWarnings("deprecation")
protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) {
if (CompletableFuture.class.isAssignableFrom(returnType)) {
return executor.submitCompletable(task);

4
spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleThreadPoolTaskExecutor.java

@ -1,5 +1,5 @@ @@ -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.
@ -47,7 +47,7 @@ import org.springframework.util.concurrent.ListenableFutureTask; @@ -47,7 +47,7 @@ import org.springframework.util.concurrent.ListenableFutureTask;
* @see org.springframework.core.task.TaskExecutor
* @see SchedulerFactoryBean#setTaskExecutor
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, InitializingBean, DisposableBean {

2
spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java

@ -310,7 +310,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe @@ -310,7 +310,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
return new Object[] {event};
}
@SuppressWarnings({"deprecation", "unchecked"})
@SuppressWarnings({"removal", "unchecked"})
protected void handleResult(Object result) {
if (reactiveStreamsPresent && new ReactiveResultHandler().subscribeToPublisher(result)) {
if (logger.isTraceEnabled()) {

15
spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java

@ -1,5 +1,5 @@ @@ -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.
@ -31,12 +31,10 @@ import org.springframework.util.concurrent.SuccessCallback; @@ -31,12 +31,10 @@ import org.springframework.util.concurrent.SuccessCallback;
* A pass-through {@code Future} handle that can be used for method signatures
* which are declared with a {@code Future} return type for asynchronous execution.
*
* <p>As of Spring 4.1, this class implements {@link ListenableFuture}, not just
* <p>As of Spring 4.1, this class implements {@code ListenableFuture}, not just
* plain {@link java.util.concurrent.Future}, along with the corresponding support
* in {@code @Async} processing.
*
* <p>As of Spring 4.2, this class also supports passing execution exceptions back
* to the caller.
* in {@code @Async} processing. As of 7.0, this will be turned back to a plain
* {@code Future} in order to focus on compatibility with existing common usage.
*
* @author Juergen Hoeller
* @author Rossen Stoyanchev
@ -48,6 +46,7 @@ import org.springframework.util.concurrent.SuccessCallback; @@ -48,6 +46,7 @@ import org.springframework.util.concurrent.SuccessCallback;
* @deprecated as of 6.0, in favor of {@link CompletableFuture}
*/
@Deprecated(since = "6.0")
@SuppressWarnings("removal")
public class AsyncResult<V> implements ListenableFuture<V> {
@Nullable
@ -145,7 +144,7 @@ public class AsyncResult<V> implements ListenableFuture<V> { @@ -145,7 +144,7 @@ public class AsyncResult<V> implements ListenableFuture<V> {
* @since 4.2
* @see Future#get()
*/
public static <V> ListenableFuture<V> forValue(V value) {
public static <V> org.springframework.util.concurrent.ListenableFuture<V> forValue(V value) {
return new AsyncResult<>(value, null);
}
@ -157,7 +156,7 @@ public class AsyncResult<V> implements ListenableFuture<V> { @@ -157,7 +156,7 @@ public class AsyncResult<V> implements ListenableFuture<V> {
* @since 4.2
* @see ExecutionException
*/
public static <V> ListenableFuture<V> forExecutionException(Throwable ex) {
public static <V> org.springframework.util.concurrent.ListenableFuture<V> forExecutionException(Throwable ex) {
return new AsyncResult<>(null, ex);
}

2
spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java

@ -62,7 +62,7 @@ import org.springframework.util.concurrent.ListenableFuture; @@ -62,7 +62,7 @@ import org.springframework.util.concurrent.ListenableFuture;
* @see DefaultManagedTaskExecutor
* @see ThreadPoolTaskExecutor
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public class ConcurrentTaskExecutor implements AsyncListenableTaskExecutor, SchedulingTaskExecutor {
private static final Executor STUB_EXECUTOR = (task -> {

9
spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java

@ -41,7 +41,6 @@ import org.springframework.scheduling.support.TaskUtils; @@ -41,7 +41,6 @@ import org.springframework.scheduling.support.TaskUtils;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ErrorHandler;
import org.springframework.util.concurrent.ListenableFuture;
/**
* Adapter that takes a {@code java.util.concurrent.ScheduledExecutorService} and
@ -219,15 +218,15 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T @@ -219,15 +218,15 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T
return super.submit(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
}
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
public org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task) {
return super.submitListenable(TaskUtils.decorateTaskWithErrorHandler(task, this.errorHandler, false));
}
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
public <T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task) {
return super.submitListenable(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
}

9
spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java

@ -44,7 +44,6 @@ import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable; @@ -44,7 +44,6 @@ import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable;
import org.springframework.scheduling.support.TaskUtils;
import org.springframework.util.Assert;
import org.springframework.util.ErrorHandler;
import org.springframework.util.concurrent.ListenableFuture;
/**
* A simple implementation of Spring's {@link TaskScheduler} interface, using
@ -270,15 +269,15 @@ public class SimpleAsyncTaskScheduler extends SimpleAsyncTaskExecutor implements @@ -270,15 +269,15 @@ public class SimpleAsyncTaskScheduler extends SimpleAsyncTaskExecutor implements
return super.submit(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
}
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
public org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task) {
return super.submitListenable(TaskUtils.decorateTaskWithErrorHandler(task, this.errorHandler, false));
}
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
public <T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task) {
return super.submitListenable(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
}

2
spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java

@ -80,7 +80,7 @@ import org.springframework.util.concurrent.ListenableFutureTask; @@ -80,7 +80,7 @@ import org.springframework.util.concurrent.ListenableFutureTask;
* @see ThreadPoolExecutorFactoryBean
* @see ConcurrentTaskExecutor
*/
@SuppressWarnings({"serial", "deprecation"})
@SuppressWarnings({"serial", "removal"})
public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor {

2
spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java

@ -74,7 +74,7 @@ import org.springframework.util.concurrent.ListenableFutureTask; @@ -74,7 +74,7 @@ import org.springframework.util.concurrent.ListenableFutureTask;
* @see ThreadPoolTaskExecutor
* @see SimpleAsyncTaskScheduler
*/
@SuppressWarnings({"serial", "deprecation"})
@SuppressWarnings({"serial", "removal"})
public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, TaskScheduler {

6
spring-context/src/test/java/example/scannable/AutowiredQualifierFooService.java

@ -1,5 +1,5 @@ @@ -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.
@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package example.scannable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import jakarta.annotation.PostConstruct;
@ -51,9 +52,8 @@ public class AutowiredQualifierFooService implements FooService { @@ -51,9 +52,8 @@ public class AutowiredQualifierFooService implements FooService {
}
@Override
@SuppressWarnings("deprecation")
public Future<String> asyncFoo(int id) {
return new org.springframework.scheduling.annotation.AsyncResult<>(this.fooDao.findFoo(id));
return CompletableFuture.completedFuture(this.fooDao.findFoo(id));
}
@Override

6
spring-context/src/test/java/example/scannable/FooServiceImpl.java

@ -1,5 +1,5 @@ @@ -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.
@ -18,6 +18,7 @@ package example.scannable; @@ -18,6 +18,7 @@ package example.scannable;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import jakarta.annotation.PostConstruct;
@ -91,10 +92,9 @@ public abstract class FooServiceImpl implements FooService { @@ -91,10 +92,9 @@ public abstract class FooServiceImpl implements FooService {
}
@Override
@SuppressWarnings("deprecation")
public Future<String> asyncFoo(int id) {
Assert.state(ServiceInvocationCounter.getThreadLocalCount() != null, "Thread-local counter not exposed");
return new org.springframework.scheduling.annotation.AsyncResult<>(fooDao().findFoo(id));
return CompletableFuture.completedFuture(fooDao().findFoo(id));
}
@Override

6
spring-context/src/test/java/example/scannable/ScopedProxyTestBean.java

@ -1,5 +1,5 @@ @@ -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.
@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package example.scannable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import org.springframework.context.annotation.Scope;
@ -33,9 +34,8 @@ public class ScopedProxyTestBean implements FooService { @@ -33,9 +34,8 @@ public class ScopedProxyTestBean implements FooService {
}
@Override
@SuppressWarnings("deprecation")
public Future<String> asyncFoo(int id) {
return new org.springframework.scheduling.annotation.AsyncResult<>("bar");
return CompletableFuture.completedFuture("bar");
}
@Override

2
spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java

@ -280,7 +280,7 @@ class AnnotationDrivenEventListenerTests { @@ -280,7 +280,7 @@ class AnnotationDrivenEventListenerTests {
}
@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
void listenableFutureReply() {
load(TestEventListener.class, ReplyEventListener.class);
org.springframework.util.concurrent.SettableListenableFuture<String> future =

8
spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncResultTests.java

@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
class AsyncResultTests {
@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void asyncResultWithCallbackAndValue() throws Exception {
String value = "val";
final Set<String> values = new HashSet<>(1);
@ -54,7 +54,7 @@ class AsyncResultTests { @@ -54,7 +54,7 @@ class AsyncResultTests {
}
@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void asyncResultWithCallbackAndException() {
IOException ex = new IOException();
final Set<Throwable> values = new HashSet<>(1);
@ -79,7 +79,7 @@ class AsyncResultTests { @@ -79,7 +79,7 @@ class AsyncResultTests {
}
@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void asyncResultWithSeparateCallbacksAndValue() throws Exception {
String value = "val";
final Set<String> values = new HashSet<>(1);
@ -92,7 +92,7 @@ class AsyncResultTests { @@ -92,7 +92,7 @@ class AsyncResultTests {
}
@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void asyncResultWithSeparateCallbacksAndException() {
IOException ex = new IOException();
final Set<Throwable> values = new HashSet<>(1);

18
spring-core/src/main/java/org/springframework/core/task/AsyncListenableTaskExecutor.java

@ -1,5 +1,5 @@ @@ -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.
@ -18,20 +18,18 @@ package org.springframework.core.task; @@ -18,20 +18,18 @@ package org.springframework.core.task;
import java.util.concurrent.Callable;
import org.springframework.util.concurrent.ListenableFuture;
/**
* Extension of the {@link AsyncTaskExecutor} interface, adding the capability to submit
* tasks for {@link ListenableFuture ListenableFutures}.
* tasks for {@code ListenableFutures}.
*
* @author Arjen Poutsma
* @since 4.0
* @see ListenableFuture
* @deprecated as of 6.0, in favor of
* {@link AsyncTaskExecutor#submitCompletable(Runnable)} and
* {@link AsyncTaskExecutor#submitCompletable(Callable)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor {
/**
@ -42,8 +40,8 @@ public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor { @@ -42,8 +40,8 @@ public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor {
* @throws TaskRejectedException if the given task was not accepted
* @deprecated in favor of {@link AsyncTaskExecutor#submitCompletable(Runnable)}
*/
@Deprecated
ListenableFuture<?> submitListenable(Runnable task);
@Deprecated(since = "6.0", forRemoval = true)
org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task);
/**
* Submit a {@code Callable} task for execution, receiving a {@code ListenableFuture}
@ -54,7 +52,7 @@ public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor { @@ -54,7 +52,7 @@ public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor {
* @throws TaskRejectedException if the given task was not accepted
* @deprecated in favor of {@link AsyncTaskExecutor#submitCompletable(Callable)}
*/
@Deprecated
<T> ListenableFuture<T> submitListenable(Callable<T> task);
@Deprecated(since = "6.0", forRemoval = true)
<T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task);
}

2
spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java

@ -58,7 +58,7 @@ import org.springframework.util.concurrent.ListenableFutureTask; @@ -58,7 +58,7 @@ import org.springframework.util.concurrent.ListenableFutureTask;
* @see org.springframework.scheduling.concurrent.SimpleAsyncTaskScheduler
* @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
*/
@SuppressWarnings({"serial", "deprecation"})
@SuppressWarnings({"serial", "removal"})
public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
implements AsyncListenableTaskExecutor, Serializable, AutoCloseable {

4
spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java

@ -1,5 +1,5 @@ @@ -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.
@ -43,7 +43,7 @@ import org.springframework.util.concurrent.ListenableFutureTask; @@ -43,7 +43,7 @@ import org.springframework.util.concurrent.ListenableFutureTask;
* @see java.util.concurrent.ExecutorService
* @see java.util.concurrent.Executors
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public class TaskExecutorAdapter implements AsyncListenableTaskExecutor {
private final Executor concurrentExecutor;

5
spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java

@ -1,5 +1,5 @@ @@ -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.
@ -32,7 +32,8 @@ import java.util.concurrent.TimeoutException; @@ -32,7 +32,8 @@ import java.util.concurrent.TimeoutException;
* @param <T> the result type returned by this Future's {@code get} method
* @deprecated as of 6.0, with no concrete replacement
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public class CompletableToListenableFutureAdapter<T> implements ListenableFuture<T> {
private final CompletableFuture<T> completableFuture;

4
spring-core/src/main/java/org/springframework/util/concurrent/FailureCallback.java

@ -1,5 +1,5 @@ @@ -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.
@ -26,7 +26,7 @@ import java.util.function.BiConsumer; @@ -26,7 +26,7 @@ import java.util.function.BiConsumer;
* @deprecated as of 6.0, in favor of
* {@link java.util.concurrent.CompletableFuture#whenComplete(BiConsumer)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@FunctionalInterface
public interface FailureCallback {

8
spring-core/src/main/java/org/springframework/util/concurrent/ListenableFuture.java

@ -34,7 +34,7 @@ import java.util.function.BiConsumer; @@ -34,7 +34,7 @@ import java.util.function.BiConsumer;
* @param <T> the result type returned by this Future's {@code get} method
* @deprecated as of 6.0, in favor of {@link CompletableFuture}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
public interface ListenableFuture<T> extends Future<T> {
/**
@ -43,7 +43,8 @@ public interface ListenableFuture<T> extends Future<T> { @@ -43,7 +43,8 @@ public interface ListenableFuture<T> extends Future<T> {
* @deprecated as of 6.0, in favor of
* {@link CompletableFuture#whenComplete(BiConsumer)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
void addCallback(ListenableFutureCallback<? super T> callback);
/**
@ -54,7 +55,8 @@ public interface ListenableFuture<T> extends Future<T> { @@ -54,7 +55,8 @@ public interface ListenableFuture<T> extends Future<T> {
* @deprecated as of 6.0, in favor of
* {@link CompletableFuture#whenComplete(BiConsumer)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback);

5
spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureAdapter.java

@ -1,5 +1,5 @@ @@ -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.
@ -34,7 +34,8 @@ import org.springframework.lang.Nullable; @@ -34,7 +34,8 @@ import org.springframework.lang.Nullable;
* @deprecated as of 6.0, in favor of
* {@link java.util.concurrent.CompletableFuture}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S> implements ListenableFuture<T> {
/**

5
spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallback.java

@ -1,5 +1,5 @@ @@ -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.
@ -29,7 +29,8 @@ import java.util.function.BiConsumer; @@ -29,7 +29,8 @@ import java.util.function.BiConsumer;
* @deprecated as of 6.0, in favor of
* {@link java.util.concurrent.CompletableFuture#whenComplete(BiConsumer)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public interface ListenableFutureCallback<T> extends SuccessCallback<T>, FailureCallback {
}

5
spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java

@ -1,5 +1,5 @@ @@ -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.
@ -35,7 +35,8 @@ import org.springframework.util.Assert; @@ -35,7 +35,8 @@ import org.springframework.util.Assert;
* @param <T> the callback result type
* @deprecated as of 6.0, with no concrete replacement
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public class ListenableFutureCallbackRegistry<T> {
private final Queue<SuccessCallback<? super T>> successCallbacks = new ArrayDeque<>(1);

5
spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureTask.java

@ -1,5 +1,5 @@ @@ -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.
@ -31,7 +31,8 @@ import org.springframework.lang.Nullable; @@ -31,7 +31,8 @@ import org.springframework.lang.Nullable;
* @param <T> the result type returned by this Future's {@code get} method
* @deprecated as of 6.0, with no concrete replacement
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public class ListenableFutureTask<T> extends FutureTask<T> implements ListenableFuture<T> {
private final ListenableFutureCallbackRegistry<T> callbacks = new ListenableFutureCallbackRegistry<>();

1
spring-core/src/main/java/org/springframework/util/concurrent/MonoToListenableFutureAdapter.java

@ -30,6 +30,7 @@ import reactor.core.publisher.Mono; @@ -30,6 +30,7 @@ import reactor.core.publisher.Mono;
* @deprecated as of 6.0, in favor of {@link Mono#toFuture()}
*/
@Deprecated(since = "6.0")
@SuppressWarnings("removal")
public class MonoToListenableFutureAdapter<T> extends CompletableToListenableFutureAdapter<T> {
public MonoToListenableFutureAdapter(Mono<T> mono) {

5
spring-core/src/main/java/org/springframework/util/concurrent/SettableListenableFuture.java

@ -1,5 +1,5 @@ @@ -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.
@ -38,7 +38,8 @@ import org.springframework.util.Assert; @@ -38,7 +38,8 @@ import org.springframework.util.Assert;
* @param <T> the result type returned by this Future's {@code get} method
* @deprecated as of 6.0, in favor of {@link CompletableFuture}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public class SettableListenableFuture<T> implements ListenableFuture<T> {
private static final Callable<Object> DUMMY_CALLABLE = () -> {

4
spring-core/src/main/java/org/springframework/util/concurrent/SuccessCallback.java

@ -1,5 +1,5 @@ @@ -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.
@ -29,7 +29,7 @@ import org.springframework.lang.Nullable; @@ -29,7 +29,7 @@ import org.springframework.lang.Nullable;
* @deprecated as of 6.0, in favor of
* {@link java.util.concurrent.CompletableFuture#whenComplete(BiConsumer)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@FunctionalInterface
public interface SuccessCallback<T> {

2
spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java

@ -33,7 +33,7 @@ import static org.mockito.Mockito.verifyNoInteractions; @@ -33,7 +33,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
* @author Arjen Poutsma
* @author Sebastien Deleuze
*/
@SuppressWarnings({ "deprecation" })
@SuppressWarnings("removal")
class ListenableFutureTaskTests {
@Test

2
spring-core/src/test/java/org/springframework/util/concurrent/MonoToListenableFutureAdapterTests.java

@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; @@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
class MonoToListenableFutureAdapterTests {
@Test

4
spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java

@ -1,5 +1,5 @@ @@ -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.
@ -36,7 +36,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -36,7 +36,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
* @author Mattias Severson
* @author Juergen Hoeller
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
class SettableListenableFutureTests {
private final SettableListenableFuture<String> settableListenableFuture = new SettableListenableFuture<>();

6
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java

@ -1,5 +1,5 @@ @@ -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.
@ -67,10 +67,12 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur @@ -67,10 +67,12 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur
* @deprecated as of 6.0, in favor of
* {@link #toCompletableFuture(Object, MethodParameter)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
@Nullable
default org.springframework.util.concurrent.ListenableFuture<?> toListenableFuture(
Object returnValue, MethodParameter returnType) {
CompletableFuture<?> result = toCompletableFuture(returnValue, returnType);
return (result != null ?
new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(result) :

16
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ListenableFutureReturnValueHandler.java

@ -1,5 +1,5 @@ @@ -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.
@ -19,7 +19,6 @@ package org.springframework.messaging.handler.invocation; @@ -19,7 +19,6 @@ package org.springframework.messaging.handler.invocation;
import java.util.concurrent.CompletableFuture;
import org.springframework.core.MethodParameter;
import org.springframework.util.concurrent.ListenableFuture;
/**
* Support for {@link ListenableFuture} as a return value type.
@ -28,22 +27,23 @@ import org.springframework.util.concurrent.ListenableFuture; @@ -28,22 +27,23 @@ import org.springframework.util.concurrent.ListenableFuture;
* @since 4.2
* @deprecated as of 6.0, in favor of {@link CompletableFutureReturnValueHandler}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public class ListenableFutureReturnValueHandler extends AbstractAsyncReturnValueHandler {
@Override
public boolean supportsReturnType(MethodParameter returnType) {
return ListenableFuture.class.isAssignableFrom(returnType.getParameterType());
return org.springframework.util.concurrent.ListenableFuture.class.isAssignableFrom(returnType.getParameterType());
}
@Override
@SuppressWarnings("unchecked")
public ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType) {
return (ListenableFuture<?>) returnValue;
public org.springframework.util.concurrent.ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType) {
return (org.springframework.util.concurrent.ListenableFuture<?>) returnValue;
}
@Override
public CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
return ((ListenableFuture<?>) returnValue).completable();
return ((org.springframework.util.concurrent.ListenableFuture<?>) returnValue).completable();
}
}

2
spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java

@ -344,7 +344,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan @@ -344,7 +344,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
}
@Override
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers() {
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>();

5
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ConnectionHandlingStompSession.java

@ -1,5 +1,5 @@ @@ -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.
@ -35,7 +35,8 @@ public interface ConnectionHandlingStompSession extends StompSession, StompTcpCo @@ -35,7 +35,8 @@ public interface ConnectionHandlingStompSession extends StompSession, StompTcpCo
* Return a future that will complete when the session is ready for use.
* @deprecated as of 6.0, in favor of {@link #getSession()}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
default org.springframework.util.concurrent.ListenableFuture<StompSession> getSessionFuture() {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
getSession());

10
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java

@ -1,5 +1,5 @@ @@ -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.
@ -96,9 +96,11 @@ public class ReactorNettyTcpStompClient extends StompClientSupport { @@ -96,9 +96,11 @@ public class ReactorNettyTcpStompClient extends StompClientSupport {
* @return a ListenableFuture for access to the session when ready for use
* @deprecated as of 6.0, in favor of {@link #connectAsync(StompSessionHandler)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
StompSessionHandler handler) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(handler));
}
@ -122,9 +124,11 @@ public class ReactorNettyTcpStompClient extends StompClientSupport { @@ -122,9 +124,11 @@ public class ReactorNettyTcpStompClient extends StompClientSupport {
* @return a ListenableFuture for access to the session when ready for use
* @deprecated as of 6.0, in favor of {@link #connectAsync(StompHeaders, StompSessionHandler)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
@Nullable StompHeaders connectHeaders, StompSessionHandler handler) {
ConnectionHandlingStompSession session = createSession(connectHeaders, handler);
this.tcpClient.connectAsync(session);
return session.getSessionFuture();

5
spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpConnection.java

@ -1,5 +1,5 @@ @@ -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.
@ -37,7 +37,8 @@ public interface TcpConnection<P> extends Closeable { @@ -37,7 +37,8 @@ public interface TcpConnection<P> extends Closeable {
* message was successfully sent
* @deprecated as of 6.0, in favor of {@link #sendAsync(Message)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
default org.springframework.util.concurrent.ListenableFuture<Void> send(Message<P> message) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
sendAsync(message));

16
spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java

@ -1,5 +1,5 @@ @@ -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.
@ -34,9 +34,11 @@ public interface TcpOperations<P> { @@ -34,9 +34,11 @@ public interface TcpOperations<P> {
* connection is successfully established
* @deprecated as of 6.0, in favor of {@link #connectAsync(TcpConnectionHandler)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
default org.springframework.util.concurrent.ListenableFuture<Void> connect(
TcpConnectionHandler<P> connectionHandler) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(connectionHandler));
}
@ -58,9 +60,11 @@ public interface TcpOperations<P> { @@ -58,9 +60,11 @@ public interface TcpOperations<P> {
* initial connection is successfully established
* @deprecated as of 6.0, in favor of {@link #connectAsync(TcpConnectionHandler, ReconnectStrategy)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
default org.springframework.util.concurrent.ListenableFuture<Void> connect(
TcpConnectionHandler<P> connectionHandler, ReconnectStrategy reconnectStrategy) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(connectionHandler, reconnectStrategy));
}
@ -81,10 +85,10 @@ public interface TcpOperations<P> { @@ -81,10 +85,10 @@ public interface TcpOperations<P> {
* connection is successfully closed
* @deprecated as of 6.0, in favor of {@link #shutdownAsync()}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
default org.springframework.util.concurrent.ListenableFuture<Void> shutdown() {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
shutdownAsync());
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(shutdownAsync());
}
/**

2
spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java

@ -571,7 +571,7 @@ public class SimpAnnotationMethodMessageHandlerTests { @@ -571,7 +571,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
@Controller
@MessageMapping("listenable-future")
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
private static class ListenableFutureController {
org.springframework.util.concurrent.ListenableFutureTask<String> future;

8
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java

@ -1,5 +1,5 @@ @@ -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.
@ -37,7 +37,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; @@ -37,7 +37,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
*/
public class DeferredResultMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public boolean supportsReturnType(MethodParameter returnType) {
Class<?> type = returnType.getParameterType();
@ -46,7 +46,7 @@ public class DeferredResultMethodReturnValueHandler implements HandlerMethodRetu @@ -46,7 +46,7 @@ public class DeferredResultMethodReturnValueHandler implements HandlerMethodRetu
CompletionStage.class.isAssignableFrom(type));
}
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
@ -75,7 +75,7 @@ public class DeferredResultMethodReturnValueHandler implements HandlerMethodRetu @@ -75,7 +75,7 @@ public class DeferredResultMethodReturnValueHandler implements HandlerMethodRetu
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(result, mavContainer);
}
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
private DeferredResult<Object> adaptListenableFuture(org.springframework.util.concurrent.ListenableFuture<?> future) {
DeferredResult<Object> result = new DeferredResult<>();
future.addCallback(new org.springframework.util.concurrent.ListenableFutureCallback<Object>() {

8
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java

@ -63,7 +63,7 @@ class DeferredResultReturnValueHandlerTests { @@ -63,7 +63,7 @@ class DeferredResultReturnValueHandlerTests {
@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void supportsReturnType() throws Exception {
assertThat(this.handler.supportsReturnType(
on(TestController.class).resolveReturnType(DeferredResult.class, String.class))).isTrue();
@ -88,7 +88,7 @@ class DeferredResultReturnValueHandlerTests { @@ -88,7 +88,7 @@ class DeferredResultReturnValueHandlerTests {
}
@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void listenableFuture() throws Exception {
org.springframework.util.concurrent.SettableListenableFuture<String> future =
new org.springframework.util.concurrent.SettableListenableFuture<>();
@ -109,7 +109,7 @@ class DeferredResultReturnValueHandlerTests { @@ -109,7 +109,7 @@ class DeferredResultReturnValueHandlerTests {
}
@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void listenableFutureWithError() throws Exception {
org.springframework.util.concurrent.SettableListenableFuture<String> future =
new org.springframework.util.concurrent.SettableListenableFuture<>();
@ -150,7 +150,7 @@ class DeferredResultReturnValueHandlerTests { @@ -150,7 +150,7 @@ class DeferredResultReturnValueHandlerTests {
DeferredResult<String> handleDeferredResult() { return null; }
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
org.springframework.util.concurrent.ListenableFuture<String> handleListenableFuture() { return null; }
CompletableFuture<String> handleCompletableFuture() { return null; }

3
spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java

@ -118,7 +118,8 @@ public abstract class AbstractWebSocketClient implements WebSocketClient { @@ -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) {

10
spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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));
}

12
spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java

@ -237,7 +237,8 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif @@ -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 @@ -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 @@ -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 @@ -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) {

6
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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());

6
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractXhrTransport.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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");
}

7
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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 {

6
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/Transport.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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));
}

6
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java

@ -1,5 +1,5 @@ @@ -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 @@ -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) {

6
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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) {

29
spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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();
}

31
spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java

@ -209,24 +209,16 @@ abstract class AbstractSockJsIntegrationTests { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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();

32
spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java

@ -22,6 +22,7 @@ import java.io.InputStream; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -218,7 +205,6 @@ class RestTemplateXhrTransportTests {
private Queue<ClientHttpResponse> responses = new LinkedBlockingDeque<>();
private TestRestTemplate(ClientHttpResponse... responses) {
this.responses.addAll(Arrays.asList(responses));
}

39
spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java

@ -18,6 +18,7 @@ package org.springframework.web.socket.sockjs.client; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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();
}

Loading…
Cancel
Save