Browse Source

Polishing

pull/25598/head
Juergen Hoeller 7 years ago
parent
commit
0f0da73043
  1. 23
      spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java
  2. 18
      spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java
  3. 4
      spring-core/src/main/java/org/springframework/util/Base64Utils.java
  4. 12
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java
  5. 6
      spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java
  6. 10
      spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java
  7. 13
      spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java
  8. 17
      spring-test/src/test/java/org/springframework/test/web/client/DefaultRequestExpectationTests.java
  9. 4
      spring-test/src/test/java/org/springframework/test/web/client/MockRestServiceServerTests.java
  10. 6
      spring-tx/src/main/java/org/springframework/transaction/annotation/Propagation.java
  11. 15
      spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java
  12. 12
      spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.java
  13. 13
      spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java
  14. 6
      spring-web/src/main/java/org/springframework/web/method/support/AsyncHandlerMethodReturnValueHandler.java
  15. 6
      spring-web/src/main/java/org/springframework/web/server/NotAcceptableStatusException.java
  16. 18
      spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java
  17. 26
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java
  18. 88
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java
  19. 13
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java
  20. 8
      spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java
  21. 20
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java
  22. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandler.java
  23. 3
      spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java
  24. 16
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java
  25. 9
      spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java

23
spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -209,13 +209,12 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T> T doGetSingleton(String name, @Nullable Class<T> requiredType) throws NamingException { private <T> T doGetSingleton(String name, @Nullable Class<T> requiredType) throws NamingException {
synchronized (this.singletonObjects) { synchronized (this.singletonObjects) {
if (this.singletonObjects.containsKey(name)) { Object singleton = this.singletonObjects.get(name);
Object jndiObject = this.singletonObjects.get(name); if (singleton != null) {
if (requiredType != null && !requiredType.isInstance(jndiObject)) { if (requiredType != null && !requiredType.isInstance(singleton)) {
throw new TypeMismatchNamingException( throw new TypeMismatchNamingException(convertJndiName(name), requiredType, singleton.getClass());
convertJndiName(name), requiredType, (jndiObject != null ? jndiObject.getClass() : null));
} }
return (T) jndiObject; return (T) singleton;
} }
T jndiObject = lookup(name, requiredType); T jndiObject = lookup(name, requiredType);
this.singletonObjects.put(name, jndiObject); this.singletonObjects.put(name, jndiObject);
@ -229,14 +228,12 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
} }
else { else {
synchronized (this.resourceTypes) { synchronized (this.resourceTypes) {
if (this.resourceTypes.containsKey(name)) { Class<?> type = this.resourceTypes.get(name);
return this.resourceTypes.get(name); if (type == null) {
} type = lookup(name, null).getClass();
else {
Class<?> type = lookup(name, null).getClass();
this.resourceTypes.put(name, type); this.resourceTypes.put(name, type);
return type;
} }
return type;
} }
} }
} }

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

@ -41,7 +41,7 @@ import org.springframework.util.ReflectionUtils;
* *
* <p>By default, depending on classpath availability, adapters are registered * <p>By default, depending on classpath availability, adapters are registered
* for Reactor, RxJava 1, RxJava 2 types, {@link CompletableFuture}, and Java 9+ * for Reactor, RxJava 1, RxJava 2 types, {@link CompletableFuture}, and Java 9+
* Flow.Publisher. * {@code Flow.Publisher}.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sebastien Deleuze * @author Sebastien Deleuze
@ -54,7 +54,7 @@ public class ReactiveAdapterRegistry {
private final boolean reactorPresent; private final boolean reactorPresent;
private final List<ReactiveAdapter> adapters = new ArrayList<>(32); private final List<ReactiveAdapter> adapters = new ArrayList<>();
/** /**
@ -112,13 +112,13 @@ public class ReactiveAdapterRegistry {
/** /**
* Register a reactive type along with functions to adapt to and from a * Register a reactive type along with functions to adapt to and from a
* Reactive Streams {@link Publisher}. The functions can assume their * Reactive Streams {@link Publisher}. The function arguments assume that
* input is never be {@code null} nor {@link Optional}. * their input is neither {@code null} nor {@link Optional}.
*/ */
public void registerReactiveType(ReactiveTypeDescriptor descriptor, public void registerReactiveType(ReactiveTypeDescriptor descriptor,
Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter) { Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter) {
if (reactorPresent) { if (this.reactorPresent) {
this.adapters.add(new ReactorAdapter(descriptor, toAdapter, fromAdapter)); this.adapters.add(new ReactorAdapter(descriptor, toAdapter, fromAdapter));
} }
else { else {
@ -128,6 +128,7 @@ public class ReactiveAdapterRegistry {
/** /**
* Get the adapter for the given reactive type. * Get the adapter for the given reactive type.
* @return the corresponding adapter, or {@code null} if none available
*/ */
@Nullable @Nullable
public ReactiveAdapter getAdapter(Class<?> reactiveType) { public ReactiveAdapter getAdapter(Class<?> reactiveType) {
@ -141,6 +142,7 @@ public class ReactiveAdapterRegistry {
* (may be {@code null} if a concrete source object is given) * (may be {@code null} if a concrete source object is given)
* @param source an instance of the reactive type * @param source an instance of the reactive type
* (i.e. to adapt from; may be {@code null} if the reactive type is specified) * (i.e. to adapt from; may be {@code null} if the reactive type is specified)
* @return the corresponding adapter, or {@code null} if none available
*/ */
@Nullable @Nullable
public ReactiveAdapter getAdapter(@Nullable Class<?> reactiveType, @Nullable Object source) { public ReactiveAdapter getAdapter(@Nullable Class<?> reactiveType, @Nullable Object source) {
@ -162,13 +164,13 @@ public class ReactiveAdapterRegistry {
/** /**
* Return a shared default {@code ReactiveAdapterRegistry} instance, lazily * Return a shared default {@code ReactiveAdapterRegistry} instance,
* building it once needed. * lazily building it once needed.
* <p><b>NOTE:</b> We highly recommend passing a long-lived, pre-configured * <p><b>NOTE:</b> We highly recommend passing a long-lived, pre-configured
* {@code ReactiveAdapterRegistry} instance for customization purposes. * {@code ReactiveAdapterRegistry} instance for customization purposes.
* This accessor is only meant as a fallback for code paths that want to * This accessor is only meant as a fallback for code paths that want to
* fall back on a default instance if one isn't provided. * fall back on a default instance if one isn't provided.
* @return the shared {@code ReactiveAdapterRegistry} instance (never {@code null}) * @return the shared {@code ReactiveAdapterRegistry} instance
* @since 5.0.2 * @since 5.0.2
*/ */
public static ReactiveAdapterRegistry getSharedInstance() { public static ReactiveAdapterRegistry getSharedInstance() {

4
spring-core/src/main/java/org/springframework/util/Base64Utils.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -89,7 +89,7 @@ public abstract class Base64Utils {
/** /**
* Base64-encode the given byte array to a String. * Base64-encode the given byte array to a String.
* @param src the original byte array (may be {@code null}) * @param src the original byte array
* @return the encoded byte array as a UTF-8 String * @return the encoded byte array as a UTF-8 String
*/ */
public static String encodeToString(byte[] src) { public static String encodeToString(byte[] src) {

12
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,8 +43,8 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur
* {@link #supportsReturnType(org.springframework.core.MethodParameter)} * {@link #supportsReturnType(org.springframework.core.MethodParameter)}
* is called and it returns {@code true}. * is called and it returns {@code true}.
* @param returnValue the value returned from the handler method * @param returnValue the value returned from the handler method
* @param returnType the type of the return value. * @param returnType the type of the return value
* @return true if the return value type represents an async value. * @return {@code true} if the return value type represents an async value
*/ */
boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType); boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType);
@ -58,9 +58,9 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur
* {@link #supportsReturnType(org.springframework.core.MethodParameter)} * {@link #supportsReturnType(org.springframework.core.MethodParameter)}
* is called and it returns {@code true}. * is called and it returns {@code true}.
* @param returnValue the value returned from the handler method * @param returnValue the value returned from the handler method
* @param returnType the type of the return value. * @param returnType the type of the return value
* @return the resulting ListenableFuture or {@code null} in which case no * @return the resulting ListenableFuture, or {@code null} in which case
* further handling will be performed. * no further handling will be performed
*/ */
@Nullable @Nullable
ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType); ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType);

6
spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,10 +42,10 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = LogFactory.getLog(getClass());
private final List<ChannelInterceptor> interceptors = new ArrayList<>(5);
private String beanName; private String beanName;
private final List<ChannelInterceptor> interceptors = new ArrayList<>(5);
public AbstractMessageChannel() { public AbstractMessageChannel() {
this.beanName = getClass().getSimpleName() + "@" + ObjectUtils.getIdentityHexString(this); this.beanName = getClass().getSimpleName() + "@" + ObjectUtils.getIdentityHexString(this);

10
spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

@ -415,7 +415,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
} }
/** /**
* Indicates whether DTD parsing should be supported. * Indicate whether DTD parsing should be supported.
* <p>Default is {@code false} meaning that DTD is disabled. * <p>Default is {@code false} meaning that DTD is disabled.
*/ */
public void setSupportDtd(boolean supportDtd) { public void setSupportDtd(boolean supportDtd) {
@ -423,14 +423,14 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
} }
/** /**
* Whether DTD parsing is supported. * Return whether DTD parsing is supported.
*/ */
public boolean isSupportDtd() { public boolean isSupportDtd() {
return this.supportDtd; return this.supportDtd;
} }
/** /**
* Indicates whether external XML entities are processed when unmarshalling. * Indicate whether external XML entities are processed when unmarshalling.
* <p>Default is {@code false}, meaning that external entities are not resolved. * <p>Default is {@code false}, meaning that external entities are not resolved.
* Note that processing of external entities will only be enabled/disabled when the * Note that processing of external entities will only be enabled/disabled when the
* {@code Source} passed to {@link #unmarshal(Source)} is a {@link SAXSource} or * {@code Source} passed to {@link #unmarshal(Source)} is a {@link SAXSource} or
@ -442,12 +442,12 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
public void setProcessExternalEntities(boolean processExternalEntities) { public void setProcessExternalEntities(boolean processExternalEntities) {
this.processExternalEntities = processExternalEntities; this.processExternalEntities = processExternalEntities;
if (processExternalEntities) { if (processExternalEntities) {
setSupportDtd(true); this.supportDtd = true;
} }
} }
/** /**
* Returns the configured value for whether XML external entities are allowed. * Return whether XML external entities are allowed.
*/ */
public boolean isProcessExternalEntities() { public boolean isProcessExternalEntities() {
return this.processExternalEntities; return this.processExternalEntities;

13
spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,7 +22,6 @@ import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.io.Writer; import java.io.Writer;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@ -87,7 +86,7 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
/** /**
* Indicates whether DTD parsing should be supported. * Indicate whether DTD parsing should be supported.
* <p>Default is {@code false} meaning that DTD is disabled. * <p>Default is {@code false} meaning that DTD is disabled.
*/ */
public void setSupportDtd(boolean supportDtd) { public void setSupportDtd(boolean supportDtd) {
@ -95,14 +94,14 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
} }
/** /**
* Whether DTD parsing is supported. * Return whether DTD parsing is supported.
*/ */
public boolean isSupportDtd() { public boolean isSupportDtd() {
return this.supportDtd; return this.supportDtd;
} }
/** /**
* Indicates whether external XML entities are processed when unmarshalling. * Indicate whether external XML entities are processed when unmarshalling.
* <p>Default is {@code false}, meaning that external entities are not resolved. * <p>Default is {@code false}, meaning that external entities are not resolved.
* Note that processing of external entities will only be enabled/disabled when the * Note that processing of external entities will only be enabled/disabled when the
* {@code Source} passed to {@link #unmarshal(Source)} is a {@link SAXSource} or * {@code Source} passed to {@link #unmarshal(Source)} is a {@link SAXSource} or
@ -114,12 +113,12 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
public void setProcessExternalEntities(boolean processExternalEntities) { public void setProcessExternalEntities(boolean processExternalEntities) {
this.processExternalEntities = processExternalEntities; this.processExternalEntities = processExternalEntities;
if (processExternalEntities) { if (processExternalEntities) {
setSupportDtd(true); this.supportDtd = true;
} }
} }
/** /**
* Returns the configured value for whether XML external entities are allowed. * Return whether XML external entities are allowed.
* @see #createXmlReader() * @see #createXmlReader()
*/ */
public boolean isProcessExternalEntities() { public boolean isProcessExternalEntities() {

17
spring-test/src/test/java/org/springframework/test/web/client/DefaultRequestExpectationTests.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,15 +26,11 @@ import org.junit.rules.ExpectedException;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequest;
import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue; import static org.springframework.http.HttpMethod.*;
import static org.springframework.http.HttpMethod.GET; import static org.springframework.test.web.client.ExpectedCount.*;
import static org.springframework.http.HttpMethod.POST; import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.ExpectedCount.once; import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
import static org.springframework.test.web.client.ExpectedCount.twice;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
/** /**
* Unit tests for {@link DefaultRequestExpectation}. * Unit tests for {@link DefaultRequestExpectation}.
@ -86,7 +82,6 @@ public class DefaultRequestExpectationTests {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private ClientHttpRequest createRequest(HttpMethod method, String url) { private ClientHttpRequest createRequest(HttpMethod method, String url) {
try { try {

4
spring-test/src/test/java/org/springframework/test/web/client/MockRestServiceServerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import org.junit.Test;
import org.springframework.test.web.client.MockRestServiceServer.MockRestServiceServerBuilder; import org.springframework.test.web.client.MockRestServiceServer.MockRestServiceServerBuilder;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.*;
import static org.springframework.http.HttpMethod.*; import static org.springframework.http.HttpMethod.*;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.response.MockRestResponseCreators.*; import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
@ -124,6 +125,7 @@ public class MockRestServiceServerTests {
try { try {
this.restTemplate.getForEntity("/some-service/some-endpoint", String.class); this.restTemplate.getForEntity("/some-service/some-endpoint", String.class);
fail("Expected exception");
} }
catch (Exception ex) { catch (Exception ex) {
this.restTemplate.postForEntity("/reporting-service/report-error", ex.toString(), String.class); this.restTemplate.postForEntity("/reporting-service/report-error", ex.toString(), String.class);

6
spring-tx/src/main/java/org/springframework/transaction/annotation/Propagation.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,7 +40,7 @@ public enum Propagation {
* Support a current transaction, execute non-transactionally if none exists. * Support a current transaction, execute non-transactionally if none exists.
* Analogous to EJB transaction attribute of the same name. * Analogous to EJB transaction attribute of the same name.
* <p>Note: For transaction managers with transaction synchronization, * <p>Note: For transaction managers with transaction synchronization,
* PROPAGATION_SUPPORTS is slightly different from no transaction at all, * {@code SUPPORTS} is slightly different from no transaction at all,
* as it defines a transaction scope that synchronization will apply for. * as it defines a transaction scope that synchronization will apply for.
* As a consequence, the same resources (JDBC Connection, Hibernate Session, etc) * As a consequence, the same resources (JDBC Connection, Hibernate Session, etc)
* will be shared for the entire specified scope. Note that this depends on * will be shared for the entire specified scope. Note that this depends on
@ -87,7 +87,7 @@ public enum Propagation {
/** /**
* Execute within a nested transaction if a current transaction exists, * Execute within a nested transaction if a current transaction exists,
* behave like PROPAGATION_REQUIRED else. There is no analogous feature in EJB. * behave like {@code REQUIRED} else. There is no analogous feature in EJB.
* <p>Note: Actual creation of a nested transaction will only work on specific * <p>Note: Actual creation of a nested transaction will only work on specific
* transaction managers. Out of the box, this only applies to the JDBC * transaction managers. Out of the box, this only applies to the JDBC
* DataSourceTransactionManager when working on a JDBC 3.0 driver. * DataSourceTransactionManager when working on a JDBC 3.0 driver.

15
spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,12 +34,11 @@ import org.springframework.lang.Nullable;
* Strategy for encoding a stream of objects of type {@code <T>} and writing * Strategy for encoding a stream of objects of type {@code <T>} and writing
* the encoded stream of bytes to an {@link ReactiveHttpOutputMessage}. * the encoded stream of bytes to an {@link ReactiveHttpOutputMessage}.
* *
* @param <T> the type of objects in the input stream
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 5.0 * @since 5.0
* @param <T> the type of objects in the input stream
*/ */
public interface HttpMessageWriter<T> { public interface HttpMessageWriter<T> {
@ -51,7 +50,7 @@ public interface HttpMessageWriter<T> {
/** /**
* Whether the given object type is supported by this writer. * Whether the given object type is supported by this writer.
* @param elementType the type of object to check * @param elementType the type of object to check
* @param mediaType the media type for the write, possibly {@code null} * @param mediaType the media type for the write (possibly {@code null})
* @return {@code true} if writable, {@code false} otherwise * @return {@code true} if writable, {@code false} otherwise
*/ */
boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType); boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType);
@ -61,8 +60,8 @@ public interface HttpMessageWriter<T> {
* @param inputStream the objects to write * @param inputStream the objects to write
* @param elementType the type of objects in the stream which must have been * @param elementType the type of objects in the stream which must have been
* previously checked via {@link #canWrite(ResolvableType, MediaType)} * previously checked via {@link #canWrite(ResolvableType, MediaType)}
* @param mediaType the content type for the write, possibly {@code null} to * @param mediaType the content type for the write (possibly {@code null} to
* indicate that the default content type of the writer must be used. * indicate that the default content type of the writer must be used)
* @param message the message to write to * @param message the message to write to
* @param hints additional information about how to encode and write * @param hints additional information about how to encode and write
* @return indicates completion or error * @return indicates completion or error
@ -78,8 +77,8 @@ public interface HttpMessageWriter<T> {
* value; for annotated controllers, the {@link MethodParameter} can be * value; for annotated controllers, the {@link MethodParameter} can be
* accessed via {@link ResolvableType#getSource()}. * accessed via {@link ResolvableType#getSource()}.
* @param elementType the type of Objects in the input stream * @param elementType the type of Objects in the input stream
* @param mediaType the content type to use, possibly {@code null} indicating * @param mediaType the content type to use (possibly {@code null} indicating
* the default content type of the writer should be used. * the default content type of the writer should be used)
* @param request the current request * @param request the current request
* @param response the current response * @param response the current response
* @return a {@link Mono} that indicates completion of writing or error * @return a {@link Mono} that indicates completion of writing or error

12
spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -71,7 +71,7 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
/** /**
* Indicates whether DTD parsing should be supported. * Indicate whether DTD parsing should be supported.
* <p>Default is {@code false} meaning that DTD is disabled. * <p>Default is {@code false} meaning that DTD is disabled.
*/ */
public void setSupportDtd(boolean supportDtd) { public void setSupportDtd(boolean supportDtd) {
@ -79,14 +79,14 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
} }
/** /**
* Whether DTD parsing is supported. * Return whether DTD parsing is supported.
*/ */
public boolean isSupportDtd() { public boolean isSupportDtd() {
return this.supportDtd; return this.supportDtd;
} }
/** /**
* Indicates whether external XML entities are processed when converting to a Source. * Indicate whether external XML entities are processed when converting to a Source.
* <p>Default is {@code false}, meaning that external entities are not resolved. * <p>Default is {@code false}, meaning that external entities are not resolved.
* <p><strong>Note:</strong> setting this option to {@code true} also * <p><strong>Note:</strong> setting this option to {@code true} also
* automatically sets {@link #setSupportDtd} to {@code true}. * automatically sets {@link #setSupportDtd} to {@code true}.
@ -94,12 +94,12 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
public void setProcessExternalEntities(boolean processExternalEntities) { public void setProcessExternalEntities(boolean processExternalEntities) {
this.processExternalEntities = processExternalEntities; this.processExternalEntities = processExternalEntities;
if (processExternalEntities) { if (processExternalEntities) {
setSupportDtd(true); this.supportDtd = true;
} }
} }
/** /**
* Returns the configured value for whether XML external entities are allowed. * Return whether XML external entities are allowed.
*/ */
public boolean isProcessExternalEntities() { public boolean isProcessExternalEntities() {
return this.processExternalEntities; return this.processExternalEntities;

13
spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -62,6 +62,7 @@ import org.springframework.util.StreamUtils;
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 3.0 * @since 3.0
* @param <T> the converted object type
*/ */
public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMessageConverter<T> { public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMessageConverter<T> {
@ -99,7 +100,7 @@ public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMe
/** /**
* Indicates whether DTD parsing should be supported. * Indicate whether DTD parsing should be supported.
* <p>Default is {@code false} meaning that DTD is disabled. * <p>Default is {@code false} meaning that DTD is disabled.
*/ */
public void setSupportDtd(boolean supportDtd) { public void setSupportDtd(boolean supportDtd) {
@ -107,14 +108,14 @@ public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMe
} }
/** /**
* Whether DTD parsing is supported. * Return whether DTD parsing is supported.
*/ */
public boolean isSupportDtd() { public boolean isSupportDtd() {
return this.supportDtd; return this.supportDtd;
} }
/** /**
* Indicates whether external XML entities are processed when converting to a Source. * Indicate whether external XML entities are processed when converting to a Source.
* <p>Default is {@code false}, meaning that external entities are not resolved. * <p>Default is {@code false}, meaning that external entities are not resolved.
* <p><strong>Note:</strong> setting this option to {@code true} also * <p><strong>Note:</strong> setting this option to {@code true} also
* automatically sets {@link #setSupportDtd} to {@code true}. * automatically sets {@link #setSupportDtd} to {@code true}.
@ -122,12 +123,12 @@ public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMe
public void setProcessExternalEntities(boolean processExternalEntities) { public void setProcessExternalEntities(boolean processExternalEntities) {
this.processExternalEntities = processExternalEntities; this.processExternalEntities = processExternalEntities;
if (processExternalEntities) { if (processExternalEntities) {
setSupportDtd(true); this.supportDtd = true;
} }
} }
/** /**
* Returns the configured value for whether XML external entities are allowed. * Return whether XML external entities are allowed.
*/ */
public boolean isProcessExternalEntities() { public boolean isProcessExternalEntities() {
return this.processExternalEntities; return this.processExternalEntities;

6
spring-web/src/main/java/org/springframework/web/method/support/AsyncHandlerMethodReturnValueHandler.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,9 +38,9 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur
/** /**
* Whether the given return value represents asynchronous computation. * Whether the given return value represents asynchronous computation.
* @param returnValue the return value * @param returnValue the value returned from the handler method
* @param returnType the return type * @param returnType the return type
* @return {@code true} if the return value is asynchronous * @return {@code true} if the return value type represents an async value
*/ */
boolean isAsyncReturnValue(@Nullable Object returnValue, MethodParameter returnType); boolean isAsyncReturnValue(@Nullable Object returnValue, MethodParameter returnType);

6
spring-web/src/main/java/org/springframework/web/server/NotAcceptableStatusException.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,10 +43,10 @@ public class NotAcceptableStatusException extends ResponseStatusException {
} }
/** /**
* Constructor for when requested Content-Type is not supported. * Constructor for when the requested Content-Type is not supported.
*/ */
public NotAcceptableStatusException(List<MediaType> supportedMediaTypes) { public NotAcceptableStatusException(List<MediaType> supportedMediaTypes) {
super(HttpStatus.NOT_ACCEPTABLE, "Could not find acceptable representation", null); super(HttpStatus.NOT_ACCEPTABLE, "Could not find acceptable representation");
this.supportedMediaTypes = Collections.unmodifiableList(supportedMediaTypes); this.supportedMediaTypes = Collections.unmodifiableList(supportedMediaTypes);
} }

18
spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -96,7 +96,7 @@ public abstract class HandlerResultHandlerSupport implements Ordered {
/** /**
* Get a {@code ReactiveAdapter} for the top-level return value type. * Get a {@code ReactiveAdapter} for the top-level return value type.
* @return the matching adapter or {@code null} * @return the matching adapter, or {@code null} if none
*/ */
@Nullable @Nullable
protected ReactiveAdapter getAdapter(HandlerResult result) { protected ReactiveAdapter getAdapter(HandlerResult result) {
@ -105,15 +105,14 @@ public abstract class HandlerResultHandlerSupport implements Ordered {
} }
/** /**
* Select the best media type for the current request through a content * Select the best media type for the current request through a content negotiation algorithm.
* negotiation algorithm.
* @param exchange the current request * @param exchange the current request
* @param producibleTypesSupplier the media types that can be produced for the current request * @param producibleTypesSupplier the media types that can be produced for the current request
* @return the selected media type or {@code null} * @return the selected media type, or {@code null} if none
*/ */
@Nullable @Nullable
protected MediaType selectMediaType(ServerWebExchange exchange, protected MediaType selectMediaType(
Supplier<List<MediaType>> producibleTypesSupplier) { ServerWebExchange exchange, Supplier<List<MediaType>> producibleTypesSupplier) {
MediaType contentType = exchange.getResponse().getHeaders().getContentType(); MediaType contentType = exchange.getResponse().getHeaders().getContentType();
if (contentType != null && contentType.isConcrete()) { if (contentType != null && contentType.isConcrete()) {
@ -151,9 +150,8 @@ public abstract class HandlerResultHandlerSupport implements Ordered {
return getContentTypeResolver().resolveMediaTypes(exchange); return getContentTypeResolver().resolveMediaTypes(exchange);
} }
@SuppressWarnings("unchecked") private List<MediaType> getProducibleTypes(
private List<MediaType> getProducibleTypes(ServerWebExchange exchange, ServerWebExchange exchange, Supplier<List<MediaType>> producibleTypesSupplier) {
Supplier<List<MediaType>> producibleTypesSupplier) {
Set<MediaType> mediaTypes = exchange.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE); Set<MediaType> mediaTypes = exchange.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
return (mediaTypes != null ? new ArrayList<>(mediaTypes) : producibleTypesSupplier.get()); return (mediaTypes != null ? new ArrayList<>(mediaTypes) : producibleTypesSupplier.get());

26
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,8 +29,6 @@ import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.ResolvableType; import org.springframework.core.ResolvableType;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver; import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
@ -110,7 +108,7 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa
* @return indicates completion or error * @return indicates completion or error
* @since 5.0.2 * @since 5.0.2
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({"unchecked", "rawtypes"})
protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParameter, protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParameter,
@Nullable MethodParameter actualParam, ServerWebExchange exchange) { @Nullable MethodParameter actualParam, ServerWebExchange exchange) {
@ -128,32 +126,30 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa
} }
else { else {
publisher = Mono.justOrEmpty(body); publisher = Mono.justOrEmpty(body);
elementType = ((bodyClass == null || bodyClass.equals(Object.class)) && body != null ? elementType = ((bodyClass == null || bodyClass == Object.class) && body != null ?
ResolvableType.forInstance(body) : bodyType); ResolvableType.forInstance(body) : bodyType);
} }
if (void.class == elementType.getRawClass() || Void.class == elementType.getRawClass()) { if (elementType.getRawClass() == void.class || elementType.getRawClass() == Void.class) {
return Mono.from((Publisher<Void>) publisher); return Mono.from((Publisher<Void>) publisher);
} }
ServerHttpRequest request = exchange.getRequest();
ServerHttpResponse response = exchange.getResponse();
MediaType bestMediaType = selectMediaType(exchange, () -> getMediaTypesFor(elementType)); MediaType bestMediaType = selectMediaType(exchange, () -> getMediaTypesFor(elementType));
if (bestMediaType != null) { if (bestMediaType != null) {
for (HttpMessageWriter<?> writer : getMessageWriters()) { for (HttpMessageWriter<?> writer : getMessageWriters()) {
if (writer.canWrite(elementType, bestMediaType)) { if (writer.canWrite(elementType, bestMediaType)) {
return writer.write((Publisher) publisher, actualType, elementType, return writer.write((Publisher) publisher, actualType, elementType,
bestMediaType, request, response, Collections.emptyMap()); bestMediaType, exchange.getRequest(), exchange.getResponse(),
Collections.emptyMap());
} }
} }
} }
else {
if (getMediaTypesFor(elementType).isEmpty()) {
return Mono.error(new IllegalStateException("No writer for : " + elementType));
}
}
return Mono.error(new NotAcceptableStatusException(getMediaTypesFor(elementType))); List<MediaType> mediaTypes = getMediaTypesFor(elementType);
if (bestMediaType == null && mediaTypes.isEmpty()) {
return Mono.error(new IllegalStateException("No HttpMessageWriter for " + elementType));
}
return Mono.error(new NotAcceptableStatusException(mediaTypes));
} }
private ResolvableType getElementType(ReactiveAdapter adapter, ResolvableType genericType) { private ResolvableType getElementType(ReactiveAdapter adapter, ResolvableType genericType) {

88
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,8 +54,9 @@ import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod
/** /**
* Package-private class to assist {@link RequestMappingHandlerAdapter} with * Package-private class to assist {@link RequestMappingHandlerAdapter} with
* resolving, initializing, and caching annotated methods declared in * resolving, initializing, and caching annotated methods declared in
* {@code @Controller} and {@code @ControllerAdvice} components. Assists with * {@code @Controller} and {@code @ControllerAdvice} components.
* the following annotations: *
* <p>Assists with the following annotations:
* <ul> * <ul>
* <li>{@code @InitBinder} * <li>{@code @InitBinder}
* <li>{@code @ModelAttribute} * <li>{@code @ModelAttribute}
@ -112,56 +113,56 @@ class ControllerMethodResolver {
private final Map<Class<?>, SessionAttributesHandler> sessionAttributesHandlerCache = new ConcurrentHashMap<>(64); private final Map<Class<?>, SessionAttributesHandler> sessionAttributesHandlerCache = new ConcurrentHashMap<>(64);
ControllerMethodResolver(ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry, ControllerMethodResolver(ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry adapterRegistry,
ConfigurableApplicationContext context, List<HttpMessageReader<?>> readers) { ConfigurableApplicationContext context, List<HttpMessageReader<?>> readers) {
Assert.notNull(customResolvers, "ArgumentResolverConfigurer is required"); Assert.notNull(customResolvers, "ArgumentResolverConfigurer is required");
Assert.notNull(readers, "'messageReaders' is required"); Assert.notNull(adapterRegistry, "ReactiveAdapterRegistry is required");
Assert.notNull(reactiveRegistry, "ReactiveAdapterRegistry is required");
Assert.notNull(context, "ApplicationContext is required"); Assert.notNull(context, "ApplicationContext is required");
Assert.notNull(readers, "HttpMessageReader List is required");
this.initBinderResolvers = initBinderResolvers(customResolvers, reactiveRegistry, context); this.initBinderResolvers = initBinderResolvers(customResolvers, adapterRegistry, context);
this.modelAttributeResolvers = modelMethodResolvers(customResolvers, reactiveRegistry, context); this.modelAttributeResolvers = modelMethodResolvers(customResolvers, adapterRegistry, context);
this.requestMappingResolvers = requestMappingResolvers(customResolvers, reactiveRegistry, context, readers); this.requestMappingResolvers = requestMappingResolvers(customResolvers, adapterRegistry, context, readers);
this.exceptionHandlerResolvers = exceptionHandlerResolvers(customResolvers, reactiveRegistry, context); this.exceptionHandlerResolvers = exceptionHandlerResolvers(customResolvers, adapterRegistry, context);
this.reactiveAdapterRegistry = reactiveRegistry; this.reactiveAdapterRegistry = adapterRegistry;
initControllerAdviceCaches(context); initControllerAdviceCaches(context);
} }
private List<SyncHandlerMethodArgumentResolver> initBinderResolvers( private List<SyncHandlerMethodArgumentResolver> initBinderResolvers(
ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry, ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry adapterRegistry,
ConfigurableApplicationContext context) { ConfigurableApplicationContext context) {
return initResolvers(customResolvers, reactiveRegistry, context, false, Collections.emptyList()).stream() return initResolvers(customResolvers, adapterRegistry, context, false, Collections.emptyList()).stream()
.filter(resolver -> resolver instanceof SyncHandlerMethodArgumentResolver) .filter(resolver -> resolver instanceof SyncHandlerMethodArgumentResolver)
.map(resolver -> (SyncHandlerMethodArgumentResolver) resolver) .map(resolver -> (SyncHandlerMethodArgumentResolver) resolver)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private static List<HandlerMethodArgumentResolver> modelMethodResolvers( private static List<HandlerMethodArgumentResolver> modelMethodResolvers(
ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry, ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry adapterRegistry,
ConfigurableApplicationContext context) { ConfigurableApplicationContext context) {
return initResolvers(customResolvers, reactiveRegistry, context, true, Collections.emptyList()); return initResolvers(customResolvers, adapterRegistry, context, true, Collections.emptyList());
} }
private static List<HandlerMethodArgumentResolver> requestMappingResolvers( private static List<HandlerMethodArgumentResolver> requestMappingResolvers(
ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry, ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry adapterRegistry,
ConfigurableApplicationContext context, List<HttpMessageReader<?>> readers) { ConfigurableApplicationContext context, List<HttpMessageReader<?>> readers) {
return initResolvers(customResolvers, reactiveRegistry, context, true, readers); return initResolvers(customResolvers, adapterRegistry, context, true, readers);
} }
private static List<HandlerMethodArgumentResolver> exceptionHandlerResolvers( private static List<HandlerMethodArgumentResolver> exceptionHandlerResolvers(
ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry, ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry adapterRegistry,
ConfigurableApplicationContext context) { ConfigurableApplicationContext context) {
return initResolvers(customResolvers, reactiveRegistry, context, false, Collections.emptyList()); return initResolvers(customResolvers, adapterRegistry, context, false, Collections.emptyList());
} }
private static List<HandlerMethodArgumentResolver> initResolvers(ArgumentResolverConfigurer customResolvers, private static List<HandlerMethodArgumentResolver> initResolvers(ArgumentResolverConfigurer customResolvers,
ReactiveAdapterRegistry reactiveRegistry, ConfigurableApplicationContext context, ReactiveAdapterRegistry adapterRegistry, ConfigurableApplicationContext context,
boolean supportDataBinding, List<HttpMessageReader<?>> readers) { boolean supportDataBinding, List<HttpMessageReader<?>> readers) {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
@ -169,48 +170,48 @@ class ControllerMethodResolver {
// Annotation-based... // Annotation-based...
List<HandlerMethodArgumentResolver> result = new ArrayList<>(); List<HandlerMethodArgumentResolver> result = new ArrayList<>();
result.add(new RequestParamMethodArgumentResolver(beanFactory, reactiveRegistry, false)); result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, false));
result.add(new RequestParamMapMethodArgumentResolver(reactiveRegistry)); result.add(new RequestParamMapMethodArgumentResolver(adapterRegistry));
result.add(new PathVariableMethodArgumentResolver(beanFactory, reactiveRegistry)); result.add(new PathVariableMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new PathVariableMapMethodArgumentResolver(reactiveRegistry)); result.add(new PathVariableMapMethodArgumentResolver(adapterRegistry));
result.add(new MatrixVariableMethodArgumentResolver(beanFactory, reactiveRegistry)); result.add(new MatrixVariableMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new MatrixVariableMapMethodArgumentResolver(reactiveRegistry)); result.add(new MatrixVariableMapMethodArgumentResolver(adapterRegistry));
if (!readers.isEmpty()) { if (!readers.isEmpty()) {
result.add(new RequestBodyArgumentResolver(readers, reactiveRegistry)); result.add(new RequestBodyArgumentResolver(readers, adapterRegistry));
result.add(new RequestPartMethodArgumentResolver(readers, reactiveRegistry)); result.add(new RequestPartMethodArgumentResolver(readers, adapterRegistry));
} }
if (supportDataBinding) { if (supportDataBinding) {
result.add(new ModelAttributeMethodArgumentResolver(reactiveRegistry, false)); result.add(new ModelAttributeMethodArgumentResolver(adapterRegistry, false));
} }
result.add(new RequestHeaderMethodArgumentResolver(beanFactory, reactiveRegistry)); result.add(new RequestHeaderMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new RequestHeaderMapMethodArgumentResolver(reactiveRegistry)); result.add(new RequestHeaderMapMethodArgumentResolver(adapterRegistry));
result.add(new CookieValueMethodArgumentResolver(beanFactory, reactiveRegistry)); result.add(new CookieValueMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new ExpressionValueMethodArgumentResolver(beanFactory, reactiveRegistry)); result.add(new ExpressionValueMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new SessionAttributeMethodArgumentResolver(beanFactory, reactiveRegistry)); result.add(new SessionAttributeMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new RequestAttributeMethodArgumentResolver(beanFactory, reactiveRegistry)); result.add(new RequestAttributeMethodArgumentResolver(beanFactory, adapterRegistry));
// Type-based... // Type-based...
if (!readers.isEmpty()) { if (!readers.isEmpty()) {
result.add(new HttpEntityArgumentResolver(readers, reactiveRegistry)); result.add(new HttpEntityArgumentResolver(readers, adapterRegistry));
} }
result.add(new ModelArgumentResolver(reactiveRegistry)); result.add(new ModelArgumentResolver(adapterRegistry));
if (supportDataBinding) { if (supportDataBinding) {
result.add(new ErrorsMethodArgumentResolver(reactiveRegistry)); result.add(new ErrorsMethodArgumentResolver(adapterRegistry));
} }
result.add(new ServerWebExchangeArgumentResolver(reactiveRegistry)); result.add(new ServerWebExchangeArgumentResolver(adapterRegistry));
result.add(new PrincipalArgumentResolver(reactiveRegistry)); result.add(new PrincipalArgumentResolver(adapterRegistry));
if (requestMappingMethod) { if (requestMappingMethod) {
result.add(new SessionStatusMethodArgumentResolver()); result.add(new SessionStatusMethodArgumentResolver());
} }
result.add(new WebSessionArgumentResolver(reactiveRegistry)); result.add(new WebSessionArgumentResolver(adapterRegistry));
// Custom... // Custom...
result.addAll(customResolvers.getCustomResolvers()); result.addAll(customResolvers.getCustomResolvers());
// Catch-all... // Catch-all...
result.add(new RequestParamMethodArgumentResolver(beanFactory, reactiveRegistry, true)); result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, true));
if (supportDataBinding) { if (supportDataBinding) {
result.add(new ModelAttributeMethodArgumentResolver(reactiveRegistry, true)); result.add(new ModelAttributeMethodArgumentResolver(adapterRegistry, true));
} }
return result; return result;
@ -336,7 +337,6 @@ class ControllerMethodResolver {
*/ */
@Nullable @Nullable
public InvocableHandlerMethod getExceptionHandlerMethod(Throwable ex, HandlerMethod handlerMethod) { public InvocableHandlerMethod getExceptionHandlerMethod(Throwable ex, HandlerMethod handlerMethod) {
Class<?> handlerType = handlerMethod.getBeanType(); Class<?> handlerType = handlerMethod.getBeanType();
// Controller-local first... // Controller-local first...

13
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -135,8 +135,7 @@ public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentR
BindingResult errors = binder.getBindingResult(); BindingResult errors = binder.getBindingResult();
if (adapter != null) { if (adapter != null) {
return adapter.fromPublisher(errors.hasErrors() ? return adapter.fromPublisher(errors.hasErrors() ?
Mono.error(new WebExchangeBindException(parameter, errors)) : Mono.error(new WebExchangeBindException(parameter, errors)) : valueMono);
valueMono);
} }
else { else {
if (errors.hasErrors() && !hasErrorsArgument(parameter)) { if (errors.hasErrors() && !hasErrorsArgument(parameter)) {
@ -163,10 +162,10 @@ public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentR
return createAttribute(attributeName, attributeClass, context, exchange); return createAttribute(attributeName, attributeClass, context, exchange);
} }
ReactiveAdapter adapterFrom = getAdapterRegistry().getAdapter(null, attribute); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(null, attribute);
if (adapterFrom != null) { if (adapter != null) {
Assert.isTrue(!adapterFrom.isMultiValue(), "Data binding only supports single-value async types"); Assert.isTrue(!adapter.isMultiValue(), "Data binding only supports single-value async types");
return Mono.from(adapterFrom.toPublisher(attribute)); return Mono.from(adapter.toPublisher(attribute));
} }
else { else {
return Mono.justOrEmpty(attribute); return Mono.justOrEmpty(attribute);

8
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -56,7 +56,7 @@ public abstract class AbstractView implements View, ApplicationContextAware {
private static final Object NO_VALUE = new Object(); private static final Object NO_VALUE = new Object();
private final ReactiveAdapterRegistry reactiveAdapterRegistry; private final ReactiveAdapterRegistry adapterRegistry;
private final List<MediaType> mediaTypes = new ArrayList<>(4); private final List<MediaType> mediaTypes = new ArrayList<>(4);
@ -74,7 +74,7 @@ public abstract class AbstractView implements View, ApplicationContextAware {
} }
public AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry) { public AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry) {
this.reactiveAdapterRegistry = reactiveAdapterRegistry; this.adapterRegistry = reactiveAdapterRegistry;
this.mediaTypes.add(ViewResolverSupport.DEFAULT_CONTENT_TYPE); this.mediaTypes.add(ViewResolverSupport.DEFAULT_CONTENT_TYPE);
} }
@ -217,7 +217,7 @@ public abstract class AbstractView implements View, ApplicationContextAware {
if (value == null) { if (value == null) {
continue; continue;
} }
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(null, value); ReactiveAdapter adapter = this.adapterRegistry.getAdapter(null, value);
if (adapter != null) { if (adapter != null) {
names.add(entry.getKey()); names.add(entry.getKey());
if (adapter.isMultiValue()) { if (adapter.isMultiValue()) {

20
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -76,14 +76,14 @@ class ReactiveTypeHandler {
private static Log logger = LogFactory.getLog(ReactiveTypeHandler.class); private static Log logger = LogFactory.getLog(ReactiveTypeHandler.class);
private final ReactiveAdapterRegistry reactiveRegistry; private final ReactiveAdapterRegistry adapterRegistry;
private final TaskExecutor taskExecutor; private final TaskExecutor taskExecutor;
private Boolean taskExecutorWarning;
private final ContentNegotiationManager contentNegotiationManager; private final ContentNegotiationManager contentNegotiationManager;
private boolean taskExecutorWarning;
public ReactiveTypeHandler() { public ReactiveTypeHandler() {
this(ReactiveAdapterRegistry.getSharedInstance(), new SyncTaskExecutor(), new ContentNegotiationManager()); this(ReactiveAdapterRegistry.getSharedInstance(), new SyncTaskExecutor(), new ContentNegotiationManager());
@ -93,10 +93,12 @@ class ReactiveTypeHandler {
Assert.notNull(registry, "ReactiveAdapterRegistry is required"); Assert.notNull(registry, "ReactiveAdapterRegistry is required");
Assert.notNull(executor, "TaskExecutor is required"); Assert.notNull(executor, "TaskExecutor is required");
Assert.notNull(manager, "ContentNegotiationManager is required"); Assert.notNull(manager, "ContentNegotiationManager is required");
this.reactiveRegistry = registry; this.adapterRegistry = registry;
this.taskExecutor = executor; this.taskExecutor = executor;
this.taskExecutorWarning = executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor;
this.contentNegotiationManager = manager; this.contentNegotiationManager = manager;
this.taskExecutorWarning =
(executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor);
} }
@ -104,7 +106,7 @@ class ReactiveTypeHandler {
* Whether the type can be adapted to a Reactive Streams {@link Publisher}. * Whether the type can be adapted to a Reactive Streams {@link Publisher}.
*/ */
public boolean isReactiveType(Class<?> type) { public boolean isReactiveType(Class<?> type) {
return (this.reactiveRegistry.hasAdapters() && this.reactiveRegistry.getAdapter(type) != null); return (this.adapterRegistry.hasAdapters() && this.adapterRegistry.getAdapter(type) != null);
} }
@ -119,7 +121,7 @@ class ReactiveTypeHandler {
ModelAndViewContainer mav, NativeWebRequest request) throws Exception { ModelAndViewContainer mav, NativeWebRequest request) throws Exception {
Assert.notNull(returnValue, "Expected return value"); Assert.notNull(returnValue, "Expected return value");
ReactiveAdapter adapter = this.reactiveRegistry.getAdapter(returnValue.getClass()); ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnValue.getClass());
Assert.state(adapter != null, () -> "Unexpected return value: " + returnValue); Assert.state(adapter != null, () -> "Unexpected return value: " + returnValue);
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric(); ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric();
@ -317,7 +319,7 @@ class ReactiveTypeHandler {
return; return;
} }
} }
if (isTerminated) { if (isTerminated) {
this.done = true; this.done = true;
Throwable ex = this.error; Throwable ex = this.error;

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

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -83,17 +83,17 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
/** /**
* Complete constructor with pluggable "reactive" type support. * Complete constructor with pluggable "reactive" type support.
* @param messageConverters converters to write emitted objects with * @param messageConverters converters to write emitted objects with
* @param reactiveRegistry for reactive return value type support * @param registry for reactive return value type support
* @param executor for blocking I/O writes of items emitted from reactive types * @param executor for blocking I/O writes of items emitted from reactive types
* @param manager for detecting streaming media types * @param manager for detecting streaming media types
* @since 5.0 * @since 5.0
*/ */
public ResponseBodyEmitterReturnValueHandler(List<HttpMessageConverter<?>> messageConverters, public ResponseBodyEmitterReturnValueHandler(List<HttpMessageConverter<?>> messageConverters,
ReactiveAdapterRegistry reactiveRegistry, TaskExecutor executor, ContentNegotiationManager manager) { ReactiveAdapterRegistry registry, TaskExecutor executor, ContentNegotiationManager manager) {
Assert.notEmpty(messageConverters, "HttpMessageConverter List must not be empty"); Assert.notEmpty(messageConverters, "HttpMessageConverter List must not be empty");
this.messageConverters = messageConverters; this.messageConverters = messageConverters;
this.reactiveHandler = new ReactiveTypeHandler(reactiveRegistry, executor, manager); this.reactiveHandler = new ReactiveTypeHandler(registry, executor, manager);
} }

3
spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.web.servlet.support;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;

16
spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -346,7 +346,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
targetUrl = replaceUriTemplateVariables(targetUrl.toString(), model, variables, enc); targetUrl = replaceUriTemplateVariables(targetUrl.toString(), model, variables, enc);
} }
if (isPropagateQueryProperties()) { if (isPropagateQueryProperties()) {
appendCurrentQueryParams(targetUrl, request); appendCurrentQueryParams(targetUrl, request);
} }
if (this.exposeModelAttributes) { if (this.exposeModelAttributes) {
appendQueryProperties(targetUrl, model, enc); appendQueryProperties(targetUrl, model, enc);
@ -368,7 +368,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
* attributes or URI variables from the current request. Model attributes * attributes or URI variables from the current request. Model attributes
* referenced in the URL are removed from the model. * referenced in the URL are removed from the model.
* @param targetUrl the redirect URL * @param targetUrl the redirect URL
* @param model Map that contains model attributes * @param model a Map that contains model attributes
* @param currentUriVariables current request URI variables to use * @param currentUriVariables current request URI variables to use
* @param encodingScheme the encoding scheme to use * @param encodingScheme the encoding scheme to use
* @throws UnsupportedEncodingException if string encoding failed * @throws UnsupportedEncodingException if string encoding failed
@ -435,7 +435,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
* Append query properties to the redirect URL. * Append query properties to the redirect URL.
* Stringifies, URL-encodes and formats model attributes as query properties. * Stringifies, URL-encodes and formats model attributes as query properties.
* @param targetUrl the StringBuilder to append the properties to * @param targetUrl the StringBuilder to append the properties to
* @param model Map that contains model attributes * @param model a Map that contains model attributes
* @param encodingScheme the encoding scheme to use * @param encodingScheme the encoding scheme to use
* @throws UnsupportedEncodingException if string encoding failed * @throws UnsupportedEncodingException if string encoding failed
* @see #queryProperties * @see #queryProperties
@ -554,8 +554,9 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
/** /**
* Determine whether the given model element value is eligible for exposure. * Determine whether the given model element value is eligible for exposure.
* <p>The default implementation considers primitives, Strings, Numbers, Dates, * <p>The default implementation considers primitives, strings, numbers, dates,
* URIs, URLs and Locale objects as eligible. This can be overridden in subclasses. * URIs, URLs etc as eligible, according to {@link BeanUtils#isSimpleValueType}.
* This can be overridden in subclasses.
* @param value the model element value * @param value the model element value
* @return whether the element value is eligible * @return whether the element value is eligible
* @see BeanUtils#isSimpleValueType * @see BeanUtils#isSimpleValueType
@ -572,7 +573,6 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
* @return the encoded output String * @return the encoded output String
* @throws UnsupportedEncodingException if thrown by the JDK URLEncoder * @throws UnsupportedEncodingException if thrown by the JDK URLEncoder
* @see java.net.URLEncoder#encode(String, String) * @see java.net.URLEncoder#encode(String, String)
* @see java.net.URLEncoder#encode(String)
*/ */
protected String urlEncode(String input, String encodingScheme) throws UnsupportedEncodingException { protected String urlEncode(String input, String encodingScheme) throws UnsupportedEncodingException {
return URLEncoder.encode(input, encodingScheme); return URLEncoder.encode(input, encodingScheme);
@ -602,7 +602,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
} }
/** /**
* Send a redirect back to the HTTP client * Send a redirect back to the HTTP client.
* @param request current HTTP request (allows for reacting to request method) * @param request current HTTP request (allows for reacting to request method)
* @param response current HTTP response (for sending response headers) * @param response current HTTP response (for sending response headers)
* @param targetUrl the target URL to redirect to * @param targetUrl the target URL to redirect to

9
spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -47,10 +47,6 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
@Override @Override
public void refresh() throws BeansException { public void refresh() throws BeansException {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("commandClass", "org.springframework.tests.sample.beans.TestBean");
pvs.add("formView", "form");
registerSingleton("/locale.do", LocaleChecker.class); registerSingleton("/locale.do", LocaleChecker.class);
addMessage("test", Locale.ENGLISH, "test message"); addMessage("test", Locale.ENGLISH, "test message");
@ -63,7 +59,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
registerSingleton("handlerMapping", BeanNameUrlHandlerMapping.class); registerSingleton("handlerMapping", BeanNameUrlHandlerMapping.class);
registerSingleton("viewResolver", InternalResourceViewResolver.class); registerSingleton("viewResolver", InternalResourceViewResolver.class);
pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("location", "org/springframework/web/context/WEB-INF/sessionContext.xml"); pvs.add("location", "org/springframework/web/context/WEB-INF/sessionContext.xml");
registerSingleton("viewResolver2", XmlViewResolver.class, pvs); registerSingleton("viewResolver2", XmlViewResolver.class, pvs);
@ -76,6 +72,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
@Override @Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
if (!(RequestContextUtils.findWebApplicationContext(request) instanceof SimpleWebApplicationContext)) { if (!(RequestContextUtils.findWebApplicationContext(request) instanceof SimpleWebApplicationContext)) {
throw new ServletException("Incorrect WebApplicationContext"); throw new ServletException("Incorrect WebApplicationContext");
} }

Loading…
Cancel
Save