Example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor wrap

List of usage examples for org.springframework.messaging.simp.stomp StompHeaderAccessor wrap

Introduction

In this page you can find the example usage for org.springframework.messaging.simp.stomp StompHeaderAccessor wrap.

Prototype

public static StompHeaderAccessor wrap(Message<?> message) 

Source Link

Document

Create an instance from the payload and headers of the given Message.

Usage

From source file:com.company.project.config.StompConnectedEvent.java

@Override
public void onApplicationEvent(SessionConnectedEvent event) {
    StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());

    logger.debug("Connected event [sessionId: " + sha.getSessionId() + " ]");
    System.out.println("Connected event [sessionId: " + sha.getSessionId() + " ]");

}

From source file:com.company.project.config.StompConnectEvent.java

@Override
public void onApplicationEvent(SessionConnectEvent event) {
    StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());

    String username = sha.getNativeHeader("username").get(0); // from jsp : stompClient.connect({username: "${pageContext.request.userPrincipal.name}"}, function(frame) {
    logger.debug("Connect event [sessionId: " + sha.getSessionId() + "; username: " + username + " ]");
    System.out.println("Connect event [sessionId: " + sha.getSessionId() + "; username: " + username + " ]");
}

From source file:com.company.project.config.PresenceChannelInterceptor.java

@Override
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {

    StompHeaderAccessor sha = StompHeaderAccessor.wrap(message);

    // ignore non-STOMP messages like heartbeat messages
    if (sha.getCommand() == null) {
        return;//  ww  w .  j av  a2 s.c om
    }

    String sessionId = sha.getSessionId();

    switch (sha.getCommand()) {
    case CONNECT:
        logger.debug("STOMP Connect [sessionId: " + sessionId + "]");
        break;
    case CONNECTED:
        logger.debug("STOMP Connected [sessionId: " + sessionId + "]");
        break;
    case DISCONNECT:
        logger.debug("STOMP Disconnect [sessionId: " + sessionId + "]");
        break;
    default:
        break;

    }
}

From source file:com.company.project.config.StompDisconnectEvent.java

@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
    StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());
    CloseStatus status = event.getCloseStatus();

    if (status.equals(CloseStatus.BAD_DATA)) {
        System.out.println("CloseStatus.BAD_DATA");
    }//from   w w  w  . j a va2 s .c  om
    if (status.equals(CloseStatus.GOING_AWAY)) {
        System.out.println("CloseStatus.GOING_AWAY");
    }
    if (status.equals(CloseStatus.NORMAL)) {
        System.out.println("CloseStatus.NORMAL");
    }
    if (status.equals(CloseStatus.NOT_ACCEPTABLE)) {
        System.out.println("CloseStatus.NOT_ACCEPTABLE");
    }
    if (status.equals(CloseStatus.NO_CLOSE_FRAME)) {
        System.out.println("CloseStatus.NO_CLOSE_FRAME");
    }
    if (status.equals(CloseStatus.NO_STATUS_CODE)) {
        System.out.println("CloseStatus.NO_STATUS_CODE");
    }
    if (status.equals(CloseStatus.POLICY_VIOLATION)) {
        System.out.println("CloseStatus.POLICY_VIOLATION");
    }
    if (status.equals(CloseStatus.PROTOCOL_ERROR)) {
        System.out.println("CloseStatus.PROTOCOL_ERROR");
    }
    if (status.equals(CloseStatus.REQUIRED_EXTENSION)) {
        System.out.println("CloseStatus.REQUIRED_EXTENSION");
    }
    if (status.equals(CloseStatus.SERVER_ERROR)) {
        System.out.println("CloseStatus.SERVER_ERROR");
    }
    if (status.equals(CloseStatus.SERVICE_RESTARTED)) {
        System.out.println("CloseStatus.SERVICE_RESTARTED");
    }
    if (status.equals(CloseStatus.SESSION_NOT_RELIABLE)) {
        System.out.println("CloseStatus.SESSION_NOT_RELIABLE");
    }
    if (status.equals(CloseStatus.TLS_HANDSHAKE_FAILURE)) {
        System.out.println("CloseStatus.TLS_HANDSHAKE_FAILURE");
    }
    if (status.equals(CloseStatus.TOO_BIG_TO_PROCESS)) {
        System.out.println("CloseStatus.TOO_BIG_TO_PROCESS");
    }

    System.out.println("CloseStatus: " + status);

    logger.debug("Disconnect event [sessionId: " + sha.getSessionId() + " ]");
    System.out.println("Disconnect event [sessionId: " + event.getSessionId() + " ]");
}

From source file:org.jimsey.projects.turbine.condenser.StompConnectEvent.java

public void onApplicationEvent(SessionConnectEvent event) {
    StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());

    // String company = sha.getNativeHeader("company").get(0);
    logger.info("Connect event: {}", ReflectionToStringBuilder.toString(sha, ToStringStyle.JSON_STYLE));
}

From source file:org.jimsey.projects.turbine.condenser.StompSubscribeEvent.java

@Override
public void onApplicationEvent(SessionSubscribeEvent event) {
    StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());
    logger.info("Subscribe event: {}", ReflectionToStringBuilder.toString(sha, ToStringStyle.JSON_STYLE));
}

From source file:jp.pigumer.web.StompConfig.java

@Override
public void configureClientInboundChannel(ChannelRegistration registration) {
    registration.setInterceptors(new ChannelInterceptorAdapter() {
        @Override// w ww  .jav  a 2 s .  c om
        public Message<?> preSend(Message<?> message, MessageChannel channel) {
            StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
            if (accessor.getCommand() == StompCommand.SUBSCRIBE) {
                LOGGER.log(Level.INFO, String.format("%s: %s", channel, message));
            }
            return message;
        }
    });
}

From source file:org.appverse.web.framework.backend.frontfacade.websocket.TestChannelInterceptor.java

@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
    if (this.destinationPatterns.isEmpty()) {
        this.messages.add(message);
    } else {//from www.  j av  a  2  s  .com
        StompHeaderAccessor headers = StompHeaderAccessor.wrap(message);
        if (headers.getDestination() != null) {
            for (String pattern : this.destinationPatterns) {
                if (this.matcher.match(pattern, headers.getDestination())) {
                    this.messages.add(message);
                    break;
                }
            }
        }
    }
    return message;
}

From source file:org.springframework.samples.portfolio.web.standalone.StandalonePortfolioControllerTests.java

@Test
public void getPositions() throws Exception {

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId("0");
    headers.setDestination("/app/positions");
    headers.setSessionId("0");
    headers.setUser(new TestPrincipal("fabrice"));
    headers.setSessionAttributes(new HashMap<String, Object>());
    Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();

    this.annotationMethodMessageHandler.handleMessage(message);

    assertEquals(1, this.clientOutboundChannel.getMessages().size());
    Message<?> reply = this.clientOutboundChannel.getMessages().get(0);

    StompHeaderAccessor replyHeaders = StompHeaderAccessor.wrap(reply);
    assertEquals("0", replyHeaders.getSessionId());
    assertEquals("0", replyHeaders.getSubscriptionId());
    assertEquals("/app/positions", replyHeaders.getDestination());

    String json = new String((byte[]) reply.getPayload(), Charset.forName("UTF-8"));
    new JsonPathExpectationsHelper("$[0].company").assertValue(json, "Citrix Systems, Inc.");
    new JsonPathExpectationsHelper("$[1].company").assertValue(json, "Dell Inc.");
    new JsonPathExpectationsHelper("$[2].company").assertValue(json, "Microsoft");
    new JsonPathExpectationsHelper("$[3].company").assertValue(json, "Oracle");
}

From source file:org.springframework.samples.portfolio.web.context.ContextPortfolioControllerTests.java

@Test
public void getPositions() throws Exception {

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId("0");
    headers.setDestination("/app/positions");
    headers.setSessionId("0");
    headers.setUser(new TestPrincipal("fabrice"));
    headers.setSessionAttributes(new HashMap<String, Object>());
    Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());

    this.clientOutboundChannelInterceptor.setIncludedDestinations("/app/positions");
    this.clientOutboundChannelInterceptor.startRecording();

    this.clientInboundChannel.send(message);

    Message<?> reply = this.clientOutboundChannelInterceptor.awaitMessage(5);
    assertNotNull(reply);/*from w ww . j a v a  2s.  co m*/

    StompHeaderAccessor replyHeaders = StompHeaderAccessor.wrap(reply);
    assertEquals("0", replyHeaders.getSessionId());
    assertEquals("0", replyHeaders.getSubscriptionId());
    assertEquals("/app/positions", replyHeaders.getDestination());

    String json = new String((byte[]) reply.getPayload(), Charset.forName("UTF-8"));
    new JsonPathExpectationsHelper("$[0].company").assertValue(json, "Citrix Systems, Inc.");
    new JsonPathExpectationsHelper("$[1].company").assertValue(json, "Dell Inc.");
    new JsonPathExpectationsHelper("$[2].company").assertValue(json, "Microsoft");
    new JsonPathExpectationsHelper("$[3].company").assertValue(json, "Oracle");
}