Package org.springframework.messaging.simp.annotation.support

Examples of org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler


  @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);

    CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(CompositeMessageConverter.class);
    assertNotNull(compositeMessageConverter);
View Full Code Here


  @Test
  public void customArgumentAndReturnValueTypes() {
    loadBeanDefinitions("websocket-config-broker-custom-argument-and-return-value-types.xml");

    SimpAnnotationMethodMessageHandler handler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);

    List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
    assertEquals(2, customResolvers.size());
    assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(0)));
    assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(1)));

    List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
    assertEquals(2, customHandlers.size());
    assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(0)));
    assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(1)));
  }
View Full Code Here

  }

  @Test
  public void clientOutboundChannelUsedByAnnotatedMethod() {
    TestChannel channel = this.simpleBrokerContext.getBean("clientOutboundChannel", TestChannel.class);
    SimpAnnotationMethodMessageHandler messageHandler = this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSessionId("sess1");
    headers.setSessionAttributes(new ConcurrentHashMap<>());
    headers.setSubscriptionId("subs1");
    headers.setDestination("/foo");
    Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();

    messageHandler.handleMessage(message);

    message = channel.messages.get(0);
    headers = StompHeaderAccessor.wrap(message);

    assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
View Full Code Here

  }

  @Test
  public void brokerChannelUsedByAnnotatedMethod() {
    TestChannel channel = this.simpleBrokerContext.getBean("brokerChannel", TestChannel.class);
    SimpAnnotationMethodMessageHandler messageHandler =
        this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
    headers.setSessionId("sess1");
    headers.setSessionAttributes(new ConcurrentHashMap<>());
    headers.setDestination("/foo");
    Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());

    messageHandler.handleMessage(message);

    message = channel.messages.get(0);
    headers = StompHeaderAccessor.wrap(message);

    assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
View Full Code Here

    assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class));
  }

  @Test
  public void customArgumentAndReturnValueTypes() throws Exception {
    SimpAnnotationMethodMessageHandler handler = this.customContext.getBean(SimpAnnotationMethodMessageHandler.class);

    List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
    assertEquals(1, customResolvers.size());
    assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(0)));

    List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
    assertEquals(1, customHandlers.size());
    assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(0)));
  }
View Full Code Here

    assertThat(config.simpValidator(), Matchers.instanceOf(TestValidator.class));
  }

  @Test
  public void simpValidatorInjected() {
    SimpAnnotationMethodMessageHandler messageHandler =
        this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);

    assertThat(messageHandler.getValidator(), Matchers.notNullValue(Validator.class));
  }
View Full Code Here

  public void customPathMatcher() {
    SimpleBrokerMessageHandler broker = this.customContext.getBean(SimpleBrokerMessageHandler.class);
    DefaultSubscriptionRegistry registry = (DefaultSubscriptionRegistry) broker.getSubscriptionRegistry();
    assertEquals("a.a", registry.getPathMatcher().combine("a", "a"));

    SimpAnnotationMethodMessageHandler handler = this.customContext.getBean(SimpAnnotationMethodMessageHandler.class);
    assertEquals("a.a", handler.getPathMatcher().combine("a", "a"));
  }
View Full Code Here

  protected void configureMessageBroker(MessageBrokerRegistry registry) {
  }

  @Bean
  public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() {
    SimpAnnotationMethodMessageHandler handler = new SimpAnnotationMethodMessageHandler(
        clientInboundChannel(), clientOutboundChannel(), brokerMessagingTemplate());

    handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes());
    handler.setMessageConverter(brokerMessageConverter());
    handler.setValidator(simpValidator());

    List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
    addArgumentResolvers(argumentResolvers);
    handler.setCustomArgumentResolvers(argumentResolvers);

    List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
    addReturnValueHandlers(returnValueHandlers);
    handler.setCustomReturnValueHandlers(returnValueHandlers);

    PathMatcher pathMatcher = this.getBrokerRegistry().getPathMatcher();
    if (pathMatcher != null) {
      handler.setPathMatcher(pathMatcher);
    }
    return handler;
  }
View Full Code Here

TOP

Related Classes of org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.