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 { @@ -114,15 +114,15 @@ public abstract class AbstractView implements View, ApplicationContextAware {
* @return
*/
@Override
public Flux<DataBuffer> render(HandlerResult result, Optional<MediaType> contentType,
public Flux<DataBuffer> 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<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 { @@ -55,6 +55,6 @@ public interface View {
* @param exchange the current exchange
* @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 @@ -121,7 +121,7 @@ public class ViewResolverResultHandler implements HandlerResultHandler, Ordered
return returnValueMono.then(returnValue -> {
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);
}
else if (returnValue instanceof CharSequence) {
@ -131,7 +131,7 @@ public class ViewResolverResultHandler implements HandlerResultHandler, Ordered @@ -131,7 +131,7 @@ public class ViewResolverResultHandler implements HandlerResultHandler, Ordered
.concatMap(resolver -> resolver.resolveViewName(viewName, locale))
.next()
.then(view -> {
Flux<DataBuffer> body = view.render(result, Optional.empty(), exchange);
Flux<DataBuffer> body = view.render(result, null, exchange);
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 { @@ -277,9 +277,7 @@ public class ViewResolverResultHandlerTests {
}
@Override
public Flux<DataBuffer> render(HandlerResult result, Optional<MediaType> contentType,
ServerWebExchange exchange) {
public Flux<DataBuffer> render(HandlerResult result, MediaType mediaType, ServerWebExchange exchange) {
String value = this.name + ": " + result.getModel().toString();
assertNotNull(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 { @@ -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<DataBuffer> flux = view.render(result, Optional.empty(), this.exchange);
Flux<DataBuffer> flux = view.render(result, null, this.exchange);
TestSubscriber<DataBuffer> subscriber = new TestSubscriber<>();
subscriber.bindTo(flux).assertValuesWith(dataBuffer ->

Loading…
Cancel
Save