Package org.springframework.messaging.simp

Examples of org.springframework.messaging.simp.SimpMessageHeaderAccessor


    assertEquals("value", this.testController.arguments.get("name"));
  }

  @Test
  public void simpleBinding() {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
    headers.setSessionId("session1");
    headers.setSessionAttributes(new ConcurrentHashMap<>());
    headers.setDestination("/pre/binding/id/12");
    Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
    this.messageHandler.handleMessage(message);

    assertEquals("simpleBinding", this.testController.method);
    assertTrue("should be bound to type long", this.testController.arguments.get("id") instanceof Long);
View Full Code Here


    assertEquals(12L, this.testController.arguments.get("id"));
  }

  @Test
  public void validationError() {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
    headers.setSessionId("session1");
    headers.setSessionAttributes(new ConcurrentHashMap<>());
    headers.setDestination("/pre/validation/payload");
    Message<?> message = MessageBuilder.withPayload(TEST_INVALID_VALUE.getBytes()).setHeaders(headers).build();
    this.messageHandler.handleMessage(message);
    assertEquals("handleValidationException", this.testController.method);
  }
View Full Code Here

  @Test
  public void simpScope() {
    Map<String, Object> map = new ConcurrentHashMap<>();
    map.put("name", "value");
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
    headers.setSessionId("session1");
    headers.setSessionAttributes(map);
    headers.setDestination("/pre/scope");
    Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
    this.messageHandler.handleMessage(message);

    assertEquals("scope", this.testController.method);
  }
View Full Code Here

    this.messageHandler.setPathMatcher(new AntPathMatcher("."));
    this.messageHandler.registerHandler(controller);
    this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));

    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
    headers.setSessionId("session1");
    headers.setSessionAttributes(new HashMap<>());
    headers.setDestination("/app1/pre.foo");
    Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
    this.messageHandler.handleMessage(message);

    assertEquals("handleFoo", controller.method);

    headers = SimpMessageHeaderAccessor.create();
    headers.setSessionId("session1");
    headers.setSessionAttributes(new HashMap<>());
    headers.setDestination("/app2/pre.foo");
    message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
    this.messageHandler.handleMessage(message);

    assertEquals("handleFoo", controller.method);
  }
View Full Code Here

    assertEquals(sess1, connectAckHeaders.getSessionId());
  }


  protected Message<String> createSubscriptionMessage(String sessionId, String subcriptionId, String destination) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
    headers.setSubscriptionId(subcriptionId);
    headers.setDestination(destination);
    headers.setSessionId(sessionId);
    return MessageBuilder.createMessage("", headers.getMessageHeaders());
  }
View Full Code Here

    this.handler.handleReturnValue(PAYLOAD, this.sendToReturnType, inputMessage);

    verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());

    Message<?> message = this.messageCaptor.getAllValues().get(0);
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
    assertEquals(sessionId, headers.getSessionId());
    assertEquals("/dest1", headers.getDestination());
    assertEquals(MIME_TYPE, headers.getContentType());
    assertNull("Subscription id should not be copied", headers.getSubscriptionId());

    message = this.messageCaptor.getAllValues().get(1);
    headers = SimpMessageHeaderAccessor.wrap(message);
    assertEquals(sessionId, headers.getSessionId());
    assertEquals("/dest2", headers.getDestination());
    assertEquals(MIME_TYPE, headers.getContentType());
    assertNull("Subscription id should not be copied", headers.getSubscriptionId());
  }
View Full Code Here

    headers.setSessionId(sessionId);
    return MessageBuilder.createMessage("", headers.getMessageHeaders());
  }

  protected Message<String> createConnectMessage(String sessionId) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT);
    headers.setSessionId(sessionId);
    return MessageBuilder.createMessage("", headers.getMessageHeaders());
  }
View Full Code Here

    this.handler.handleReturnValue(PAYLOAD, this.sendToDefaultDestReturnType, inputMessage);

    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());

    Message<?> message = this.messageCaptor.getAllValues().get(0);
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
    assertEquals(sessionId, headers.getSessionId());
    assertEquals("/topic/dest", headers.getDestination());
    assertEquals(MIME_TYPE, headers.getContentType());
    assertNull("Subscription id should not be copied", headers.getSubscriptionId());
  }
View Full Code Here

    headers.setSessionId(sessionId);
    return MessageBuilder.createMessage("", headers.getMessageHeaders());
  }

  protected Message<String> createMessage(String destination, String payload) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
    headers.setDestination(destination);
    return MessageBuilder.createMessage("", headers.getMessageHeaders());
  }
View Full Code Here

    return MessageBuilder.createMessage("", headers.getMessageHeaders());
  }

  protected boolean assertCapturedMessage(String sessionId, String subcriptionId, String destination) {
    for (Message<?> message : this.messageCaptor.getAllValues()) {
      SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
      if (sessionId.equals(headers.getSessionId())) {
        if (subcriptionId.equals(headers.getSubscriptionId())) {
          if (destination.equals(headers.getDestination())) {
            return true;
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.springframework.messaging.simp.SimpMessageHeaderAccessor

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.