use of org.springframework.core.codec.ByteArrayEncoder 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.ByteArrayEncoder in project spring-framework by spring-projects.
the class BaseDefaultCodecs method getBaseTypedWriters.
/**
* Return "base" typed writers only, i.e. common to client and server.
*/
final List<HttpMessageWriter<?>> getBaseTypedWriters() {
if (!this.registerDefaults) {
return Collections.emptyList();
}
List<HttpMessageWriter<?>> writers = new ArrayList<>();
addCodec(writers, new EncoderHttpMessageWriter<>(new ByteArrayEncoder()));
addCodec(writers, new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
addCodec(writers, new EncoderHttpMessageWriter<>(new DataBufferEncoder()));
if (nettyByteBufPresent) {
addCodec(writers, new EncoderHttpMessageWriter<>(new NettyByteBufEncoder()));
}
addCodec(writers, new ResourceHttpMessageWriter());
addCodec(writers, new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
if (protobufPresent) {
addCodec(writers, new ProtobufHttpMessageWriter(this.protobufEncoder != null ? (ProtobufEncoder) this.protobufEncoder : new ProtobufEncoder()));
}
return writers;
}
use of org.springframework.core.codec.ByteArrayEncoder in project spring-framework by spring-projects.
the class RSocketMessageHandlerTests method getRSocketStrategiesReflectsCurrentState.
@Test
public void getRSocketStrategiesReflectsCurrentState() {
RSocketMessageHandler handler = new RSocketMessageHandler();
// 1. Set properties
handler.setDecoders(Collections.singletonList(new ByteArrayDecoder()));
handler.setEncoders(Collections.singletonList(new ByteArrayEncoder()));
handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
handler.setMetadataExtractor(new DefaultMetadataExtractor());
handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
RSocketStrategies strategies = handler.getRSocketStrategies();
assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
// 2. Set properties again
handler.setDecoders(Collections.singletonList(StringDecoder.allMimeTypes()));
handler.setEncoders(Collections.singletonList(CharSequenceEncoder.allMimeTypes()));
handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
handler.setMetadataExtractor(new DefaultMetadataExtractor());
handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
handler.afterPropertiesSet();
strategies = handler.getRSocketStrategies();
assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
}
use of org.springframework.core.codec.ByteArrayEncoder in project spring-framework by spring-projects.
the class RSocketMessageHandlerTests method getRSocketStrategies.
@Test
public void getRSocketStrategies() {
RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setDecoders(Collections.singletonList(new ByteArrayDecoder()));
handler.setEncoders(Collections.singletonList(new ByteArrayEncoder()));
handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
handler.setMetadataExtractor(new DefaultMetadataExtractor());
handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
RSocketStrategies strategies = handler.getRSocketStrategies();
assertThat(strategies).isNotNull();
assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
}
use of org.springframework.core.codec.ByteArrayEncoder 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