Browse Source

Rename ViewResolverResultHandler to ViewResolution~

pull/1111/head
Rossen Stoyanchev 9 years ago
parent
commit
793638e610
  1. 3
      spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandler.java
  2. 21
      spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java
  3. 6
      spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolver.java
  4. 6
      spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java
  5. 26
      spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java

3
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}. * {@code RequestedContentTypeResolver}.
* *
* @param messageConverters converters for writing the response body with * @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<HttpMessageConverter<?>> messageConverters, public ResponseBodyResultHandler(List<HttpMessageConverter<?>> messageConverters,
ConversionService conversionService, RequestedContentTypeResolver contentTypeResolver) { ConversionService conversionService, RequestedContentTypeResolver contentTypeResolver) {

21
spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverResultHandler.java → 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 * {@code HandlerResultHandler} that performs view resolution by resolving a
* handler to a {@link View} which is then used to render the response. * {@link View} instance first and then rendering the response with it.
* A handler may also return a {@code View} instance and/or async variants that * If the return value is a String, the configured {@link ViewResolver}s will
* provide a String view name or a {@code View}. * be consulted to resolve that to a {@link View} instance.
* *
* <p>This result handler should be ordered after others that may also interpret * <p>This result handler should be ordered late relative to other result
* a String return value for example in combination with {@code @ResponseBody}. * handlers. See {@link #setOrder(int)} for more details.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class ViewResolverResultHandler implements HandlerResultHandler, Ordered { public class ViewResolutionResultHandler implements HandlerResultHandler, Ordered {
private final List<ViewResolver> viewResolvers = new ArrayList<>(4); private final List<ViewResolver> viewResolvers = new ArrayList<>(4);
@ -55,7 +55,12 @@ public class ViewResolverResultHandler implements HandlerResultHandler, Ordered
private int order = Ordered.LOWEST_PRECEDENCE; private int order = Ordered.LOWEST_PRECEDENCE;
public ViewResolverResultHandler(List<ViewResolver> 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<ViewResolver> resolvers, ConversionService service) {
Assert.notEmpty(resolvers, "At least one ViewResolver is required."); Assert.notEmpty(resolvers, "At least one ViewResolver is required.");
Assert.notNull(service, "'conversionService' is required."); Assert.notNull(service, "'conversionService' is required.");
this.viewResolvers.addAll(resolvers); this.viewResolvers.addAll(resolvers);

6
spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolver.java

@ -10,11 +10,11 @@ import reactor.core.publisher.Mono;
* *
* <p>The process of view resolution is driven through a ViewResolver-based * <p>The process of view resolution is driven through a ViewResolver-based
* {@code HandlerResultHandler} implementation called * {@code HandlerResultHandler} implementation called
* {@link org.springframework.web.reactive.result.view.ViewResolverResultHandler * {@link ViewResolutionResultHandler
* ViewResolverResultHandler}. * ViewResolutionResultHandler}.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @see org.springframework.web.reactive.result.view.ViewResolverResultHandler * @see ViewResolutionResultHandler
*/ */
public interface ViewResolver { public interface ViewResolver {

6
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.client.RestTemplate;
import org.springframework.web.reactive.DispatcherHandler; import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.reactive.result.SimpleResultHandler; 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.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.FreeMarkerConfigurer;
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
@ -424,9 +424,9 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
} }
@Bean @Bean
public ViewResolverResultHandler viewResolverResultHandler() { public ViewResolutionResultHandler viewResolverResultHandler() {
List<ViewResolver> resolvers = Collections.singletonList(freeMarkerViewResolver()); List<ViewResolver> resolvers = Collections.singletonList(freeMarkerViewResolver());
return new ViewResolverResultHandler(resolvers, conversionService()); return new ViewResolutionResultHandler(resolvers, conversionService());
} }
@Bean @Bean

26
spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolverResultHandlerTests.java → 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 * @author Rossen Stoyanchev
*/ */
public class ViewResolverResultHandlerTests { public class ViewResolutionResultHandlerTests {
private static final Charset UTF_8 = Charset.forName("UTF-8"); private static final Charset UTF_8 = Charset.forName("UTF-8");
@ -107,7 +107,7 @@ public class ViewResolverResultHandlerTests {
ResolvableType returnType = ResolvableType.forMethodParameter(method, -1); ResolvableType returnType = ResolvableType.forMethodParameter(method, -1);
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.model); HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.model);
List<ViewResolver> resolvers = Collections.singletonList(mock(ViewResolver.class)); List<ViewResolver> resolvers = Collections.singletonList(mock(ViewResolver.class));
ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService);
assertTrue(handler.supports(result)); assertTrue(handler.supports(result));
} }
@ -115,7 +115,7 @@ public class ViewResolverResultHandlerTests {
public void viewReference() throws Exception { public void viewReference() throws Exception {
TestView view = new TestView("account"); TestView view = new TestView("account");
List<ViewResolver> resolvers = Collections.singletonList(mock(ViewResolver.class)); List<ViewResolver> 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)); handle(handler, view, ResolvableType.forClass(View.class));
new TestSubscriber<DataBuffer>().bindTo(this.response.getBody()) new TestSubscriber<DataBuffer>().bindTo(this.response.getBody())
@ -126,7 +126,7 @@ public class ViewResolverResultHandlerTests {
public void viewReferenceMono() throws Exception { public void viewReferenceMono() throws Exception {
TestView view = new TestView("account"); TestView view = new TestView("account");
List<ViewResolver> resolvers = Collections.singletonList(mock(ViewResolver.class)); List<ViewResolver> 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")); handle(handler, Mono.just(view), methodReturnType("handleMonoView"));
new TestSubscriber<DataBuffer>().bindTo(this.response.getBody()) new TestSubscriber<DataBuffer>().bindTo(this.response.getBody())
@ -138,7 +138,7 @@ public class ViewResolverResultHandlerTests {
TestView view = new TestView("account"); TestView view = new TestView("account");
TestViewResolver resolver = new TestViewResolver().addView(view); TestViewResolver resolver = new TestViewResolver().addView(view);
List<ViewResolver> resolvers = Collections.singletonList(resolver); List<ViewResolver> 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)); handle(handler, "account", ResolvableType.forClass(String.class));
TestSubscriber<DataBuffer> subscriber = new TestSubscriber<>(); TestSubscriber<DataBuffer> subscriber = new TestSubscriber<>();
@ -151,7 +151,7 @@ public class ViewResolverResultHandlerTests {
TestView view = new TestView("account"); TestView view = new TestView("account");
TestViewResolver resolver = new TestViewResolver().addView(view); TestViewResolver resolver = new TestViewResolver().addView(view);
List<ViewResolver> resolvers = Collections.singletonList(resolver); List<ViewResolver> 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")); handle(handler, Mono.just("account"), methodReturnType("handleMonoString"));
new TestSubscriber<DataBuffer>().bindTo(this.response.getBody()) new TestSubscriber<DataBuffer>().bindTo(this.response.getBody())
@ -165,7 +165,7 @@ public class ViewResolverResultHandlerTests {
TestViewResolver resolver1 = new TestViewResolver().addView(view1); TestViewResolver resolver1 = new TestViewResolver().addView(view1);
TestViewResolver resolver2 = new TestViewResolver().addView(view2); TestViewResolver resolver2 = new TestViewResolver().addView(view2);
List<ViewResolver> resolvers = Arrays.asList(resolver1, resolver2); List<ViewResolver> 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)); handle(handler, "profile", ResolvableType.forClass(String.class));
new TestSubscriber<DataBuffer>().bindTo(this.response.getBody()) new TestSubscriber<DataBuffer>().bindTo(this.response.getBody())
@ -175,7 +175,7 @@ public class ViewResolverResultHandlerTests {
@Test @Test
public void viewNameWithNoMatch() throws Exception { public void viewNameWithNoMatch() throws Exception {
List<ViewResolver> resolvers = Collections.singletonList(mock(ViewResolver.class)); List<ViewResolver> resolvers = Collections.singletonList(mock(ViewResolver.class));
ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService);
TestSubscriber<Void> subscriber = handle(handler, "account", ResolvableType.forClass(String.class)); TestSubscriber<Void> subscriber = handle(handler, "account", ResolvableType.forClass(String.class));
subscriber.assertNoValues(); subscriber.assertNoValues();
@ -184,7 +184,7 @@ public class ViewResolverResultHandlerTests {
@Test @Test
public void viewNameNotSpecified() throws Exception { public void viewNameNotSpecified() throws Exception {
List<ViewResolver> resolvers = Collections.singletonList(mock(ViewResolver.class)); List<ViewResolver> resolvers = Collections.singletonList(mock(ViewResolver.class));
ViewResolverResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService); ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService);
TestSubscriber<Void> subscriber = handle(handler, null, ResolvableType.forClass(String.class)); TestSubscriber<Void> subscriber = handle(handler, null, ResolvableType.forClass(String.class));
subscriber.assertErrorWith(ex -> subscriber.assertErrorWith(ex ->
@ -196,7 +196,7 @@ public class ViewResolverResultHandlerTests {
TestView view = new TestView("account"); TestView view = new TestView("account");
TestViewResolver resolver = new TestViewResolver().addView(view); TestViewResolver resolver = new TestViewResolver().addView(view);
List<ViewResolver> resolvers = Collections.singletonList(resolver); List<ViewResolver> resolvers = Collections.singletonList(resolver);
HandlerResultHandler handler = new ViewResolverResultHandler(resolvers, this.conversionService) { HandlerResultHandler handler = new ViewResolutionResultHandler(resolvers, this.conversionService) {
@Override @Override
protected String getDefaultViewName(ServerWebExchange exchange, HandlerResult result) { protected String getDefaultViewName(ServerWebExchange exchange, HandlerResult result) {
return "account"; return "account";
@ -218,8 +218,8 @@ public class ViewResolverResultHandlerTests {
resolver1.setOrder(2); resolver1.setOrder(2);
resolver2.setOrder(1); resolver2.setOrder(1);
ViewResolverResultHandler resultHandler = ViewResolutionResultHandler resultHandler =
new ViewResolverResultHandler(resolvers, this.conversionService); new ViewResolutionResultHandler(resolvers, this.conversionService);
assertEquals(Arrays.asList(resolver2, resolver1), resultHandler.getViewResolvers()); assertEquals(Arrays.asList(resolver2, resolver1), resultHandler.getViewResolvers());
} }
Loading…
Cancel
Save