Browse Source

Handle unresolved view name

pull/1111/head
Rossen Stoyanchev 9 years ago
parent
commit
33c5a19769
  1. 6
      spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java
  2. 5
      spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java

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

@ -151,6 +151,7 @@ public class ViewResolutionResultHandler implements HandlerResultHandler, Ordere @@ -151,6 +151,7 @@ public class ViewResolutionResultHandler implements HandlerResultHandler, Ordere
return Flux.fromIterable(getViewResolvers())
.concatMap(resolver -> resolver.resolveViewName(viewName, locale))
.next()
.otherwiseIfEmpty(handleUnresolvedViewName(viewName))
.then(view -> {
Flux<DataBuffer> body = view.render(result, null, exchange);
return exchange.getResponse().setBody(body);
@ -201,4 +202,9 @@ public class ViewResolutionResultHandler implements HandlerResultHandler, Ordere @@ -201,4 +202,9 @@ public class ViewResolutionResultHandler implements HandlerResultHandler, Ordere
return StringUtils.stripFilenameExtension(path);
}
private Mono<View> handleUnresolvedViewName(String viewName) {
return Mono.error(new IllegalStateException(
"Could not resolve view with name '" + viewName + "'."));
}
}

5
spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java

@ -154,9 +154,8 @@ public class ViewResolutionResultHandlerTests { @@ -154,9 +154,8 @@ public class ViewResolutionResultHandlerTests {
@Test
public void viewNameUnresolved() throws Exception {
TestSubscriber<Void> subscriber = handle("/path", "account", ResolvableType.forClass(String.class));
subscriber.assertNoValues();
handle("/path", "account", ResolvableType.forClass(String.class))
.assertErrorMessage("Could not resolve view with name 'account'.");
}
@Test

Loading…
Cancel
Save