diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java index 07c37c3cd74..ea503479962 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java @@ -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 { * @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 task, AsyncTaskExecutor executor, Class returnType) { if (CompletableFuture.class.isAssignableFrom(returnType)) { return executor.submitCompletable(task); diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleThreadPoolTaskExecutor.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleThreadPoolTaskExecutor.java index 811d76c9ef3..f6ad049f58d 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleThreadPoolTaskExecutor.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleThreadPoolTaskExecutor.java @@ -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; * @see org.springframework.core.task.TaskExecutor * @see SchedulerFactoryBean#setTaskExecutor */ -@SuppressWarnings("deprecation") +@SuppressWarnings("removal") public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, InitializingBean, DisposableBean { diff --git a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java index a72d1a01fe2..8da15087bf7 100644 --- a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java +++ b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java @@ -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()) { diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java index 784a3e3f1ca..3a7b5f0812c 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java @@ -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; * 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. * - *

As of Spring 4.1, this class implements {@link ListenableFuture}, not just + *

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. - * - *

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; * @deprecated as of 6.0, in favor of {@link CompletableFuture} */ @Deprecated(since = "6.0") +@SuppressWarnings("removal") public class AsyncResult implements ListenableFuture { @Nullable @@ -145,7 +144,7 @@ public class AsyncResult implements ListenableFuture { * @since 4.2 * @see Future#get() */ - public static ListenableFuture forValue(V value) { + public static org.springframework.util.concurrent.ListenableFuture forValue(V value) { return new AsyncResult<>(value, null); } @@ -157,7 +156,7 @@ public class AsyncResult implements ListenableFuture { * @since 4.2 * @see ExecutionException */ - public static ListenableFuture forExecutionException(Throwable ex) { + public static org.springframework.util.concurrent.ListenableFuture forExecutionException(Throwable ex) { return new AsyncResult<>(null, ex); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java index b4eae437c2b..12da3290727 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java @@ -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 -> { diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java index 7461ab6bdb4..98c7e81a996 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java @@ -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 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 ListenableFuture submitListenable(Callable task) { + public org.springframework.util.concurrent.ListenableFuture submitListenable(Callable task) { return super.submitListenable(new DelegatingErrorHandlingCallable<>(task, this.errorHandler)); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java index 2646ea866db..7aed3aaa02e 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java @@ -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 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 ListenableFuture submitListenable(Callable task) { + public org.springframework.util.concurrent.ListenableFuture submitListenable(Callable task) { return super.submitListenable(new DelegatingErrorHandlingCallable<>(task, this.errorHandler)); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java index 0890d8e7651..3fb627a6ef0 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java @@ -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 { diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java index 3cc17d0ef5f..bd143226061 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java @@ -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 { diff --git a/spring-context/src/test/java/example/scannable/AutowiredQualifierFooService.java b/spring-context/src/test/java/example/scannable/AutowiredQualifierFooService.java index 69f09081dc1..559ac9edf29 100644 --- a/spring-context/src/test/java/example/scannable/AutowiredQualifierFooService.java +++ b/spring-context/src/test/java/example/scannable/AutowiredQualifierFooService.java @@ -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 @@ 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 { } @Override - @SuppressWarnings("deprecation") public Future asyncFoo(int id) { - return new org.springframework.scheduling.annotation.AsyncResult<>(this.fooDao.findFoo(id)); + return CompletableFuture.completedFuture(this.fooDao.findFoo(id)); } @Override diff --git a/spring-context/src/test/java/example/scannable/FooServiceImpl.java b/spring-context/src/test/java/example/scannable/FooServiceImpl.java index 11cd8390e68..8ce1c9315aa 100644 --- a/spring-context/src/test/java/example/scannable/FooServiceImpl.java +++ b/spring-context/src/test/java/example/scannable/FooServiceImpl.java @@ -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; 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 { } @Override - @SuppressWarnings("deprecation") public Future 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 diff --git a/spring-context/src/test/java/example/scannable/ScopedProxyTestBean.java b/spring-context/src/test/java/example/scannable/ScopedProxyTestBean.java index 84829191179..8c15a915b08 100644 --- a/spring-context/src/test/java/example/scannable/ScopedProxyTestBean.java +++ b/spring-context/src/test/java/example/scannable/ScopedProxyTestBean.java @@ -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 @@ 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 { } @Override - @SuppressWarnings("deprecation") public Future asyncFoo(int id) { - return new org.springframework.scheduling.annotation.AsyncResult<>("bar"); + return CompletableFuture.completedFuture("bar"); } @Override diff --git a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java index a52c27d1126..25879472874 100644 --- a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java @@ -280,7 +280,7 @@ class AnnotationDrivenEventListenerTests { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") void listenableFutureReply() { load(TestEventListener.class, ReplyEventListener.class); org.springframework.util.concurrent.SettableListenableFuture future = diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncResultTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncResultTests.java index f8b9849a278..56c2ed42d91 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncResultTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncResultTests.java @@ -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 values = new HashSet<>(1); @@ -54,7 +54,7 @@ class AsyncResultTests { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") public void asyncResultWithCallbackAndException() { IOException ex = new IOException(); final Set values = new HashSet<>(1); @@ -79,7 +79,7 @@ class AsyncResultTests { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") public void asyncResultWithSeparateCallbacksAndValue() throws Exception { String value = "val"; final Set values = new HashSet<>(1); @@ -92,7 +92,7 @@ class AsyncResultTests { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") public void asyncResultWithSeparateCallbacksAndException() { IOException ex = new IOException(); final Set values = new HashSet<>(1); diff --git a/spring-core/src/main/java/org/springframework/core/task/AsyncListenableTaskExecutor.java b/spring-core/src/main/java/org/springframework/core/task/AsyncListenableTaskExecutor.java index 854da24c4d4..a89a7efd126 100644 --- a/spring-core/src/main/java/org/springframework/core/task/AsyncListenableTaskExecutor.java +++ b/spring-core/src/main/java/org/springframework/core/task/AsyncListenableTaskExecutor.java @@ -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; 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 { * @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 { * @throws TaskRejectedException if the given task was not accepted * @deprecated in favor of {@link AsyncTaskExecutor#submitCompletable(Callable)} */ - @Deprecated - ListenableFuture submitListenable(Callable task); + @Deprecated(since = "6.0", forRemoval = true) + org.springframework.util.concurrent.ListenableFuture submitListenable(Callable task); } diff --git a/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java b/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java index e4ed38acc0b..701f94a2caf 100644 --- a/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java +++ b/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java @@ -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 { diff --git a/spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java b/spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java index c7085ffa75f..02916ab6037 100644 --- a/spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java +++ b/spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java @@ -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; * @see java.util.concurrent.ExecutorService * @see java.util.concurrent.Executors */ -@SuppressWarnings("deprecation") +@SuppressWarnings("removal") public class TaskExecutorAdapter implements AsyncListenableTaskExecutor { private final Executor concurrentExecutor; diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java b/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java index 79ef15391e2..0c50053c327 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java @@ -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; * @param 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 implements ListenableFuture { private final CompletableFuture completableFuture; diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/FailureCallback.java b/spring-core/src/main/java/org/springframework/util/concurrent/FailureCallback.java index 5dbc062ca23..e24adfdd6f7 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/FailureCallback.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/FailureCallback.java @@ -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; * @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 { diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFuture.java b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFuture.java index cd6125c9d50..fc8c0e5f207 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFuture.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFuture.java @@ -34,7 +34,7 @@ import java.util.function.BiConsumer; * @param 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 extends Future { /** @@ -43,7 +43,8 @@ public interface ListenableFuture extends Future { * @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 callback); /** @@ -54,7 +55,8 @@ public interface ListenableFuture extends Future { * @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 successCallback, FailureCallback failureCallback); diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureAdapter.java b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureAdapter.java index 7c12263be35..0ddc5bc4290 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureAdapter.java @@ -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; * @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 extends FutureAdapter implements ListenableFuture { /** diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallback.java b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallback.java index ad875f361d9..dfd0f4e2448 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallback.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallback.java @@ -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; * @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 extends SuccessCallback, FailureCallback { } diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java index 9c5093a2964..178d549c162 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java @@ -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; * @param 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 { private final Queue> successCallbacks = new ArrayDeque<>(1); diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureTask.java b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureTask.java index 71601200a70..271fc083263 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureTask.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureTask.java @@ -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; * @param 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 extends FutureTask implements ListenableFuture { private final ListenableFutureCallbackRegistry callbacks = new ListenableFutureCallbackRegistry<>(); diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/MonoToListenableFutureAdapter.java b/spring-core/src/main/java/org/springframework/util/concurrent/MonoToListenableFutureAdapter.java index df3f0df5052..f55162a0856 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/MonoToListenableFutureAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/MonoToListenableFutureAdapter.java @@ -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 extends CompletableToListenableFutureAdapter { public MonoToListenableFutureAdapter(Mono mono) { diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/SettableListenableFuture.java b/spring-core/src/main/java/org/springframework/util/concurrent/SettableListenableFuture.java index 7f33ff28394..e7cb0c75567 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/SettableListenableFuture.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/SettableListenableFuture.java @@ -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; * @param 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 implements ListenableFuture { private static final Callable DUMMY_CALLABLE = () -> { diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/SuccessCallback.java b/spring-core/src/main/java/org/springframework/util/concurrent/SuccessCallback.java index 2e6a6af322a..8ecba36eb61 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/SuccessCallback.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/SuccessCallback.java @@ -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; * @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 { diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java index 01e08bc6ac4..04c4f562331 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java +++ b/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java @@ -33,7 +33,7 @@ import static org.mockito.Mockito.verifyNoInteractions; * @author Arjen Poutsma * @author Sebastien Deleuze */ -@SuppressWarnings({ "deprecation" }) +@SuppressWarnings("removal") class ListenableFutureTaskTests { @Test diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/MonoToListenableFutureAdapterTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/MonoToListenableFutureAdapterTests.java index 278451b46ef..a0f019478fd 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/MonoToListenableFutureAdapterTests.java +++ b/spring-core/src/test/java/org/springframework/util/concurrent/MonoToListenableFutureAdapterTests.java @@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -@SuppressWarnings("deprecation") +@SuppressWarnings("removal") class MonoToListenableFutureAdapterTests { @Test diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java index 5fd9af58305..ca2d4ffb8de 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java +++ b/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java @@ -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; * @author Mattias Severson * @author Juergen Hoeller */ -@SuppressWarnings("deprecation") +@SuppressWarnings("removal") class SettableListenableFutureTests { private final SettableListenableFuture settableListenableFuture = new SettableListenableFuture<>(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java index 311969d82c6..f6342f6f847 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java @@ -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 * @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) : diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ListenableFutureReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ListenableFutureReturnValueHandler.java index f2b6c1cf956..b692d05917c 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ListenableFutureReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ListenableFutureReturnValueHandler.java @@ -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; 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; * @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(); } + } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java index 707b953e3f0..41ecfb1730e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java @@ -344,7 +344,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan } @Override - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") protected List initReturnValueHandlers() { List handlers = new ArrayList<>(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ConnectionHandlingStompSession.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ConnectionHandlingStompSession.java index 947b640c2f8..40faa0bcd59 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ConnectionHandlingStompSession.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ConnectionHandlingStompSession.java @@ -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 * 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 getSessionFuture() { return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>( getSession()); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java index 5ee2bb2d65b..d16ab82b328 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java @@ -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 { * @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 connect( StompSessionHandler handler) { + return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>( connectAsync(handler)); } @@ -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 connect( @Nullable StompHeaders connectHeaders, StompSessionHandler handler) { + ConnectionHandlingStompSession session = createSession(connectHeaders, handler); this.tcpClient.connectAsync(session); return session.getSessionFuture(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpConnection.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpConnection.java index d6eda9dbb97..545b1f3d121 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpConnection.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpConnection.java @@ -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

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 send(Message

message) { return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>( sendAsync(message)); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java index 4a4849d177c..6ee521358da 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java @@ -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

{ * 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 connect( TcpConnectionHandler

connectionHandler) { + return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>( connectAsync(connectionHandler)); } @@ -58,9 +60,11 @@ public interface TcpOperations

{ * 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 connect( TcpConnectionHandler

connectionHandler, ReconnectStrategy reconnectStrategy) { + return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>( connectAsync(connectionHandler, reconnectStrategy)); } @@ -81,10 +85,10 @@ public interface TcpOperations

{ * 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 shutdown() { - return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>( - shutdownAsync()); + return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(shutdownAsync()); } /** diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java index 01488981b68..15a7e39d005 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java @@ -571,7 +571,7 @@ public class SimpAnnotationMethodMessageHandlerTests { @Controller @MessageMapping("listenable-future") - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") private static class ListenableFutureController { org.springframework.util.concurrent.ListenableFutureTask future; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java index 2fa01bc58fe..3d77f00df1c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java @@ -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; */ 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 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 WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(result, mavContainer); } - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") private DeferredResult adaptListenableFuture(org.springframework.util.concurrent.ListenableFuture future) { DeferredResult result = new DeferredResult<>(); future.addCallback(new org.springframework.util.concurrent.ListenableFutureCallback() { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java index b986ac6da79..938d2820397 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java @@ -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 { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") public void listenableFuture() throws Exception { org.springframework.util.concurrent.SettableListenableFuture future = new org.springframework.util.concurrent.SettableListenableFuture<>(); @@ -109,7 +109,7 @@ class DeferredResultReturnValueHandlerTests { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") public void listenableFutureWithError() throws Exception { org.springframework.util.concurrent.SettableListenableFuture future = new org.springframework.util.concurrent.SettableListenableFuture<>(); @@ -150,7 +150,7 @@ class DeferredResultReturnValueHandlerTests { DeferredResult handleDeferredResult() { return null; } - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") org.springframework.util.concurrent.ListenableFuture handleListenableFuture() { return null; } CompletableFuture handleCompletableFuture() { return null; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java index 8a5a3905fab..6b47f22413c 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java @@ -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 doHandshakeInternal( WebSocketHandler webSocketHandler, HttpHeaders headers, URI uri, List subProtocols, List extensions, Map attributes) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java index 82810b2d7d3..3bfbf577906 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java @@ -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 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 doHandshake( WebSocketHandler webSocketHandler, @Nullable WebSocketHttpHeaders headers, URI uri) { + return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>( execute(webSocketHandler, headers, uri)); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java index 247a739ba51..08682ead23d 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java @@ -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 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 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 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 connect( URI url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java index 8f761605355..c0327f290c2 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java @@ -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 connectFuture) { this(request, handler, connectFuture.completable()); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractXhrTransport.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractXhrTransport.java index 0b5a8de7043..68677901fc8 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractXhrTransport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractXhrTransport.java @@ -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 connectFuture) { + throw new UnsupportedOperationException("connectInternal has been deprecated in favor of connectInternal"); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java index b637acbb015..f0fc1f8e774 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java @@ -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 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, Runnable { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/Transport.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/Transport.java index 91b3fde6b29..fd273f05305 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/Transport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/Transport.java @@ -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 connect( TransportRequest request, WebSocketHandler webSocketHandler) { + return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>( connectAsync(request, webSocketHandler)); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java index 26f97a09a7a..029e2d29f90 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java @@ -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 connectFuture) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java index 2eb82afd3d0..b00091d6030 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrClientSockJsSession.java @@ -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 connectFuture) { diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java index 19816d24314..eef50c7d854 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java @@ -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 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 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 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 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 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 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(); } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java index 21ab0659775..6299ab45c7b 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java @@ -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 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(); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java index e32b78c6f2d..d26da902830 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java @@ -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 connect( - ClientHttpResponse... responses) { + private CompletableFuture connect(ClientHttpResponse... responses) { return connect(new TestRestTemplate(responses)); } - @SuppressWarnings("deprecation") - private org.springframework.util.concurrent.ListenableFuture connect( - RestOperations restTemplate, ClientHttpResponse... responses) { - + private CompletableFuture 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 responses = new LinkedBlockingDeque<>(); - private TestRestTemplate(ClientHttpResponse... responses) { this.responses.addAll(Arrays.asList(responses)); } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java index 10da16a5fc8..88b3321c8ea 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java @@ -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 connectCallback = mock(); + private final BiConsumer 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 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 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(); }