Polishing
This commit is contained in:
parent
5a111125c1
commit
ea534b6820
|
|
@ -45,7 +45,7 @@ import org.springframework.transaction.annotation.AnnotationTransactionAttribute
|
|||
* @see javax.transaction.Transactional
|
||||
* @see AnnotationTransactionAspect
|
||||
*/
|
||||
@RequiredTypes({"javax.transaction.Transactional"})
|
||||
@RequiredTypes("javax.transaction.Transactional")
|
||||
public aspect JtaAnnotationTransactionAspect extends AbstractTransactionAspect {
|
||||
|
||||
public JtaAnnotationTransactionAspect() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -97,7 +97,7 @@ public class MessageMethodArgumentResolver implements HandlerMethodArgumentResol
|
|||
private Class<?> getPayloadType(MethodParameter parameter) {
|
||||
Type genericParamType = parameter.getGenericParameterType();
|
||||
ResolvableType resolvableType = ResolvableType.forType(genericParamType).as(Message.class);
|
||||
return resolvableType.getGeneric(0).resolve(Object.class);
|
||||
return resolvableType.getGeneric().resolve(Object.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -36,6 +36,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||
|
||||
/**
|
||||
* Mock implementation of {@link ClientHttpRequest}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
|
|
@ -97,11 +98,9 @@ public class MockClientHttpRequest extends AbstractClientHttpRequest {
|
|||
|
||||
/**
|
||||
* Configure a custom handler for writing the request body.
|
||||
*
|
||||
* <p>The default write handler consumes and caches the request body so it
|
||||
* may be accessed subsequently, e.g. in test assertions. Use this property
|
||||
* when the request body is an infinite stream.
|
||||
*
|
||||
* @param writeHandler the write handler to use returning {@code Mono<Void>}
|
||||
* when the body has been "written" (i.e. consumed).
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -125,10 +125,8 @@ public class MockServerHttpResponse extends AbstractServerHttpResponse {
|
|||
* charset or "UTF-8" by default.
|
||||
*/
|
||||
public Mono<String> getBodyAsString() {
|
||||
|
||||
Charset charset = Optional.ofNullable(getHeaders().getContentType()).map(MimeType::getCharset)
|
||||
.orElse(StandardCharsets.UTF_8);
|
||||
|
||||
return getBody()
|
||||
.reduce(bufferFactory().allocateBuffer(), (previous, current) -> {
|
||||
previous.write(current);
|
||||
|
|
@ -139,7 +137,6 @@ public class MockServerHttpResponse extends AbstractServerHttpResponse {
|
|||
}
|
||||
|
||||
private static String bufferToString(DataBuffer buffer, Charset charset) {
|
||||
Assert.notNull(charset, "'charset' must not be null");
|
||||
byte[] bytes = new byte[buffer.readableByteCount()];
|
||||
buffer.read(bytes);
|
||||
return new String(bytes, charset);
|
||||
|
|
|
|||
|
|
@ -239,13 +239,16 @@ public abstract class AbstractRequestExpectationManager implements RequestExpect
|
|||
|
||||
/**
|
||||
* Add expectations to this group.
|
||||
* @deprecated as of 5.0.3 please use {@link #addAllExpectations(Collection)} instead.
|
||||
* @deprecated as of 5.0.3, if favor of {@link #addAllExpectations}
|
||||
*/
|
||||
@Deprecated
|
||||
public void updateAll(Collection<RequestExpectation> expectations) {
|
||||
expectations.forEach(this::updateInternal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all expectations for this group.
|
||||
*/
|
||||
public void reset() {
|
||||
this.expectations.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
|
|||
Map<String, Object> hints) {
|
||||
|
||||
boolean shouldWrap = isServerSentEvent(elementType);
|
||||
ResolvableType valueType = (shouldWrap ? elementType.getGeneric(0) : elementType);
|
||||
ResolvableType valueType = (shouldWrap ? elementType.getGeneric() : elementType);
|
||||
|
||||
return stringDecoder.decode(message.getBody(), STRING_TYPE, null, Collections.emptyMap())
|
||||
.bufferUntil(line -> line.equals(""))
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -123,7 +123,7 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa
|
|||
ResolvableType elementType;
|
||||
if (adapter != null) {
|
||||
publisher = adapter.toPublisher(body);
|
||||
ResolvableType genericType = bodyType.getGeneric(0);
|
||||
ResolvableType genericType = bodyType.getGeneric();
|
||||
elementType = getElementType(adapter, genericType);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ public abstract class AbstractView implements View, ApplicationContextAware {
|
|||
private static final Object NO_VALUE = new Object();
|
||||
|
||||
|
||||
private final List<MediaType> mediaTypes = new ArrayList<>(4);
|
||||
private final ReactiveAdapterRegistry reactiveAdapterRegistry;
|
||||
|
||||
private final ReactiveAdapterRegistry adapterRegistry;
|
||||
private final List<MediaType> mediaTypes = new ArrayList<>(4);
|
||||
|
||||
private Charset defaultCharset = StandardCharsets.UTF_8;
|
||||
|
||||
|
|
@ -73,9 +73,9 @@ public abstract class AbstractView implements View, ApplicationContextAware {
|
|||
this(ReactiveAdapterRegistry.getSharedInstance());
|
||||
}
|
||||
|
||||
public AbstractView(ReactiveAdapterRegistry registry) {
|
||||
public AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry) {
|
||||
this.reactiveAdapterRegistry = reactiveAdapterRegistry;
|
||||
this.mediaTypes.add(ViewResolverSupport.DEFAULT_CONTENT_TYPE);
|
||||
this.adapterRegistry = registry;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ public abstract class AbstractView implements View, ApplicationContextAware {
|
|||
|
||||
/**
|
||||
* Prepare the model to render.
|
||||
* @param model Map with name Strings as keys and corresponding model
|
||||
* @param model a Map with name Strings as keys and corresponding model
|
||||
* objects as values (Map can also be {@code null} in case of empty model)
|
||||
* @param contentType the content type selected to render with which should
|
||||
* match one of the {@link #getSupportedMediaTypes() supported media types}.
|
||||
|
|
@ -209,7 +209,6 @@ public abstract class AbstractView implements View, ApplicationContextAware {
|
|||
* @return {@code Mono} for the completion of async attributes resolution
|
||||
*/
|
||||
protected Mono<Void> resolveAsyncAttributes(Map<String, Object> model) {
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
List<Mono<?>> valueMonos = new ArrayList<>();
|
||||
|
||||
|
|
@ -218,7 +217,7 @@ public abstract class AbstractView implements View, ApplicationContextAware {
|
|||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
ReactiveAdapter adapter = this.adapterRegistry.getAdapter(null, value);
|
||||
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(null, value);
|
||||
if (adapter != null) {
|
||||
names.add(entry.getKey());
|
||||
if (adapter.isMultiValue()) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import org.springframework.util.ObjectUtils;
|
|||
public abstract class AbstractAnnotationConfigDispatcherHandlerInitializer
|
||||
extends AbstractDispatcherHandlerInitializer {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>This implementation creates an {@link AnnotationConfigApplicationContext},
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue