org.springframework.http.codec.protobuf.ProtobufDecoder Java Examples
The following examples show how to use
org.springframework.http.codec.protobuf.ProtobufDecoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CancelWithoutDemandCodecTests.java From spring-analysis-note with MIT License | 7 votes |
@Test // gh-22731 public void cancelWithProtobufDecoder() throws InterruptedException { ProtobufDecoder decoder = new ProtobufDecoder(); Mono<DataBuffer> input = Mono.fromCallable(() -> { Msg msg = Msg.newBuilder().setFoo("Foo").build(); byte[] bytes = msg.toByteArray(); DataBuffer buffer = this.bufferFactory.allocateBuffer(bytes.length); buffer.write(bytes); return buffer; }); Flux<Message> messages = decoder.decode(input, ResolvableType.forType(Msg.class), new MimeType("application", "x-protobuf"), Collections.emptyMap()); ZeroDemandMessageSubscriber subscriber = new ZeroDemandMessageSubscriber(); messages.subscribe(subscriber); subscriber.cancel(); }
Example #2
Source File: BaseDefaultCodecs.java From spring-analysis-note with MIT License | 6 votes |
/** * Return readers that support specific types. */ final List<HttpMessageReader<?>> getTypedReaders() { if (!this.registerDefaults) { return Collections.emptyList(); } List<HttpMessageReader<?>> readers = new ArrayList<>(); readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder())); readers.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); readers.add(new DecoderHttpMessageReader<>(new DataBufferDecoder())); readers.add(new ResourceHttpMessageReader()); readers.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly())); if (protobufPresent) { Decoder<?> decoder = this.protobufDecoder != null ? this.protobufDecoder : new ProtobufDecoder(); readers.add(new DecoderHttpMessageReader<>(decoder)); } FormHttpMessageReader formReader = new FormHttpMessageReader(); formReader.setEnableLoggingRequestDetails(this.enableLoggingRequestDetails); readers.add(formReader); extendTypedReaders(readers); return readers; }
Example #3
Source File: ServerCodecConfigurerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void defaultReaders() { List<HttpMessageReader<?>> readers = this.configurer.getReaders(); assertEquals(13, readers.size()); assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ResourceHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertStringDecoder(getNextDecoder(readers), true); assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass()); assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertEquals(DefaultMultipartMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertEquals(MultipartHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass()); assertStringDecoder(getNextDecoder(readers), false); }
Example #4
Source File: ClientCodecConfigurerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void defaultReaders() { List<HttpMessageReader<?>> readers = this.configurer.getReaders(); assertEquals(12, readers.size()); assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ResourceHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertStringDecoder(getNextDecoder(readers), true); assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass()); assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); // SPR-16804 assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass()); assertSseReader(readers); assertStringDecoder(getNextDecoder(readers), false); }
Example #5
Source File: CodecConfigurerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void defaultReaders() { List<HttpMessageReader<?>> readers = this.configurer.getReaders(); assertEquals(11, readers.size()); assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ResourceHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertStringDecoder(getNextDecoder(readers), true); assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass()); assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass()); assertStringDecoder(getNextDecoder(readers), false); }
Example #6
Source File: CodecConfigurerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void encoderDecoderOverrides() { Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder(); Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder(); 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().protobufDecoder(protobufDecoder); this.configurer.defaultCodecs().protobufEncoder(protobufEncoder); this.configurer.defaultCodecs().jaxb2Decoder(jaxb2Decoder); this.configurer.defaultCodecs().jaxb2Encoder(jaxb2Encoder); assertDecoderInstance(jacksonDecoder); assertDecoderInstance(protobufDecoder); assertDecoderInstance(jaxb2Decoder); assertEncoderInstance(jacksonEncoder); assertEncoderInstance(protobufEncoder); assertEncoderInstance(jaxb2Encoder); }
Example #7
Source File: BaseDefaultCodecs.java From java-technology-stack with MIT License | 6 votes |
/** * Return readers that support specific types. */ final List<HttpMessageReader<?>> getTypedReaders() { if (!this.registerDefaults) { return Collections.emptyList(); } List<HttpMessageReader<?>> readers = new ArrayList<>(); readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder())); readers.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); readers.add(new DecoderHttpMessageReader<>(new DataBufferDecoder())); readers.add(new DecoderHttpMessageReader<>(new ResourceDecoder())); readers.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly())); if (protobufPresent) { Decoder<?> decoder = this.protobufDecoder != null ? this.protobufDecoder : new ProtobufDecoder(); readers.add(new DecoderHttpMessageReader<>(decoder)); } FormHttpMessageReader formReader = new FormHttpMessageReader(); formReader.setEnableLoggingRequestDetails(this.enableLoggingRequestDetails); readers.add(formReader); extendTypedReaders(readers); return readers; }
Example #8
Source File: ServerCodecConfigurerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void defaultReaders() { List<HttpMessageReader<?>> readers = this.configurer.getReaders(); assertEquals(13, readers.size()); assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ResourceDecoder.class, getNextDecoder(readers).getClass()); assertStringDecoder(getNextDecoder(readers), true); assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass()); assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertEquals(SynchronossPartHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertEquals(MultipartHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass()); assertStringDecoder(getNextDecoder(readers), false); }
Example #9
Source File: ClientCodecConfigurerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void defaultReaders() { List<HttpMessageReader<?>> readers = this.configurer.getReaders(); assertEquals(12, readers.size()); assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ResourceDecoder.class, getNextDecoder(readers).getClass()); assertStringDecoder(getNextDecoder(readers), true); assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass()); assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); // SPR-16804 assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass()); assertSseReader(readers); assertStringDecoder(getNextDecoder(readers), false); }
Example #10
Source File: CodecConfigurerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void defaultReaders() { List<HttpMessageReader<?>> readers = this.configurer.getReaders(); assertEquals(11, readers.size()); assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ResourceDecoder.class, getNextDecoder(readers).getClass()); assertStringDecoder(getNextDecoder(readers), true); assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass()); assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass()); assertStringDecoder(getNextDecoder(readers), false); }
Example #11
Source File: CodecConfigurerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void encoderDecoderOverrides() { Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder(); Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder(); 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().protobufDecoder(protobufDecoder); this.configurer.defaultCodecs().protobufEncoder(protobufEncoder); this.configurer.defaultCodecs().jaxb2Decoder(jaxb2Decoder); this.configurer.defaultCodecs().jaxb2Encoder(jaxb2Encoder); assertDecoderInstance(jacksonDecoder); assertDecoderInstance(protobufDecoder); assertDecoderInstance(jaxb2Decoder); assertEncoderInstance(jacksonEncoder); assertEncoderInstance(protobufEncoder); assertEncoderInstance(jaxb2Encoder); }
Example #12
Source File: CodecConfigurerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void defaultAndCustomReaders() { Decoder<?> customDecoder1 = mock(Decoder.class); Decoder<?> customDecoder2 = mock(Decoder.class); given(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(false); given(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).willReturn(true); HttpMessageReader<?> customReader1 = mock(HttpMessageReader.class); HttpMessageReader<?> customReader2 = mock(HttpMessageReader.class); given(customReader1.canRead(ResolvableType.forClass(Object.class), null)).willReturn(false); given(customReader2.canRead(ResolvableType.forClass(Object.class), null)).willReturn(true); this.configurer.customCodecs().decoder(customDecoder1); this.configurer.customCodecs().decoder(customDecoder2); this.configurer.customCodecs().reader(customReader1); this.configurer.customCodecs().reader(customReader2); List<HttpMessageReader<?>> readers = this.configurer.getReaders(); assertEquals(15, readers.size()); assertSame(customDecoder1, getNextDecoder(readers)); assertSame(customReader1, readers.get(this.index.getAndIncrement())); assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ResourceHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertEquals(StringDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass()); assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertSame(customDecoder2, getNextDecoder(readers)); assertSame(customReader2, readers.get(this.index.getAndIncrement())); assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass()); assertEquals(StringDecoder.class, getNextDecoder(readers).getClass()); }
Example #13
Source File: CodecConfigurerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void defaultAndCustomReaders() { Decoder<?> customDecoder1 = mock(Decoder.class); Decoder<?> customDecoder2 = mock(Decoder.class); when(customDecoder1.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(false); when(customDecoder2.canDecode(ResolvableType.forClass(Object.class), null)).thenReturn(true); HttpMessageReader<?> customReader1 = mock(HttpMessageReader.class); HttpMessageReader<?> customReader2 = mock(HttpMessageReader.class); when(customReader1.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(false); when(customReader2.canRead(ResolvableType.forClass(Object.class), null)).thenReturn(true); this.configurer.customCodecs().decoder(customDecoder1); this.configurer.customCodecs().decoder(customDecoder2); this.configurer.customCodecs().reader(customReader1); this.configurer.customCodecs().reader(customReader2); List<HttpMessageReader<?>> readers = this.configurer.getReaders(); assertEquals(15, readers.size()); assertEquals(ByteArrayDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ByteBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(DataBufferDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ResourceDecoder.class, getNextDecoder(readers).getClass()); assertEquals(StringDecoder.class, getNextDecoder(readers).getClass()); assertEquals(ProtobufDecoder.class, getNextDecoder(readers).getClass()); assertEquals(FormHttpMessageReader.class, readers.get(this.index.getAndIncrement()).getClass()); assertSame(customDecoder1, getNextDecoder(readers)); assertSame(customReader1, readers.get(this.index.getAndIncrement())); assertEquals(Jackson2JsonDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jackson2SmileDecoder.class, getNextDecoder(readers).getClass()); assertEquals(Jaxb2XmlDecoder.class, getNextDecoder(readers).getClass()); assertSame(customDecoder2, getNextDecoder(readers)); assertSame(customReader2, readers.get(this.index.getAndIncrement())); assertEquals(StringDecoder.class, getNextDecoder(readers).getClass()); }
Example #14
Source File: ProtobufCodecInitializer.java From spring-fu with Apache License 2.0 | 4 votes |
@Override protected void register(GenericApplicationContext context, CodecConfigurer configurer) { configurer.customCodecs().encoder(new ProtobufEncoder()); configurer.customCodecs().decoder(new ProtobufDecoder()); }