Search in sources :

Example 1 with CharSequenceEncoder

use of org.springframework.core.codec.CharSequenceEncoder 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 CharSequenceEncoder

use of org.springframework.core.codec.CharSequenceEncoder in project spring-framework by spring-projects.

the class HttpMessageWriterViewTests method extractObjectMultipleMatchesNotSupported.

@Test
public void extractObjectMultipleMatchesNotSupported() throws Exception {
    HttpMessageWriterView view = new HttpMessageWriterView(new CharSequenceEncoder());
    view.setModelKeys(new HashSet<>(Arrays.asList("foo1", "foo2")));
    this.model.addAttribute("foo1", "bar1");
    this.model.addAttribute("foo2", "bar2");
    try {
        view.extractObjectToRender(this.model);
        fail();
    } catch (IllegalStateException ex) {
        String message = ex.getMessage();
        assertTrue(message, message.contains("Map rendering is not supported"));
    }
}
Also used : CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) Test(org.junit.Test)

Example 3 with CharSequenceEncoder

use of org.springframework.core.codec.CharSequenceEncoder in project spring-framework by spring-projects.

the class DefaultExchangeStrategiesBuilder method defaultWriters.

private void defaultWriters() {
    messageWriter(new EncoderHttpMessageWriter<>(new ByteArrayEncoder()));
    messageWriter(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
    messageWriter(new EncoderHttpMessageWriter<>(new CharSequenceEncoder()));
    messageWriter(new ResourceHttpMessageWriter());
    messageWriter(new FormHttpMessageWriter());
    if (jaxb2Present) {
        messageWriter(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
    }
    if (jackson2Present) {
        messageWriter(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
    }
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) FormHttpMessageWriter(org.springframework.http.codec.FormHttpMessageWriter) CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder)

Example 4 with CharSequenceEncoder

use of org.springframework.core.codec.CharSequenceEncoder in project spring-framework by spring-projects.

the class CancelWithoutDemandCodecTests method cancelWithEncoderHttpMessageWriterAndSingleValue.

// gh-22107
@Test
public void cancelWithEncoderHttpMessageWriterAndSingleValue() {
    CharSequenceEncoder encoder = CharSequenceEncoder.allMimeTypes();
    HttpMessageWriter<CharSequence> writer = new EncoderHttpMessageWriter<>(encoder);
    CancellingOutputMessage outputMessage = new CancellingOutputMessage(this.bufferFactory);
    writer.write(Mono.just("foo"), ResolvableType.forType(String.class), MediaType.TEXT_PLAIN, outputMessage, Collections.emptyMap()).block(Duration.ofSeconds(5));
}
Also used : CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) Test(org.junit.jupiter.api.Test)

Aggregations

CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)4 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)2 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)2 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)2 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)2 Jaxb2XmlEncoder (org.springframework.http.codec.xml.Jaxb2XmlEncoder)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 DataBufferEncoder (org.springframework.core.codec.DataBufferEncoder)1 Encoder (org.springframework.core.codec.Encoder)1 FormHttpMessageWriter (org.springframework.http.codec.FormHttpMessageWriter)1 Jackson2ServerHttpMessageWriter (org.springframework.http.codec.Jackson2ServerHttpMessageWriter)1 ServerSentEventHttpMessageWriter (org.springframework.http.codec.ServerSentEventHttpMessageWriter)1