org.springframework.core.codec.StringDecoder Java Examples
The following examples show how to use
org.springframework.core.codec.StringDecoder.
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: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 8 votes |
@Test public void toEntityList() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #2
Source File: MessageMappingMessageHandlerTests.java From spring-analysis-note with MIT License | 6 votes |
private MessageMappingMessageHandler initMesssageHandler() { List<Decoder<?>> decoders = Collections.singletonList(StringDecoder.allMimeTypes()); List<Encoder<?>> encoders = Collections.singletonList(CharSequenceEncoder.allMimeTypes()); ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance(); this.returnValueHandler = new TestEncoderMethodReturnValueHandler(encoders, registry); PropertySource<?> source = new MapPropertySource("test", Collections.singletonMap("path", "path123")); StaticApplicationContext context = new StaticApplicationContext(); context.getEnvironment().getPropertySources().addFirst(source); context.registerSingleton("testController", TestController.class); context.refresh(); MessageMappingMessageHandler messageHandler = new MessageMappingMessageHandler(); messageHandler.getReturnValueHandlerConfigurer().addCustomHandler(this.returnValueHandler); messageHandler.setApplicationContext(context); messageHandler.setEmbeddedValueResolver(new EmbeddedValueResolver(context.getBeanFactory())); messageHandler.setDecoders(decoders); messageHandler.afterPropertiesSet(); return messageHandler; }
Example #3
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void bodyToMonoTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Mono<String> resultMono = defaultClientResponse.bodyToMono(new ParameterizedTypeReference<String>() { }); assertEquals("foo", resultMono.block()); }
Example #4
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void bodyToFlux() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class); Mono<List<String>> result = resultFlux.collectList(); assertEquals(Collections.singletonList("foo"), result.block()); }
Example #5
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void bodyToFluxTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Flux<String> resultFlux = defaultClientResponse.bodyToFlux(new ParameterizedTypeReference<String>() { }); Mono<List<String>> result = resultFlux.collectList(); assertEquals(Collections.singletonList("foo"), result.block()); }
Example #6
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void toEntity() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block(); assertEquals("foo", result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #7
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 #8
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void toEntityTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity( new ParameterizedTypeReference<String>() { }).block(); assertEquals("foo", result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #9
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void toEntityList() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #10
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void toEntityListTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList( new ParameterizedTypeReference<String>() { }).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #11
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void toEntityListTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList( new ParameterizedTypeReference<String>() { }).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #12
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void toEntityTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity( new ParameterizedTypeReference<String>() { }).block(); assertEquals("foo", result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #13
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void toEntity() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block(); assertEquals("foo", result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #14
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void bodyToFluxTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); Flux<String> resultFlux = defaultClientResponse.bodyToFlux(new ParameterizedTypeReference<String>() { }); Mono<List<String>> result = resultFlux.collectList(); assertEquals(Collections.singletonList("foo"), result.block()); }
Example #15
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void bodyToFlux() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class); Mono<List<String>> result = resultFlux.collectList(); assertEquals(Collections.singletonList("foo"), result.block()); }
Example #16
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void bodyToMonoTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); Mono<String> resultMono = defaultClientResponse.bodyToMono(new ParameterizedTypeReference<String>() { }); assertEquals("foo", resultMono.block()); }
Example #17
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 #18
Source File: WebFluxConfigurationSupportTests.java From java-technology-stack with MIT License | 5 votes |
@Override protected void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { configurer.registerDefaults(false); configurer.customCodecs().decoder(StringDecoder.textPlainOnly()); configurer.customCodecs().decoder(new Jaxb2XmlDecoder()); configurer.customCodecs().encoder(CharSequenceEncoder.textPlainOnly()); configurer.customCodecs().encoder(new Jaxb2XmlEncoder()); }
Example #19
Source File: RequestPredicateAttributesTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void createRequest() { MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com/path").build(); MockServerWebExchange webExchange = MockServerWebExchange.from(request); webExchange.getAttributes().put("exchange", "bar"); this.request = new DefaultServerRequest(webExchange, Collections.singletonList( new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()))); }
Example #20
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void toEntityListWithUnknownStatusCode() throws Exception { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_PLAIN); when(mockResponse.getHeaders()).thenReturn(httpHeaders); when(mockResponse.getStatusCode()).thenThrow(new IllegalArgumentException("999")); when(mockResponse.getRawStatusCode()).thenReturn(999); when(mockResponse.getBody()).thenReturn(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); try { result.getStatusCode(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ex) { // do nothing } assertEquals(999, result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #21
Source File: BaseDefaultCodecs.java From java-technology-stack with MIT License | 5 votes |
/** * Return readers that need to be at the end, after all others. */ final List<HttpMessageReader<?>> getCatchAllReaders() { if (!this.registerDefaults) { return Collections.emptyList(); } List<HttpMessageReader<?>> result = new ArrayList<>(); result.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); return result; }
Example #22
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void toEntityWithUnknownStatusCode() throws Exception { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_PLAIN); when(mockResponse.getHeaders()).thenReturn(httpHeaders); when(mockResponse.getStatusCode()).thenThrow(new IllegalArgumentException("999")); when(mockResponse.getRawStatusCode()).thenReturn(999); when(mockResponse.getBody()).thenReturn(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block(); assertEquals("foo", result.getBody()); try { result.getStatusCode(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ex) { // do nothing } assertEquals(999, result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #23
Source File: ServerCodecConfigurerTests.java From java-technology-stack with MIT License | 5 votes |
@SuppressWarnings("unchecked") private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) { assertEquals(StringDecoder.class, decoder.getClass()); assertTrue(decoder.canDecode(forClass(String.class), MimeTypeUtils.TEXT_PLAIN)); assertEquals(!textOnly, decoder.canDecode(forClass(String.class), MediaType.TEXT_EVENT_STREAM)); Flux<String> flux = (Flux<String>) decoder.decode( Flux.just(new DefaultDataBufferFactory().wrap("line1\nline2".getBytes(StandardCharsets.UTF_8))), ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN, Collections.emptyMap()); assertEquals(Arrays.asList("line1", "line2"), flux.collectList().block(Duration.ZERO)); }
Example #24
Source File: ClientCodecConfigurerTests.java From java-technology-stack with MIT License | 5 votes |
@SuppressWarnings("unchecked") private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) { assertEquals(StringDecoder.class, decoder.getClass()); assertTrue(decoder.canDecode(forClass(String.class), MimeTypeUtils.TEXT_PLAIN)); assertEquals(!textOnly, decoder.canDecode(forClass(String.class), MediaType.TEXT_EVENT_STREAM)); Flux<String> decoded = (Flux<String>) decoder.decode( Flux.just(new DefaultDataBufferFactory().wrap("line1\nline2".getBytes(StandardCharsets.UTF_8))), ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN, Collections.emptyMap()); assertEquals(Arrays.asList("line1", "line2"), decoded.collectList().block(Duration.ZERO)); }
Example #25
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 #26
Source File: RSocketBufferLeakTests.java From spring-analysis-note with MIT License | 5 votes |
@Bean public RSocketStrategies rsocketStrategies() { return RSocketStrategies.builder() .decoder(StringDecoder.allMimeTypes()) .encoder(CharSequenceEncoder.allMimeTypes()) .dataBufferFactory(new LeakAwareNettyDataBufferFactory(PooledByteBufAllocator.DEFAULT)) .build(); }
Example #27
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void bodyToMono() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Mono<String> resultMono = defaultClientResponse.bodyToMono(String.class); assertEquals("foo", resultMono.block()); }
Example #28
Source File: BodyExtractorsTests.java From java-technology-stack with MIT License | 5 votes |
@Before 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()); SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader(); 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<String, Object>(); }
Example #29
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 #30
Source File: ClientCodecConfigurerTests.java From spring-analysis-note with MIT License | 5 votes |
@SuppressWarnings("unchecked") private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) { assertEquals(StringDecoder.class, decoder.getClass()); assertTrue(decoder.canDecode(forClass(String.class), MimeTypeUtils.TEXT_PLAIN)); assertEquals(!textOnly, decoder.canDecode(forClass(String.class), MediaType.TEXT_EVENT_STREAM)); Flux<String> decoded = (Flux<String>) decoder.decode( Flux.just(new DefaultDataBufferFactory().wrap("line1\nline2".getBytes(StandardCharsets.UTF_8))), ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN, Collections.emptyMap()); assertEquals(Arrays.asList("line1", "line2"), decoded.collectList().block(Duration.ZERO)); }