parent
3543e47841
commit
a7c736915a
|
@ -16,8 +16,11 @@
|
|||
|
||||
package org.springframework.core.codec;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
|
@ -26,17 +29,15 @@ import org.springframework.lang.Nullable;
|
|||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Decoder for {@link ByteBuf ByteBufs}.
|
||||
*
|
||||
* @author Vladislav Kisel
|
||||
* @since 5.3
|
||||
*/
|
||||
public class ByteBufDecoder extends AbstractDataBufferDecoder<ByteBuf> {
|
||||
public class NettyByteBufDecoder extends AbstractDataBufferDecoder<ByteBuf> {
|
||||
|
||||
public ByteBufDecoder() {
|
||||
public NettyByteBufDecoder() {
|
||||
super(MimeTypeUtils.ALL);
|
||||
}
|
||||
|
||||
|
@ -51,18 +52,17 @@ public class ByteBufDecoder extends AbstractDataBufferDecoder<ByteBuf> {
|
|||
public ByteBuf decode(DataBuffer dataBuffer, ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
// Copies the dataBuffer if needed only
|
||||
ByteBuf byteBuf;
|
||||
if (dataBuffer instanceof NettyDataBuffer) {
|
||||
byteBuf = ((NettyDataBuffer) dataBuffer).getNativeBuffer();
|
||||
} else {
|
||||
byteBuf = Unpooled.wrappedBuffer(dataBuffer.asByteBuffer());
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(Hints.getLogPrefix(hints) + "Read " + byteBuf.readableBytes() + " bytes");
|
||||
logger.debug(Hints.getLogPrefix(hints) + "Read " + dataBuffer.readableByteCount() + " bytes");
|
||||
}
|
||||
if (dataBuffer instanceof NettyDataBuffer) {
|
||||
return ((NettyDataBuffer) dataBuffer).getNativeBuffer();
|
||||
}
|
||||
ByteBuf byteBuf;
|
||||
byte[] bytes = new byte[dataBuffer.readableByteCount()];
|
||||
dataBuffer.read(bytes);
|
||||
byteBuf = Unpooled.wrappedBuffer(bytes);
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
return byteBuf;
|
||||
}
|
||||
|
|
@ -16,8 +16,12 @@
|
|||
|
||||
package org.springframework.core.codec;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
|
@ -25,9 +29,6 @@ import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
|||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Encoder for {@link ByteBuf ByteBufs}.
|
||||
|
@ -35,17 +36,17 @@ import java.util.Map;
|
|||
* @author Vladislav Kisel
|
||||
* @since 5.3
|
||||
*/
|
||||
public class ByteBufEncoder extends AbstractEncoder<ByteBuf> {
|
||||
public class NettyByteBufEncoder extends AbstractEncoder<ByteBuf> {
|
||||
|
||||
public ByteBufEncoder() {
|
||||
public NettyByteBufEncoder() {
|
||||
super(MimeTypeUtils.ALL);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
|
||||
Class<?> clazz = elementType.toClass();
|
||||
return super.canEncode(elementType, mimeType) && ByteBuf.class.isAssignableFrom(clazz);
|
||||
public boolean canEncode(ResolvableType type, @Nullable MimeType mimeType) {
|
||||
Class<?> clazz = type.toClass();
|
||||
return super.canEncode(type, mimeType) && ByteBuf.class.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,18 +62,16 @@ public class ByteBufEncoder extends AbstractEncoder<ByteBuf> {
|
|||
public DataBuffer encodeValue(ByteBuf byteBuf, DataBufferFactory bufferFactory,
|
||||
ResolvableType valueType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
DataBuffer dataBuffer;
|
||||
if (bufferFactory instanceof NettyDataBufferFactory) {
|
||||
dataBuffer = ((NettyDataBufferFactory) bufferFactory).wrap(byteBuf);
|
||||
} else {
|
||||
dataBuffer = bufferFactory.wrap(byteBuf.nioBuffer());
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled() && !Hints.isLoggingSuppressed(hints)) {
|
||||
String logPrefix = Hints.getLogPrefix(hints);
|
||||
logger.debug(logPrefix + "Writing " + dataBuffer.readableByteCount() + " bytes");
|
||||
logger.debug(logPrefix + "Writing " + byteBuf.readableBytes() + " bytes");
|
||||
}
|
||||
return dataBuffer;
|
||||
if (bufferFactory instanceof NettyDataBufferFactory) {
|
||||
return ((NettyDataBufferFactory) bufferFactory).wrap(byteBuf);
|
||||
}
|
||||
byte[] bytes = new byte[byteBuf.readableBytes()];
|
||||
byteBuf.readBytes(bytes);
|
||||
byteBuf.release();
|
||||
return bufferFactory.wrap(bytes);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,32 +16,33 @@
|
|||
|
||||
package org.springframework.core.codec;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.testfixture.codec.AbstractDecoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Vladislav Kisel
|
||||
*/
|
||||
class ByteBufDecoderTests extends AbstractDecoderTests<ByteBufDecoder> {
|
||||
class NettyByteBufDecoderTests extends AbstractDecoderTests<NettyByteBufDecoder> {
|
||||
|
||||
private final byte[] fooBytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
private final byte[] barBytes = "bar".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
ByteBufDecoderTests() {
|
||||
super(new ByteBufDecoder());
|
||||
NettyByteBufDecoderTests() {
|
||||
super(new NettyByteBufDecoder());
|
||||
}
|
||||
|
||||
@Override
|
|
@ -16,29 +16,30 @@
|
|||
|
||||
package org.springframework.core.codec;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.testfixture.codec.AbstractEncoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Vladislav Kisel
|
||||
*/
|
||||
class ByteBufEncoderTests extends AbstractEncoderTests<ByteBufEncoder> {
|
||||
class NettyByteBufEncoderTests extends AbstractEncoderTests<NettyByteBufEncoder> {
|
||||
|
||||
private final byte[] fooBytes = "foo".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
private final byte[] barBytes = "bar".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
ByteBufEncoderTests() {
|
||||
super(new ByteBufEncoder());
|
||||
NettyByteBufEncoderTests() {
|
||||
super(new NettyByteBufEncoder());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +52,7 @@ class ByteBufEncoderTests extends AbstractEncoderTests<ByteBufEncoder> {
|
|||
assertThat(this.encoder.canEncode(ResolvableType.forClass(ByteBuf.class),
|
||||
MimeTypeUtils.APPLICATION_JSON)).isTrue();
|
||||
|
||||
// SPR-15464
|
||||
// gh-20024
|
||||
assertThat(this.encoder.canEncode(ResolvableType.NONE, null)).isFalse();
|
||||
}
|
||||
|
||||
|
@ -60,12 +61,9 @@ class ByteBufEncoderTests extends AbstractEncoderTests<ByteBufEncoder> {
|
|||
public void encode() {
|
||||
Flux<ByteBuf> input = Flux.just(this.fooBytes, this.barBytes).map(Unpooled::copiedBuffer);
|
||||
|
||||
Unpooled.copiedBuffer(this.fooBytes, this.barBytes);
|
||||
|
||||
testEncodeAll(input, ByteBuf.class, step -> step
|
||||
.consumeNextWith(expectBytes(this.fooBytes))
|
||||
.consumeNextWith(expectBytes(this.barBytes))
|
||||
.verifyComplete());
|
||||
}
|
||||
|
||||
}
|
|
@ -31,6 +31,8 @@ import org.springframework.core.codec.DataBufferDecoder;
|
|||
import org.springframework.core.codec.DataBufferEncoder;
|
||||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.codec.NettyByteBufDecoder;
|
||||
import org.springframework.core.codec.NettyByteBufEncoder;
|
||||
import org.springframework.core.codec.ResourceDecoder;
|
||||
import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.http.codec.CodecConfigurer;
|
||||
|
@ -78,6 +80,8 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
|
|||
|
||||
static final boolean synchronossMultipartPresent;
|
||||
|
||||
static final boolean nettyByteBufPresent;
|
||||
|
||||
static {
|
||||
ClassLoader classLoader = BaseCodecConfigurer.class.getClassLoader();
|
||||
jackson2Present = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) &&
|
||||
|
@ -86,6 +90,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
|
|||
jaxb2Present = ClassUtils.isPresent("javax.xml.bind.Binder", classLoader);
|
||||
protobufPresent = ClassUtils.isPresent("com.google.protobuf.Message", classLoader);
|
||||
synchronossMultipartPresent = ClassUtils.isPresent("org.synchronoss.cloud.nio.multipart.NioMultipartParser", classLoader);
|
||||
nettyByteBufPresent = ClassUtils.isPresent("io.netty.buffer.ByteBuf", classLoader);
|
||||
}
|
||||
|
||||
|
||||
|
@ -223,6 +228,9 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
|
|||
addCodec(readers, new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
|
||||
addCodec(readers, new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
|
||||
addCodec(readers, new DecoderHttpMessageReader<>(new DataBufferDecoder()));
|
||||
if (nettyByteBufPresent) {
|
||||
addCodec(readers, new DecoderHttpMessageReader<>(new NettyByteBufDecoder()));
|
||||
}
|
||||
addCodec(readers, new ResourceHttpMessageReader(new ResourceDecoder()));
|
||||
addCodec(readers, new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly()));
|
||||
if (protobufPresent) {
|
||||
|
@ -399,6 +407,9 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
|
|||
writers.add(new EncoderHttpMessageWriter<>(new ByteArrayEncoder()));
|
||||
writers.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
|
||||
writers.add(new EncoderHttpMessageWriter<>(new DataBufferEncoder()));
|
||||
if (nettyByteBufPresent) {
|
||||
writers.add(new EncoderHttpMessageWriter<>(new NettyByteBufEncoder()));
|
||||
}
|
||||
writers.add(new ResourceHttpMessageWriter());
|
||||
writers.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
|
||||
if (protobufPresent) {
|
||||
|
|
|
@ -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.
|
||||
|
@ -36,6 +36,8 @@ import org.springframework.core.codec.DataBufferDecoder;
|
|||
import org.springframework.core.codec.DataBufferEncoder;
|
||||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.codec.NettyByteBufDecoder;
|
||||
import org.springframework.core.codec.NettyByteBufEncoder;
|
||||
import org.springframework.core.codec.ResourceDecoder;
|
||||
import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
|
@ -79,10 +81,11 @@ public class ClientCodecConfigurerTests {
|
|||
@Test
|
||||
public void defaultReaders() {
|
||||
List<HttpMessageReader<?>> readers = this.configurer.getReaders();
|
||||
assertThat(readers.size()).isEqualTo(12);
|
||||
assertThat(readers.size()).isEqualTo(13);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteArrayDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteBufferDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(DataBufferDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(NettyByteBufDecoder.class);
|
||||
assertThat(readers.get(this.index.getAndIncrement()).getClass()).isEqualTo(ResourceHttpMessageReader.class);
|
||||
assertStringDecoder(getNextDecoder(readers), true);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ProtobufDecoder.class);
|
||||
|
@ -98,10 +101,11 @@ public class ClientCodecConfigurerTests {
|
|||
@Test
|
||||
public void defaultWriters() {
|
||||
List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
|
||||
assertThat(writers.size()).isEqualTo(11);
|
||||
assertThat(writers.size()).isEqualTo(12);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteArrayEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteBufferEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(DataBufferEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(NettyByteBufEncoder.class);
|
||||
assertThat(writers.get(index.getAndIncrement()).getClass()).isEqualTo(ResourceHttpMessageWriter.class);
|
||||
assertStringEncoder(getNextEncoder(writers), true);
|
||||
assertThat(writers.get(index.getAndIncrement()).getClass()).isEqualTo(ProtobufHttpMessageWriter.class);
|
||||
|
@ -126,10 +130,11 @@ public class ClientCodecConfigurerTests {
|
|||
int size = 99;
|
||||
this.configurer.defaultCodecs().maxInMemorySize(size);
|
||||
List<HttpMessageReader<?>> readers = this.configurer.getReaders();
|
||||
assertThat(readers.size()).isEqualTo(12);
|
||||
assertThat(readers.size()).isEqualTo(13);
|
||||
assertThat(((ByteArrayDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((ByteBufferDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((DataBufferDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((NettyByteBufDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((ResourceDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((StringDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((ProtobufDecoder) getNextDecoder(readers)).getMaxMessageSize()).isEqualTo(size);
|
||||
|
@ -182,7 +187,7 @@ public class ClientCodecConfigurerTests {
|
|||
writers = findCodec(this.configurer.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
|
||||
|
||||
assertThat(sseDecoder).isNotSameAs(jackson2Decoder);
|
||||
assertThat(writers).hasSize(10);
|
||||
assertThat(writers).hasSize(11);
|
||||
}
|
||||
|
||||
@Test // gh-24194
|
||||
|
@ -192,7 +197,7 @@ public class ClientCodecConfigurerTests {
|
|||
List<HttpMessageWriter<?>> writers =
|
||||
findCodec(clone.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
|
||||
|
||||
assertThat(writers).hasSize(10);
|
||||
assertThat(writers).hasSize(11);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -206,7 +211,7 @@ public class ClientCodecConfigurerTests {
|
|||
List<HttpMessageWriter<?>> writers =
|
||||
findCodec(clone.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
|
||||
|
||||
assertThat(writers).hasSize(10);
|
||||
assertThat(writers).hasSize(11);
|
||||
}
|
||||
|
||||
private Decoder<?> getNextDecoder(List<HttpMessageReader<?>> readers) {
|
||||
|
|
|
@ -34,6 +34,8 @@ import org.springframework.core.codec.DataBufferDecoder;
|
|||
import org.springframework.core.codec.DataBufferEncoder;
|
||||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.codec.NettyByteBufDecoder;
|
||||
import org.springframework.core.codec.NettyByteBufEncoder;
|
||||
import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.CodecConfigurer;
|
||||
|
@ -77,10 +79,11 @@ public class CodecConfigurerTests {
|
|||
@Test
|
||||
public void defaultReaders() {
|
||||
List<HttpMessageReader<?>> readers = this.configurer.getReaders();
|
||||
assertThat(readers.size()).isEqualTo(11);
|
||||
assertThat(readers.size()).isEqualTo(12);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteArrayDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteBufferDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(DataBufferDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(NettyByteBufDecoder.class);
|
||||
assertThat(readers.get(this.index.getAndIncrement()).getClass()).isEqualTo(ResourceHttpMessageReader.class);
|
||||
assertStringDecoder(getNextDecoder(readers), true);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ProtobufDecoder.class);
|
||||
|
@ -94,10 +97,11 @@ public class CodecConfigurerTests {
|
|||
@Test
|
||||
public void defaultWriters() {
|
||||
List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
|
||||
assertThat(writers.size()).isEqualTo(10);
|
||||
assertThat(writers.size()).isEqualTo(11);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteArrayEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteBufferEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(DataBufferEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(NettyByteBufEncoder.class);
|
||||
assertThat(writers.get(index.getAndIncrement()).getClass()).isEqualTo(ResourceHttpMessageWriter.class);
|
||||
assertStringEncoder(getNextEncoder(writers), true);
|
||||
assertThat(writers.get(index.getAndIncrement()).getClass()).isEqualTo(ProtobufHttpMessageWriter.class);
|
||||
|
@ -129,12 +133,13 @@ public class CodecConfigurerTests {
|
|||
|
||||
List<HttpMessageReader<?>> readers = this.configurer.getReaders();
|
||||
|
||||
assertThat(readers.size()).isEqualTo(15);
|
||||
assertThat(readers.size()).isEqualTo(16);
|
||||
assertThat(getNextDecoder(readers)).isSameAs(customDecoder1);
|
||||
assertThat(readers.get(this.index.getAndIncrement())).isSameAs(customReader1);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteArrayDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteBufferDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(DataBufferDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(NettyByteBufDecoder.class);
|
||||
assertThat(readers.get(this.index.getAndIncrement()).getClass()).isEqualTo(ResourceHttpMessageReader.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(StringDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ProtobufDecoder.class);
|
||||
|
@ -169,12 +174,13 @@ public class CodecConfigurerTests {
|
|||
|
||||
List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
|
||||
|
||||
assertThat(writers.size()).isEqualTo(14);
|
||||
assertThat(writers.size()).isEqualTo(15);
|
||||
assertThat(getNextEncoder(writers)).isSameAs(customEncoder1);
|
||||
assertThat(writers.get(this.index.getAndIncrement())).isSameAs(customWriter1);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteArrayEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteBufferEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(DataBufferEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(NettyByteBufEncoder.class);
|
||||
assertThat(writers.get(index.getAndIncrement()).getClass()).isEqualTo(ResourceHttpMessageWriter.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(CharSequenceEncoder.class);
|
||||
assertThat(writers.get(index.getAndIncrement()).getClass()).isEqualTo(ProtobufHttpMessageWriter.class);
|
||||
|
|
|
@ -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.
|
||||
|
@ -36,6 +36,8 @@ import org.springframework.core.codec.DataBufferDecoder;
|
|||
import org.springframework.core.codec.DataBufferEncoder;
|
||||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.codec.NettyByteBufDecoder;
|
||||
import org.springframework.core.codec.NettyByteBufEncoder;
|
||||
import org.springframework.core.codec.ResourceDecoder;
|
||||
import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
|
@ -80,10 +82,11 @@ public class ServerCodecConfigurerTests {
|
|||
@Test
|
||||
public void defaultReaders() {
|
||||
List<HttpMessageReader<?>> readers = this.configurer.getReaders();
|
||||
assertThat(readers.size()).isEqualTo(13);
|
||||
assertThat(readers.size()).isEqualTo(14);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteArrayDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteBufferDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(DataBufferDecoder.class);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(NettyByteBufDecoder.class);
|
||||
assertThat(readers.get(this.index.getAndIncrement()).getClass()).isEqualTo(ResourceHttpMessageReader.class);
|
||||
assertStringDecoder(getNextDecoder(readers), true);
|
||||
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ProtobufDecoder.class);
|
||||
|
@ -99,10 +102,11 @@ public class ServerCodecConfigurerTests {
|
|||
@Test
|
||||
public void defaultWriters() {
|
||||
List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
|
||||
assertThat(writers.size()).isEqualTo(11);
|
||||
assertThat(writers.size()).isEqualTo(12);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteArrayEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteBufferEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(DataBufferEncoder.class);
|
||||
assertThat(getNextEncoder(writers).getClass()).isEqualTo(NettyByteBufEncoder.class);
|
||||
assertThat(writers.get(index.getAndIncrement()).getClass()).isEqualTo(ResourceHttpMessageWriter.class);
|
||||
assertStringEncoder(getNextEncoder(writers), true);
|
||||
assertThat(writers.get(index.getAndIncrement()).getClass()).isEqualTo(ProtobufHttpMessageWriter.class);
|
||||
|
@ -135,6 +139,7 @@ public class ServerCodecConfigurerTests {
|
|||
assertThat(((ByteArrayDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((ByteBufferDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((DataBufferDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((NettyByteBufDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((ResourceDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((StringDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
|
||||
assertThat(((ProtobufDecoder) getNextDecoder(readers)).getMaxMessageSize()).isEqualTo(size);
|
||||
|
|
|
@ -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.
|
||||
|
@ -77,7 +77,7 @@ public class DelegatingWebFluxConfigurationTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerMapping() throws Exception {
|
||||
public void requestMappingHandlerMapping() {
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||
delegatingConfig.requestMappingHandlerMapping(delegatingConfig.webFluxContentTypeResolver());
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class DelegatingWebFluxConfigurationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerAdapter() throws Exception {
|
||||
public void requestMappingHandlerAdapter() {
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||
ReactiveAdapterRegistry reactiveAdapterRegistry = delegatingConfig.webFluxAdapterRegistry();
|
||||
ServerCodecConfigurer serverCodecConfigurer = delegatingConfig.serverCodecConfigurer();
|
||||
|
@ -108,11 +108,11 @@ public class DelegatingWebFluxConfigurationTests {
|
|||
boolean condition = initializer.getValidator() instanceof LocalValidatorFactoryBean;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(initializer.getConversionService()).isSameAs(formatterRegistry.getValue());
|
||||
assertThat(codecsConfigurer.getValue().getReaders().size()).isEqualTo(13);
|
||||
assertThat(codecsConfigurer.getValue().getReaders().size()).isEqualTo(14);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceHandlerMapping() throws Exception {
|
||||
public void resourceHandlerMapping() {
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||
willAnswer(invocation -> {
|
||||
ResourceHandlerRegistry registry = invocation.getArgument(0);
|
||||
|
@ -126,7 +126,7 @@ public class DelegatingWebFluxConfigurationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void responseBodyResultHandler() throws Exception {
|
||||
public void responseBodyResultHandler() {
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||
delegatingConfig.responseBodyResultHandler(
|
||||
delegatingConfig.webFluxAdapterRegistry(),
|
||||
|
@ -138,7 +138,7 @@ public class DelegatingWebFluxConfigurationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void viewResolutionResultHandler() throws Exception {
|
||||
public void viewResolutionResultHandler() {
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||
delegatingConfig.viewResolutionResultHandler(delegatingConfig.webFluxAdapterRegistry(),
|
||||
delegatingConfig.webFluxContentTypeResolver());
|
||||
|
|
|
@ -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.
|
||||
|
@ -97,7 +97,7 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
|
|||
public class WebFluxConfigurationSupportTests {
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerMapping() throws Exception {
|
||||
public void requestMappingHandlerMapping() {
|
||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||
final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
|
@ -118,7 +118,8 @@ public class WebFluxConfigurationSupportTests {
|
|||
assertThat(mapping.getContentTypeResolver()).isSameAs(resolver);
|
||||
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON));
|
||||
assertThat(resolver.resolveMediaTypes(exchange)).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
assertThat(resolver.resolveMediaTypes(exchange))
|
||||
.isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -138,11 +139,12 @@ public class WebFluxConfigurationSupportTests {
|
|||
|
||||
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
|
||||
assertThat(map.size()).isEqualTo(1);
|
||||
assertThat(map.keySet().iterator().next().getPatternsCondition().getPatterns()).isEqualTo(Collections.singleton(new PathPatternParser().parse("/api/user/{id}")));
|
||||
assertThat(map.keySet().iterator().next().getPatternsCondition().getPatterns())
|
||||
.isEqualTo(Collections.singleton(new PathPatternParser().parse("/api/user/{id}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerAdapter() throws Exception {
|
||||
public void requestMappingHandlerAdapter() {
|
||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||
|
||||
String name = "requestMappingHandlerAdapter";
|
||||
|
@ -150,7 +152,7 @@ public class WebFluxConfigurationSupportTests {
|
|||
assertThat(adapter).isNotNull();
|
||||
|
||||
List<HttpMessageReader<?>> readers = adapter.getMessageReaders();
|
||||
assertThat(readers.size()).isEqualTo(13);
|
||||
assertThat(readers.size()).isEqualTo(14);
|
||||
|
||||
ResolvableType multiValueMapType = forClassWithGenerics(MultiValueMap.class, String.class, String.class);
|
||||
|
||||
|
@ -180,7 +182,7 @@ public class WebFluxConfigurationSupportTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void customMessageConverterConfig() throws Exception {
|
||||
public void customMessageConverterConfig() {
|
||||
ApplicationContext context = loadConfig(CustomMessageConverterConfig.class);
|
||||
|
||||
String name = "requestMappingHandlerAdapter";
|
||||
|
@ -195,7 +197,7 @@ public class WebFluxConfigurationSupportTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void responseEntityResultHandler() throws Exception {
|
||||
public void responseEntityResultHandler() {
|
||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||
|
||||
String name = "responseEntityResultHandler";
|
||||
|
@ -205,7 +207,7 @@ public class WebFluxConfigurationSupportTests {
|
|||
assertThat(handler.getOrder()).isEqualTo(0);
|
||||
|
||||
List<HttpMessageWriter<?>> writers = handler.getMessageWriters();
|
||||
assertThat(writers.size()).isEqualTo(11);
|
||||
assertThat(writers.size()).isEqualTo(12);
|
||||
|
||||
assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
|
||||
assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
|
||||
|
@ -223,7 +225,7 @@ public class WebFluxConfigurationSupportTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void responseBodyResultHandler() throws Exception {
|
||||
public void responseBodyResultHandler() {
|
||||
ApplicationContext context = loadConfig(WebFluxConfig.class);
|
||||
|
||||
String name = "responseBodyResultHandler";
|
||||
|
@ -233,7 +235,7 @@ public class WebFluxConfigurationSupportTests {
|
|||
assertThat(handler.getOrder()).isEqualTo(100);
|
||||
|
||||
List<HttpMessageWriter<?>> writers = handler.getMessageWriters();
|
||||
assertThat(writers.size()).isEqualTo(11);
|
||||
assertThat(writers.size()).isEqualTo(12);
|
||||
|
||||
assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
|
||||
assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
|
||||
|
@ -251,7 +253,7 @@ public class WebFluxConfigurationSupportTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void viewResolutionResultHandler() throws Exception {
|
||||
public void viewResolutionResultHandler() {
|
||||
ApplicationContext context = loadConfig(CustomViewResolverConfig.class);
|
||||
|
||||
String name = "viewResolutionResultHandler";
|
||||
|
@ -272,7 +274,7 @@ public class WebFluxConfigurationSupportTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resourceHandler() throws Exception {
|
||||
public void resourceHandler() {
|
||||
ApplicationContext context = loadConfig(CustomResourceHandlingConfig.class);
|
||||
|
||||
String name = "resourceHandlerMapping";
|
||||
|
|
Loading…
Reference in New Issue