Search in sources :

Example 6 with ByteBufferDecoder

use of org.springframework.core.codec.ByteBufferDecoder in project spring-framework by spring-projects.

the class BodyExtractorsTests method createContext.

@BeforeEach
public void createContext() {
    final List<HttpMessageReader<?>> messageReaders = new ArrayList<>();
    messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
    messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
    messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
    messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
    messageReaders.add(new FormHttpMessageReader());
    DefaultPartHttpMessageReader partReader = new DefaultPartHttpMessageReader();
    messageReaders.add(partReader);
    messageReaders.add(new MultipartHttpMessageReader(partReader));
    messageReaders.add(new FormHttpMessageReader());
    this.context = new BodyExtractor.Context() {

        @Override
        public List<HttpMessageReader<?>> messageReaders() {
            return messageReaders;
        }

        @Override
        public Optional<ServerHttpResponse> serverResponse() {
            return serverResponse;
        }

        @Override
        public Map<String, Object> hints() {
            return hints;
        }
    };
    this.hints = new HashMap<>();
}
Also used : MultipartHttpMessageReader(org.springframework.http.codec.multipart.MultipartHttpMessageReader) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) Optional(java.util.Optional) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) ArrayList(java.util.ArrayList) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) MultipartHttpMessageReader(org.springframework.http.codec.multipart.MultipartHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with ByteBufferDecoder

use of org.springframework.core.codec.ByteBufferDecoder 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 8 with ByteBufferDecoder

use of org.springframework.core.codec.ByteBufferDecoder 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 9 with ByteBufferDecoder

use of org.springframework.core.codec.ByteBufferDecoder 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)

Aggregations

ByteBufferDecoder (org.springframework.core.codec.ByteBufferDecoder)9 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)7 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)6 DecoderHttpMessageReader (org.springframework.http.codec.DecoderHttpMessageReader)5 FormHttpMessageReader (org.springframework.http.codec.FormHttpMessageReader)5 Jaxb2XmlDecoder (org.springframework.http.codec.xml.Jaxb2XmlDecoder)5 DataBufferDecoder (org.springframework.core.codec.DataBufferDecoder)4 ResourceDecoder (org.springframework.core.codec.ResourceDecoder)4 StringDecoder (org.springframework.core.codec.StringDecoder)4 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Test (org.junit.jupiter.api.Test)3 NettyByteBufDecoder (org.springframework.core.codec.NettyByteBufDecoder)3 ResourceHttpMessageReader (org.springframework.http.codec.ResourceHttpMessageReader)3 ProtobufDecoder (org.springframework.http.codec.protobuf.ProtobufDecoder)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2