Search in sources :

Example 1 with CodecConfigurer

use of cn.taketoday.http.codec.CodecConfigurer in project today-infrastructure by TAKETODAY.

the class CodecConfigurerTests method cloneDefaultCodecs.

@Test
void cloneDefaultCodecs() {
    CodecConfigurer clone = this.configurer.clone();
    Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
    Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder();
    ProtobufDecoder protoDecoder = new ProtobufDecoder();
    ProtobufEncoder protoEncoder = new ProtobufEncoder();
    clone.defaultCodecs().jackson2JsonDecoder(jacksonDecoder);
    clone.defaultCodecs().jackson2JsonEncoder(jacksonEncoder);
    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());
    // 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());
}
Also used : ResourceHttpMessageReader(cn.taketoday.http.codec.ResourceHttpMessageReader) ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) Decoder(cn.taketoday.core.codec.Decoder) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) ByteBufferEncoder(cn.taketoday.core.codec.ByteBufferEncoder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) NettyByteBufEncoder(cn.taketoday.core.codec.NettyByteBufEncoder) CharSequenceEncoder(cn.taketoday.core.codec.CharSequenceEncoder) CodecConfigurer(cn.taketoday.http.codec.CodecConfigurer) FormHttpMessageReader(cn.taketoday.http.codec.FormHttpMessageReader) StringDecoder(cn.taketoday.core.codec.StringDecoder) EncoderHttpMessageWriter(cn.taketoday.http.codec.EncoderHttpMessageWriter) ByteBufferDecoder(cn.taketoday.core.codec.ByteBufferDecoder) DataBufferEncoder(cn.taketoday.core.codec.DataBufferEncoder) ByteArrayDecoder(cn.taketoday.core.codec.ByteArrayDecoder) Jackson2SmileDecoder(cn.taketoday.http.codec.json.Jackson2SmileDecoder) ResolvableType(cn.taketoday.core.ResolvableType) HttpMessageWriter(cn.taketoday.http.codec.HttpMessageWriter) MimeTypeUtils(cn.taketoday.util.MimeTypeUtils) ProtobufDecoder(cn.taketoday.http.codec.protobuf.ProtobufDecoder) Collectors(java.util.stream.Collectors) ResourceHttpMessageWriter(cn.taketoday.http.codec.ResourceHttpMessageWriter) Test(org.junit.jupiter.api.Test) ServerSentEventHttpMessageReader(cn.taketoday.http.codec.ServerSentEventHttpMessageReader) List(java.util.List) ByteArrayEncoder(cn.taketoday.core.codec.ByteArrayEncoder) Jackson2SmileEncoder(cn.taketoday.http.codec.json.Jackson2SmileEncoder) DataBufferDecoder(cn.taketoday.core.codec.DataBufferDecoder) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) ProtobufHttpMessageWriter(cn.taketoday.http.codec.protobuf.ProtobufHttpMessageWriter) NettyByteBufDecoder(cn.taketoday.core.codec.NettyByteBufDecoder) DecoderHttpMessageReader(cn.taketoday.http.codec.DecoderHttpMessageReader) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) HttpMessageReader(cn.taketoday.http.codec.HttpMessageReader) MediaType(cn.taketoday.http.MediaType) Encoder(cn.taketoday.core.codec.Encoder) Mockito.mock(org.mockito.Mockito.mock) DecoderHttpMessageReader(cn.taketoday.http.codec.DecoderHttpMessageReader) ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) EncoderHttpMessageWriter(cn.taketoday.http.codec.EncoderHttpMessageWriter) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) ByteBufferEncoder(cn.taketoday.core.codec.ByteBufferEncoder) NettyByteBufEncoder(cn.taketoday.core.codec.NettyByteBufEncoder) CharSequenceEncoder(cn.taketoday.core.codec.CharSequenceEncoder) DataBufferEncoder(cn.taketoday.core.codec.DataBufferEncoder) ByteArrayEncoder(cn.taketoday.core.codec.ByteArrayEncoder) Jackson2SmileEncoder(cn.taketoday.http.codec.json.Jackson2SmileEncoder) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) Encoder(cn.taketoday.core.codec.Encoder) ProtobufDecoder(cn.taketoday.http.codec.protobuf.ProtobufDecoder) Decoder(cn.taketoday.core.codec.Decoder) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) StringDecoder(cn.taketoday.core.codec.StringDecoder) ByteBufferDecoder(cn.taketoday.core.codec.ByteBufferDecoder) ByteArrayDecoder(cn.taketoday.core.codec.ByteArrayDecoder) Jackson2SmileDecoder(cn.taketoday.http.codec.json.Jackson2SmileDecoder) ProtobufDecoder(cn.taketoday.http.codec.protobuf.ProtobufDecoder) DataBufferDecoder(cn.taketoday.core.codec.DataBufferDecoder) NettyByteBufDecoder(cn.taketoday.core.codec.NettyByteBufDecoder) CodecConfigurer(cn.taketoday.http.codec.CodecConfigurer) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) Test(org.junit.jupiter.api.Test)

Example 2 with CodecConfigurer

use of cn.taketoday.http.codec.CodecConfigurer in project today-framework by TAKETODAY.

the class CodecConfigurerTests method cloneDefaultCodecs.

@Test
void cloneDefaultCodecs() {
    CodecConfigurer clone = this.configurer.clone();
    Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
    Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder();
    ProtobufDecoder protoDecoder = new ProtobufDecoder();
    ProtobufEncoder protoEncoder = new ProtobufEncoder();
    clone.defaultCodecs().jackson2JsonDecoder(jacksonDecoder);
    clone.defaultCodecs().jackson2JsonEncoder(jacksonEncoder);
    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());
    // 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());
}
Also used : ResourceHttpMessageReader(cn.taketoday.http.codec.ResourceHttpMessageReader) ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) Decoder(cn.taketoday.core.codec.Decoder) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) ByteBufferEncoder(cn.taketoday.core.codec.ByteBufferEncoder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) NettyByteBufEncoder(cn.taketoday.core.codec.NettyByteBufEncoder) CharSequenceEncoder(cn.taketoday.core.codec.CharSequenceEncoder) CodecConfigurer(cn.taketoday.http.codec.CodecConfigurer) FormHttpMessageReader(cn.taketoday.http.codec.FormHttpMessageReader) StringDecoder(cn.taketoday.core.codec.StringDecoder) EncoderHttpMessageWriter(cn.taketoday.http.codec.EncoderHttpMessageWriter) ByteBufferDecoder(cn.taketoday.core.codec.ByteBufferDecoder) DataBufferEncoder(cn.taketoday.core.codec.DataBufferEncoder) ByteArrayDecoder(cn.taketoday.core.codec.ByteArrayDecoder) Jackson2SmileDecoder(cn.taketoday.http.codec.json.Jackson2SmileDecoder) ResolvableType(cn.taketoday.core.ResolvableType) HttpMessageWriter(cn.taketoday.http.codec.HttpMessageWriter) MimeTypeUtils(cn.taketoday.util.MimeTypeUtils) ProtobufDecoder(cn.taketoday.http.codec.protobuf.ProtobufDecoder) Collectors(java.util.stream.Collectors) ResourceHttpMessageWriter(cn.taketoday.http.codec.ResourceHttpMessageWriter) Test(org.junit.jupiter.api.Test) ServerSentEventHttpMessageReader(cn.taketoday.http.codec.ServerSentEventHttpMessageReader) List(java.util.List) ByteArrayEncoder(cn.taketoday.core.codec.ByteArrayEncoder) Jackson2SmileEncoder(cn.taketoday.http.codec.json.Jackson2SmileEncoder) DataBufferDecoder(cn.taketoday.core.codec.DataBufferDecoder) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) ProtobufHttpMessageWriter(cn.taketoday.http.codec.protobuf.ProtobufHttpMessageWriter) NettyByteBufDecoder(cn.taketoday.core.codec.NettyByteBufDecoder) DecoderHttpMessageReader(cn.taketoday.http.codec.DecoderHttpMessageReader) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) HttpMessageReader(cn.taketoday.http.codec.HttpMessageReader) MediaType(cn.taketoday.http.MediaType) Encoder(cn.taketoday.core.codec.Encoder) Mockito.mock(org.mockito.Mockito.mock) DecoderHttpMessageReader(cn.taketoday.http.codec.DecoderHttpMessageReader) ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) EncoderHttpMessageWriter(cn.taketoday.http.codec.EncoderHttpMessageWriter) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) ByteBufferEncoder(cn.taketoday.core.codec.ByteBufferEncoder) NettyByteBufEncoder(cn.taketoday.core.codec.NettyByteBufEncoder) CharSequenceEncoder(cn.taketoday.core.codec.CharSequenceEncoder) DataBufferEncoder(cn.taketoday.core.codec.DataBufferEncoder) ByteArrayEncoder(cn.taketoday.core.codec.ByteArrayEncoder) Jackson2SmileEncoder(cn.taketoday.http.codec.json.Jackson2SmileEncoder) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) Encoder(cn.taketoday.core.codec.Encoder) ProtobufDecoder(cn.taketoday.http.codec.protobuf.ProtobufDecoder) Decoder(cn.taketoday.core.codec.Decoder) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) StringDecoder(cn.taketoday.core.codec.StringDecoder) ByteBufferDecoder(cn.taketoday.core.codec.ByteBufferDecoder) ByteArrayDecoder(cn.taketoday.core.codec.ByteArrayDecoder) Jackson2SmileDecoder(cn.taketoday.http.codec.json.Jackson2SmileDecoder) ProtobufDecoder(cn.taketoday.http.codec.protobuf.ProtobufDecoder) DataBufferDecoder(cn.taketoday.core.codec.DataBufferDecoder) NettyByteBufDecoder(cn.taketoday.core.codec.NettyByteBufDecoder) CodecConfigurer(cn.taketoday.http.codec.CodecConfigurer) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) Test(org.junit.jupiter.api.Test)

Example 3 with CodecConfigurer

use of cn.taketoday.http.codec.CodecConfigurer in project today-framework by TAKETODAY.

the class CodecConfigurerTests method cloneCustomCodecs.

@Test
void cloneCustomCodecs() {
    this.configurer.registerDefaults(false);
    assertThat(this.configurer.getReaders()).isEmpty();
    assertThat(this.configurer.getWriters()).isEmpty();
    this.configurer.customCodecs().register(new Jackson2JsonEncoder());
    this.configurer.customCodecs().register(new Jackson2JsonDecoder());
    this.configurer.customCodecs().register(new ServerSentEventHttpMessageReader());
    this.configurer.customCodecs().register(new ServerSentEventHttpMessageWriter());
    assertThat(this.configurer.getReaders()).hasSize(2);
    assertThat(this.configurer.getWriters()).hasSize(2);
    CodecConfigurer clone = this.configurer.clone();
    assertThat(this.configurer.getReaders()).hasSize(2);
    assertThat(this.configurer.getWriters()).hasSize(2);
    assertThat(clone.getReaders()).hasSize(2);
    assertThat(clone.getWriters()).hasSize(2);
}
Also used : ServerSentEventHttpMessageReader(cn.taketoday.http.codec.ServerSentEventHttpMessageReader) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) CodecConfigurer(cn.taketoday.http.codec.CodecConfigurer) Test(org.junit.jupiter.api.Test)

Example 4 with CodecConfigurer

use of cn.taketoday.http.codec.CodecConfigurer in project today-framework by TAKETODAY.

the class CodecConfigurerTests method cloneEmptyCustomCodecs.

@Test
void cloneEmptyCustomCodecs() {
    this.configurer.registerDefaults(false);
    assertThat(this.configurer.getReaders()).isEmpty();
    assertThat(this.configurer.getWriters()).isEmpty();
    CodecConfigurer clone = this.configurer.clone();
    clone.customCodecs().register(new Jackson2JsonEncoder());
    clone.customCodecs().register(new Jackson2JsonDecoder());
    clone.customCodecs().register(new ServerSentEventHttpMessageReader());
    clone.customCodecs().register(new ServerSentEventHttpMessageWriter());
    assertThat(this.configurer.getReaders()).isEmpty();
    assertThat(this.configurer.getWriters()).isEmpty();
    assertThat(clone.getReaders()).hasSize(2);
    assertThat(clone.getWriters()).hasSize(2);
}
Also used : ServerSentEventHttpMessageReader(cn.taketoday.http.codec.ServerSentEventHttpMessageReader) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) CodecConfigurer(cn.taketoday.http.codec.CodecConfigurer) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) Test(org.junit.jupiter.api.Test)

Example 5 with CodecConfigurer

use of cn.taketoday.http.codec.CodecConfigurer in project today-infrastructure by TAKETODAY.

the class CodecConfigurerTests method cloneCustomCodecs.

@Test
void cloneCustomCodecs() {
    this.configurer.registerDefaults(false);
    assertThat(this.configurer.getReaders()).isEmpty();
    assertThat(this.configurer.getWriters()).isEmpty();
    this.configurer.customCodecs().register(new Jackson2JsonEncoder());
    this.configurer.customCodecs().register(new Jackson2JsonDecoder());
    this.configurer.customCodecs().register(new ServerSentEventHttpMessageReader());
    this.configurer.customCodecs().register(new ServerSentEventHttpMessageWriter());
    assertThat(this.configurer.getReaders()).hasSize(2);
    assertThat(this.configurer.getWriters()).hasSize(2);
    CodecConfigurer clone = this.configurer.clone();
    assertThat(this.configurer.getReaders()).hasSize(2);
    assertThat(this.configurer.getWriters()).hasSize(2);
    assertThat(clone.getReaders()).hasSize(2);
    assertThat(clone.getWriters()).hasSize(2);
}
Also used : ServerSentEventHttpMessageReader(cn.taketoday.http.codec.ServerSentEventHttpMessageReader) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) CodecConfigurer(cn.taketoday.http.codec.CodecConfigurer) Test(org.junit.jupiter.api.Test)

Aggregations

CodecConfigurer (cn.taketoday.http.codec.CodecConfigurer)6 ServerSentEventHttpMessageReader (cn.taketoday.http.codec.ServerSentEventHttpMessageReader)6 ServerSentEventHttpMessageWriter (cn.taketoday.http.codec.ServerSentEventHttpMessageWriter)6 Jackson2JsonDecoder (cn.taketoday.http.codec.json.Jackson2JsonDecoder)6 Jackson2JsonEncoder (cn.taketoday.http.codec.json.Jackson2JsonEncoder)6 Test (org.junit.jupiter.api.Test)6 ResolvableType (cn.taketoday.core.ResolvableType)2 ByteArrayDecoder (cn.taketoday.core.codec.ByteArrayDecoder)2 ByteArrayEncoder (cn.taketoday.core.codec.ByteArrayEncoder)2 ByteBufferDecoder (cn.taketoday.core.codec.ByteBufferDecoder)2 ByteBufferEncoder (cn.taketoday.core.codec.ByteBufferEncoder)2 CharSequenceEncoder (cn.taketoday.core.codec.CharSequenceEncoder)2 DataBufferDecoder (cn.taketoday.core.codec.DataBufferDecoder)2 DataBufferEncoder (cn.taketoday.core.codec.DataBufferEncoder)2 Decoder (cn.taketoday.core.codec.Decoder)2 Encoder (cn.taketoday.core.codec.Encoder)2 NettyByteBufDecoder (cn.taketoday.core.codec.NettyByteBufDecoder)2 NettyByteBufEncoder (cn.taketoday.core.codec.NettyByteBufEncoder)2 StringDecoder (cn.taketoday.core.codec.StringDecoder)2 MediaType (cn.taketoday.http.MediaType)2