Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -86,9 +86,7 @@ class ReactiveTypeHandler {
|
||||
this(ReactiveAdapterRegistry.getSharedInstance(), new SyncTaskExecutor(), new ContentNegotiationManager());
|
||||
}
|
||||
|
||||
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor,
|
||||
ContentNegotiationManager manager) {
|
||||
|
||||
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor, ContentNegotiationManager manager) {
|
||||
Assert.notNull(registry, "ReactiveAdapterRegistry is required");
|
||||
Assert.notNull(executor, "TaskExecutor is required");
|
||||
Assert.notNull(manager, "ContentNegotiationManager is required");
|
||||
@@ -120,7 +118,7 @@ class ReactiveTypeHandler {
|
||||
ReactiveAdapter adapter = this.reactiveRegistry.getAdapter(returnValue.getClass());
|
||||
Assert.state(adapter != null, "Unexpected return value: " + returnValue);
|
||||
|
||||
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric(0);
|
||||
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric();
|
||||
Class<?> elementClass = elementType.resolve(Object.class);
|
||||
|
||||
Collection<MediaType> mediaTypes = getMediaTypes(request);
|
||||
@@ -249,7 +247,7 @@ class ReactiveTypeHandler {
|
||||
schedule();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void schedule() {
|
||||
try {
|
||||
this.taskExecutor.execute(this);
|
||||
@@ -264,7 +262,7 @@ class ReactiveTypeHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.done) {
|
||||
@@ -310,7 +308,7 @@ class ReactiveTypeHandler {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (this.executing.decrementAndGet() != 0) {
|
||||
schedule();
|
||||
}
|
||||
@@ -324,7 +322,6 @@ class ReactiveTypeHandler {
|
||||
this.subscription.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -407,16 +404,12 @@ class ReactiveTypeHandler {
|
||||
|
||||
private final CollectedValuesList values;
|
||||
|
||||
|
||||
DeferredResultSubscriber(DeferredResult<Object> result, ReactiveAdapter adapter,
|
||||
ResolvableType elementType) {
|
||||
|
||||
DeferredResultSubscriber(DeferredResult<Object> result, ReactiveAdapter adapter, ResolvableType elementType) {
|
||||
this.result = result;
|
||||
this.multiValueSource = adapter.isMultiValue();
|
||||
this.values = new CollectedValuesList(elementType);
|
||||
}
|
||||
|
||||
|
||||
public void connect(ReactiveAdapter adapter, Object returnValue) {
|
||||
Publisher<Object> publisher = adapter.toPublisher(returnValue);
|
||||
publisher.subscribe(this);
|
||||
@@ -452,6 +445,10 @@ class ReactiveTypeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List of collect values where all elements are a specified type.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
static class CollectedValuesList extends ArrayList<Object> {
|
||||
|
||||
@@ -466,4 +463,4 @@ class ReactiveTypeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -20,7 +20,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -83,17 +82,14 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
|
||||
|
||||
/**
|
||||
* Complete constructor with pluggable "reactive" type support.
|
||||
*
|
||||
* @param messageConverters converters to write emitted objects with
|
||||
* @param reactiveRegistry for reactive return value type support
|
||||
* @param executor for blocking I/O writes of items emitted from reactive types
|
||||
* @param manager for detecting streaming media types
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public ResponseBodyEmitterReturnValueHandler(List<HttpMessageConverter<?>> messageConverters,
|
||||
ReactiveAdapterRegistry reactiveRegistry, TaskExecutor executor,
|
||||
ContentNegotiationManager manager) {
|
||||
ReactiveAdapterRegistry reactiveRegistry, TaskExecutor executor, ContentNegotiationManager manager) {
|
||||
|
||||
Assert.notEmpty(messageConverters, "HttpMessageConverter List must not be empty");
|
||||
this.messageConverters = messageConverters;
|
||||
@@ -103,16 +99,16 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
|
||||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
|
||||
Class<?> bodyType = ResponseEntity.class.isAssignableFrom(returnType.getParameterType()) ?
|
||||
ResolvableType.forMethodParameter(returnType).getGeneric(0).resolve() :
|
||||
ResolvableType.forMethodParameter(returnType).getGeneric().resolve() :
|
||||
returnType.getParameterType();
|
||||
|
||||
return bodyType != null && (ResponseBodyEmitter.class.isAssignableFrom(bodyType) ||
|
||||
this.reactiveHandler.isReactiveType(bodyType));
|
||||
return (bodyType != null && (ResponseBodyEmitter.class.isAssignableFrom(bodyType) ||
|
||||
this.reactiveHandler.isReactiveType(bodyType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("resource")
|
||||
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -259,7 +259,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
||||
this.returnValue = returnValue;
|
||||
this.returnType = (returnValue instanceof ReactiveTypeHandler.CollectedValuesList ?
|
||||
((ReactiveTypeHandler.CollectedValuesList) returnValue).getReturnType() :
|
||||
ResolvableType.forType(super.getGenericParameterType()).getGeneric(0));
|
||||
ResolvableType.forType(super.getGenericParameterType()).getGeneric());
|
||||
}
|
||||
|
||||
public ConcurrentResultMethodParameter(ConcurrentResultMethodParameter original) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -50,13 +50,14 @@ public class StreamingResponseBodyReturnValueHandler implements HandlerMethodRet
|
||||
return true;
|
||||
}
|
||||
else if (ResponseEntity.class.isAssignableFrom(returnType.getParameterType())) {
|
||||
Class<?> bodyType = ResolvableType.forMethodParameter(returnType).getGeneric(0).resolve();
|
||||
Class<?> bodyType = ResolvableType.forMethodParameter(returnType).getGeneric().resolve();
|
||||
return (bodyType != null && StreamingResponseBody.class.isAssignableFrom(bodyType));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("resource")
|
||||
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user