org.springframework.core.codec.ByteArrayDecoder Java Examples
The following examples show how to use
org.springframework.core.codec.ByteArrayDecoder.
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: ControllerMethodResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@Before public void setup() { ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer(); resolvers.addCustomResolver(new CustomArgumentResolver()); resolvers.addCustomResolver(new CustomSyncArgumentResolver()); ServerCodecConfigurer codecs = ServerCodecConfigurer.create(); codecs.customCodecs().decoder(new ByteArrayDecoder()); codecs.customCodecs().decoder(new ByteBufferDecoder()); AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); applicationContext.registerBean(TestControllerAdvice.class); applicationContext.refresh(); this.methodResolver = new ControllerMethodResolver( resolvers, ReactiveAdapterRegistry.getSharedInstance(), applicationContext, codecs.getReaders()); Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::handle).method(); this.handlerMethod = new HandlerMethod(new TestController(), method); }
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: ControllerMethodResolverTests.java From java-technology-stack with MIT License | 6 votes |
@Before public void setup() { ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer(); resolvers.addCustomResolver(new CustomArgumentResolver()); resolvers.addCustomResolver(new CustomSyncArgumentResolver()); ServerCodecConfigurer codecs = ServerCodecConfigurer.create(); codecs.customCodecs().decoder(new ByteArrayDecoder()); codecs.customCodecs().decoder(new ByteBufferDecoder()); AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); applicationContext.registerBean(TestControllerAdvice.class); applicationContext.refresh(); this.methodResolver = new ControllerMethodResolver( resolvers, ReactiveAdapterRegistry.getSharedInstance(), applicationContext, codecs.getReaders()); Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::handle).method(); this.handlerMethod = new HandlerMethod(new TestController(), method); }
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 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 #12
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()); }