From 03a997c9d4ce6815d3a07c4d4b20b3f18554ed7c Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 1 Jun 2016 18:07:54 -0400 Subject: [PATCH] Remove outdated DataBufferFactory properties Removed in favor of accessing the factory from the response. --- .../reactive/result/view/AbstractView.java | 23 ------------------- .../result/view/UrlBasedViewResolver.java | 1 - .../result/view/ViewResolverSupport.java | 21 ----------------- .../view/freemarker/FreeMarkerView.java | 2 +- .../RequestMappingIntegrationTests.java | 13 ++++------- 5 files changed, 6 insertions(+), 54 deletions(-) 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 7e882596f7..b56f721a59 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 @@ -23,14 +23,10 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferFactory; -import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.MediaType; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; @@ -49,8 +45,6 @@ public abstract class AbstractView implements View, ApplicationContextAware { private final List mediaTypes = new ArrayList<>(4); - private DataBufferFactory bufferAllocator = new DefaultDataBufferFactory(); - private ApplicationContext applicationContext; @@ -79,23 +73,6 @@ public abstract class AbstractView implements View, ApplicationContextAware { return this.mediaTypes; } - /** - * Configure the {@link DataBufferFactory} to use for write I/O. - *

By default this is set to {@link DefaultDataBufferFactory}. - * @param bufferAllocator the factory to use - */ - public void setBufferAllocator(DataBufferFactory bufferAllocator) { - Assert.notNull(bufferAllocator, "'bufferAllocator' is required."); - this.bufferAllocator = bufferAllocator; - } - - /** - * Return the configured buffer factory, never {@code null}. - */ - public DataBufferFactory getBufferAllocator() { - return this.bufferAllocator; - } - @Override public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java index 651205f385..510886fdac 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java @@ -193,7 +193,6 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements ViewRes protected AbstractUrlBasedView createUrlBasedView(String viewName) { AbstractUrlBasedView view = (AbstractUrlBasedView) BeanUtils.instantiateClass(getViewClass()); view.setSupportedMediaTypes(getSupportedMediaTypes()); - view.setBufferAllocator(getBufferAllocator()); view.setUrl(getPrefix() + viewName + getSuffix()); return view; } diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java index 9d334dbaba..7c38a1fc12 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java @@ -22,8 +22,6 @@ import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.Ordered; -import org.springframework.core.io.buffer.DataBufferFactory; -import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.MediaType; import org.springframework.util.Assert; @@ -40,8 +38,6 @@ public abstract class ViewResolverSupport implements ApplicationContextAware, Or private List mediaTypes = new ArrayList<>(4); - private DataBufferFactory bufferAllocator = new DefaultDataBufferFactory(); - private ApplicationContext applicationContext; private int order = Integer.MAX_VALUE; @@ -71,23 +67,6 @@ public abstract class ViewResolverSupport implements ApplicationContextAware, Or return this.mediaTypes; } - /** - * Configure the {@link DataBufferFactory} to use for write I/O. - *

By default this is set to {@link DefaultDataBufferFactory}. - * @param bufferAllocator the factory to use - */ - public void setBufferAllocator(DataBufferFactory bufferAllocator) { - Assert.notNull(bufferAllocator, "'bufferAllocator' is required."); - this.bufferAllocator = bufferAllocator; - } - - /** - * Return the configured buffer factory, never {@code null}. - */ - public DataBufferFactory getBufferAllocator() { - return this.bufferAllocator; - } - @Override public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java index 61841172c5..8818d87355 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java @@ -164,7 +164,7 @@ public class FreeMarkerView extends AbstractUrlBasedView { logger.debug("Rendering FreeMarker template [" + getUrl() + "]."); } Locale locale = Locale.getDefault(); // TODO - DataBuffer dataBuffer = getBufferAllocator().allocateBuffer(); + DataBuffer dataBuffer = exchange.getResponse().bufferFactory().allocateBuffer(); try { Writer writer = new OutputStreamWriter(dataBuffer.asOutputStream()); getTemplate(locale).process(freeMarkerModel, writer); diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java index 561d407395..7ff5e36a67 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java @@ -82,7 +82,9 @@ import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigu import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import static org.junit.Assert.*; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** @@ -382,9 +384,6 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati @SuppressWarnings("unused") static class FrameworkConfig { - private DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); - - @Bean public RequestMappingHandlerMapping handlerMapping() { return new RequestMappingHandlerMapping(); @@ -429,9 +428,7 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati @Bean public ViewResolver freeMarkerViewResolver() { - FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver("", ".ftl"); - viewResolver.setBufferAllocator(this.dataBufferFactory); - return viewResolver; + return new FreeMarkerViewResolver("", ".ftl"); } @Bean @@ -564,7 +561,7 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati @RequestMapping("/stream-create") public Publisher streamCreate(@RequestBody Flux personStream) { - return personStream.toList().doOnSuccess(persons::addAll).then(); + return personStream.asList().doOnSuccess(persons::addAll).then(); } @RequestMapping("/person-capitalize")