Search in sources :

Example 1 with ProtobufDecoder

use of org.springframework.http.codec.protobuf.ProtobufDecoder in project spring-framework by spring-projects.

the class BaseDefaultCodecs method initTypedReaders.

/**
 * Reset and initialize typed readers.
 * @since 5.3.3
 */
protected void initTypedReaders() {
    this.typedReaders.clear();
    if (!this.registerDefaults) {
        return;
    }
    addCodec(this.typedReaders, new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
    addCodec(this.typedReaders, new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
    addCodec(this.typedReaders, new DecoderHttpMessageReader<>(new DataBufferDecoder()));
    if (nettyByteBufPresent) {
        addCodec(this.typedReaders, new DecoderHttpMessageReader<>(new NettyByteBufDecoder()));
    }
    addCodec(this.typedReaders, new ResourceHttpMessageReader(new ResourceDecoder()));
    addCodec(this.typedReaders, new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly()));
    if (protobufPresent) {
        addCodec(this.typedReaders, new DecoderHttpMessageReader<>(this.protobufDecoder != null ? (ProtobufDecoder) this.protobufDecoder : new ProtobufDecoder()));
    }
    addCodec(this.typedReaders, new FormHttpMessageReader());
    // client vs server..
    extendTypedReaders(this.typedReaders);
}
Also used : FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) NettyByteBufDecoder(org.springframework.core.codec.NettyByteBufDecoder) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) AbstractDataBufferDecoder(org.springframework.core.codec.AbstractDataBufferDecoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) ResourceHttpMessageReader(org.springframework.http.codec.ResourceHttpMessageReader) ResourceDecoder(org.springframework.core.codec.ResourceDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder)

Example 2 with ProtobufDecoder

use of org.springframework.http.codec.protobuf.ProtobufDecoder in project spring-framework by spring-projects.

the class ClientCodecConfigurerTests method maxInMemorySize.

@Test
public void maxInMemorySize() {
    int size = 99;
    this.configurer.defaultCodecs().maxInMemorySize(size);
    List<HttpMessageReader<?>> readers = this.configurer.getReaders();
    assertThat(readers.size()).isEqualTo(14);
    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);
    assertThat(((FormHttpMessageReader) nextReader(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((KotlinSerializationJsonDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2JsonDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2SmileDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jaxb2XmlDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    ServerSentEventHttpMessageReader reader = (ServerSentEventHttpMessageReader) nextReader(readers);
    assertThat(reader.getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2JsonDecoder) reader.getDecoder()).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((StringDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
}
Also used : Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) ResourceDecoder(org.springframework.core.codec.ResourceDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ServerSentEventHttpMessageReader(org.springframework.http.codec.ServerSentEventHttpMessageReader) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) ResourceHttpMessageReader(org.springframework.http.codec.ResourceHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) NettyByteBufDecoder(org.springframework.core.codec.NettyByteBufDecoder) KotlinSerializationJsonDecoder(org.springframework.http.codec.json.KotlinSerializationJsonDecoder) ServerSentEventHttpMessageReader(org.springframework.http.codec.ServerSentEventHttpMessageReader) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Jackson2SmileDecoder(org.springframework.http.codec.json.Jackson2SmileDecoder) Test(org.junit.jupiter.api.Test)

Example 3 with ProtobufDecoder

use of org.springframework.http.codec.protobuf.ProtobufDecoder in project spring-framework by spring-projects.

the class ServerCodecConfigurerTests method maxInMemorySize.

@Test
public void maxInMemorySize() {
    int size = 99;
    this.configurer.defaultCodecs().maxInMemorySize(size);
    List<HttpMessageReader<?>> readers = this.configurer.getReaders();
    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);
    assertThat(((FormHttpMessageReader) nextReader(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((DefaultPartHttpMessageReader) nextReader(readers)).getMaxInMemorySize()).isEqualTo(size);
    MultipartHttpMessageReader multipartReader = (MultipartHttpMessageReader) nextReader(readers);
    DefaultPartHttpMessageReader reader = (DefaultPartHttpMessageReader) multipartReader.getPartReader();
    assertThat((reader).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((KotlinSerializationJsonDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2JsonDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2SmileDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jaxb2XmlDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((StringDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
}
Also used : MultipartHttpMessageReader(org.springframework.http.codec.multipart.MultipartHttpMessageReader) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) ResourceDecoder(org.springframework.core.codec.ResourceDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) ResourceHttpMessageReader(org.springframework.http.codec.ResourceHttpMessageReader) MultipartHttpMessageReader(org.springframework.http.codec.multipart.MultipartHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) NettyByteBufDecoder(org.springframework.core.codec.NettyByteBufDecoder) KotlinSerializationJsonDecoder(org.springframework.http.codec.json.KotlinSerializationJsonDecoder) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Jackson2SmileDecoder(org.springframework.http.codec.json.Jackson2SmileDecoder) Test(org.junit.jupiter.api.Test)

Example 4 with ProtobufDecoder

use of org.springframework.http.codec.protobuf.ProtobufDecoder in project spring-framework by spring-projects.

the class CodecConfigurerTests method encoderDecoderOverrides.

@Test
void encoderDecoderOverrides() {
    Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
    Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder();
    Jackson2SmileDecoder smileDecoder = new Jackson2SmileDecoder();
    Jackson2SmileEncoder smileEncoder = new Jackson2SmileEncoder();
    ProtobufDecoder protobufDecoder = new ProtobufDecoder(ExtensionRegistry.newInstance());
    ProtobufEncoder protobufEncoder = new ProtobufEncoder();
    Jaxb2XmlEncoder jaxb2Encoder = new Jaxb2XmlEncoder();
    Jaxb2XmlDecoder jaxb2Decoder = new Jaxb2XmlDecoder();
    this.configurer.defaultCodecs().jackson2JsonDecoder(jacksonDecoder);
    this.configurer.defaultCodecs().jackson2JsonEncoder(jacksonEncoder);
    this.configurer.defaultCodecs().jackson2SmileDecoder(smileDecoder);
    this.configurer.defaultCodecs().jackson2SmileEncoder(smileEncoder);
    this.configurer.defaultCodecs().protobufDecoder(protobufDecoder);
    this.configurer.defaultCodecs().protobufEncoder(protobufEncoder);
    this.configurer.defaultCodecs().jaxb2Decoder(jaxb2Decoder);
    this.configurer.defaultCodecs().jaxb2Encoder(jaxb2Encoder);
    assertDecoderInstance(jacksonDecoder);
    assertDecoderInstance(smileDecoder);
    assertDecoderInstance(protobufDecoder);
    assertDecoderInstance(jaxb2Decoder);
    assertEncoderInstance(jacksonEncoder);
    assertEncoderInstance(smileEncoder);
    assertEncoderInstance(protobufEncoder);
    assertEncoderInstance(jaxb2Encoder);
}
Also used : ProtobufEncoder(org.springframework.http.codec.protobuf.ProtobufEncoder) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jackson2SmileEncoder(org.springframework.http.codec.json.Jackson2SmileEncoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) Jackson2SmileDecoder(org.springframework.http.codec.json.Jackson2SmileDecoder) Test(org.junit.jupiter.api.Test)

Example 5 with ProtobufDecoder

use of org.springframework.http.codec.protobuf.ProtobufDecoder in project spring-framework by spring-projects.

the class CodecConfigurerTests method cloneDefaultCodecs.

@Test
void cloneDefaultCodecs() {
    CodecConfigurer clone = this.configurer.clone();
    Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
    Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder();
    Jaxb2XmlDecoder jaxb2Decoder = new Jaxb2XmlDecoder();
    Jaxb2XmlEncoder jaxb2Encoder = new Jaxb2XmlEncoder();
    ProtobufDecoder protoDecoder = new ProtobufDecoder();
    ProtobufEncoder protoEncoder = new ProtobufEncoder();
    clone.defaultCodecs().jackson2JsonDecoder(jacksonDecoder);
    clone.defaultCodecs().jackson2JsonEncoder(jacksonEncoder);
    clone.defaultCodecs().jaxb2Decoder(jaxb2Decoder);
    clone.defaultCodecs().jaxb2Encoder(jaxb2Encoder);
    clone.defaultCodecs().protobufDecoder(protoDecoder);
    clone.defaultCodecs().protobufEncoder(protoEncoder);
    // Clone has the customized the customizations
    List<Decoder<?>> decoders = clone.getReaders().stream().filter(reader -> reader instanceof DecoderHttpMessageReader).map(reader -> ((DecoderHttpMessageReader<?>) reader).getDecoder()).collect(Collectors.toList());
    List<Encoder<?>> encoders = clone.getWriters().stream().filter(writer -> writer instanceof EncoderHttpMessageWriter).map(reader -> ((EncoderHttpMessageWriter<?>) reader).getEncoder()).collect(Collectors.toList());
    assertThat(decoders).contains(jacksonDecoder, jaxb2Decoder, protoDecoder);
    assertThat(encoders).contains(jacksonEncoder, jaxb2Encoder, protoEncoder);
    // Original does not have the customizations
    decoders = this.configurer.getReaders().stream().filter(reader -> reader instanceof DecoderHttpMessageReader).map(reader -> ((DecoderHttpMessageReader<?>) reader).getDecoder()).collect(Collectors.toList());
    encoders = this.configurer.getWriters().stream().filter(writer -> writer instanceof EncoderHttpMessageWriter).map(reader -> ((EncoderHttpMessageWriter<?>) reader).getEncoder()).collect(Collectors.toList());
    assertThat(decoders).doesNotContain(jacksonDecoder, jaxb2Decoder, protoDecoder);
    assertThat(encoders).doesNotContain(jacksonEncoder, jaxb2Encoder, protoEncoder);
}
Also used : CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) Decoder(org.springframework.core.codec.Decoder) ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) ServerSentEventHttpMessageReader(org.springframework.http.codec.ServerSentEventHttpMessageReader) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) NettyByteBufDecoder(org.springframework.core.codec.NettyByteBufDecoder) KotlinSerializationJsonEncoder(org.springframework.http.codec.json.KotlinSerializationJsonEncoder) EncoderHttpMessageWriter(org.springframework.http.codec.EncoderHttpMessageWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) ResolvableType(org.springframework.core.ResolvableType) ResourceHttpMessageReader(org.springframework.http.codec.ResourceHttpMessageReader) Encoder(org.springframework.core.codec.Encoder) Jackson2SmileDecoder(org.springframework.http.codec.json.Jackson2SmileDecoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) KotlinSerializationJsonDecoder(org.springframework.http.codec.json.KotlinSerializationJsonDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) MediaType(org.springframework.http.MediaType) ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) NettyByteBufEncoder(org.springframework.core.codec.NettyByteBufEncoder) CodecConfigurer(org.springframework.http.codec.CodecConfigurer) MimeTypeUtils(org.springframework.util.MimeTypeUtils) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) Collectors(java.util.stream.Collectors) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) Test(org.junit.jupiter.api.Test) DataBufferEncoder(org.springframework.core.codec.DataBufferEncoder) ProtobufEncoder(org.springframework.http.codec.protobuf.ProtobufEncoder) List(java.util.List) Jackson2SmileEncoder(org.springframework.http.codec.json.Jackson2SmileEncoder) ProtobufHttpMessageWriter(org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) Mockito.mock(org.mockito.Mockito.mock) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) ProtobufEncoder(org.springframework.http.codec.protobuf.ProtobufEncoder) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) Decoder(org.springframework.core.codec.Decoder) NettyByteBufDecoder(org.springframework.core.codec.NettyByteBufDecoder) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) Jackson2SmileDecoder(org.springframework.http.codec.json.Jackson2SmileDecoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) KotlinSerializationJsonDecoder(org.springframework.http.codec.json.KotlinSerializationJsonDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) EncoderHttpMessageWriter(org.springframework.http.codec.EncoderHttpMessageWriter) CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) KotlinSerializationJsonEncoder(org.springframework.http.codec.json.KotlinSerializationJsonEncoder) Encoder(org.springframework.core.codec.Encoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) NettyByteBufEncoder(org.springframework.core.codec.NettyByteBufEncoder) DataBufferEncoder(org.springframework.core.codec.DataBufferEncoder) ProtobufEncoder(org.springframework.http.codec.protobuf.ProtobufEncoder) Jackson2SmileEncoder(org.springframework.http.codec.json.Jackson2SmileEncoder) CodecConfigurer(org.springframework.http.codec.CodecConfigurer) Test(org.junit.jupiter.api.Test)

Aggregations

ProtobufDecoder (org.springframework.http.codec.protobuf.ProtobufDecoder)6 Test (org.junit.jupiter.api.Test)5 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)4 ByteBufferDecoder (org.springframework.core.codec.ByteBufferDecoder)4 DataBufferDecoder (org.springframework.core.codec.DataBufferDecoder)4 NettyByteBufDecoder (org.springframework.core.codec.NettyByteBufDecoder)4 FormHttpMessageReader (org.springframework.http.codec.FormHttpMessageReader)4 ResourceHttpMessageReader (org.springframework.http.codec.ResourceHttpMessageReader)4 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)4 Jackson2SmileDecoder (org.springframework.http.codec.json.Jackson2SmileDecoder)4 Jaxb2XmlDecoder (org.springframework.http.codec.xml.Jaxb2XmlDecoder)4 ResourceDecoder (org.springframework.core.codec.ResourceDecoder)3 StringDecoder (org.springframework.core.codec.StringDecoder)3 DecoderHttpMessageReader (org.springframework.http.codec.DecoderHttpMessageReader)3 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)3 KotlinSerializationJsonDecoder (org.springframework.http.codec.json.KotlinSerializationJsonDecoder)3 ServerSentEventHttpMessageReader (org.springframework.http.codec.ServerSentEventHttpMessageReader)2 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)2 Jackson2SmileEncoder (org.springframework.http.codec.json.Jackson2SmileEncoder)2 ProtobufEncoder (org.springframework.http.codec.protobuf.ProtobufEncoder)2