use of org.springframework.core.codec.ByteBufferEncoder 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));
}
}
use of org.springframework.core.codec.ByteBufferEncoder 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<>(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 AbstractMessageWriterResultHandler(writerList, resolver) {
};
}
use of org.springframework.core.codec.ByteBufferEncoder in project spring-framework by spring-projects.
the class MessageWriterResultHandlerTests method unsupportedReturnType.
// SPR-13135
@Test
public void unsupportedReturnType() throws Exception {
ByteArrayOutputStream body = new ByteArrayOutputStream();
MethodParameter type = on(TestController.class).resolveReturnType(OutputStream.class);
HttpMessageWriter<?> writer = new EncoderHttpMessageWriter<>(new ByteBufferEncoder());
Mono<Void> mono = initResultHandler(writer).writeBody(body, type, this.exchange);
StepVerifier.create(mono).expectError(IllegalStateException.class).verify();
}
use of org.springframework.core.codec.ByteBufferEncoder in project spring-framework by spring-projects.
the class ResponseBodyResultHandlerTests method setup.
@Before
public void setup() throws Exception {
List<HttpMessageWriter<?>> writerList = new ArrayList<>(5);
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()));
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
this.resultHandler = new ResponseBodyResultHandler(writerList, resolver);
}
use of org.springframework.core.codec.ByteBufferEncoder 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()));
}
}
Aggregations