use of org.springframework.messaging.converter.CompositeMessageConverter in project spring-boot by spring-projects.
the class WebSocketMessagingAutoConfigurationTests method getDefaultConverters.
private List<MessageConverter> getDefaultConverters() {
DelegatingWebSocketMessageBrokerConfiguration configuration = new DelegatingWebSocketMessageBrokerConfiguration();
CompositeMessageConverter compositeDefaultConverter = configuration.brokerMessageConverter();
return compositeDefaultConverter.getConverters();
}
use of org.springframework.messaging.converter.CompositeMessageConverter in project spring-framework by spring-projects.
the class MessageBrokerConfigurationTests method configureMessageConvertersCustomAndDefault.
@Test
public void configureMessageConvertersCustomAndDefault() {
final MessageConverter testConverter = mock(MessageConverter.class);
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
@Override
protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
messageConverters.add(testConverter);
return true;
}
};
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
assertThat(compositeConverter.getConverters()).hasSize(4);
Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
assertThat(iterator.next()).isEqualTo(testConverter);
assertThat(iterator.next()).isInstanceOf(StringMessageConverter.class);
assertThat(iterator.next()).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(iterator.next()).isInstanceOf(MappingJackson2MessageConverter.class);
}
use of org.springframework.messaging.converter.CompositeMessageConverter in project spring-framework by spring-projects.
the class MessageBrokerConfigurationTests method configureMessageConvertersDefault.
@Test
public void configureMessageConvertersDefault() {
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig();
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
List<MessageConverter> converters = compositeConverter.getConverters();
assertThat(converters).hasSize(3);
assertThat(converters.get(0)).isInstanceOf(StringMessageConverter.class);
assertThat(converters.get(1)).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(converters.get(2)).isInstanceOf(MappingJackson2MessageConverter.class);
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
assertThat(((DefaultContentTypeResolver) resolver).getDefaultMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
}
use of org.springframework.messaging.converter.CompositeMessageConverter in project spring-framework by spring-projects.
the class TestValidator method annotationMethodMessageHandler.
@Test
public void annotationMethodMessageHandler() {
loadBeanDefinitions("websocket-config-broker-simple.xml");
SimpAnnotationMethodMessageHandler annotationMethodMessageHandler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
assertThat(annotationMethodMessageHandler).isNotNull();
MessageConverter messageConverter = annotationMethodMessageHandler.getMessageConverter();
assertThat(messageConverter).isNotNull();
assertThat(messageConverter instanceof CompositeMessageConverter).isTrue();
String name = MessageBrokerBeanDefinitionParser.MESSAGE_CONVERTER_BEAN_NAME;
CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(name, CompositeMessageConverter.class);
assertThat(compositeMessageConverter).isNotNull();
name = MessageBrokerBeanDefinitionParser.MESSAGING_TEMPLATE_BEAN_NAME;
SimpMessagingTemplate simpMessagingTemplate = this.appContext.getBean(name, SimpMessagingTemplate.class);
assertThat(simpMessagingTemplate).isNotNull();
assertThat(simpMessagingTemplate.getUserDestinationPrefix()).isEqualTo("/personal/");
List<MessageConverter> converters = compositeMessageConverter.getConverters();
assertThat(converters).hasSize(3);
assertThat(converters.get(0)).isInstanceOf(StringMessageConverter.class);
assertThat(converters.get(1)).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(converters.get(2)).isInstanceOf(MappingJackson2MessageConverter.class);
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
assertThat(((DefaultContentTypeResolver) resolver).getDefaultMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(annotationMethodMessageHandler);
Object pathMatcher = handlerAccessor.getPropertyValue("pathMatcher");
String pathSeparator = (String) new DirectFieldAccessor(pathMatcher).getPropertyValue("pathSeparator");
assertThat(pathSeparator).isEqualTo(".");
}
use of org.springframework.messaging.converter.CompositeMessageConverter in project spring-framework by spring-projects.
the class TestValidator method messageConverters.
@Test
public void messageConverters() {
loadBeanDefinitions("websocket-config-broker-converters.xml");
CompositeMessageConverter compositeConverter = this.appContext.getBean(CompositeMessageConverter.class);
assertThat(compositeConverter).isNotNull();
assertThat(compositeConverter.getConverters().size()).isEqualTo(4);
assertThat(compositeConverter.getConverters().iterator().next().getClass()).isEqualTo(StringMessageConverter.class);
}
Aggregations