Shared static instance of DefaultDataBufferFactory
This commit is contained in:
@@ -52,8 +52,6 @@ public class MockClientHttpRequest extends AbstractClientHttpRequest {
|
||||
|
||||
private final URI url;
|
||||
|
||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
private Flux<DataBuffer> body = Flux.error(
|
||||
new IllegalStateException("The body is not set. " +
|
||||
"Did handling complete with success? Is a custom \"writeHandler\" configured?"));
|
||||
@@ -103,7 +101,7 @@ public class MockClientHttpRequest extends AbstractClientHttpRequest {
|
||||
|
||||
@Override
|
||||
public DataBufferFactory bufferFactory() {
|
||||
return this.bufferFactory;
|
||||
return DefaultDataBufferFactory.sharedInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,6 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -55,8 +54,6 @@ public class MockClientHttpResponse implements ClientHttpResponse {
|
||||
|
||||
private Flux<DataBuffer> body = Flux.empty();
|
||||
|
||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
public MockClientHttpResponse(HttpStatus status) {
|
||||
Assert.notNull(status, "HttpStatus is required");
|
||||
@@ -109,7 +106,7 @@ public class MockClientHttpResponse implements ClientHttpResponse {
|
||||
private DataBuffer toDataBuffer(String body, Charset charset) {
|
||||
byte[] bytes = body.getBytes(charset);
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
|
||||
return this.bufferFactory.wrap(byteBuffer);
|
||||
return DefaultDataBufferFactory.sharedInstance.wrap(byteBuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
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.HttpCookie;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -428,8 +427,6 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
private static class DefaultBodyBuilder implements BodyBuilder {
|
||||
|
||||
private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory();
|
||||
|
||||
private final String methodValue;
|
||||
|
||||
private final URI url;
|
||||
@@ -579,7 +576,9 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
@Override
|
||||
public MockServerHttpRequest body(String body) {
|
||||
return body(Flux.just(BUFFER_FACTORY.wrap(body.getBytes(getCharset()))));
|
||||
byte[] bytes = body.getBytes(getCharset());
|
||||
DataBuffer buffer = DefaultDataBufferFactory.sharedInstance.wrap(bytes);
|
||||
return body(Flux.just(buffer));
|
||||
}
|
||||
|
||||
private Charset getCharset() {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MockServerHttpResponse extends AbstractServerHttpResponse {
|
||||
|
||||
|
||||
public MockServerHttpResponse() {
|
||||
this(new DefaultDataBufferFactory());
|
||||
this(DefaultDataBufferFactory.sharedInstance);
|
||||
}
|
||||
|
||||
public MockServerHttpResponse(DataBufferFactory dataBufferFactory) {
|
||||
|
||||
@@ -29,7 +29,6 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
|
||||
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.HttpMethod;
|
||||
import org.springframework.http.client.reactive.ClientHttpConnector;
|
||||
@@ -125,16 +124,13 @@ class WiretapConnector implements ClientHttpConnector {
|
||||
*/
|
||||
final static class WiretapRecorder {
|
||||
|
||||
private static final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
@Nullable
|
||||
private final Flux<? extends DataBuffer> publisher;
|
||||
|
||||
@Nullable
|
||||
private final Flux<? extends Publisher<? extends DataBuffer>> publisherNested;
|
||||
|
||||
private final DataBuffer buffer = bufferFactory.allocateBuffer();
|
||||
private final DataBuffer buffer = DefaultDataBufferFactory.sharedInstance.allocateBuffer();
|
||||
|
||||
private final MonoProcessor<byte[]> content = MonoProcessor.create();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user