From 793638e610fa01cfffa53e1edcab56c98b2d5751 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 26 May 2016 17:48:35 -0400 Subject: [PATCH] Rename ViewResolverResultHandler to ViewResolution~ --- .../annotation/ResponseBodyResultHandler.java | 3 ++- ....java => ViewResolutionResultHandler.java} | 21 +++++++++------ .../reactive/result/view/ViewResolver.java | 6 ++--- .../RequestMappingIntegrationTests.java | 6 ++--- ... => ViewResolutionResultHandlerTests.java} | 26 +++++++++---------- 5 files changed, 34 insertions(+), 28 deletions(-) rename spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/{ViewResolverResultHandler.java => ViewResolutionResultHandler.java} (87%) rename spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/{ViewResolverResultHandlerTests.java => ViewResolutionResultHandlerTests.java} (90%) diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandler.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandler.java index 5cc5fa3960..8a64f6c86c 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandler.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandler.java @@ -92,7 +92,8 @@ public class ResponseBodyResultHandler implements HandlerResultHandler, Ordered * {@code RequestedContentTypeResolver}. * * @param messageConverters converters for writing the response body with - * @param conversionService for converting to Flux and Mono from other reactive types + * @param conversionService for converting other reactive types (e.g. + * rx.Observable, rx.Single, etc.) to Flux or Mono */ public ResponseBodyResultHandler(List> messageConverters, ConversionService conversionService, RequestedContentTypeResolver contentTypeResolver) { diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverResultHandler.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java similarity index 87% rename from spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverResultHandler.java rename to spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java index 51cfc1d5de..93f11c57dc 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverResultHandler.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java @@ -36,17 +36,17 @@ import org.springframework.web.server.ServerWebExchange; /** - * {@code HandlerResultHandler} that resolves a String return value from a - * handler to a {@link View} which is then used to render the response. - * A handler may also return a {@code View} instance and/or async variants that - * provide a String view name or a {@code View}. + * {@code HandlerResultHandler} that performs view resolution by resolving a + * {@link View} instance first and then rendering the response with it. + * If the return value is a String, the configured {@link ViewResolver}s will + * be consulted to resolve that to a {@link View} instance. * - *

This result handler should be ordered after others that may also interpret - * a String return value for example in combination with {@code @ResponseBody}. + *

This result handler should be ordered late relative to other result + * handlers. See {@link #setOrder(int)} for more details. * * @author Rossen Stoyanchev */ -public class ViewResolverResultHandler implements HandlerResultHandler, Ordered { +public class ViewResolutionResultHandler implements HandlerResultHandler, Ordered { private final List viewResolvers = new ArrayList<>(4); @@ -55,7 +55,12 @@ public class ViewResolverResultHandler implements HandlerResultHandler, Ordered private int order = Ordered.LOWEST_PRECEDENCE; - public ViewResolverResultHandler(List resolvers, ConversionService service) { + /** + * Constructor with {@code ViewResolver}s tand a {@code ConversionService}. + * @param resolvers the resolver to use + * @param service for converting other reactive types (e.g. rx.Single) to Mono + */ + public ViewResolutionResultHandler(List resolvers, ConversionService service) { Assert.notEmpty(resolvers, "At least one ViewResolver is required."); Assert.notNull(service, "'conversionService' is required."); this.viewResolvers.addAll(resolvers); diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolver.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolver.java index 4ba8e38669..f275f2bf42 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolver.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolver.java @@ -10,11 +10,11 @@ import reactor.core.publisher.Mono; * *

The process of view resolution is driven through a ViewResolver-based * {@code HandlerResultHandler} implementation called - * {@link org.springframework.web.reactive.result.view.ViewResolverResultHandler - * ViewResolverResultHandler}. + * {@link ViewResolutionResultHandler + * ViewResolutionResultHandler}. * * @author Rossen Stoyanchev - * @see org.springframework.web.reactive.result.view.ViewResolverResultHandler + * @see ViewResolutionResultHandler */ public interface ViewResolver { diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java index 0e38a43b6b..c866052e9d 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java @@ -76,8 +76,8 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.DispatcherHandler; import org.springframework.web.reactive.result.SimpleResultHandler; +import org.springframework.web.reactive.result.view.ViewResolutionResultHandler; import org.springframework.web.reactive.result.view.ViewResolver; -import org.springframework.web.reactive.result.view.ViewResolverResultHandler; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; @@ -424,9 +424,9 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati } @Bean - public ViewResolverResultHandler viewResolverResultHandler() { + public ViewResolutionResultHandler viewResolverResultHandler() { List resolvers = Collections.singletonList(freeMarkerViewResolver()); - return new ViewResolverResultHandler(resolvers, conversionService()); + return new ViewResolutionResultHandler(resolvers, conversionService()); } @Bean diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolverResultHandlerTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java similarity index 90% rename from spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolverResultHandlerTests.java rename to spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java index 1da4de85a9..ce8373647f 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolverResultHandlerTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java @@ -63,10 +63,10 @@ import static org.mockito.Mockito.mock; /** - * Unit tests for {@link ViewResolverResultHandler}. + * Unit tests for {@link ViewResolutionResultHandler}. * @author Rossen Stoyanchev */ -public class ViewResolverResultHandlerTests { +public class ViewResolutionResultHandlerTests { private static final Charset UTF_8 = Charset.forName("UTF-8"); @@ -107,7 +107,7 @@ public class ViewResolverResultHandlerTests { ResolvableType returnType = ResolvableType.forMethodParameter(method, -1); HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.model); List resolvers = Collections.singletonList(mock(ViewResolver.class)); - ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); + ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService); assertTrue(handler.supports(result)); } @@ -115,7 +115,7 @@ public class ViewResolverResultHandlerTests { public void viewReference() throws Exception { TestView view = new TestView("account"); List resolvers = Collections.singletonList(mock(ViewResolver.class)); - ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); + ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService); handle(handler, view, ResolvableType.forClass(View.class)); new TestSubscriber().bindTo(this.response.getBody()) @@ -126,7 +126,7 @@ public class ViewResolverResultHandlerTests { public void viewReferenceMono() throws Exception { TestView view = new TestView("account"); List resolvers = Collections.singletonList(mock(ViewResolver.class)); - ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); + ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService); handle(handler, Mono.just(view), methodReturnType("handleMonoView")); new TestSubscriber().bindTo(this.response.getBody()) @@ -138,7 +138,7 @@ public class ViewResolverResultHandlerTests { TestView view = new TestView("account"); TestViewResolver resolver = new TestViewResolver().addView(view); List resolvers = Collections.singletonList(resolver); - ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); + ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService); handle(handler, "account", ResolvableType.forClass(String.class)); TestSubscriber subscriber = new TestSubscriber<>(); @@ -151,7 +151,7 @@ public class ViewResolverResultHandlerTests { TestView view = new TestView("account"); TestViewResolver resolver = new TestViewResolver().addView(view); List resolvers = Collections.singletonList(resolver); - ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); + ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService); handle(handler, Mono.just("account"), methodReturnType("handleMonoString")); new TestSubscriber().bindTo(this.response.getBody()) @@ -165,7 +165,7 @@ public class ViewResolverResultHandlerTests { TestViewResolver resolver1 = new TestViewResolver().addView(view1); TestViewResolver resolver2 = new TestViewResolver().addView(view2); List resolvers = Arrays.asList(resolver1, resolver2); - ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); + ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService); handle(handler, "profile", ResolvableType.forClass(String.class)); new TestSubscriber().bindTo(this.response.getBody()) @@ -175,7 +175,7 @@ public class ViewResolverResultHandlerTests { @Test public void viewNameWithNoMatch() throws Exception { List resolvers = Collections.singletonList(mock(ViewResolver.class)); - ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); + ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService); TestSubscriber subscriber = handle(handler, "account", ResolvableType.forClass(String.class)); subscriber.assertNoValues(); @@ -184,7 +184,7 @@ public class ViewResolverResultHandlerTests { @Test public void viewNameNotSpecified() throws Exception { List resolvers = Collections.singletonList(mock(ViewResolver.class)); - ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); + ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService); TestSubscriber subscriber = handle(handler, null, ResolvableType.forClass(String.class)); subscriber.assertErrorWith(ex -> @@ -196,7 +196,7 @@ public class ViewResolverResultHandlerTests { TestView view = new TestView("account"); TestViewResolver resolver = new TestViewResolver().addView(view); List resolvers = Collections.singletonList(resolver); - HandlerResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService) { + HandlerResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService) { @Override protected String getDefaultViewName(ServerWebExchange exchange, HandlerResult result) { return "account"; @@ -218,8 +218,8 @@ public class ViewResolverResultHandlerTests { resolver1.setOrder(2); resolver2.setOrder(1); - ViewResolverResultHandler resultHandler = - new ViewResolverResultHandler(resolvers, this.conversionService); + ViewResolutionResultHandler resultHandler = + new ViewResolutionResultHandler(resolvers, this.conversionService); assertEquals(Arrays.asList(resolver2, resolver1), resultHandler.getViewResolvers()); }