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

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

Introduction

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

Prototype

public static StompHeaderAccessor create(StompCommand command) 

Source Link

Document

Create an instance for the given STOMP command.

Usage

From source file:com.codeveo.lago.bot.stomp.client.WebSocketStompSession.java

public void subscribe(String destination, String receiptId) {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId("sub-" + this.subscriptionIndex.getAndIncrement());
    headers.setDestination(destination);
    if (receiptId != null) {
        headers.setReceipt(receiptId);/*w  ww  . j  a  v  a 2  s. c  om*/
    }
    sendInternal(MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build());
}

From source file:fr.jugorleans.poker.client.stomp.WebSocketStompSession.java

public void subscribe(String destination, String receiptId) {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId("sub" + this.subscriptionIndex.getAndIncrement());
    headers.setDestination(destination);
    if (receiptId != null) {
        headers.setReceipt(receiptId);//w  w w .  j a v a2s  . c  o  m
    }
    sendInternal(MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build());
}

From source file:com.codeveo.lago.bot.stomp.client.WebSocketStompSession.java

public void send(String destination, Object payload) {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
    headers.setDestination(destination);
    sendInternal(/*www  .ja  v a 2  s .  c om*/
            (Message<byte[]>) this.messageConverter.toMessage(payload, new MessageHeaders(headers.toMap())));
}

From source file:org.tmarciniak.mtp.web.websocket.support.client.WebSocketStompSession.java

@SuppressWarnings("unchecked")
public void send(String destination, Object payload) {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
    headers.setDestination(destination);
    Message<?> message = this.messageConverter.toMessage(payload, new MessageHeaders(headers.toMap()));
    sendInternal((Message<byte[]>) message);
}

From source file:com.codeveo.lago.bot.stomp.client.WebSocketStompSession.java

public void disconnect() {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.DISCONNECT);
    Message<byte[]> message = MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build();
    sendInternal(message);//from   ww w.j  av a 2s.  c om
    try {
        this.webSocketSession.close(CloseStatus.GOING_AWAY);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:fr.jugorleans.poker.client.stomp.WebSocketStompSession.java

public void disconnect() {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.DISCONNECT);
    Message<byte[]> message = MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build();
    sendInternal(message);//from w w w. ja v a2 s. co  m
    try {
        this.webSocketSession.close();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

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:smpp.networking.SimpleStompClient.java

public void subscribe(String destination, MessageHandler messageHandler) {

    String id = String.valueOf(this.subscriptionIndex.getAndIncrement());
    this.subscriptionHandlers.put(id, messageHandler);

    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSubscriptionId(id);/*from ww  w.  j av a 2s . c  o  m*/
    headers.setDestination(destination);

    Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
    byte[] bytes = encoder.encode(message);
    try {
        this.session.getRemote().sendString(new String(bytes, DEFAULT_CHARSET));
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

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);/* w ww.j a v  a2  s.c om*/

    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.standalone.StandalonePortfolioControllerTests.java

@Test
public void executeTrade() throws Exception {

    Trade trade = new Trade();
    trade.setAction(Trade.TradeAction.Buy);
    trade.setTicker("DELL");
    trade.setShares(25);//  w  ww .j a  va 2s  .c o  m

    byte[] payload = new ObjectMapper().writeValueAsBytes(trade);

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

    this.annotationMethodMessageHandler.handleMessage(message);

    assertEquals(1, this.tradeService.getTrades().size());
    Trade actual = this.tradeService.getTrades().get(0);

    assertEquals(Trade.TradeAction.Buy, actual.getAction());
    assertEquals("DELL", actual.getTicker());
    assertEquals(25, actual.getShares());
    assertEquals("fabrice", actual.getUsername());
}