diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java index b26fdd0d28..5593926007 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java @@ -114,15 +114,15 @@ public abstract class AbstractView implements View, ApplicationContextAware { * @return */ @Override - public Flux render(HandlerResult result, Optional contentType, + public Flux render(HandlerResult result, MediaType contentType, ServerWebExchange exchange) { if (logger.isTraceEnabled()) { logger.trace("Rendering view with model " + result.getModel()); } - if (contentType.isPresent()) { - exchange.getResponse().getHeaders().setContentType(contentType.get()); + if (contentType != null) { + exchange.getResponse().getHeaders().setContentType(contentType); } Map mergedModel = getModelAttributes(result, exchange); diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/View.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/View.java index b9b82f6faa..cfc9866ba5 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/View.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/View.java @@ -55,6 +55,6 @@ public interface View { * @param exchange the current exchange * @return the output stream */ - Flux render(HandlerResult result, Optional contentType, ServerWebExchange exchange); + Flux render(HandlerResult result, MediaType contentType, ServerWebExchange exchange); } 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/ViewResolverResultHandler.java index 1ea8a1b5c1..4b3ed3639a 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/ViewResolverResultHandler.java @@ -121,7 +121,7 @@ public class ViewResolverResultHandler implements HandlerResultHandler, Ordered return returnValueMono.then(returnValue -> { if (returnValue instanceof View) { - Flux body = ((View) returnValue).render(result, Optional.empty(), exchange); + Flux body = ((View) returnValue).render(result, null, exchange); return exchange.getResponse().setBody(body); } else if (returnValue instanceof CharSequence) { @@ -131,7 +131,7 @@ public class ViewResolverResultHandler implements HandlerResultHandler, Ordered .concatMap(resolver -> resolver.resolveViewName(viewName, locale)) .next() .then(view -> { - Flux body = view.render(result, Optional.empty(), exchange); + Flux body = view.render(result, null, exchange); return exchange.getResponse().setBody(body); }); } 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/ViewResolverResultHandlerTests.java index 1208a8e1ae..23c6a1eaf8 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/ViewResolverResultHandlerTests.java @@ -277,9 +277,7 @@ public class ViewResolverResultHandlerTests { } @Override - public Flux render(HandlerResult result, Optional contentType, - ServerWebExchange exchange) { - + public Flux render(HandlerResult result, MediaType mediaType, ServerWebExchange exchange) { String value = this.name + ": " + result.getModel().toString(); assertNotNull(value); return Flux.just(asDataBuffer(value)); diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java index 7d705a0ac0..bb28907238 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java @@ -127,7 +127,7 @@ public class FreeMarkerViewTests { ModelMap model = new ExtendedModelMap(); model.addAttribute("hello", "hi FreeMarker"); HandlerResult result = new HandlerResult(new Object(), "", ResolvableType.NONE, model); - Flux flux = view.render(result, Optional.empty(), this.exchange); + Flux flux = view.render(result, null, this.exchange); TestSubscriber subscriber = new TestSubscriber<>(); subscriber.bindTo(flux).assertValuesWith(dataBuffer ->