Search in sources :

Example 11 with CompositeMessageConverter

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();
}
Also used : CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) DelegatingWebSocketMessageBrokerConfiguration(org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration)

Example 12 with CompositeMessageConverter

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);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) 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)

Example 13 with CompositeMessageConverter

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);
}
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 14 with CompositeMessageConverter

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(".");
}
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)

Example 15 with CompositeMessageConverter

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);
}
Also used : CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) Test(org.junit.jupiter.api.Test)

Aggregations

CompositeMessageConverter (org.springframework.messaging.converter.CompositeMessageConverter)15 MessageConverter (org.springframework.messaging.converter.MessageConverter)10 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)9 MappingJackson2MessageConverter (org.springframework.messaging.converter.MappingJackson2MessageConverter)8 Test (org.junit.jupiter.api.Test)7 ByteArrayMessageConverter (org.springframework.messaging.converter.ByteArrayMessageConverter)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 List (java.util.List)3 DefaultContentTypeResolver (org.springframework.messaging.converter.DefaultContentTypeResolver)3 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 MapMessageConverter (org.springframework.integration.support.converter.MapMessageConverter)2 SimpleMessageConverter (org.springframework.integration.support.converter.SimpleMessageConverter)2 SubProtocolHandlerRegistry (org.springframework.integration.websocket.support.SubProtocolHandlerRegistry)2 ContentTypeResolver (org.springframework.messaging.converter.ContentTypeResolver)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 Collections (java.util.Collections)1 UUID (java.util.UUID)1