Browse Source

Remove java.util.Optional from View contract

pull/1111/head
Rossen Stoyanchev 9 years ago
parent
commit
bc782902d7
  1. 6
      spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java
  2. 2
      spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/View.java
  3. 4
      spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverResultHandler.java
  4. 4
      spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolverResultHandlerTests.java
  5. 2
      spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java

6
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 * @return
*/ */
@Override @Override
public Flux<DataBuffer> render(HandlerResult result, Optional<MediaType> contentType, public Flux<DataBuffer> render(HandlerResult result, MediaType contentType,
ServerWebExchange exchange) { ServerWebExchange exchange) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Rendering view with model " + result.getModel()); logger.trace("Rendering view with model " + result.getModel());
} }
if (contentType.isPresent()) { if (contentType != null) {
exchange.getResponse().getHeaders().setContentType(contentType.get()); exchange.getResponse().getHeaders().setContentType(contentType);
} }
Map<String, Object> mergedModel = getModelAttributes(result, exchange); Map<String, Object> mergedModel = getModelAttributes(result, exchange);

2
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 * @param exchange the current exchange
* @return the output stream * @return the output stream
*/ */
Flux<DataBuffer> render(HandlerResult result, Optional<MediaType> contentType, ServerWebExchange exchange); Flux<DataBuffer> render(HandlerResult result, MediaType contentType, ServerWebExchange exchange);
} }

4
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 -> { return returnValueMono.then(returnValue -> {
if (returnValue instanceof View) { if (returnValue instanceof View) {
Flux<DataBuffer> body = ((View) returnValue).render(result, Optional.empty(), exchange); Flux<DataBuffer> body = ((View) returnValue).render(result, null, exchange);
return exchange.getResponse().setBody(body); return exchange.getResponse().setBody(body);
} }
else if (returnValue instanceof CharSequence) { else if (returnValue instanceof CharSequence) {
@ -131,7 +131,7 @@ public class ViewResolverResultHandler implements HandlerResultHandler, Ordered
.concatMap(resolver -> resolver.resolveViewName(viewName, locale)) .concatMap(resolver -> resolver.resolveViewName(viewName, locale))
.next() .next()
.then(view -> { .then(view -> {
Flux<DataBuffer> body = view.render(result, Optional.empty(), exchange); Flux<DataBuffer> body = view.render(result, null, exchange);
return exchange.getResponse().setBody(body); return exchange.getResponse().setBody(body);
}); });
} }

4
spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolverResultHandlerTests.java

@ -277,9 +277,7 @@ public class ViewResolverResultHandlerTests {
} }
@Override @Override
public Flux<DataBuffer> render(HandlerResult result, Optional<MediaType> contentType, public Flux<DataBuffer> render(HandlerResult result, MediaType mediaType, ServerWebExchange exchange) {
ServerWebExchange exchange) {
String value = this.name + ": " + result.getModel().toString(); String value = this.name + ": " + result.getModel().toString();
assertNotNull(value); assertNotNull(value);
return Flux.just(asDataBuffer(value)); return Flux.just(asDataBuffer(value));

2
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(); ModelMap model = new ExtendedModelMap();
model.addAttribute("hello", "hi FreeMarker"); model.addAttribute("hello", "hi FreeMarker");
HandlerResult result = new HandlerResult(new Object(), "", ResolvableType.NONE, model); HandlerResult result = new HandlerResult(new Object(), "", ResolvableType.NONE, model);
Flux<DataBuffer> flux = view.render(result, Optional.empty(), this.exchange); Flux<DataBuffer> flux = view.render(result, null, this.exchange);
TestSubscriber<DataBuffer> subscriber = new TestSubscriber<>(); TestSubscriber<DataBuffer> subscriber = new TestSubscriber<>();
subscriber.bindTo(flux).assertValuesWith(dataBuffer -> subscriber.bindTo(flux).assertValuesWith(dataBuffer ->

Loading…
Cancel
Save