Shared static instance of DefaultDataBufferFactory
This commit is contained in:
@@ -186,7 +186,7 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
|
||||
this.body = Flux.just(body).
|
||||
map(s -> {
|
||||
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
|
||||
return new DefaultDataBufferFactory().wrap(bytes);
|
||||
return DefaultDataBufferFactory.sharedInstance.wrap(bytes);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.context.i18n.LocaleContext;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.Hints;
|
||||
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.HttpCookie;
|
||||
@@ -151,11 +150,10 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
|
||||
public ServerRequest.Builder body(String body) {
|
||||
Assert.notNull(body, "Body must not be null");
|
||||
releaseBody();
|
||||
DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
|
||||
this.body = Flux.just(body).
|
||||
map(s -> {
|
||||
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
|
||||
return dataBufferFactory.wrap(bytes);
|
||||
return DefaultDataBufferFactory.sharedInstance.wrap(bytes);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -21,7 +21,6 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
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.util.DigestUtils;
|
||||
@@ -39,13 +38,12 @@ import org.springframework.util.StreamUtils;
|
||||
*/
|
||||
public class ContentVersionStrategy extends AbstractFileNameVersionStrategy {
|
||||
|
||||
private static final DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<String> getResourceVersion(Resource resource) {
|
||||
Flux<DataBuffer> flux =
|
||||
DataBufferUtils.read(resource, dataBufferFactory, StreamUtils.BUFFER_SIZE);
|
||||
Flux<DataBuffer> flux = DataBufferUtils.read(
|
||||
resource, DefaultDataBufferFactory.sharedInstance, StreamUtils.BUFFER_SIZE);
|
||||
|
||||
return DataBufferUtils.join(flux)
|
||||
.map(buffer -> {
|
||||
byte[] result = new byte[buffer.readableByteCount()];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -29,7 +29,6 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.reactive.socket.HandshakeInfo;
|
||||
@@ -59,8 +58,6 @@ public class JettyWebSocketClient implements WebSocketClient, Lifecycle {
|
||||
|
||||
private final boolean externallyManaged;
|
||||
|
||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor that creates and manages an instance of a Jetty
|
||||
@@ -157,7 +154,8 @@ public class JettyWebSocketClient implements WebSocketClient, Lifecycle {
|
||||
private Object createHandler(URI url, WebSocketHandler handler, MonoProcessor<Void> completion) {
|
||||
return new JettyWebSocketHandlerAdapter(handler, session -> {
|
||||
HandshakeInfo info = createHandshakeInfo(url, session);
|
||||
return new JettyWebSocketSession(session, info, this.bufferFactory, completion);
|
||||
return new JettyWebSocketSession(
|
||||
session, info, DefaultDataBufferFactory.sharedInstance, completion);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -55,8 +55,6 @@ public class StandardWebSocketClient implements WebSocketClient {
|
||||
private static final Log logger = LogFactory.getLog(StandardWebSocketClient.class);
|
||||
|
||||
|
||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
private final WebSocketContainer webSocketContainer;
|
||||
|
||||
|
||||
@@ -129,7 +127,7 @@ public class StandardWebSocketClient implements WebSocketClient {
|
||||
protected StandardWebSocketSession createWebSocketSession(Session session, HandshakeInfo info,
|
||||
MonoProcessor<Void> completion) {
|
||||
|
||||
return new StandardWebSocketSession(session, info, this.bufferFactory, completion);
|
||||
return new StandardWebSocketSession(session, info, DefaultDataBufferFactory.sharedInstance, completion);
|
||||
}
|
||||
|
||||
private ClientEndpointConfig createEndpointConfig(Configurator configurator, List<String> subProtocols) {
|
||||
@@ -140,7 +138,7 @@ public class StandardWebSocketClient implements WebSocketClient {
|
||||
}
|
||||
|
||||
protected DataBufferFactory bufferFactory() {
|
||||
return this.bufferFactory;
|
||||
return DefaultDataBufferFactory.sharedInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -65,8 +65,6 @@ public class UndertowWebSocketClient implements WebSocketClient {
|
||||
|
||||
private final Consumer<ConnectionBuilder> builderConsumer;
|
||||
|
||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with the {@link XnioWorker} to pass to
|
||||
@@ -198,7 +196,8 @@ public class UndertowWebSocketClient implements WebSocketClient {
|
||||
DefaultNegotiation negotiation, WebSocketChannel channel) {
|
||||
|
||||
HandshakeInfo info = createHandshakeInfo(url, negotiation);
|
||||
UndertowWebSocketSession session = new UndertowWebSocketSession(channel, info, this.bufferFactory, completion);
|
||||
DataBufferFactory bufferFactory = DefaultDataBufferFactory.sharedInstance;
|
||||
UndertowWebSocketSession session = new UndertowWebSocketSession(channel, info, bufferFactory, completion);
|
||||
UndertowWebSocketHandlerAdapter adapter = new UndertowWebSocketHandlerAdapter(session);
|
||||
|
||||
channel.getReceiveSetter().set(adapter);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -102,7 +102,7 @@ public class DispatcherHandlerTests {
|
||||
@Override
|
||||
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
|
||||
byte[] bytes = ((String) result.getReturnValue()).getBytes(StandardCharsets.UTF_8);
|
||||
DataBuffer dataBuffer = new DefaultDataBufferFactory().wrap(bytes);
|
||||
DataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(bytes);
|
||||
return exchange.getResponse().writeWith(Mono.just(dataBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -119,7 +119,7 @@ public class BodyExtractorsTests {
|
||||
public void toMono() {
|
||||
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
|
||||
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBufferFactory factory = DefaultDataBufferFactory.sharedInstance;
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
@@ -138,9 +138,8 @@ public class BodyExtractorsTests {
|
||||
BodyExtractor<Mono<Map<String, String>>, ReactiveHttpInputMessage> extractor =
|
||||
BodyExtractors.toMono(new ParameterizedTypeReference<Map<String, String>>() {});
|
||||
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("{\"username\":\"foo\",\"password\":\"bar\"}".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "{\"username\":\"foo\",\"password\":\"bar\"}".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/").contentType(MediaType.APPLICATION_JSON).body(body);
|
||||
@@ -160,9 +159,8 @@ public class BodyExtractorsTests {
|
||||
BodyExtractor<Mono<User>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(User.class);
|
||||
this.hints.put(JSON_VIEW_HINT, SafeToDeserialize.class);
|
||||
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("{\"username\":\"foo\",\"password\":\"bar\"}".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "{\"username\":\"foo\",\"password\":\"bar\"}".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
@@ -193,9 +191,8 @@ public class BodyExtractorsTests {
|
||||
|
||||
@Test
|
||||
public void toMonoVoidAsClientShouldConsumeAndCancel() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
TestPublisher<DataBuffer> body = TestPublisher.create();
|
||||
|
||||
BodyExtractor<Mono<Void>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(Void.class);
|
||||
@@ -232,9 +229,8 @@ public class BodyExtractorsTests {
|
||||
public void toFlux() {
|
||||
BodyExtractor<Flux<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toFlux(String.class);
|
||||
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
|
||||
@@ -251,9 +247,9 @@ public class BodyExtractorsTests {
|
||||
BodyExtractor<Flux<User>, ReactiveHttpInputMessage> extractor = BodyExtractors.toFlux(User.class);
|
||||
this.hints.put(JSON_VIEW_HINT, SafeToDeserialize.class);
|
||||
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
String text = "[{\"username\":\"foo\",\"password\":\"bar\"},{\"username\":\"bar\",\"password\":\"baz\"}]";
|
||||
DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap(text.getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
@@ -279,9 +275,8 @@ public class BodyExtractorsTests {
|
||||
public void toFluxUnacceptable() {
|
||||
BodyExtractor<Flux<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toFlux(String.class);
|
||||
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
@@ -313,9 +308,8 @@ public class BodyExtractorsTests {
|
||||
|
||||
@Test
|
||||
public void toFormData() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
String text = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
|
||||
DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap(text.getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
@@ -360,9 +354,8 @@ public class BodyExtractorsTests {
|
||||
"\r\n" +
|
||||
"-----------------------------9051914041544843365972754266--\r\n";
|
||||
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap(bodyContents.getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = bodyContents.getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/")
|
||||
@@ -403,9 +396,8 @@ public class BodyExtractorsTests {
|
||||
public void toDataBuffers() {
|
||||
BodyExtractor<Flux<DataBuffer>, ReactiveHttpInputMessage> extractor = BodyExtractors.toDataBuffers();
|
||||
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
|
||||
|
||||
@@ -421,9 +421,8 @@ public class BodyInsertersTests {
|
||||
|
||||
@Test
|
||||
public void ofDataBuffers() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
BodyInserter<Flux<DataBuffer>, ReactiveHttpOutputMessage> inserter = BodyInserters.fromDataBuffers(body);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -118,7 +118,7 @@ public class DefaultClientRequestBuilderTests {
|
||||
BodyInserter<String, ClientHttpRequest> inserter =
|
||||
(response, strategies) -> {
|
||||
byte[] bodyBytes = body.getBytes(UTF_8);
|
||||
DataBuffer buffer = new DefaultDataBufferFactory().wrap(bodyBytes);
|
||||
DataBuffer buffer = DefaultDataBufferFactory.sharedInstance.wrap(bodyBytes);
|
||||
|
||||
return response.writeWith(Mono.just(buffer));
|
||||
};
|
||||
|
||||
@@ -23,7 +23,6 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
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.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -41,14 +40,11 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*/
|
||||
public class DefaultClientResponseBuilderTests {
|
||||
|
||||
private final DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
@Test
|
||||
public void normal() {
|
||||
Flux<DataBuffer> body = Flux.just("baz")
|
||||
.map(s -> s.getBytes(StandardCharsets.UTF_8))
|
||||
.map(dataBufferFactory::wrap);
|
||||
.map(DefaultDataBufferFactory.sharedInstance::wrap);
|
||||
|
||||
ClientResponse response = ClientResponse.create(HttpStatus.BAD_GATEWAY, ExchangeStrategies.withDefaults())
|
||||
.header("foo", "bar")
|
||||
@@ -71,7 +67,7 @@ public class DefaultClientResponseBuilderTests {
|
||||
public void mutate() {
|
||||
Flux<DataBuffer> otherBody = Flux.just("foo", "bar")
|
||||
.map(s -> s.getBytes(StandardCharsets.UTF_8))
|
||||
.map(dataBufferFactory::wrap);
|
||||
.map(DefaultDataBufferFactory.sharedInstance::wrap);
|
||||
|
||||
HttpRequest mockClientHttpRequest = new MockClientHttpRequest(HttpMethod.GET, "/path");
|
||||
|
||||
|
||||
@@ -125,9 +125,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void body() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
mockTextPlainResponse(body);
|
||||
|
||||
@@ -141,9 +140,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void bodyToMono() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
mockTextPlainResponse(body);
|
||||
|
||||
@@ -157,9 +155,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void bodyToMonoTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
mockTextPlainResponse(body);
|
||||
|
||||
@@ -175,9 +172,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void bodyToFlux() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
mockTextPlainResponse(body);
|
||||
|
||||
@@ -192,9 +188,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void bodyToFluxTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
mockTextPlainResponse(body);
|
||||
|
||||
@@ -211,9 +206,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void toEntity() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
mockTextPlainResponse(body);
|
||||
|
||||
@@ -230,9 +224,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void toEntityWithUnknownStatusCode() throws Exception {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer
|
||||
= factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
@@ -255,9 +248,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void toEntityTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
mockTextPlainResponse(body);
|
||||
|
||||
@@ -276,9 +268,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void toEntityList() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
mockTextPlainResponse(body);
|
||||
|
||||
@@ -295,9 +286,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void toEntityListWithUnknownStatusCode() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
@@ -320,8 +310,8 @@ public class DefaultClientResponseTests {
|
||||
|
||||
@Test
|
||||
public void toEntityListTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
mockTextPlainResponse(body);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -197,10 +197,9 @@ public class ExchangeFilterFunctionsTests {
|
||||
|
||||
@Test
|
||||
public void limitResponseSize() {
|
||||
DefaultDataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
DataBuffer b1 = dataBuffer("foo", bufferFactory);
|
||||
DataBuffer b2 = dataBuffer("bar", bufferFactory);
|
||||
DataBuffer b3 = dataBuffer("baz", bufferFactory);
|
||||
DataBuffer b1 = dataBuffer("foo");
|
||||
DataBuffer b2 = dataBuffer("bar");
|
||||
DataBuffer b3 = dataBuffer("baz");
|
||||
|
||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||
ClientResponse response = ClientResponse.create(HttpStatus.OK).body(Flux.just(b1, b2, b3)).build();
|
||||
@@ -222,8 +221,8 @@ public class ExchangeFilterFunctionsTests {
|
||||
return value;
|
||||
}
|
||||
|
||||
private DataBuffer dataBuffer(String foo, DefaultDataBufferFactory bufferFactory) {
|
||||
return bufferFactory.wrap(foo.getBytes(StandardCharsets.UTF_8));
|
||||
private DataBuffer dataBuffer(String foo) {
|
||||
return DefaultDataBufferFactory.sharedInstance.wrap(foo.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -627,7 +627,7 @@ class WebClientIntegrationTests {
|
||||
prepareResponse(response -> {});
|
||||
|
||||
Resource resource = new ClassPathResource("largeTextFile.txt", getClass());
|
||||
Flux<DataBuffer> body = DataBufferUtils.read(resource, new DefaultDataBufferFactory(), 4096);
|
||||
Flux<DataBuffer> body = DataBufferUtils.read(resource, DefaultDataBufferFactory.sharedInstance, 4096);
|
||||
|
||||
Mono<Void> result = this.webClient.post()
|
||||
.uri("/")
|
||||
|
||||
@@ -23,7 +23,6 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
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.ResponseCookie;
|
||||
@@ -42,9 +41,6 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
*/
|
||||
public class DefaultServerRequestBuilderTests {
|
||||
|
||||
private final DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
@Test
|
||||
public void from() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("https://example.com")
|
||||
@@ -58,7 +54,7 @@ public class DefaultServerRequestBuilderTests {
|
||||
|
||||
Flux<DataBuffer> body = Flux.just("baz")
|
||||
.map(s -> s.getBytes(StandardCharsets.UTF_8))
|
||||
.map(dataBufferFactory::wrap);
|
||||
.map(DefaultDataBufferFactory.sharedInstance::wrap);
|
||||
|
||||
ServerRequest result = ServerRequest.from(other)
|
||||
.method(HttpMethod.HEAD)
|
||||
|
||||
@@ -239,9 +239,8 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void body() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
@@ -259,9 +258,8 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void bodyToMono() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
@@ -278,9 +276,8 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void bodyToMonoParameterizedTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
@@ -298,9 +295,8 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void bodyToMonoDecodingException() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("{\"invalid\":\"json\" ".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "{\"invalid\":\"json\" ".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
@@ -320,9 +316,8 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void bodyToFlux() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
@@ -339,9 +334,8 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void bodyToFluxParameterizedTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
@@ -359,9 +353,8 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void bodyUnacceptable() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
@@ -380,9 +373,8 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void formData() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo=bar&baz=qux".getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = "foo=bar&baz=qux".getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
@@ -414,9 +406,8 @@ public class DefaultServerRequestTests {
|
||||
"\r\n" +
|
||||
"qux\r\n" +
|
||||
"--12345--\r\n";
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap(data.getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
|
||||
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
|
||||
Flux<DataBuffer> body = Flux.just(dataBuffer);
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
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.CacheControl;
|
||||
@@ -71,12 +70,8 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
private static final Duration TIMEOUT = Duration.ofSeconds(1);
|
||||
|
||||
|
||||
private ResourceWebHandler handler;
|
||||
|
||||
private DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
List<Resource> locations = new ArrayList<>(2);
|
||||
@@ -596,7 +591,7 @@ public class ResourceWebHandlerTests {
|
||||
String boundary = "--" + exchange.getResponse().getHeaders().getContentType().toString().substring(30);
|
||||
|
||||
Mono<DataBuffer> reduced = Flux.from(exchange.getResponse().getBody())
|
||||
.reduce(this.bufferFactory.allocateBuffer(), (previous, current) -> {
|
||||
.reduce(DefaultDataBufferFactory.sharedInstance.allocateBuffer(), (previous, current) -> {
|
||||
previous.write(current);
|
||||
DataBufferUtils.release(current);
|
||||
return previous;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -117,7 +117,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra
|
||||
}
|
||||
|
||||
private static DataBuffer asDataBuffer(String text) {
|
||||
DefaultDataBuffer buffer = new DefaultDataBufferFactory().allocateBuffer();
|
||||
DefaultDataBuffer buffer = DefaultDataBufferFactory.sharedInstance.allocateBuffer();
|
||||
return buffer.write(text.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
@@ -292,7 +292,8 @@ public class InvocableHandlerMethodTests {
|
||||
}
|
||||
|
||||
private Flux<DataBuffer> getBody(String body) {
|
||||
return Flux.just(new DefaultDataBufferFactory().wrap(body.getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
|
||||
return Flux.just(DefaultDataBufferFactory.sharedInstance.wrap(bytes));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
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.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -487,9 +486,8 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
|
||||
@GetMapping("/publisher")
|
||||
public Publisher<ByteBuffer> getPublisher() {
|
||||
DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
|
||||
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
|
||||
return encoder.encode(Mono.just(new Person("Robert")), dataBufferFactory,
|
||||
return encoder.encode(Mono.just(new Person("Robert")), DefaultDataBufferFactory.sharedInstance,
|
||||
ResolvableType.forClass(Person.class), JSON, Collections.emptyMap()).map(DataBuffer::asByteBuffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -398,7 +398,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
model = new TreeMap<>(model);
|
||||
String value = this.name + ": " + model.toString();
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(value.getBytes(UTF_8));
|
||||
DataBuffer dataBuffer = new DefaultDataBufferFactory().wrap(byteBuffer);
|
||||
DataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(byteBuffer);
|
||||
return response.writeWith(Flux.just(dataBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user