Search in sources :

Example 1 with ContentTypeResolver

use of org.springframework.messaging.converter.ContentTypeResolver 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);
}
Also used : MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) DefaultContentTypeResolver(org.springframework.messaging.converter.DefaultContentTypeResolver) 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.jupiter.api.Test)

Example 2 with ContentTypeResolver

use of org.springframework.messaging.converter.ContentTypeResolver 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(".");
}
Also used : SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) DefaultContentTypeResolver(org.springframework.messaging.converter.DefaultContentTypeResolver) 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.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 ByteArrayMessageConverter (org.springframework.messaging.converter.ByteArrayMessageConverter)2 CompositeMessageConverter (org.springframework.messaging.converter.CompositeMessageConverter)2 ContentTypeResolver (org.springframework.messaging.converter.ContentTypeResolver)2 DefaultContentTypeResolver (org.springframework.messaging.converter.DefaultContentTypeResolver)2 MappingJackson2MessageConverter (org.springframework.messaging.converter.MappingJackson2MessageConverter)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