Search in sources :

Example 6 with Jaxb2XmlEncoder

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

the class DefaultHandlerStrategiesBuilder method defaultConfiguration.

public void defaultConfiguration() {
    messageReader(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
    messageReader(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
    messageReader(new DecoderHttpMessageReader<>(new StringDecoder()));
    messageReader(new FormHttpMessageReader());
    messageWriter(new EncoderHttpMessageWriter<>(new ByteArrayEncoder()));
    messageWriter(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
    messageWriter(new EncoderHttpMessageWriter<>(new CharSequenceEncoder()));
    messageWriter(new ResourceHttpMessageWriter());
    if (jaxb2Present) {
        messageReader(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
        messageWriter(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
    }
    if (jackson2Present) {
        messageReader(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
        Jackson2JsonEncoder jsonEncoder = new Jackson2JsonEncoder();
        messageWriter(new Jackson2ServerHttpMessageWriter(jsonEncoder));
        messageWriter(new ServerSentEventHttpMessageWriter(Collections.singletonList(jsonEncoder)));
    } else {
        messageWriter(new ServerSentEventHttpMessageWriter());
    }
    localeResolver(DEFAULT_LOCALE_RESOLVER);
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) StringDecoder(org.springframework.core.codec.StringDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) Jackson2ServerHttpMessageWriter(org.springframework.http.codec.Jackson2ServerHttpMessageWriter) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder)

Example 7 with Jaxb2XmlEncoder

use of org.springframework.http.codec.xml.Jaxb2XmlEncoder 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 8 with Jaxb2XmlEncoder

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

Jaxb2XmlEncoder (org.springframework.http.codec.xml.Jaxb2XmlEncoder)8 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)7 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)7 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)7 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)7 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)4 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)4 ArrayList (java.util.ArrayList)3 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)3 ServerSentEventHttpMessageWriter (org.springframework.http.codec.ServerSentEventHttpMessageWriter)3 RequestedContentTypeResolver (org.springframework.web.reactive.accept.RequestedContentTypeResolver)3 RequestedContentTypeResolverBuilder (org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder)3 Before (org.junit.Before)2 FormHttpMessageWriter (org.springframework.http.codec.FormHttpMessageWriter)2 Jackson2ServerHttpMessageWriter (org.springframework.http.codec.Jackson2ServerHttpMessageWriter)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 Test (org.junit.Test)1 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)1