use of org.springframework.messaging.converter.MessageConverter in project spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method brokerMessageConverter.
@Bean
public CompositeMessageConverter brokerMessageConverter() {
List<MessageConverter> converters = new ArrayList<>();
boolean registerDefaults = configureMessageConverters(converters);
if (registerDefaults) {
converters.add(new StringMessageConverter());
converters.add(new ByteArrayMessageConverter());
if (jackson2Present) {
converters.add(createJacksonConverter());
}
}
return new CompositeMessageConverter(converters);
}
use of org.springframework.messaging.converter.MessageConverter in project spring-framework by spring-projects.
the class TestMessagePostProcessor method convertAndSendNoMatchingConverter.
@Test(expected = MessageConversionException.class)
public void convertAndSendNoMatchingConverter() {
MessageConverter converter = new CompositeMessageConverter(Arrays.<MessageConverter>asList(new MappingJackson2MessageConverter()));
this.template.setMessageConverter(converter);
this.headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML);
this.template.convertAndSend("home", "payload", new MessageHeaders(this.headers));
}
use of org.springframework.messaging.converter.MessageConverter in project spring-framework by spring-projects.
the class DefaultMessageHandlerMethodFactoryTests method customMessageConverterFailure.
@Test
public void customMessageConverterFailure() throws Exception {
DefaultMessageHandlerMethodFactory instance = createInstance();
MessageConverter messageConverter = new ByteArrayMessageConverter();
instance.setMessageConverter(messageConverter);
instance.afterPropertiesSet();
InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class);
thrown.expect(MessageConversionException.class);
invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build());
}
use of org.springframework.messaging.converter.MessageConverter in project spring-framework by spring-projects.
the class MessageBrokerConfigurationTests method configureMessageConvertersCustom.
@Test
public void configureMessageConvertersCustom() {
final MessageConverter testConverter = mock(MessageConverter.class);
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
@Override
protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
messageConverters.add(testConverter);
return false;
}
};
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
assertThat(compositeConverter.getConverters().size(), Matchers.is(1));
Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
assertThat(iterator.next(), Matchers.is(testConverter));
}
use of org.springframework.messaging.converter.MessageConverter 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);
assertNotNull(annotationMethodMessageHandler);
MessageConverter messageConverter = annotationMethodMessageHandler.getMessageConverter();
assertNotNull(messageConverter);
assertTrue(messageConverter instanceof CompositeMessageConverter);
String name = MessageBrokerBeanDefinitionParser.MESSAGE_CONVERTER_BEAN_NAME;
CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(name, CompositeMessageConverter.class);
assertNotNull(compositeMessageConverter);
name = MessageBrokerBeanDefinitionParser.MESSAGING_TEMPLATE_BEAN_NAME;
SimpMessagingTemplate simpMessagingTemplate = this.appContext.getBean(name, SimpMessagingTemplate.class);
assertNotNull(simpMessagingTemplate);
assertEquals("/personal/", simpMessagingTemplate.getUserDestinationPrefix());
List<MessageConverter> converters = compositeMessageConverter.getConverters();
assertThat(converters.size(), Matchers.is(3));
assertThat(converters.get(0), Matchers.instanceOf(StringMessageConverter.class));
assertThat(converters.get(1), Matchers.instanceOf(ByteArrayMessageConverter.class));
assertThat(converters.get(2), Matchers.instanceOf(MappingJackson2MessageConverter.class));
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
assertEquals(MimeTypeUtils.APPLICATION_JSON, ((DefaultContentTypeResolver) resolver).getDefaultMimeType());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(annotationMethodMessageHandler);
String pathSeparator = (String) new DirectFieldAccessor(handlerAccessor.getPropertyValue("pathMatcher")).getPropertyValue("pathSeparator");
assertEquals(".", pathSeparator);
}
Aggregations