From dda9762072bd4e1ceda3736740d25bb78de49f38 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 8 Nov 2016 11:01:58 +0100 Subject: [PATCH] Moved WebExchangeDataBinder to web.bind.support (alongside WebRequestDataBinder) Issue: SPR-14542 --- .../web/reactive/BindingContext.java | 7 +++---- .../AbstractMessageReaderArgumentResolver.java | 4 ++-- .../annotation/InitBinderBindingContext.java | 2 +- .../ModelAttributeMethodArgumentResolver.java | 4 ++-- .../result/view/ViewResolutionResultHandler.java | 2 +- .../WebReactiveConfigurationSupportTests.java | 14 +++----------- .../annotation/BindingContextFactoryTests.java | 2 +- .../annotation/ErrorsArgumentResolverTests.java | 2 +- .../ModelAttributeMethodArgumentResolverTests.java | 2 +- .../{ => support}/WebExchangeBindException.java | 3 ++- .../bind/{ => support}/WebExchangeDataBinder.java | 9 ++++----- ...est.java => EncoderHttpMessageWriterTests.java} | 5 ++--- .../server/reactive/bootstrap/JettyHttpServer.java | 2 -- .../reactive/bootstrap/TomcatHttpServer.java | 2 -- .../{ => support}/WebExchangeDataBinderTests.java | 5 ++--- 15 files changed, 25 insertions(+), 40 deletions(-) rename spring-web/src/main/java/org/springframework/web/bind/{ => support}/WebExchangeBindException.java (99%) rename spring-web/src/main/java/org/springframework/web/bind/{ => support}/WebExchangeDataBinder.java (97%) rename spring-web/src/test/java/org/springframework/http/codec/{EncoderHttpMessageWriterTest.java => EncoderHttpMessageWriterTests.java} (96%) rename spring-web/src/test/java/org/springframework/web/bind/{ => support}/WebExchangeDataBinderTests.java (98%) diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/BindingContext.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/BindingContext.java index ad75e8b55c9..482e007bd22 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/BindingContext.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/BindingContext.java @@ -18,9 +18,8 @@ package org.springframework.web.reactive; import org.springframework.ui.Model; import org.springframework.validation.support.BindingAwareConcurrentModel; -import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.WebExchangeDataBinder; import org.springframework.web.bind.support.WebBindingInitializer; +import org.springframework.web.bind.support.WebExchangeDataBinder; import org.springframework.web.server.ServerWebExchange; /** @@ -60,7 +59,7 @@ public class BindingContext { * @param exchange the current exchange * @param target the object to create a data binder for * @param name the name of the target object - * @return the {@link WebDataBinder} instance + * @return the {@link WebExchangeDataBinder} instance */ public WebExchangeDataBinder createDataBinder(ServerWebExchange exchange, Object target, String name) { WebExchangeDataBinder dataBinder = createBinderInstance(target, name); @@ -75,7 +74,7 @@ public class BindingContext { * for applying type conversion to simple types. * @param exchange the current exchange * @param name the name of the target object - * @return a Mono for the created {@link WebDataBinder} instance + * @return a Mono for the created {@link WebExchangeDataBinder} instance */ public WebExchangeDataBinder createDataBinder(ServerWebExchange exchange, String name) { return createDataBinder(exchange, null, name); diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java index 33d7ba54960..c5c11b3b770 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java @@ -39,8 +39,8 @@ import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.util.Assert; import org.springframework.validation.Validator; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.WebExchangeBindException; -import org.springframework.web.bind.WebExchangeDataBinder; +import org.springframework.web.bind.support.WebExchangeBindException; +import org.springframework.web.bind.support.WebExchangeDataBinder; import org.springframework.web.reactive.BindingContext; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebInputException; diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java index 8514e68eb49..c87c69def0b 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java @@ -21,9 +21,9 @@ import java.util.Collection; import java.util.List; import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.WebExchangeDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.support.WebBindingInitializer; +import org.springframework.web.bind.support.WebExchangeDataBinder; import org.springframework.web.method.HandlerMethod; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.HandlerResult; diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java index 9756b9a7334..afff4e87fb1 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java @@ -35,9 +35,9 @@ import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; import org.springframework.validation.Errors; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.WebExchangeBindException; -import org.springframework.web.bind.WebExchangeDataBinder; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.support.WebExchangeBindException; +import org.springframework.web.bind.support.WebExchangeDataBinder; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver; import org.springframework.web.server.ServerWebExchange; diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java index 674d3cb79aa..814588a9157 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java @@ -40,8 +40,8 @@ import org.springframework.ui.Model; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.WebExchangeDataBinder; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.support.WebExchangeDataBinder; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.HandlerResult; import org.springframework.web.reactive.HandlerResultHandler; diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/WebReactiveConfigurationSupportTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/WebReactiveConfigurationSupportTests.java index a5d57aaab60..767d112655e 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/WebReactiveConfigurationSupportTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/WebReactiveConfigurationSupportTests.java @@ -48,8 +48,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; import org.springframework.validation.Validator; -import org.springframework.web.bind.WebExchangeDataBinder; import org.springframework.web.bind.support.WebBindingInitializer; +import org.springframework.web.bind.support.WebExchangeDataBinder; import org.springframework.web.reactive.accept.RequestedContentTypeResolver; import org.springframework.web.reactive.handler.AbstractHandlerMapping; import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping; @@ -68,16 +68,8 @@ import org.springframework.web.server.WebHandler; import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.session.MockWebSessionManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM; -import static org.springframework.http.MediaType.APPLICATION_XML; -import static org.springframework.http.MediaType.IMAGE_PNG; -import static org.springframework.http.MediaType.TEXT_PLAIN; +import static org.junit.Assert.*; +import static org.springframework.http.MediaType.*; /** * Unit tests for {@link WebReactiveConfigurationSupport}. diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java index 4b71e4cfeaf..2ac3ea5b076 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java @@ -32,10 +32,10 @@ import org.springframework.ui.Model; import org.springframework.util.ObjectUtils; import org.springframework.validation.Validator; import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.WebExchangeDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.support.WebExchangeDataBinder; import org.springframework.web.method.HandlerMethod; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.config.WebReactiveConfigurationSupport; diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java index da647ee36d0..d1e8e526299 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java @@ -29,8 +29,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse; import org.springframework.validation.BindingResult; import org.springframework.validation.Errors; -import org.springframework.web.bind.WebExchangeDataBinder; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.support.WebExchangeDataBinder; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.result.ResolvableMethod; import org.springframework.web.server.ServerWebExchange; diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java index 028ec80f2b3..61de7292195 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java @@ -36,9 +36,9 @@ import org.springframework.util.MultiValueMap; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; -import org.springframework.web.bind.WebExchangeBindException; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; +import org.springframework.web.bind.support.WebExchangeBindException; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.result.ResolvableMethod; import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver; diff --git a/spring-web/src/main/java/org/springframework/web/bind/WebExchangeBindException.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java similarity index 99% rename from spring-web/src/main/java/org/springframework/web/bind/WebExchangeBindException.java rename to spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java index 99182fa8850..df57e6b7f17 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/WebExchangeBindException.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.web.bind; + +package org.springframework.web.bind.support; import java.beans.PropertyEditor; import java.util.List; diff --git a/spring-web/src/main/java/org/springframework/web/bind/WebExchangeDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java similarity index 97% rename from spring-web/src/main/java/org/springframework/web/bind/WebExchangeDataBinder.java rename to spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java index 4152444a234..4eb74556496 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/WebExchangeDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.web.bind; + +package org.springframework.web.bind.support; import java.util.Arrays; import java.util.Collections; @@ -27,6 +28,7 @@ import org.springframework.beans.MutablePropertyValues; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.WebDataBinder; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.server.ServerWebExchange; @@ -39,7 +41,6 @@ import org.springframework.web.server.ServerWebExchange; */ public class WebExchangeDataBinder extends WebDataBinder { - /** * Create a new instance, with default object name. * @param target the target object to bind onto (or {@code null} if the @@ -65,12 +66,10 @@ public class WebExchangeDataBinder extends WebDataBinder { * Bind the URL query parameters or form data of the body of the given request * to this binder's target. The request body is parsed if the content-type * is "application/x-www-form-urlencoded". - * * @param exchange the current exchange. * @return a {@code Mono} to indicate the result */ public Mono bind(ServerWebExchange exchange) { - ServerHttpRequest request = exchange.getRequest(); Mono> queryParams = Mono.just(request.getQueryParams()); Mono> formParams = @@ -136,4 +135,4 @@ public class WebExchangeDataBinder extends WebDataBinder { return Collections.emptyMap(); } -} \ No newline at end of file +} diff --git a/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTest.java b/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java similarity index 96% rename from spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTest.java rename to spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java index 8a5a7cba279..e9bd2eaea88 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTest.java +++ b/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.codec; import java.nio.ByteBuffer; import java.util.Collections; -import org.jetbrains.annotations.NotNull; import org.junit.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -40,7 +40,7 @@ import static org.junit.Assert.*; * @author Marcin Kamionowski * @author Rossen Stoyanchev */ -public class EncoderHttpMessageWriterTest { +public class EncoderHttpMessageWriterTests { private MockServerHttpResponse response = new MockServerHttpResponse(); @@ -74,7 +74,6 @@ public class EncoderHttpMessageWriterTest { .verify(); } - @NotNull private EncoderHttpMessageWriter createWriter(Encoder encoder) { return new EncoderHttpMessageWriter<>(encoder); } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/JettyHttpServer.java b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/JettyHttpServer.java index 0fa775839e2..81c15ebf87b 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/JettyHttpServer.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/JettyHttpServer.java @@ -20,7 +20,6 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.InitializingBean; import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; @@ -52,7 +51,6 @@ public class JettyHttpServer extends HttpServerSupport implements HttpServer, In this.jettyServer.addConnector(connector); } - @NotNull private ServletHttpHandlerAdapter initServletHttpHandlerAdapter() { if (getHttpHandlerMap() != null) { return new ServletHttpHandlerAdapter(getHttpHandlerMap()); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/TomcatHttpServer.java b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/TomcatHttpServer.java index b9c305e06d3..0c854e63bd9 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/TomcatHttpServer.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/TomcatHttpServer.java @@ -21,7 +21,6 @@ import java.io.File; import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; import org.apache.catalina.startup.Tomcat; -import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.InitializingBean; import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; @@ -64,7 +63,6 @@ public class TomcatHttpServer extends HttpServerSupport implements HttpServer, I rootContext.addServletMappingDecoded("/", "httpHandlerServlet"); } - @NotNull private ServletHttpHandlerAdapter initServletHttpHandlerAdapter() { if (getHttpHandlerMap() != null) { return new ServletHttpHandlerAdapter(getHttpHandlerMap()); diff --git a/spring-web/src/test/java/org/springframework/web/bind/WebExchangeDataBinderTests.java b/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java similarity index 98% rename from spring-web/src/test/java/org/springframework/web/bind/WebExchangeDataBinderTests.java rename to spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java index 5cd54066bf1..014df311609 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/WebExchangeDataBinderTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.web.bind; + +package org.springframework.web.bind.support; import java.beans.PropertyEditorSupport; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Iterator; -import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; @@ -227,7 +227,6 @@ public class WebExchangeDataBinderTests { return builder.toString(); } - @NotNull private ServerWebExchange createExchange() { return new DefaultServerWebExchange( this.request, new MockServerHttpResponse(), new DefaultWebSessionManager());