diff --git a/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java b/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java index fb6b06150b..0eaa89515d 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java @@ -22,6 +22,7 @@ import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferAllocator; /** * A "reactive" HTTP output message that accepts output as a {@link Publisher}. @@ -48,4 +49,11 @@ public interface ReactiveHttpOutputMessage extends HttpMessage { */ Mono setBody(Publisher body); + /** + * Returns a {@link DataBufferAllocator} that can be used for creating the body. + * @return a buffer allocator + * @see #setBody(Publisher) + */ + DataBufferAllocator allocator(); + } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java index 5ff05bc20d..4179184c28 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java @@ -61,6 +61,11 @@ public class ReactorClientHttpRequest extends AbstractClientHttpRequest { this.httpClient = httpClient; } + @Override + public DataBufferAllocator allocator() { + return this.allocator; + } + @Override public HttpMethod getMethod() { return this.httpMethod; diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpRequest.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpRequest.java index 7ab96b37c6..16887b0225 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpRequest.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpRequest.java @@ -17,7 +17,6 @@ package org.springframework.http.client.reactive; import java.net.URI; -import java.util.Collection; import java.util.List; import java.util.Map; @@ -32,6 +31,7 @@ import reactor.core.publisher.Mono; import rx.Observable; import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferAllocator; import org.springframework.core.io.buffer.NettyDataBufferAllocator; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; @@ -60,6 +60,11 @@ public class RxNettyClientHttpRequest extends AbstractClientHttpRequest { this.allocator = allocator; } + @Override + public DataBufferAllocator allocator() { + return this.allocator; + } + /** * Set the body of the message to the given {@link Publisher}. * diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java index 91eff4024e..a06bf640c3 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.server.reactive; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferAllocator; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseCookie; import org.springframework.util.Assert; @@ -39,32 +41,48 @@ import org.springframework.util.MultiValueMap; */ public abstract class AbstractServerHttpResponse implements ServerHttpResponse { + private static final int STATE_NEW = 1; + + private static final int STATE_COMMITTING = 2; + + private static final int STATE_COMMITTED = 3; + private final HttpHeaders headers; private final MultiValueMap cookies; - private AtomicReference state = new AtomicReference<>(State.NEW); + private final AtomicInteger state = new AtomicInteger(STATE_NEW); private final List>> beforeCommitActions = new ArrayList<>(4); + private final DataBufferAllocator allocator; - protected AbstractServerHttpResponse() { + public AbstractServerHttpResponse(DataBufferAllocator allocator) { + Assert.notNull(allocator, "'allocator' must not be null"); + + this.allocator = allocator; this.headers = new HttpHeaders(); this.cookies = new LinkedMultiValueMap(); } + @Override + public final DataBufferAllocator allocator() { + return this.allocator; + } @Override public HttpHeaders getHeaders() { - if (State.COMITTED.equals(this.state.get())) { + if (STATE_COMMITTED == this.state.get()) { return HttpHeaders.readOnlyHttpHeaders(this.headers); } - return this.headers; + else { + return this.headers; + } } @Override public MultiValueMap getCookies() { - if (State.COMITTED.equals(this.state.get())) { + if (STATE_COMMITTED == this.state.get()) { return CollectionUtils.unmodifiableMultiValueMap(this.cookies); } return this.cookies; @@ -78,16 +96,16 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse { private Mono applyBeforeCommit() { Mono mono = Mono.empty(); - if (this.state.compareAndSet(State.NEW, State.COMMITTING)) { + if (this.state.compareAndSet(STATE_NEW, STATE_COMMITTING)) { for (Supplier> action : this.beforeCommitActions) { - mono = mono.after(() -> action.get()); + mono = mono.after(action); } mono = mono.otherwise(ex -> { // Ignore errors from beforeCommit actions return Mono.empty(); }); mono = mono.after(() -> { - this.state.set(State.COMITTED); + this.state.set(STATE_COMMITTED); writeHeaders(); writeCookies(); return Mono.empty(); @@ -125,7 +143,4 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse { return applyBeforeCommit(); } - - private enum State { NEW, COMMITTING, COMITTED } - } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java index cf7136a4fa..7c5442b805 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.server.reactive; import reactor.core.publisher.Mono; @@ -44,7 +45,8 @@ public class ReactorHttpHandlerAdapter public Mono apply(HttpChannel channel) { ReactorServerHttpRequest adaptedRequest = new ReactorServerHttpRequest(channel, allocator); - ReactorServerHttpResponse adaptedResponse = new ReactorServerHttpResponse(channel); + ReactorServerHttpResponse adaptedResponse = + new ReactorServerHttpResponse(channel, allocator); return this.httpHandler.handle(adaptedRequest, adaptedResponse); } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java index e2f220c137..8951934d55 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.server.reactive; import java.time.Duration; @@ -27,6 +28,7 @@ import reactor.io.netty.http.model.Cookie; import reactor.io.netty.http.model.Status; import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferAllocator; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; import org.springframework.util.Assert; @@ -41,8 +43,9 @@ public class ReactorServerHttpResponse extends AbstractServerHttpResponse { private final HttpChannel channel; - - public ReactorServerHttpResponse(HttpChannel response) { + public ReactorServerHttpResponse(HttpChannel response, + DataBufferAllocator allocator) { + super(allocator); Assert.notNull("'response' must not be null."); this.channel = response; } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java index 6023d34ff7..a3ec1909b1 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java @@ -46,7 +46,8 @@ public class RxNettyHttpHandlerAdapter implements RequestHandler result = this.httpHandler.handle(adaptedRequest, adaptedResponse); return RxJava1ObservableConverter.from(result); } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java index ebcf5fad1b..2d310c93de 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java @@ -29,6 +29,7 @@ import rx.Observable; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.NettyDataBuffer; +import org.springframework.core.io.buffer.NettyDataBufferAllocator; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; import org.springframework.util.Assert; @@ -43,8 +44,11 @@ public class RxNettyServerHttpResponse extends AbstractServerHttpResponse { private final HttpServerResponse response; - public RxNettyServerHttpResponse(HttpServerResponse response) { + public RxNettyServerHttpResponse(HttpServerResponse response, + NettyDataBufferAllocator allocator) { + super(allocator); Assert.notNull("'response', response must not be null."); + this.response = response; } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java index 80b447c43c..1182221df4 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java @@ -82,7 +82,8 @@ public class ServletHttpHandlerAdapter extends HttpServlet { this.bufferSize); ServletServerHttpResponse response = - new ServletServerHttpResponse(synchronizer, this.bufferSize); + new ServletServerHttpResponse(synchronizer, this.bufferSize, + this.allocator); HandlerResultSubscriber resultSubscriber = new HandlerResultSubscriber(synchronizer); diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java index 465a73eff3..35cfbb00fe 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java @@ -34,6 +34,7 @@ import org.reactivestreams.Subscription; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferAllocator; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseCookie; @@ -53,7 +54,8 @@ public class ServletServerHttpResponse extends AbstractServerHttpResponse { private final ResponseBodySubscriber responseBodySubscriber; public ServletServerHttpResponse(ServletAsyncContextSynchronizer synchronizer, - int bufferSize) throws IOException { + int bufferSize, DataBufferAllocator allocator) throws IOException { + super(allocator); Assert.notNull(synchronizer, "'synchronizer' must not be null"); this.response = (HttpServletResponse) synchronizer.getResponse(); @@ -62,7 +64,6 @@ public class ServletServerHttpResponse extends AbstractServerHttpResponse { this.response.getOutputStream().setWriteListener(responseBodySubscriber); } - public HttpServletResponse getServletResponse() { return this.response; } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java index d391f0c5f0..340ac750b0 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java @@ -57,6 +57,7 @@ public class UndertowHttpHandlerAdapter implements io.undertow.server.HttpHandle private final HttpHandler delegate; + // TODO: use UndertowDBA when introduced private final DataBufferAllocator allocator; public UndertowHttpHandlerAdapter(HttpHandler delegate, @@ -76,7 +77,9 @@ public class UndertowHttpHandlerAdapter implements io.undertow.server.HttpHandle ResponseBodySubscriber responseBodySubscriber = new ResponseBodySubscriber(exchange); ServerHttpResponse response = new UndertowServerHttpResponse(exchange, - publisher -> Mono.from(subscriber -> publisher.subscribe(responseBodySubscriber))); + publisher -> Mono + .from(subscriber -> publisher.subscribe(responseBodySubscriber)), + allocator); exchange.dispatch(); diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java index 910f913f70..a10806ca57 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java @@ -28,6 +28,7 @@ import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferAllocator; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; import org.springframework.util.Assert; @@ -44,10 +45,10 @@ public class UndertowServerHttpResponse extends AbstractServerHttpResponse { private final Function, Mono> responseBodyWriter; - public UndertowServerHttpResponse(HttpServerExchange exchange, - Function, Mono> responseBodyWriter) { - + Function, Mono> responseBodyWriter, + DataBufferAllocator allocator) { + super(allocator); Assert.notNull(exchange, "'exchange' is required."); Assert.notNull(responseBodyWriter, "'responseBodyWriter' must not be null"); this.exchange = exchange; diff --git a/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/DefaultHttpRequestBuilder.java b/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/DefaultHttpRequestBuilder.java index 5ee4731a12..c6105e2582 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/DefaultHttpRequestBuilder.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/DefaultHttpRequestBuilder.java @@ -30,6 +30,7 @@ import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.codec.Encoder; +import org.springframework.core.io.buffer.DataBufferAllocator; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -146,7 +147,10 @@ public class DefaultHttpRequestBuilder implements HttpRequestBuilder { Optional> messageEncoder = resolveEncoder(requestBodyType, mediaType); if (messageEncoder.isPresent()) { - request.setBody(messageEncoder.get().encode(this.contentPublisher, requestBodyType, mediaType)); + DataBufferAllocator allocator = request.allocator(); + request.setBody(messageEncoder.get() + .encode(this.contentPublisher, allocator, requestBodyType, + mediaType)); } else { // TODO: wrap with client exception? diff --git a/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/WebClient.java b/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/WebClient.java index e6488c1f7b..317048314d 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/WebClient.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/WebClient.java @@ -86,8 +86,8 @@ public final class WebClient { public WebClient(ClientHttpRequestFactory requestFactory) { this.requestFactory = requestFactory; DataBufferAllocator allocator = new DefaultDataBufferAllocator(); - this.messageEncoders = Arrays.asList(new ByteBufferEncoder(allocator), new StringEncoder(allocator), - new JacksonJsonEncoder(allocator)); + this.messageEncoders = Arrays.asList(new ByteBufferEncoder(), new StringEncoder(), + new JacksonJsonEncoder()); this.messageDecoders = Arrays.asList(new ByteBufferDecoder(), new StringDecoder(allocator), new JacksonJsonDecoder(new JsonObjectDecoder())); } diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/method/annotation/ResponseBodyResultHandler.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/method/annotation/ResponseBodyResultHandler.java index 0e5af148dd..10f4470754 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/method/annotation/ResponseBodyResultHandler.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/method/annotation/ResponseBodyResultHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.codec.Encoder; import org.springframework.core.convert.ConversionService; +import org.springframework.core.io.buffer.DataBufferAllocator; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; @@ -192,7 +193,10 @@ public class ResponseBodyResultHandler implements HandlerResultHandler, Ordered if (encoder != null) { ServerHttpResponse response = exchange.getResponse(); response.getHeaders().setContentType(selectedMediaType); - return response.setBody(encoder.encode((Publisher) publisher, elementType, selectedMediaType)); + DataBufferAllocator allocator = response.allocator(); + return response.setBody( + encoder.encode((Publisher) publisher, allocator, elementType, + selectedMediaType)); } } diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java index 42a672ce8d..75a54e0415 100644 --- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java +++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.server.reactive; import java.util.function.Supplier; @@ -22,6 +23,8 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DefaultDataBufferAllocator; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; @@ -41,6 +44,8 @@ public class MockServerHttpResponse implements ServerHttpResponse { private Publisher body; + private DataBufferAllocator allocator = new DefaultDataBufferAllocator(); + @Override public void setStatusCode(HttpStatus status) { @@ -80,4 +85,9 @@ public class MockServerHttpResponse implements ServerHttpResponse { return Mono.empty(); } + @Override + public DataBufferAllocator allocator() { + return this.allocator; + } + } diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java index dc2f5bf1b3..6b2977598f 100644 --- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.server.reactive; import java.nio.ByteBuffer; @@ -31,10 +32,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; /** * @author Rossen Stoyanchev @@ -147,6 +145,9 @@ public class ServerHttpResponseTests { private final List content = new ArrayList<>(); + public TestServerHttpResponse() { + super(new DefaultDataBufferAllocator()); + } @Override public void setStatusCode(HttpStatus status) { diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java index 21adec20d7..92617fda03 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java @@ -232,8 +232,7 @@ public class DispatcherHandlerErrorTests { @Bean public ResponseBodyResultHandler resultHandler() { - List> encoders = Collections - .singletonList(new StringEncoder(new DefaultDataBufferAllocator())); + List> encoders = Collections.singletonList(new StringEncoder()); return new ResponseBodyResultHandler(encoders, new DefaultConversionService()); } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/method/annotation/RequestMappingIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/method/annotation/RequestMappingIntegrationTests.java index 250dcc6645..2ecc53a10c 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/method/annotation/RequestMappingIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/method/annotation/RequestMappingIntegrationTests.java @@ -379,9 +379,8 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati @Bean public ResponseBodyResultHandler responseBodyResultHandler() { - List> encoders = Arrays.asList( - new ByteBufferEncoder(this.allocator), new StringEncoder(this.allocator), - new JacksonJsonEncoder(this.allocator, new JsonObjectEncoder(this.allocator))); + List> encoders = Arrays.asList(new ByteBufferEncoder(), + new StringEncoder(), new JacksonJsonEncoder(new JsonObjectEncoder())); ResponseBodyResultHandler resultHandler = new ResponseBodyResultHandler(encoders, conversionService()); resultHandler.setOrder(1); return resultHandler; @@ -458,8 +457,9 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati @RequestMapping("/raw") public Publisher rawResponseBody() { - JacksonJsonEncoder encoder = new JacksonJsonEncoder(new DefaultDataBufferAllocator()); - return encoder.encode(Mono.just(new Person("Robert")), + DataBufferAllocator allocator = new DefaultDataBufferAllocator(); + JacksonJsonEncoder encoder = new JacksonJsonEncoder(); + return encoder.encode(Mono.just(new Person("Robert")), allocator, ResolvableType.forClass(Person.class), MediaType.APPLICATION_JSON).map(DataBuffer::asByteBuffer); } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/method/annotation/ResponseBodyResultHandlerTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/method/annotation/ResponseBodyResultHandlerTests.java index b0e0b09c50..8216843c3f 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/method/annotation/ResponseBodyResultHandlerTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/method/annotation/ResponseBodyResultHandlerTests.java @@ -24,7 +24,6 @@ import org.reactivestreams.Publisher; import org.springframework.core.ResolvableType; import org.springframework.core.codec.support.StringEncoder; import org.springframework.core.convert.support.DefaultConversionService; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; import org.springframework.ui.ExtendedModelMap; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.method.HandlerMethod; @@ -42,7 +41,7 @@ public class ResponseBodyResultHandlerTests { @Test public void supports() throws NoSuchMethodException { ResponseBodyResultHandler handler = new ResponseBodyResultHandler(Collections.singletonList( - new StringEncoder(new DefaultDataBufferAllocator())), + new StringEncoder()), new DefaultConversionService()); TestController controller = new TestController();