Search in sources :

Example 6 with RequestedContentTypeResolver

use of org.springframework.web.reactive.accept.RequestedContentTypeResolver in project spring-framework by spring-projects.

the class WebFluxConfigurationSupportTests method responseEntityResultHandler.

@Test
public void responseEntityResultHandler() throws Exception {
    ApplicationContext context = loadConfig(WebFluxConfig.class);
    String name = "responseEntityResultHandler";
    ResponseEntityResultHandler handler = context.getBean(name, ResponseEntityResultHandler.class);
    assertNotNull(handler);
    assertEquals(0, handler.getOrder());
    List<HttpMessageWriter<?>> writers = handler.getMessageWriters();
    assertEquals(8, writers.size());
    assertHasMessageWriter(writers, byte[].class, APPLICATION_OCTET_STREAM);
    assertHasMessageWriter(writers, ByteBuffer.class, APPLICATION_OCTET_STREAM);
    assertHasMessageWriter(writers, String.class, TEXT_PLAIN);
    assertHasMessageWriter(writers, Resource.class, IMAGE_PNG);
    assertHasMessageWriter(writers, TestBean.class, APPLICATION_XML);
    assertHasMessageWriter(writers, TestBean.class, APPLICATION_JSON);
    assertHasMessageWriter(writers, TestBean.class, MediaType.parseMediaType("text/event-stream"));
    name = "webFluxContentTypeResolver";
    RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
    assertSame(resolver, handler.getContentTypeResolver());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) EncoderHttpMessageWriter(org.springframework.http.codec.EncoderHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) ResponseEntityResultHandler(org.springframework.web.reactive.result.method.annotation.ResponseEntityResultHandler) RequestedContentTypeResolver(org.springframework.web.reactive.accept.RequestedContentTypeResolver) Test(org.junit.Test)

Example 7 with RequestedContentTypeResolver

use of org.springframework.web.reactive.accept.RequestedContentTypeResolver in project spring-framework by spring-projects.

the class ResponseEntityResultHandlerTests method createHandler.

private ResponseEntityResultHandler createHandler(HttpMessageWriter<?>... writers) {
    List<HttpMessageWriter<?>> writerList;
    if (ObjectUtils.isEmpty(writers)) {
        writerList = new ArrayList<>();
        writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
        writerList.add(new EncoderHttpMessageWriter<>(new CharSequenceEncoder()));
        writerList.add(new ResourceHttpMessageWriter());
        writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
        writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
    } else {
        writerList = Arrays.asList(writers);
    }
    RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
    return new ResponseEntityResultHandler(writerList, resolver);
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) EncoderHttpMessageWriter(org.springframework.http.codec.EncoderHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) RequestedContentTypeResolver(org.springframework.web.reactive.accept.RequestedContentTypeResolver) CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) RequestedContentTypeResolverBuilder(org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder)

Aggregations

RequestedContentTypeResolver (org.springframework.web.reactive.accept.RequestedContentTypeResolver)7 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)5 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)5 Test (org.junit.Test)3 ApplicationContext (org.springframework.context.ApplicationContext)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)3 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)3 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)3 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)3 Jaxb2XmlEncoder (org.springframework.http.codec.xml.Jaxb2XmlEncoder)3 RequestedContentTypeResolverBuilder (org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder)3 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 MediaType (org.springframework.http.MediaType)1 HeaderContentTypeResolver (org.springframework.web.reactive.accept.HeaderContentTypeResolver)1 RequestMappingHandlerMapping (org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping)1 ResponseBodyResultHandler (org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler)1 ResponseEntityResultHandler (org.springframework.web.reactive.result.method.annotation.ResponseEntityResultHandler)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1