Search in sources :

Example 1 with SimpMessagingTemplate

use of org.springframework.messaging.simp.SimpMessagingTemplate in project spring-framework by spring-projects.

the class SimpAnnotationMethodMessageHandlerTests method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel);
    brokerTemplate.setMessageConverter(this.converter);
    this.messageHandler = new TestSimpAnnotationMethodMessageHandler(brokerTemplate, this.channel, this.channel);
    this.messageHandler.setApplicationContext(new StaticApplicationContext());
    this.messageHandler.setValidator(new StringTestValidator(TEST_INVALID_VALUE));
    this.messageHandler.afterPropertiesSet();
    this.testController = new TestController();
}
Also used : SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Before(org.junit.Before)

Example 2 with SimpMessagingTemplate

use of org.springframework.messaging.simp.SimpMessagingTemplate in project spring-framework by spring-projects.

the class WebSocketAnnotationMethodMessageHandlerTests method setUp.

@Before
public void setUp() throws Exception {
    this.applicationContext = new StaticApplicationContext();
    this.applicationContext.registerSingleton("controller", TestController.class);
    this.applicationContext.registerSingleton("controllerAdvice", TestControllerAdvice.class);
    this.applicationContext.refresh();
    SubscribableChannel channel = Mockito.mock(SubscribableChannel.class);
    SimpMessageSendingOperations brokerTemplate = new SimpMessagingTemplate(channel);
    this.messageHandler = new TestWebSocketAnnotationMethodMessageHandler(brokerTemplate, channel, channel);
    this.messageHandler.setApplicationContext(this.applicationContext);
    this.messageHandler.afterPropertiesSet();
}
Also used : SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) SimpMessageSendingOperations(org.springframework.messaging.simp.SimpMessageSendingOperations) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Before(org.junit.Before)

Example 3 with SimpMessagingTemplate

use of org.springframework.messaging.simp.SimpMessagingTemplate 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 4 with SimpMessagingTemplate

use of org.springframework.messaging.simp.SimpMessagingTemplate in project spring-framework by spring-projects.

the class AbstractMessageBrokerConfiguration method brokerMessagingTemplate.

@Bean
public SimpMessagingTemplate brokerMessagingTemplate() {
    SimpMessagingTemplate template = new SimpMessagingTemplate(brokerChannel());
    String prefix = getBrokerRegistry().getUserDestinationPrefix();
    if (prefix != null) {
        template.setUserDestinationPrefix(prefix);
    }
    template.setMessageConverter(brokerMessageConverter());
    return template;
}
Also used : SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) Bean(org.springframework.context.annotation.Bean)

Example 5 with SimpMessagingTemplate

use of org.springframework.messaging.simp.SimpMessagingTemplate in project spring-framework by spring-projects.

the class UserRegistryMessageHandlerTests method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(this.brokerChannel.send(any())).thenReturn(true);
    this.converter = new MappingJackson2MessageConverter();
    SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
    brokerTemplate.setMessageConverter(this.converter);
    this.localRegistry = mock(SimpUserRegistry.class);
    this.multiServerRegistry = new MultiServerUserRegistry(this.localRegistry);
    this.handler = new UserRegistryMessageHandler(this.multiServerRegistry, brokerTemplate, "/topic/simp-user-registry", this.taskScheduler);
}
Also used : SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) Before(org.junit.Before)

Aggregations

SimpMessagingTemplate (org.springframework.messaging.simp.SimpMessagingTemplate)7 Before (org.junit.Before)5 MappingJackson2MessageConverter (org.springframework.messaging.converter.MappingJackson2MessageConverter)4 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)3 Method (java.lang.reflect.Method)2 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)2 Test (org.junit.Test)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 Bean (org.springframework.context.annotation.Bean)1 MethodParameter (org.springframework.core.MethodParameter)1 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)1 SubscribableChannel (org.springframework.messaging.SubscribableChannel)1 ByteArrayMessageConverter (org.springframework.messaging.converter.ByteArrayMessageConverter)1 CompositeMessageConverter (org.springframework.messaging.converter.CompositeMessageConverter)1 ContentTypeResolver (org.springframework.messaging.converter.ContentTypeResolver)1 DefaultContentTypeResolver (org.springframework.messaging.converter.DefaultContentTypeResolver)1 MessageConverter (org.springframework.messaging.converter.MessageConverter)1 SimpMessageSendingOperations (org.springframework.messaging.simp.SimpMessageSendingOperations)1 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)1