Search in sources :

Example 1 with TestEncoderMethodReturnValueHandler

use of org.springframework.messaging.handler.invocation.reactive.TestEncoderMethodReturnValueHandler in project spring-framework by spring-projects.

the class MessageMappingMessageHandlerTests method initMesssageHandler.

private MessageMappingMessageHandler initMesssageHandler() {
    List<Decoder<?>> decoders = Collections.singletonList(StringDecoder.allMimeTypes());
    List<Encoder<?>> encoders = Collections.singletonList(CharSequenceEncoder.allMimeTypes());
    ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
    this.returnValueHandler = new TestEncoderMethodReturnValueHandler(encoders, registry);
    PropertySource<?> source = new MapPropertySource("test", Collections.singletonMap("path", "path123"));
    StaticApplicationContext context = new StaticApplicationContext();
    context.getEnvironment().getPropertySources().addFirst(source);
    context.registerSingleton("testController", TestController.class);
    context.refresh();
    MessageMappingMessageHandler messageHandler = new MessageMappingMessageHandler();
    messageHandler.getReturnValueHandlerConfigurer().addCustomHandler(this.returnValueHandler);
    messageHandler.setApplicationContext(context);
    messageHandler.setEmbeddedValueResolver(new EmbeddedValueResolver(context.getBeanFactory()));
    messageHandler.setDecoders(decoders);
    messageHandler.afterPropertiesSet();
    return messageHandler;
}
Also used : TestEncoderMethodReturnValueHandler(org.springframework.messaging.handler.invocation.reactive.TestEncoderMethodReturnValueHandler) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) Encoder(org.springframework.core.codec.Encoder) MapPropertySource(org.springframework.core.env.MapPropertySource) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) EmbeddedValueResolver(org.springframework.beans.factory.config.EmbeddedValueResolver) Decoder(org.springframework.core.codec.Decoder) StringDecoder(org.springframework.core.codec.StringDecoder)

Aggregations

EmbeddedValueResolver (org.springframework.beans.factory.config.EmbeddedValueResolver)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)1 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)1 Decoder (org.springframework.core.codec.Decoder)1 Encoder (org.springframework.core.codec.Encoder)1 StringDecoder (org.springframework.core.codec.StringDecoder)1 MapPropertySource (org.springframework.core.env.MapPropertySource)1 TestEncoderMethodReturnValueHandler (org.springframework.messaging.handler.invocation.reactive.TestEncoderMethodReturnValueHandler)1