Merge branch '5.1.x'

This commit is contained in:
Juergen Hoeller
2019-07-05 18:22:02 +02:00
11 changed files with 207 additions and 115 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.ListenableFuture;
/**
@@ -139,9 +138,10 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet
@Nullable
public ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType) {
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
Assert.state(handler instanceof AsyncHandlerMethodReturnValueHandler,
"AsyncHandlerMethodReturnValueHandler required");
return ((AsyncHandlerMethodReturnValueHandler) handler).toListenableFuture(returnValue, returnType);
if (handler instanceof AsyncHandlerMethodReturnValueHandler) {
return ((AsyncHandlerMethodReturnValueHandler) handler).toListenableFuture(returnValue, returnType);
}
return null;
}
}

View File

@@ -21,7 +21,6 @@ import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapter;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.MonoToListenableFutureAdapter;
@@ -60,8 +59,10 @@ public class ReactiveReturnValueHandler extends AbstractAsyncReturnValueHandler
@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)));
if (adapter != null) {
return new MonoToListenableFutureAdapter<>(Mono.from(adapter.toPublisher(returnValue)));
}
return null;
}
}

View File

@@ -74,6 +74,7 @@ import org.springframework.messaging.support.MessageHeaderInitializer;
import org.springframework.stereotype.Controller;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringValueResolver;
@@ -93,6 +94,10 @@ import org.springframework.validation.Validator;
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
implements EmbeddedValueResolverAware, SmartLifecycle {
private static final boolean reactorPresent = ClassUtils.isPresent(
"reactor.core.publisher.Flux", SimpAnnotationMethodMessageHandler.class.getClassLoader());
private final SubscribableChannel clientInboundChannel;
private final SimpMessageSendingOperations clientMessagingTemplate;
@@ -328,7 +333,9 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
handlers.add(new ListenableFutureReturnValueHandler());
handlers.add(new CompletableFutureReturnValueHandler());
handlers.add(new ReactiveReturnValueHandler());
if (reactorPresent) {
handlers.add(new ReactiveReturnValueHandler());
}
// Annotation-based return value types