Search in sources :

Example 1 with DefaultContentTypeResolver

use of org.springframework.messaging.converter.DefaultContentTypeResolver in project spring-framework by spring-projects.

the class AbstractMessageBrokerConfiguration method createJacksonConverter.

protected MappingJackson2MessageConverter createJacksonConverter() {
    DefaultContentTypeResolver resolver = new DefaultContentTypeResolver();
    resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON);
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setContentTypeResolver(resolver);
    return converter;
}
Also used : MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) DefaultContentTypeResolver(org.springframework.messaging.converter.DefaultContentTypeResolver)

Example 2 with DefaultContentTypeResolver

use of org.springframework.messaging.converter.DefaultContentTypeResolver 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);
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) ByteArrayMessageConverter(org.springframework.messaging.converter.ByteArrayMessageConverter) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ContentTypeResolver(org.springframework.messaging.converter.ContentTypeResolver) DefaultContentTypeResolver(org.springframework.messaging.converter.DefaultContentTypeResolver) SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) ByteArrayMessageConverter(org.springframework.messaging.converter.ByteArrayMessageConverter) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) MessageConverter(org.springframework.messaging.converter.MessageConverter) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) Test(org.junit.Test)

Example 3 with DefaultContentTypeResolver

use of org.springframework.messaging.converter.DefaultContentTypeResolver 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.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());
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) ByteArrayMessageConverter(org.springframework.messaging.converter.ByteArrayMessageConverter) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) ContentTypeResolver(org.springframework.messaging.converter.ContentTypeResolver) DefaultContentTypeResolver(org.springframework.messaging.converter.DefaultContentTypeResolver) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) ByteArrayMessageConverter(org.springframework.messaging.converter.ByteArrayMessageConverter) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) MessageConverter(org.springframework.messaging.converter.MessageConverter) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) Test(org.junit.Test)

Aggregations

DefaultContentTypeResolver (org.springframework.messaging.converter.DefaultContentTypeResolver)3 MappingJackson2MessageConverter (org.springframework.messaging.converter.MappingJackson2MessageConverter)3 Test (org.junit.Test)2 ByteArrayMessageConverter (org.springframework.messaging.converter.ByteArrayMessageConverter)2 CompositeMessageConverter (org.springframework.messaging.converter.CompositeMessageConverter)2 ContentTypeResolver (org.springframework.messaging.converter.ContentTypeResolver)2 MessageConverter (org.springframework.messaging.converter.MessageConverter)2 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 SimpMessagingTemplate (org.springframework.messaging.simp.SimpMessagingTemplate)1 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)1