Search in sources :

Example 1 with ProtobufEncoder

use of cn.taketoday.http.codec.protobuf.ProtobufEncoder 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 ProtobufEncoder

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

the class CancelWithoutDemandCodecTests method cancelWithProtobufEncoder.

// gh-22543
@Test
public void cancelWithProtobufEncoder() {
    ProtobufEncoder encoder = new ProtobufEncoder();
    Msg msg = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build();
    Flux<DataBuffer> flux = encoder.encode(Mono.just(msg), this.bufferFactory, ResolvableType.fromClass(Msg.class), new MimeType("application", "x-protobuf"), Collections.emptyMap());
    BaseSubscriber<DataBuffer> subscriber = new ZeroDemandSubscriber();
    // Assume sync execution (e.g. encoding with Flux.just)..
    flux.subscribe(subscriber);
    subscriber.cancel();
}
Also used : Msg(cn.taketoday.protobuf.Msg) SecondMsg(cn.taketoday.protobuf.SecondMsg) ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) MimeType(cn.taketoday.util.MimeType) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 3 with ProtobufEncoder

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

the class CancelWithoutDemandCodecTests method cancelWithProtobufEncoder.

// gh-22543
@Test
public void cancelWithProtobufEncoder() {
    ProtobufEncoder encoder = new ProtobufEncoder();
    Msg msg = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build();
    Flux<DataBuffer> flux = encoder.encode(Mono.just(msg), this.bufferFactory, ResolvableType.fromClass(Msg.class), new MimeType("application", "x-protobuf"), Collections.emptyMap());
    BaseSubscriber<DataBuffer> subscriber = new ZeroDemandSubscriber();
    // Assume sync execution (e.g. encoding with Flux.just)..
    flux.subscribe(subscriber);
    subscriber.cancel();
}
Also used : Msg(cn.taketoday.protobuf.Msg) SecondMsg(cn.taketoday.protobuf.SecondMsg) ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) MimeType(cn.taketoday.util.MimeType) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 4 with ProtobufEncoder

use of cn.taketoday.http.codec.protobuf.ProtobufEncoder 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 5 with ProtobufEncoder

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

the class BaseDefaultCodecs method getBaseTypedWriters.

/**
 * Return "base" typed writers only, i.e. common to client and server.
 */
final List<HttpMessageWriter<?>> getBaseTypedWriters() {
    if (!this.registerDefaults) {
        return Collections.emptyList();
    }
    List<HttpMessageWriter<?>> writers = new ArrayList<>();
    addCodec(writers, new EncoderHttpMessageWriter<>(new ByteArrayEncoder()));
    addCodec(writers, new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
    addCodec(writers, new EncoderHttpMessageWriter<>(new DataBufferEncoder()));
    if (nettyByteBufPresent) {
        addCodec(writers, new EncoderHttpMessageWriter<>(new NettyByteBufEncoder()));
    }
    addCodec(writers, new ResourceHttpMessageWriter());
    addCodec(writers, new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
    if (protobufPresent) {
        addCodec(writers, new ProtobufHttpMessageWriter(this.protobufEncoder != null ? (ProtobufEncoder) this.protobufEncoder : new ProtobufEncoder()));
    }
    return writers;
}
Also used : ByteBufferEncoder(cn.taketoday.core.codec.ByteBufferEncoder) ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) MultipartHttpMessageWriter(cn.taketoday.http.codec.multipart.MultipartHttpMessageWriter) FormHttpMessageWriter(cn.taketoday.http.codec.FormHttpMessageWriter) EncoderHttpMessageWriter(cn.taketoday.http.codec.EncoderHttpMessageWriter) HttpMessageWriter(cn.taketoday.http.codec.HttpMessageWriter) ResourceHttpMessageWriter(cn.taketoday.http.codec.ResourceHttpMessageWriter) ProtobufHttpMessageWriter(cn.taketoday.http.codec.protobuf.ProtobufHttpMessageWriter) ByteArrayEncoder(cn.taketoday.core.codec.ByteArrayEncoder) DataBufferEncoder(cn.taketoday.core.codec.DataBufferEncoder) ArrayList(java.util.ArrayList) NettyByteBufEncoder(cn.taketoday.core.codec.NettyByteBufEncoder) ResourceHttpMessageWriter(cn.taketoday.http.codec.ResourceHttpMessageWriter) ProtobufHttpMessageWriter(cn.taketoday.http.codec.protobuf.ProtobufHttpMessageWriter)

Aggregations

ProtobufEncoder (cn.taketoday.http.codec.protobuf.ProtobufEncoder)8 Test (org.junit.jupiter.api.Test)6 ByteArrayEncoder (cn.taketoday.core.codec.ByteArrayEncoder)4 ByteBufferEncoder (cn.taketoday.core.codec.ByteBufferEncoder)4 DataBufferEncoder (cn.taketoday.core.codec.DataBufferEncoder)4 NettyByteBufEncoder (cn.taketoday.core.codec.NettyByteBufEncoder)4 EncoderHttpMessageWriter (cn.taketoday.http.codec.EncoderHttpMessageWriter)4 HttpMessageWriter (cn.taketoday.http.codec.HttpMessageWriter)4 ResourceHttpMessageWriter (cn.taketoday.http.codec.ResourceHttpMessageWriter)4 ServerSentEventHttpMessageWriter (cn.taketoday.http.codec.ServerSentEventHttpMessageWriter)4 Jackson2JsonDecoder (cn.taketoday.http.codec.json.Jackson2JsonDecoder)4 Jackson2JsonEncoder (cn.taketoday.http.codec.json.Jackson2JsonEncoder)4 Jackson2SmileDecoder (cn.taketoday.http.codec.json.Jackson2SmileDecoder)4 Jackson2SmileEncoder (cn.taketoday.http.codec.json.Jackson2SmileEncoder)4 ProtobufDecoder (cn.taketoday.http.codec.protobuf.ProtobufDecoder)4 ProtobufHttpMessageWriter (cn.taketoday.http.codec.protobuf.ProtobufHttpMessageWriter)4 ResolvableType (cn.taketoday.core.ResolvableType)2 ByteArrayDecoder (cn.taketoday.core.codec.ByteArrayDecoder)2 ByteBufferDecoder (cn.taketoday.core.codec.ByteBufferDecoder)2 CharSequenceEncoder (cn.taketoday.core.codec.CharSequenceEncoder)2