Browse Source

Polishing

pull/1894/head
Juergen Hoeller 8 years ago
parent
commit
1b09718104
  1. 8
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ReactiveReturnValueHandler.java
  2. 6
      spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactory.java

8
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ReactiveReturnValueHandler.java

@ -22,11 +22,12 @@ import org.springframework.core.MethodParameter; @@ -22,11 +22,12 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapter;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.messaging.support.MonoToListenableFutureAdapter;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.ListenableFuture;
/**
* Support for single-value reactive types (like {@code Mono} or {@code Single}) as a
* return value type.
* Support for single-value reactive types (like {@code Mono} or {@code Single})
* as a return value type.
*
* @author Sebastien Deleuze
* @since 5.1
@ -53,12 +54,13 @@ public class ReactiveReturnValueHandler extends AbstractAsyncReturnValueHandler @@ -53,12 +54,13 @@ public class ReactiveReturnValueHandler extends AbstractAsyncReturnValueHandler
@Override
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnType.getParameterType(), returnValue);
return !adapter.isMultiValue() && !adapter.isNoValue();
return (adapter != null && !adapter.isMultiValue() && !adapter.isNoValue());
}
@Override
public ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType) {
ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnType.getParameterType(), returnValue);
Assert.state(adapter != null, () -> "No ReactiveAdapter found for " + returnType.getParameterType());
return new MonoToListenableFutureAdapter<>(Mono.from(adapter.toPublisher(returnValue)));
}

6
spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactory.java

@ -21,6 +21,7 @@ import java.net.MalformedURLException; @@ -21,6 +21,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
@ -118,8 +119,9 @@ public class OkHttp3ClientHttpRequestFactory @@ -118,8 +119,9 @@ public class OkHttp3ClientHttpRequestFactory
public void destroy() throws IOException {
if (this.defaultClient) {
// Clean up the client if we created it in the constructor
if (this.client.cache() != null) {
this.client.cache().close();
Cache cache = this.client.cache();
if (cache != null) {
cache.close();
}
this.client.dispatcher().executorService().shutdown();
}

Loading…
Cancel
Save