Browse Source

Polishing

pull/1577/head
Juergen Hoeller 7 years ago
parent
commit
3d1023be8c
  1. 22
      spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java
  2. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

22
spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java

@ -33,10 +33,7 @@ import org.springframework.lang.Nullable; @@ -33,10 +33,7 @@ import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import static org.springframework.core.ReactiveTypeDescriptor.multiValue;
import static org.springframework.core.ReactiveTypeDescriptor.noValue;
import static org.springframework.core.ReactiveTypeDescriptor.singleOptionalValue;
import static org.springframework.core.ReactiveTypeDescriptor.singleRequiredValue;
import static org.springframework.core.ReactiveTypeDescriptor.*;
/**
* A registry of adapters to adapt a Reactive Streams {@link Publisher} to/from
@ -94,11 +91,8 @@ public class ReactiveAdapterRegistry { @@ -94,11 +91,8 @@ public class ReactiveAdapterRegistry {
try {
new ReactorJdkFlowAdapterRegistrar().registerAdapter(this);
}
catch (NoSuchMethodException ex) {
throw new IllegalStateException("Failed to find JdkFlowAdapter methods", ex);
}
catch (Throwable ex) {
// Ignore
// Ignore for the time being...
// We can fall back on "reactive-streams-flow-bridge" (once released)
}
}
@ -254,16 +248,10 @@ public class ReactiveAdapterRegistry { @@ -254,16 +248,10 @@ public class ReactiveAdapterRegistry {
private static class ReactorJdkFlowAdapterRegistrar {
// TODO: remove reflection when build requires JDK 9+
void registerAdapter(ReactiveAdapterRegistry registry)
throws NoSuchMethodException, ClassNotFoundException {
String name = "java.util.concurrent.Flow.Publisher";
Class<?> type = ClassUtils.forName(name, getClass().getClassLoader());
Method toFlowMethod = getMethod("publisherToFlowPublisher", Publisher.class);
void registerAdapter(ReactiveAdapterRegistry registry) throws Exception {
Class<?> type = ClassUtils.forName("java.util.concurrent.Flow.Publisher", getClass().getClassLoader());
Method toFluxMethod = getMethod("flowPublisherToFlux", type);
Method toFlowMethod = getMethod("publisherToFlowPublisher", Publisher.class);
Object emptyFlow = ReflectionUtils.invokeMethod(toFlowMethod, null, Flux.empty());
registry.registerReactiveType(

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

@ -286,13 +286,11 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { @@ -286,13 +286,11 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
@Override
public <T extends Annotation> boolean hasMethodAnnotation(Class<T> annotationType) {
// Ensure @ResponseBody-style handling for values collected from a reactive type
// even if actual return type is ResponseEntity<Flux<T>>
return ResponseBody.class.equals(annotationType) &&
this.returnValue instanceof ReactiveTypeHandler.CollectedValuesList ||
super.hasMethodAnnotation(annotationType);
return (super.hasMethodAnnotation(annotationType) ||
(annotationType == ResponseBody.class &&
this.returnValue instanceof ReactiveTypeHandler.CollectedValuesList));
}
@Override

Loading…
Cancel
Save