Search in sources :

Example 1 with Jaxb2XmlEncoder

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

the class WebFluxConfigurationSupport method addDefaultHttpMessageWriters.

/**
	 * Adds default converters that sub-classes can call from
	 * {@link #configureMessageWriters(List)}.
	 */
protected final void addDefaultHttpMessageWriters(List<HttpMessageWriter<?>> writers) {
    List<Encoder<?>> sseDataEncoders = new ArrayList<>();
    writers.add(new EncoderHttpMessageWriter<>(new ByteArrayEncoder()));
    writers.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
    writers.add(new EncoderHttpMessageWriter<>(new DataBufferEncoder()));
    writers.add(new EncoderHttpMessageWriter<>(new CharSequenceEncoder()));
    writers.add(new ResourceHttpMessageWriter());
    if (jaxb2Present) {
        writers.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
    }
    if (jackson2Present) {
        Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
        writers.add(new Jackson2ServerHttpMessageWriter(encoder));
        sseDataEncoders.add(encoder);
        HttpMessageWriter<Object> writer = new ServerSentEventHttpMessageWriter(sseDataEncoders);
        writers.add(new Jackson2ServerHttpMessageWriter(writer));
    } else {
        writers.add(new ServerSentEventHttpMessageWriter(sseDataEncoders));
    }
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ArrayList(java.util.ArrayList) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) Jackson2ServerHttpMessageWriter(org.springframework.http.codec.Jackson2ServerHttpMessageWriter) CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) DataBufferEncoder(org.springframework.core.codec.DataBufferEncoder) ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) Encoder(org.springframework.core.codec.Encoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) DataBufferEncoder(org.springframework.core.codec.DataBufferEncoder) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder)

Example 2 with Jaxb2XmlEncoder

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

the class HttpMessageWriterViewTests method extractObjectNotSupported.

@Test
public void extractObjectNotSupported() throws Exception {
    HttpMessageWriterView view = new HttpMessageWriterView(new Jaxb2XmlEncoder());
    view.setModelKeys(new HashSet<>(Collections.singletonList("foo1")));
    this.model.addAttribute("foo1", "bar1");
    try {
        view.extractObjectToRender(this.model);
        fail();
    } catch (IllegalStateException ex) {
        String message = ex.getMessage();
        assertTrue(message, message.contains("[foo1] is not supported"));
    }
}
Also used : Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Test(org.junit.Test)

Example 3 with Jaxb2XmlEncoder

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

the class CancelWithoutDemandCodecTests method cancelWithJaxb2.

// gh-22107
@Test
public void cancelWithJaxb2() {
    Jaxb2XmlEncoder encoder = new Jaxb2XmlEncoder();
    Flux<DataBuffer> flux = encoder.encode(Mono.just(new Pojo("foo", "bar")), this.bufferFactory, ResolvableType.forClass(Pojo.class), MediaType.APPLICATION_XML, Collections.emptyMap());
    BaseSubscriber<DataBuffer> subscriber = new ZeroDemandSubscriber();
    // Assume sync execution (e.g. encoding with Flux.just)..
    flux.subscribe(subscriber);
    subscriber.cancel();
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 4 with Jaxb2XmlEncoder

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

the class MessageWriterResultHandlerTests method initResultHandler.

private AbstractMessageWriterResultHandler initResultHandler(HttpMessageWriter<?>... writers) {
    List<HttpMessageWriter<?>> writerList;
    if (ObjectUtils.isEmpty(writers)) {
        writerList = new ArrayList<>();
        writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
        writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
        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 AbstractMessageWriterResultHandler(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) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) RequestedContentTypeResolverBuilder(org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder)

Example 5 with Jaxb2XmlEncoder

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

the class ResponseBodyResultHandlerTests method setup.

@BeforeEach
public void setup() throws Exception {
    List<HttpMessageWriter<?>> writerList = new ArrayList<>(5);
    writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
    writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
    writerList.add(new ResourceHttpMessageWriter());
    writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
    writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
    RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
    this.resultHandler = new ResponseBodyResultHandler(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) ArrayList(java.util.ArrayList) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) RequestedContentTypeResolver(org.springframework.web.reactive.accept.RequestedContentTypeResolver) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) RequestedContentTypeResolverBuilder(org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Jaxb2XmlEncoder (org.springframework.http.codec.xml.Jaxb2XmlEncoder)10 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)8 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)7 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)7 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)5 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)5 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)3 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)3 ServerSentEventHttpMessageWriter (org.springframework.http.codec.ServerSentEventHttpMessageWriter)3 List (java.util.List)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 DataBufferEncoder (org.springframework.core.codec.DataBufferEncoder)2 Encoder (org.springframework.core.codec.Encoder)2 FormHttpMessageWriter (org.springframework.http.codec.FormHttpMessageWriter)2 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)2 Jackson2SmileDecoder (org.springframework.http.codec.json.Jackson2SmileDecoder)2 Jackson2SmileEncoder (org.springframework.http.codec.json.Jackson2SmileEncoder)2 ProtobufDecoder (org.springframework.http.codec.protobuf.ProtobufDecoder)2