Search in sources :

Example 6 with EncoderHttpMessageWriter

use of org.springframework.http.codec.EncoderHttpMessageWriter in project spring-framework by spring-projects.

the class BodyInsertersTests method createContext.

@Before
public void createContext() {
    final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
    messageWriters.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
    messageWriters.add(new EncoderHttpMessageWriter<>(new CharSequenceEncoder()));
    messageWriters.add(new ResourceHttpMessageWriter());
    messageWriters.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
    Jackson2JsonEncoder jsonEncoder = new Jackson2JsonEncoder();
    messageWriters.add(new EncoderHttpMessageWriter<>(jsonEncoder));
    messageWriters.add(new ServerSentEventHttpMessageWriter(Collections.singletonList(jsonEncoder)));
    messageWriters.add(new FormHttpMessageWriter());
    this.context = new BodyInserter.Context() {

        @Override
        public Supplier<Stream<HttpMessageWriter<?>>> messageWriters() {
            return messageWriters::stream;
        }

        @Override
        public Map<String, Object> hints() {
            return hints;
        }
    };
    this.hints = new HashMap<>();
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) EncoderHttpMessageWriter(org.springframework.http.codec.EncoderHttpMessageWriter) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) FormHttpMessageWriter(org.springframework.http.codec.FormHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) ArrayList(java.util.ArrayList) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) Supplier(java.util.function.Supplier) FormHttpMessageWriter(org.springframework.http.codec.FormHttpMessageWriter) CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) HashMap(java.util.HashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Before(org.junit.Before)

Example 7 with EncoderHttpMessageWriter

use of org.springframework.http.codec.EncoderHttpMessageWriter 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

EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)7 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)6 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)5 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)5 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)4 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)4 Jaxb2XmlEncoder (org.springframework.http.codec.xml.Jaxb2XmlEncoder)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 RequestedContentTypeResolver (org.springframework.web.reactive.accept.RequestedContentTypeResolver)3 RequestedContentTypeResolverBuilder (org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder)3 ByteBuffer (java.nio.ByteBuffer)2 List (java.util.List)2 Before (org.junit.Before)2 DataBuffer (org.springframework.core.io.buffer.DataBuffer)2 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)2 HttpMethod (org.springframework.http.HttpMethod)2 BodyInserter (org.springframework.web.reactive.function.BodyInserter)2 Mono (reactor.core.publisher.Mono)2 StepVerifier (reactor.test.StepVerifier)2