use of org.springframework.messaging.converter.CompositeMessageConverter in project spring-integration by spring-projects.
the class WebSocketParserTests method testCustomOutboundChannelAdapter.
@Test
public void testCustomOutboundChannelAdapter() throws URISyntaxException {
assertSame(this.clientWebSocketContainer, TestUtils.getPropertyValue(this.customOutboundAdapter, "webSocketContainer"));
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.customOutboundAdapter, "subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
assertSame(this.stompSubProtocolHandler, TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"));
Map<?, ?> protocolHandlers = TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class);
assertEquals(3, protocolHandlers.size());
// See warn log message.
for (Object handler : protocolHandlers.values()) {
assertSame(this.stompSubProtocolHandler, handler);
}
assertTrue(TestUtils.getPropertyValue(this.customOutboundAdapter, "mergeWithDefaultConverters", Boolean.class));
CompositeMessageConverter compositeMessageConverter = TestUtils.getPropertyValue(this.customOutboundAdapter, "messageConverter", CompositeMessageConverter.class);
List<MessageConverter> converters = compositeMessageConverter.getConverters();
assertEquals(5, converters.size());
assertSame(this.simpleMessageConverter, converters.get(0));
assertSame(this.mapMessageConverter, converters.get(1));
assertThat(converters.get(2), instanceOf(StringMessageConverter.class));
assertTrue(TestUtils.getPropertyValue(this.customOutboundAdapter, "client", Boolean.class));
}
use of org.springframework.messaging.converter.CompositeMessageConverter in project ArTEMiS by ls1intum.
the class WebsocketConfiguration method brokerMessageConverter.
@Override
public CompositeMessageConverter brokerMessageConverter() {
// NOTE: We need to replace the default messageConverter for WebSocket messages
// with a messageConverter that uses the same ObjectMapper that our REST endpoints use.
// This gives us consistency in how specific datatypes are serialized (e.g. timestamps)
DefaultContentTypeResolver resolver = new DefaultContentTypeResolver();
resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON);
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setObjectMapper(objectMapper);
converter.setContentTypeResolver(resolver);
Set<MessageConverter> messageConverterSet = new HashSet<>();
messageConverterSet.add(converter);
return new CompositeMessageConverter(messageConverterSet);
}
use of org.springframework.messaging.converter.CompositeMessageConverter in project spring-cloud-stream by spring-cloud.
the class MessageChannelConfigurerTests method testObjectMapperConfig.
@Test
public void testObjectMapperConfig() throws Exception {
CompositeMessageConverter converters = (CompositeMessageConverter) messageConverterFactory.getMessageConverterForType(MimeTypeUtils.APPLICATION_JSON);
for (MessageConverter converter : converters.getConverters()) {
DirectFieldAccessor converterAccessor = new DirectFieldAccessor(converter);
ObjectMapper objectMapper = (ObjectMapper) converterAccessor.getPropertyValue("objectMapper");
// assert that the ObjectMapper used by the converters is compliant with the
// Boot configuration
assertThat(!objectMapper.getSerializationConfig().isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)).withFailMessage("SerializationFeature 'WRITE_DATES_AS_TIMESTAMPS' should be disabled");
// assert that the globally set bean is used by the converters
}
}
use of org.springframework.messaging.converter.CompositeMessageConverter in project spring-cloud-stream by spring-cloud.
the class MessageChannelToInputFluxParameterAdapterTests method testWrapperFluxSupportsMultipleSubscriptions.
@Test
public void testWrapperFluxSupportsMultipleSubscriptions() throws Exception {
List<String> results = Collections.synchronizedList(new ArrayList<>());
CountDownLatch latch = new CountDownLatch(4);
final MessageChannelToInputFluxParameterAdapter messageChannelToInputFluxParameterAdapter = new MessageChannelToInputFluxParameterAdapter(new CompositeMessageConverter(Collections.singleton(new MappingJackson2MessageConverter())));
final Method processMethod = ReflectionUtils.findMethod(MessageChannelToInputFluxParameterAdapterTests.class, "process", Flux.class);
final DirectChannel adaptedChannel = new DirectChannel();
@SuppressWarnings("unchecked") final Flux<Message<?>> adapterFlux = (Flux<Message<?>>) messageChannelToInputFluxParameterAdapter.adapt(adaptedChannel, new MethodParameter(processMethod, 0));
String uuid1 = UUID.randomUUID().toString();
String uuid2 = UUID.randomUUID().toString();
adapterFlux.map(m -> m.getPayload() + uuid1).subscribe(s -> {
results.add(s);
latch.countDown();
});
adapterFlux.map(m -> m.getPayload() + uuid2).subscribe(s -> {
results.add(s);
latch.countDown();
});
adaptedChannel.send(MessageBuilder.withPayload("A").build());
adaptedChannel.send(MessageBuilder.withPayload("B").build());
assertThat(latch.await(5000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(results).containsExactlyInAnyOrder("A" + uuid1, "B" + uuid1, "A" + uuid2, "B" + uuid2);
}
use of org.springframework.messaging.converter.CompositeMessageConverter in project spring-framework by spring-projects.
the class TestValidator method messageConvertersDefaultsOff.
@Test
public void messageConvertersDefaultsOff() {
loadBeanDefinitions("websocket-config-broker-converters-defaults-off.xml");
CompositeMessageConverter compositeConverter = this.appContext.getBean(CompositeMessageConverter.class);
assertThat(compositeConverter).isNotNull();
assertThat(compositeConverter.getConverters().size()).isEqualTo(1);
assertThat(compositeConverter.getConverters().iterator().next().getClass()).isEqualTo(StringMessageConverter.class);
}
Aggregations