use of org.springframework.http.codec.HttpMessageReader in project spring-framework by spring-projects.
the class WebFluxConfigurationSupportTests method customMessageConverterConfig.
@Test
public void customMessageConverterConfig() throws Exception {
ApplicationContext context = loadConfig(CustomMessageConverterConfig.class);
String name = "requestMappingHandlerAdapter";
RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
List<HttpMessageReader<?>> messageReaders = adapter.getMessageReaders();
assertEquals(2, messageReaders.size());
assertHasMessageReader(messageReaders, String.class, TEXT_PLAIN);
assertHasMessageReader(messageReaders, TestBean.class, APPLICATION_XML);
}
use of org.springframework.http.codec.HttpMessageReader in project spring-framework by spring-projects.
the class WebFluxConfigurationSupportTests method requestMappingHandlerAdapter.
@Test
public void requestMappingHandlerAdapter() throws Exception {
ApplicationContext context = loadConfig(WebFluxConfig.class);
String name = "requestMappingHandlerAdapter";
RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
List<HttpMessageReader<?>> readers = adapter.getMessageReaders();
assertEquals(7, readers.size());
assertHasMessageReader(readers, byte[].class, APPLICATION_OCTET_STREAM);
assertHasMessageReader(readers, ByteBuffer.class, APPLICATION_OCTET_STREAM);
assertHasMessageReader(readers, String.class, TEXT_PLAIN);
assertHasMessageReader(readers, Resource.class, IMAGE_PNG);
assertHasMessageReader(readers, TestBean.class, APPLICATION_XML);
assertHasMessageReader(readers, TestBean.class, APPLICATION_JSON);
assertHasMessageReader(readers, TestBean.class, null);
WebBindingInitializer bindingInitializer = adapter.getWebBindingInitializer();
assertNotNull(bindingInitializer);
WebExchangeDataBinder binder = new WebExchangeDataBinder(new Object());
bindingInitializer.initBinder(binder);
name = "webFluxConversionService";
ConversionService service = context.getBean(name, ConversionService.class);
assertSame(service, binder.getConversionService());
name = "webFluxValidator";
Validator validator = context.getBean(name, Validator.class);
assertSame(validator, binder.getValidator());
}
use of org.springframework.http.codec.HttpMessageReader in project spring-framework by spring-projects.
the class DefaultServerRequestTests method body.
@Test
public void body() 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(mockRequest.getHeaders()).thenReturn(httpHeaders);
when(mockRequest.getBody()).thenReturn(body);
Set<HttpMessageReader<?>> messageReaders = Collections.singleton(new DecoderHttpMessageReader<String>(new StringDecoder()));
when(mockHandlerStrategies.messageReaders()).thenReturn(messageReaders::stream);
Mono<String> resultMono = defaultRequest.body(toMono(String.class));
assertEquals("foo", resultMono.block());
}
use of org.springframework.http.codec.HttpMessageReader in project spring-framework by spring-projects.
the class DefaultServerRequestTests method bodyUnacceptable.
@Test
public void bodyUnacceptable() 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(mockRequest.getHeaders()).thenReturn(httpHeaders);
when(mockRequest.getBody()).thenReturn(body);
Set<HttpMessageReader<?>> messageReaders = Collections.emptySet();
when(mockHandlerStrategies.messageReaders()).thenReturn(messageReaders::stream);
Flux<String> resultFlux = defaultRequest.bodyToFlux(String.class);
StepVerifier.create(resultFlux).expectError(UnsupportedMediaTypeStatusException.class).verify();
}
use of org.springframework.http.codec.HttpMessageReader in project spring-framework by spring-projects.
the class DefaultClientResponseTests method body.
@Test
public void body() 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.getBody()).thenReturn(body);
Set<HttpMessageReader<?>> messageReaders = Collections.singleton(new DecoderHttpMessageReader<String>(new StringDecoder()));
when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders::stream);
Mono<String> resultMono = defaultClientResponse.body(toMono(String.class));
assertEquals("foo", resultMono.block());
}
Aggregations