org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame

Here are the examples of the java api class org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame taken from open source projects.

1. StompV11Test#testHeartBeat()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testHeartBeat() throws Exception {
    //no heart beat at all if heat-beat absent
    ClientStompFrame frame = connV11.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    ClientStompFrame reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    Thread.sleep(5000);
    assertEquals(0, connV11.getFrameQueueSize());
    connV11.disconnect();
    //no heart beat for (0,0)
    connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = connV11.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "0,0");
    frame.addHeader("accept-version", "1.0,1.1");
    reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    assertEquals("0,0", reply.getHeader("heart-beat"));
    Thread.sleep(5000);
    assertEquals(0, connV11.getFrameQueueSize());
    connV11.disconnect();
    //heart-beat (1,0), should receive a min client ping accepted by server
    connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = connV11.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "1,0");
    frame.addHeader("accept-version", "1.0,1.1");
    reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    assertEquals("0,500", reply.getHeader("heart-beat"));
    Thread.sleep(2000);
    //now server side should be disconnected because we didn't send ping for 2 sec
    frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World");
    //send will fail
    try {
        connV11.sendFrame(frame);
        fail("connection should have been destroyed by now");
    } catch (IOException e) {
    }
    //heart-beat (1,0), start a ping, then send a message, should be ok.
    connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = connV11.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "1,0");
    frame.addHeader("accept-version", "1.0,1.1");
    reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    assertEquals("0,500", reply.getHeader("heart-beat"));
    System.out.println("========== start pinger!");
    connV11.startPinger(500);
    Thread.sleep(2000);
    //now server side should be disconnected because we didn't send ping for 2 sec
    frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World");
    //send will be ok
    connV11.sendFrame(frame);
    connV11.stopPinger();
    connV11.disconnect();
}

2. StompV12Test#testHeartBeat()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testHeartBeat() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    //no heart beat at all if heat-beat absent
    ClientStompFrame frame = conn.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    ClientStompFrame reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    Thread.sleep(5000);
    Assert.assertEquals(0, conn.getFrameQueueSize());
    conn.disconnect();
    //no heart beat for (0,0)
    conn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    frame = conn.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "0,0");
    frame.addHeader("accept-version", "1.0,1.1,1.2");
    reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    Assert.assertEquals("0,0", reply.getHeader("heart-beat"));
    Thread.sleep(5000);
    Assert.assertEquals(0, conn.getFrameQueueSize());
    conn.disconnect();
    //heart-beat (1,0), should receive a min client ping accepted by server
    conn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    frame = conn.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "1,0");
    frame.addHeader("accept-version", "1.0,1.2");
    reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    Assert.assertEquals("0,500", reply.getHeader("heart-beat"));
    Thread.sleep(2000);
    //now server side should be disconnected because we didn't send ping for 2 sec
    frame = conn.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World");
    //send will fail
    try {
        conn.sendFrame(frame);
        Assert.fail("connection should have been destroyed by now");
    } catch (IOException e) {
    }
    //heart-beat (1,0), start a ping, then send a message, should be ok.
    conn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    frame = conn.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "1,0");
    frame.addHeader("accept-version", "1.0,1.1,1.2");
    reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    Assert.assertEquals("0,500", reply.getHeader("heart-beat"));
    conn.startPinger(500);
    Thread.sleep(2000);
    frame = conn.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World");
    //send will be ok
    conn.sendFrame(frame);
    conn.stopPinger();
    conn.disconnect();
}

3. StompV11Test#testSendMessageWithCustomHeadersAndSelector()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendMessageWithCustomHeadersAndSelector() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue, "foo = 'abc'");
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("foo", "abc");
    frame.addHeader("bar", "123");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("bar", "123", message.getStringProperty("bar"));
}

4. StompV12Test#testSendMessageWithCustomHeadersAndSelector()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendMessageWithCustomHeadersAndSelector() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue, "foo = 'abc'");
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("foo", "abc");
    frame.addHeader("bar", "123");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World");
    connV12.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("bar", "123", message.getStringProperty("bar"));
}

5. StompV11Test#testSendAndReceiveOnDifferentConnections()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendAndReceiveOnDifferentConnections() throws Exception {
    connV11.connect(defUser, defPass);
    ClientStompFrame sendFrame = connV11.createFrame("SEND");
    sendFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    sendFrame.setBody("Hello World");
    connV11.sendFrame(sendFrame);
    StompClientConnection connV11_2 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    connV11_2.connect(defUser, defPass);
    this.subscribe(connV11_2, "sub1", "auto");
    ClientStompFrame frame = connV11_2.receiveFrame(2000);
    assertEquals("MESSAGE", frame.getCommand());
    assertEquals("Hello World", frame.getBody());
    connV11.disconnect();
    connV11_2.disconnect();
}

6. StompV11Test#testJMSXGroupIdCanBeSet()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testJMSXGroupIdCanBeSet() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("JMSXGroupID", "TEST");
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    // differ from StompConnect
    Assert.assertEquals("TEST", message.getStringProperty("JMSXGroupID"));
}

7. StompV11Test#ack()

Project: activemq-artemis
Source File: StompV11Test.java
View license
private void ack(StompClientConnection conn, String subId, ClientStompFrame frame) throws IOException, InterruptedException {
    String messageID = frame.getHeader("message-id");
    ClientStompFrame ackFrame = conn.createFrame("ACK");
    ackFrame.addHeader("subscription", subId);
    ackFrame.addHeader("message-id", messageID);
    ClientStompFrame response = conn.sendFrame(ackFrame);
    if (response != null) {
        throw new IOException("failed to ack " + response);
    }
}

8. StompV11Test#testSendMessageToNonExistentJmsQueueWithoutAutoCreation()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendMessageToNonExistentJmsQueueWithoutAutoCreation() throws Exception {
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setAutoCreateJmsQueues(false);
    server.getActiveMQServer().getAddressSettingsRepository().addMatch("#", addressSettings);
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    String guid = UUID.randomUUID().toString();
    frame.addHeader("destination", "jms.queue.NonExistentQueue" + guid);
    frame.addHeader("receipt", "1234");
    frame.setBody("Hello World");
    frame = connV11.sendFrame(frame);
    assertTrue(frame.getCommand().equals("ERROR"));
    assertEquals("1234", frame.getHeader("receipt-id"));
    System.out.println("message: " + frame.getHeader("message"));
    connV11.disconnect();
}

9. StompV11Test#testSendMessageToNonExistentJmsQueueWithAutoCreation()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendMessageToNonExistentJmsQueueWithAutoCreation() throws Exception {
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    String guid = UUID.randomUUID().toString();
    frame.addHeader("destination", "jms.queue.NonExistentQueue" + guid);
    frame.addHeader("receipt", "1234");
    frame.setBody("Hello World");
    frame = connV11.sendFrame(frame);
    assertTrue(frame.getCommand().equals("RECEIPT"));
    assertEquals("1234", frame.getHeader("receipt-id"));
    System.out.println("message: " + frame.getHeader("message"));
    connV11.disconnect();
}

10. StompV11Test#testReceiveContentType()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testReceiveContentType() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader(Stomp.Headers.CONTENT_TYPE, "text/plain");
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("text/plain", message.getStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_CONTENT_TYPE.toString()));
}

11. StompV12Test#testSendAndReceiveOnDifferentConnections()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendAndReceiveOnDifferentConnections() throws Exception {
    connV12.connect(defUser, defPass);
    ClientStompFrame sendFrame = connV12.createFrame("SEND");
    sendFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    sendFrame.setBody("Hello World");
    connV12.sendFrame(sendFrame);
    StompClientConnection connV12_2 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    connV12_2.connect(defUser, defPass);
    this.subscribe(connV12_2, "sub1", "auto");
    ClientStompFrame frame = connV12_2.receiveFrame(2000);
    Assert.assertEquals("MESSAGE", frame.getCommand());
    Assert.assertEquals("Hello World", frame.getBody());
    connV12.disconnect();
    connV12_2.disconnect();
}

12. StompV12Test#testJMSXGroupIdCanBeSet()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testJMSXGroupIdCanBeSet() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("JMSXGroupID", "TEST");
    frame.setBody("Hello World");
    connV12.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    // differ from StompConnect
    Assert.assertEquals("TEST", message.getStringProperty("JMSXGroupID"));
}

13. StompV12Test#testSendMessageToNonExistentJmsQueueWithoutAutoCreation()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendMessageToNonExistentJmsQueueWithoutAutoCreation() throws Exception {
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setAutoCreateJmsQueues(false);
    server.getActiveMQServer().getAddressSettingsRepository().addMatch("#", addressSettings);
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    String guid = UUID.randomUUID().toString();
    frame.addHeader("destination", "jms.queue.NonExistentQueue" + guid);
    frame.addHeader("receipt", "1234");
    frame.setBody("Hello World");
    frame = connV12.sendFrame(frame);
    Assert.assertTrue(frame.getCommand().equals("ERROR"));
    Assert.assertEquals("1234", frame.getHeader("receipt-id"));
    System.out.println("message: " + frame.getHeader("message"));
    waitDisconnect(connV12);
    Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", connV12.isConnected());
}

14. StompV12Test#testSendMessageToNonExistentJmsQueueWithAutoCreation()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendMessageToNonExistentJmsQueueWithAutoCreation() throws Exception {
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    String guid = UUID.randomUUID().toString();
    frame.addHeader("destination", "jms.queue.NonExistentQueue" + guid);
    frame.addHeader("receipt", "1234");
    frame.setBody("Hello World");
    frame = connV12.sendFrame(frame);
    Assert.assertTrue(frame.getCommand().equals("RECEIPT"));
    Assert.assertEquals("1234", frame.getHeader("receipt-id"));
    System.out.println("message: " + frame.getHeader("message"));
    connV12.disconnect();
}

15. StompV11Test#testSendMessage()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendMessage() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    // Assert default priority 4 is used when priority header is not set
    Assert.assertEquals("getJMSPriority", 4, message.getJMSPriority());
    // Make sure that the timestamp is valid - should
    // be very close to the current time.
    long tnow = System.currentTimeMillis();
    long tmsg = message.getJMSTimestamp();
    Assert.assertTrue(Math.abs(tnow - tmsg) < 1000);
}

16. StompV11Test#commitTransaction()

Project: activemq-artemis
Source File: StompV11Test.java
View license
private void commitTransaction(StompClientConnection conn, String txID, boolean receipt) throws IOException, InterruptedException {
    ClientStompFrame beginFrame = conn.createFrame("COMMIT");
    beginFrame.addHeader("transaction", txID);
    if (receipt) {
        beginFrame.addHeader("receipt", "1234");
    }
    ClientStompFrame resp = conn.sendFrame(beginFrame);
    if (receipt) {
        assertEquals("1234", resp.getHeader("receipt-id"));
    }
}

17. StompV11Test#ack()

Project: activemq-artemis
Source File: StompV11Test.java
View license
private void ack(StompClientConnection conn, String subId, String mid, String txID) throws IOException, InterruptedException {
    ClientStompFrame ackFrame = conn.createFrame("ACK");
    ackFrame.addHeader("subscription", subId);
    ackFrame.addHeader("message-id", mid);
    if (txID != null) {
        ackFrame.addHeader("transaction", txID);
    }
    conn.sendFrame(ackFrame);
}

18. StompV11Test#unsubscribe()

Project: activemq-artemis
Source File: StompV11Test.java
View license
private void unsubscribe(StompClientConnection conn, String subId, boolean receipt) throws IOException, InterruptedException {
    ClientStompFrame subFrame = conn.createFrame("UNSUBSCRIBE");
    subFrame.addHeader("id", subId);
    if (receipt) {
        subFrame.addHeader("receipt", "4321");
    }
    ClientStompFrame f = conn.sendFrame(subFrame);
    if (receipt) {
        System.out.println("response: " + f);
        assertEquals("RECEIPT", f.getCommand());
        assertEquals("4321", f.getHeader("receipt-id"));
    }
}

19. StompV12Test#testSendMessage()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendMessage() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World");
    connV12.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    // Assert default priority 4 is used when priority header is not set
    Assert.assertEquals("getJMSPriority", 4, message.getJMSPriority());
    // Make sure that the timestamp is valid - should
    // be very close to the current time.
    long tnow = System.currentTimeMillis();
    long tmsg = message.getJMSTimestamp();
    Assert.assertTrue(Math.abs(tnow - tmsg) < 1000);
}

20. StompV12Test#commitTransaction()

Project: activemq-artemis
Source File: StompV12Test.java
View license
private void commitTransaction(StompClientConnection conn, String txID, boolean receipt) throws IOException, InterruptedException {
    ClientStompFrame beginFrame = conn.createFrame("COMMIT");
    beginFrame.addHeader("transaction", txID);
    if (receipt) {
        beginFrame.addHeader("receipt", "1234");
    }
    ClientStompFrame resp = conn.sendFrame(beginFrame);
    if (receipt) {
        Assert.assertEquals("1234", resp.getHeader("receipt-id"));
    }
}

21. StompV12Test#ack()

Project: activemq-artemis
Source File: StompV12Test.java
View license
private void ack(StompClientConnection conn, ClientStompFrame frame) throws IOException, InterruptedException {
    String messageID = frame.getHeader("ack");
    ClientStompFrame ackFrame = conn.createFrame("ACK");
    ackFrame.addHeader("id", messageID);
    ClientStompFrame response = conn.sendFrame(ackFrame);
    if (response != null) {
        throw new IOException("failed to ack " + response);
    }
}

22. StompV12Test#unsubscribe()

Project: activemq-artemis
Source File: StompV12Test.java
View license
private void unsubscribe(StompClientConnection conn, String subId, boolean receipt) throws IOException, InterruptedException {
    ClientStompFrame subFrame = conn.createFrame("UNSUBSCRIBE");
    subFrame.addHeader("id", subId);
    if (receipt) {
        subFrame.addHeader("receipt", "4321");
    }
    ClientStompFrame f = conn.sendFrame(subFrame);
    if (receipt) {
        System.out.println("response: " + f);
        Assert.assertEquals("RECEIPT", f.getCommand());
        Assert.assertEquals("4321", f.getHeader("receipt-id"));
    }
}

23. StompV12Test#testHeaderRepetitive()

Project: activemq-artemis
Source File: StompV12Test.java
View license
//test that repetitive headers
@Test
public void testHeaderRepetitive() throws Exception {
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setAutoCreateJmsQueues(false);
    server.getActiveMQServer().getAddressSettingsRepository().addMatch("#", addressSettings);
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    String body = "Hello World!";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("destination", "aNonexistentQueue");
    frame.addHeader("content-type", "application/xml");
    frame.addHeader("content-length", cLen);
    frame.addHeader("foo", "value1");
    frame.addHeader("foo", "value2");
    frame.addHeader("foo", "value3");
    frame.setBody(body);
    connV12.sendFrame(frame);
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    Assert.assertEquals("MESSAGE", frame.getCommand());
    Assert.assertEquals(body, frame.getBody());
    System.out.println("received: " + frame);
    Assert.assertEquals("value1", frame.getHeader("foo"));
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.disconnect();
    //should get error
    frame = connV12.createFrame("SEND");
    body = "Hello World!";
    cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    frame.addHeader("destination", "aNonexistentQueue");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "application/xml");
    frame.addHeader("content-length", cLen);
    frame.addHeader("receipt", "1234");
    frame.setBody(body);
    ClientStompFrame reply = connV12.sendFrame(frame);
    Assert.assertEquals("ERROR", reply.getCommand());
}

24. StompV11Test#testNegotiation()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testNegotiation() throws Exception {
    // case 1 accept-version absent. It is a 1.0 connect
    ClientStompFrame frame = connV11.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    ClientStompFrame reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    //reply headers: version, session, server
    assertEquals(null, reply.getHeader("version"));
    connV11.disconnect();
    // case 2 accept-version=1.0, result: 1.0
    connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = connV11.createFrame("CONNECT");
    frame.addHeader("accept-version", "1.0");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    //reply headers: version, session, server
    assertEquals("1.0", reply.getHeader("version"));
    connV11.disconnect();
    // case 3 accept-version=1.1, result: 1.1
    connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = connV11.createFrame("CONNECT");
    frame.addHeader("accept-version", "1.1");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    //reply headers: version, session, server
    assertEquals("1.1", reply.getHeader("version"));
    connV11.disconnect();
    // case 4 accept-version=1.0,1.1,1.2, result 1.1
    connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = connV11.createFrame("CONNECT");
    frame.addHeader("accept-version", "1.0,1.1,1.3");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    //reply headers: version, session, server
    assertEquals("1.1", reply.getHeader("version"));
    connV11.disconnect();
    // case 5 accept-version=1.2, result error
    connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = connV11.createFrame("CONNECT");
    frame.addHeader("accept-version", "1.3");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    reply = connV11.sendFrame(frame);
    assertEquals("ERROR", reply.getCommand());
    System.out.println("Got error frame " + reply);
}

25. StompV11Test#testNack()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testNack() throws Exception {
    connV11.connect(defUser, defPass);
    subscribe(connV11, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    String messageID = frame.getHeader("message-id");
    nack(connV11, "sub1", messageID);
    unsubscribe(connV11, "sub1");
    connV11.disconnect();
    //Nack makes the message be dropped.
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}

26. StompV11Test#testAck()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testAck() throws Exception {
    connV11.connect(defUser, defPass);
    subscribe(connV11, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    String messageID = frame.getHeader("message-id");
    ack(connV11, "sub1", messageID, null);
    unsubscribe(connV11, "sub1");
    connV11.disconnect();
    //Nack makes the message be dropped.
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}

27. StompV11Test#testBodyWithUTF8()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testBodyWithUTF8() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, getName(), "auto");
    String text = "A" + "" + "" + "" + "C";
    System.out.println(text);
    sendMessage(text);
    ClientStompFrame frame = connV11.receiveFrame();
    System.out.println(frame);
    Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
    Assert.assertNotNull(frame.getHeader("destination"));
    Assert.assertTrue(frame.getBody().equals(text));
    connV11.disconnect();
}

28. StompV11Test#testDurableSubscriber()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testDurableSubscriber() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, "sub1", "client", getName());
    this.subscribe(connV11, "sub1", "client", getName());
    ClientStompFrame frame = connV11.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals("ERROR"));
    connV11.disconnect();
}

29. StompV11Test#testSubscribeWithAutoAckAndSelector()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSubscribeWithAutoAckAndSelector() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, "sub1", "auto", null, "foo = 'zzz'");
    sendMessage("Ignored message", "foo", "1234");
    sendMessage("Real message", "foo", "zzz");
    ClientStompFrame frame = connV11.receiveFrame();
    Assert.assertTrue("Should have received the real message but got: " + frame, frame.getBody().equals("Real message"));
    connV11.disconnect();
}

30. StompV11Test#testRedeliveryWithClientAck()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testRedeliveryWithClientAck() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, "subId", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    assertTrue(frame.getCommand().equals("MESSAGE"));
    connV11.disconnect();
    // message should be received since message was not acknowledged
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertTrue(message.getJMSRedelivered());
}

31. StompV11Test#testSubscribeToTopic()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSubscribeToTopic() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribeTopic(connV11, "sub1", null, null, true);
    sendMessage(getName(), topic);
    ClientStompFrame frame = connV11.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
    Assert.assertTrue(frame.getHeader("destination").equals(getTopicPrefix() + getTopicName()));
    Assert.assertTrue(frame.getBody().equals(getName()));
    this.unsubscribe(connV11, "sub1", true);
    sendMessage(getName(), topic);
    frame = connV11.receiveFrame(1000);
    assertNull(frame);
    connV11.disconnect();
}

32. StompV11Test#testSubscribeWithAutoAck()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSubscribeWithAutoAck() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, "sub1", "auto");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    Assert.assertEquals("MESSAGE", frame.getCommand());
    Assert.assertNotNull(frame.getHeader("destination"));
    Assert.assertEquals(getName(), frame.getBody());
    connV11.disconnect();
    // message should not be received as it was auto-acked
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}

33. StompV11Test#testSubscribeWithAutoAckAndBytesMessage()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSubscribeWithAutoAckAndBytesMessage() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, "sub1", "auto");
    byte[] payload = new byte[] { 1, 2, 3, 4, 5 };
    sendMessage(payload, queue);
    ClientStompFrame frame = connV11.receiveFrame();
    assertEquals("MESSAGE", frame.getCommand());
    System.out.println("Message: " + frame);
    assertEquals("5", frame.getHeader("content-length"));
    assertEquals(null, frame.getHeader("type"));
    assertEquals(frame.getBody(), new String(payload, StandardCharsets.UTF_8));
    connV11.disconnect();
}

34. StompV11Test#testSubscribeWithClientAck()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSubscribeWithClientAck() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    this.ack(connV11, "sub1", frame);
    connV11.disconnect();
    // message should not be received since message was acknowledged by the client
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}

35. StompV11Test#testSubscribeWithID()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSubscribeWithID() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, "mysubid", "auto");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    Assert.assertTrue(frame.getHeader("subscription") != null);
    connV11.disconnect();
}

36. StompV11Test#testUnsubscribe()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testUnsubscribe() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, "sub1", "auto");
    // send a message to our queue
    sendMessage("first message");
    // receive message from socket
    ClientStompFrame frame = connV11.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
    // remove suscription
    this.unsubscribe(connV11, "sub1", true);
    // send a message to our queue
    sendMessage("second message");
    frame = connV11.receiveFrame(1000);
    assertNull(frame);
    connV11.disconnect();
}

37. StompV11Test#testSendContentType()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendContentType() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, "sub1", "auto");
    MessageProducer producer = session.createProducer(queue);
    BytesMessage message = session.createBytesMessage();
    message.setStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_CONTENT_TYPE.toString(), "text/plain");
    message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
    producer.send(message);
    ClientStompFrame frame = connV11.receiveFrame();
    Assert.assertNotNull(frame);
    Assert.assertEquals("text/plain", frame.getHeader(Stomp.Headers.CONTENT_TYPE));
    connV11.disconnect();
}

38. StompV12Test#testNegotiation()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testNegotiation() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection("1.0", hostname, port);
    // case 1 accept-version absent. It is a 1.0 connect
    ClientStompFrame frame = conn.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    ClientStompFrame reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    //reply headers: version, session, server
    Assert.assertEquals(null, reply.getHeader("version"));
    conn.disconnect();
    // case 2 accept-version=1.0, result: 1.0
    conn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = conn.createFrame("CONNECT");
    frame.addHeader("accept-version", "1.0");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    //reply headers: version, session, server
    Assert.assertEquals("1.0", reply.getHeader("version"));
    conn.disconnect();
    // case 3 accept-version=1.1, result: 1.1
    conn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = conn.createFrame("CONNECT");
    frame.addHeader("accept-version", "1.1");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    //reply headers: version, session, server
    Assert.assertEquals("1.1", reply.getHeader("version"));
    conn.disconnect();
    // case 4 accept-version=1.0,1.1,1.3, result 1.2
    conn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = conn.createFrame("CONNECT");
    frame.addHeader("accept-version", "1.0,1.1,1.3");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    //reply headers: version, session, server
    Assert.assertEquals("1.1", reply.getHeader("version"));
    conn.disconnect();
    // case 5 accept-version=1.3, result error
    conn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = conn.createFrame("CONNECT");
    frame.addHeader("accept-version", "1.3");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals("ERROR", reply.getCommand());
    System.out.println("Got error frame " + reply);
}

39. StompV12Test#testNack()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testNack() throws Exception {
    connV12.connect(defUser, defPass);
    subscribe(connV12, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV12.receiveFrame();
    String messageID = frame.getHeader("message-id");
    nack(connV12, messageID);
    unsubscribe(connV12, "sub1");
    connV12.disconnect();
    //Nack makes the message be dropped.
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}

40. StompV12Test#testAck()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testAck() throws Exception {
    connV12.connect(defUser, defPass);
    subscribe(connV12, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV12.receiveFrame();
    String messageID = frame.getHeader("ack");
    Assert.assertNotNull(messageID);
    ack(connV12, messageID, null);
    unsubscribe(connV12, "sub1");
    connV12.disconnect();
    //Nack makes the message be dropped.
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}

41. StompV12Test#testBodyWithUTF8()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testBodyWithUTF8() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribe(connV12, getName(), "auto");
    String text = "A" + "" + "" + "" + "C";
    System.out.println(text);
    sendMessage(text);
    ClientStompFrame frame = connV12.receiveFrame();
    System.out.println(frame);
    Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
    Assert.assertNotNull(frame.getHeader("destination"));
    Assert.assertTrue(frame.getBody().equals(text));
    connV12.disconnect();
}

42. StompV12Test#testDurableSubscriber()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testDurableSubscriber() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribe(connV12, "sub1", "client", getName());
    this.subscribe(connV12, "sub1", "client", getName());
    ClientStompFrame frame = connV12.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals("ERROR"));
    waitDisconnect(connV12);
    Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", connV12.isConnected());
}

43. StompV12Test#testSubscribeWithAutoAckAndSelector()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSubscribeWithAutoAckAndSelector() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribe(connV12, "sub1", "auto", null, "foo = 'zzz'");
    sendMessage("Ignored message", "foo", "1234");
    sendMessage("Real message", "foo", "zzz");
    ClientStompFrame frame = connV12.receiveFrame();
    Assert.assertTrue("Should have received the real message but got: " + frame, frame.getBody().equals("Real message"));
    connV12.disconnect();
}

44. StompV12Test#testRedeliveryWithClientAck()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testRedeliveryWithClientAck() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribe(connV12, "subId", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV12.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
    connV12.disconnect();
    // message should be received since message was not acknowledged
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertTrue(message.getJMSRedelivered());
}

45. StompV12Test#testSubscribeToTopic()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSubscribeToTopic() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribeTopic(connV12, "sub1", null, null, true);
    sendMessage(getName(), topic);
    ClientStompFrame frame = connV12.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
    Assert.assertTrue(frame.getHeader("destination").equals(getTopicPrefix() + getTopicName()));
    Assert.assertTrue(frame.getBody().equals(getName()));
    this.unsubscribe(connV12, "sub1", true);
    sendMessage(getName(), topic);
    frame = connV12.receiveFrame(1000);
    Assert.assertNull(frame);
    connV12.disconnect();
}

46. StompV12Test#testSubscribeWithAutoAck()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSubscribeWithAutoAck() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribe(connV12, "sub1", "auto");
    sendMessage(getName());
    ClientStompFrame frame = connV12.receiveFrame();
    Assert.assertEquals("MESSAGE", frame.getCommand());
    Assert.assertNotNull(frame.getHeader("destination"));
    Assert.assertEquals(getName(), frame.getBody());
    connV12.disconnect();
    // message should not be received as it was auto-acked
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}

47. StompV12Test#testSubscribeWithAutoAckAndBytesMessage()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSubscribeWithAutoAckAndBytesMessage() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribe(connV12, "sub1", "auto");
    byte[] payload = new byte[] { 1, 2, 3, 4, 5 };
    sendMessage(payload, queue);
    ClientStompFrame frame = connV12.receiveFrame();
    Assert.assertEquals("MESSAGE", frame.getCommand());
    System.out.println("Message: " + frame);
    Assert.assertEquals("5", frame.getHeader("content-length"));
    Assert.assertEquals(null, frame.getHeader("type"));
    Assert.assertEquals(frame.getBody(), new String(payload, StandardCharsets.UTF_8));
    connV12.disconnect();
}

48. StompV12Test#testSubscribeWithClientAck()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSubscribeWithClientAck() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribe(connV12, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV12.receiveFrame();
    ack(connV12, frame);
    connV12.disconnect();
    // message should not be received since message was acknowledged by the client
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}

49. StompV12Test#testSubscribeWithID()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSubscribeWithID() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribe(connV12, "mysubid", "auto");
    sendMessage(getName());
    ClientStompFrame frame = connV12.receiveFrame();
    Assert.assertTrue(frame.getHeader("subscription") != null);
    connV12.disconnect();
}

50. StompV12Test#testUnsubscribe()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testUnsubscribe() throws Exception {
    connV12.connect(defUser, defPass);
    this.subscribe(connV12, "sub1", "auto");
    // send a message to our queue
    sendMessage("first message");
    // receive message from socket
    ClientStompFrame frame = connV12.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
    // remove suscription
    this.unsubscribe(connV12, "sub1", true);
    // send a message to our queue
    sendMessage("second message");
    frame = connV12.receiveFrame(1000);
    Assert.assertNull(frame);
    connV12.disconnect();
}

51. ExtraStompTest#testNoGarbageOnPersistentRedeliveryV10()

View license
@Test
public void testNoGarbageOnPersistentRedeliveryV10() throws Exception {
    ClientStompFrame frame = connV10.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", "11");
    frame.addHeader("persistent", "true");
    frame.setBody("Hello World");
    connV10.sendFrame(frame);
    frame = connV10.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", "11");
    frame.addHeader("persistent", "true");
    frame.setBody("Hello World");
    connV10.sendFrame(frame);
    ClientStompFrame subFrame = connV10.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "client");
    connV10.sendFrame(subFrame);
    // receive but don't ack
    frame = connV10.receiveFrame(10000);
    frame = connV10.receiveFrame(10000);
    System.out.println("received: " + frame);
    //unsub
    ClientStompFrame unsubFrame = connV10.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    connV10.sendFrame(unsubFrame);
    subFrame = connV10.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    connV10.sendFrame(subFrame);
    frame = connV10.receiveFrame(10000);
    frame = connV10.receiveFrame(10000);
    //second receive will get problem if trailing bytes
    assertEquals("Hello World", frame.getBody());
    System.out.println("received again: " + frame);
    //unsub
    unsubFrame = connV10.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    connV10.sendFrame(unsubFrame);
}

52. ExtraStompTest#testNoGarbageOnPersistentRedeliveryV11()

View license
@Test
public void testNoGarbageOnPersistentRedeliveryV11() throws Exception {
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", "11");
    frame.addHeader("persistent", "true");
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", "11");
    frame.addHeader("persistent", "true");
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    ClientStompFrame subFrame = connV11.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "client");
    connV11.sendFrame(subFrame);
    // receive but don't ack
    frame = connV11.receiveFrame(10000);
    frame = connV11.receiveFrame(10000);
    System.out.println("received: " + frame);
    //unsub
    ClientStompFrame unsubFrame = connV11.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    connV11.sendFrame(unsubFrame);
    subFrame = connV11.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    connV11.sendFrame(subFrame);
    frame = connV11.receiveFrame(10000);
    frame = connV11.receiveFrame(10000);
    //second receive will get problem if trailing bytes
    assertEquals("Hello World", frame.getBody());
    System.out.println("received again: " + frame);
    //unsub
    unsubFrame = connV11.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    connV11.sendFrame(unsubFrame);
}

53. StompV12Test#testHeadersPadding()

Project: activemq-artemis
Source File: StompV12Test.java
View license
//padding shouldn't be trimmed
@Test
public void testHeadersPadding() throws Exception {
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    String body = "<p>Hello World!</p>";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "application/xml");
    frame.addHeader("content-length", cLen);
    frame.addHeader(" header1", "value1 ");
    frame.addHeader("  header2", "value2   ");
    frame.addHeader("header3 ", " value3");
    frame.addHeader(" header4 ", " value4 ");
    frame.addHeader(" header 5  ", " value 5 ");
    frame.addHeader("header6", "\t value\t 6 \t");
    frame.setBody(body);
    connV12.sendFrame(frame);
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    Assert.assertEquals("MESSAGE", frame.getCommand());
    Assert.assertEquals(body, frame.getBody());
    System.out.println("received: " + frame);
    Assert.assertEquals(null, frame.getHeader("header1"));
    Assert.assertEquals("value1 ", frame.getHeader(" header1"));
    Assert.assertEquals("value2   ", frame.getHeader("  header2"));
    Assert.assertEquals(" value3", frame.getHeader("header3 "));
    Assert.assertEquals(" value4 ", frame.getHeader(" header4 "));
    Assert.assertEquals(" value 5 ", frame.getHeader(" header 5  "));
    Assert.assertEquals("\t value\t 6 \t", frame.getHeader("header6"));
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.disconnect();
}

54. ExtraStompTest#testSendAndReceive10()

View license
@Test
public void testSendAndReceive10() throws Exception {
    String msg1 = "Hello World 1!";
    String msg2 = "Hello World 2!";
    ClientStompFrame frame = connV10.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", String.valueOf(msg1.getBytes(StandardCharsets.UTF_8).length));
    frame.addHeader("persistent", "true");
    frame.setBody(msg1);
    connV10.sendFrame(frame);
    ClientStompFrame frame2 = connV10.createFrame("SEND");
    frame2.addHeader("destination", getQueuePrefix() + getQueueName());
    frame2.addHeader("content-length", String.valueOf(msg2.getBytes(StandardCharsets.UTF_8).length));
    frame2.addHeader("persistent", "true");
    frame2.setBody(msg2);
    connV10.sendFrame(frame2);
    ClientStompFrame subFrame = connV10.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    connV10.sendFrame(subFrame);
    frame = connV10.receiveFrame();
    System.out.println("received " + frame);
    assertEquals("MESSAGE", frame.getCommand());
    assertEquals("a-sub", frame.getHeader("subscription"));
    assertNotNull(frame.getHeader("message-id"));
    assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader("destination"));
    assertEquals(msg1, frame.getBody());
    frame = connV10.receiveFrame();
    System.out.println("received " + frame);
    assertEquals("MESSAGE", frame.getCommand());
    assertEquals("a-sub", frame.getHeader("subscription"));
    assertNotNull(frame.getHeader("message-id"));
    assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader("destination"));
    assertEquals(msg2, frame.getBody());
    //unsub
    ClientStompFrame unsubFrame = connV10.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    connV10.sendFrame(unsubFrame);
}

55. ExtraStompTest#testSendAndReceive11()

View license
@Test
public void testSendAndReceive11() throws Exception {
    String msg1 = "Hello World 1!";
    String msg2 = "Hello World 2!";
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", String.valueOf(msg1.getBytes(StandardCharsets.UTF_8).length));
    frame.addHeader("persistent", "true");
    frame.setBody(msg1);
    connV11.sendFrame(frame);
    ClientStompFrame frame2 = connV11.createFrame("SEND");
    frame2.addHeader("destination", getQueuePrefix() + getQueueName());
    frame2.addHeader("content-length", String.valueOf(msg2.getBytes(StandardCharsets.UTF_8).length));
    frame2.addHeader("persistent", "true");
    frame2.setBody(msg2);
    connV11.sendFrame(frame2);
    ClientStompFrame subFrame = connV11.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    connV11.sendFrame(subFrame);
    frame = connV11.receiveFrame();
    System.out.println("received " + frame);
    assertEquals("MESSAGE", frame.getCommand());
    assertEquals("a-sub", frame.getHeader("subscription"));
    assertNotNull(frame.getHeader("message-id"));
    assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader("destination"));
    assertEquals(msg1, frame.getBody());
    frame = connV11.receiveFrame();
    System.out.println("received " + frame);
    assertEquals("MESSAGE", frame.getCommand());
    assertEquals("a-sub", frame.getHeader("subscription"));
    assertNotNull(frame.getHeader("message-id"));
    assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader("destination"));
    assertEquals(msg2, frame.getBody());
    //unsub
    ClientStompFrame unsubFrame = connV11.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    connV11.sendFrame(unsubFrame);
}

56. ExtraStompTest#testNoGarbageAfterPersistentMessageV10()

View license
@Test
public void testNoGarbageAfterPersistentMessageV10() throws Exception {
    ClientStompFrame subFrame = connV10.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    connV10.sendFrame(subFrame);
    ClientStompFrame frame = connV10.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", "11");
    frame.addHeader("persistent", "true");
    frame.setBody("Hello World");
    connV10.sendFrame(frame);
    frame = connV10.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", "11");
    frame.addHeader("persistent", "true");
    frame.setBody("Hello World");
    connV10.sendFrame(frame);
    frame = connV10.receiveFrame(10000);
    System.out.println("received: " + frame);
    assertEquals("Hello World", frame.getBody());
    //if activemq sends trailing garbage bytes, the second message
    //will not be normal
    frame = connV10.receiveFrame(10000);
    System.out.println("received: " + frame);
    assertEquals("Hello World", frame.getBody());
    //unsub
    ClientStompFrame unsubFrame = connV10.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    connV10.sendFrame(unsubFrame);
}

57. ExtraStompTest#testNoGarbageAfterPersistentMessageV11()

View license
@Test
public void testNoGarbageAfterPersistentMessageV11() throws Exception {
    ClientStompFrame subFrame = connV11.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    connV11.sendFrame(subFrame);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", "11");
    frame.addHeader("persistent", "true");
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-length", "11");
    frame.addHeader("persistent", "true");
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    frame = connV11.receiveFrame(10000);
    System.out.println("received: " + frame);
    assertEquals("Hello World", frame.getBody());
    //if activemq sends trailing garbage bytes, the second message
    //will not be normal
    frame = connV11.receiveFrame(10000);
    System.out.println("received: " + frame);
    assertEquals("Hello World", frame.getBody());
    //unsub
    ClientStompFrame unsubFrame = connV11.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    connV11.sendFrame(unsubFrame);
}

58. StompV11Test#testHeartBeat2()

Project: activemq-artemis
Source File: StompV11Test.java
View license
//server ping
@Test
public void testHeartBeat2() throws Exception {
    //heart-beat (1,1)
    ClientStompFrame frame = connV11.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "1,1");
    frame.addHeader("accept-version", "1.0,1.1");
    ClientStompFrame reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    assertEquals("500,500", reply.getHeader("heart-beat"));
    connV11.disconnect();
    //heart-beat (500,1000)
    connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    frame = connV11.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "500,1000");
    frame.addHeader("accept-version", "1.0,1.1");
    reply = connV11.sendFrame(frame);
    assertEquals("CONNECTED", reply.getCommand());
    assertEquals("1000,500", reply.getHeader("heart-beat"));
    System.out.println("========== start pinger!");
    connV11.startPinger(500);
    Thread.sleep(10000);
    //now check the frame size
    int size = connV11.getServerPingNumber();
    System.out.println("ping received: " + size);
    assertTrue(size > 5);
    //now server side should be disconnected because we didn't send ping for 2 sec
    frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World");
    //send will be ok
    connV11.sendFrame(frame);
    connV11.disconnect();
}

59. StompV12Test#testHeartBeat2()

Project: activemq-artemis
Source File: StompV12Test.java
View license
//server ping
@Test
public void testHeartBeat2() throws Exception {
    //heart-beat (1,1)
    ClientStompFrame frame = connV12.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "1,1");
    frame.addHeader("accept-version", "1.0,1.1,1.2");
    ClientStompFrame reply = connV12.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    Assert.assertEquals("500,500", reply.getHeader("heart-beat"));
    connV12.disconnect();
    //heart-beat (500,1000)
    connV12 = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    frame = connV12.createFrame("CONNECT");
    frame.addHeader("host", "127.0.0.1");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("heart-beat", "500,1000");
    frame.addHeader("accept-version", "1.0,1.1,1.2");
    reply = connV12.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    Assert.assertEquals("1000,500", reply.getHeader("heart-beat"));
    connV12.startPinger(500);
    Thread.sleep(10000);
    //now check the frame size
    int size = connV12.getServerPingNumber();
    System.out.println("ping received: " + size);
    Assert.assertTrue("size: " + size, size > 5);
    //now server side should be disconnected because we didn't send ping for 2 sec
    frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World");
    //send will be ok
    connV12.sendFrame(frame);
    connV12.disconnect();
}

60. StompV12Test#testHeaderContentLength()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testHeaderContentLength() throws Exception {
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    String body = "Hello World 1!";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "application/xml");
    frame.addHeader("content-length", cLen);
    frame.setBody(body + "extra");
    connV12.sendFrame(frame);
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    Assert.assertEquals("MESSAGE", frame.getCommand());
    Assert.assertEquals(body, frame.getBody());
    Assert.assertEquals(cLen, frame.getHeader("content-length"));
    //send again without content-length header
    frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "application/xml");
    frame.setBody(body + "extra");
    connV12.sendFrame(frame);
    //receive again. extra should received.
    frame = newConn.receiveFrame();
    Assert.assertEquals(body + "extra", frame.getBody());
    //although sender didn't send the content-length header,
    //the server should add it anyway
    Assert.assertEquals((body + "extra").getBytes(StandardCharsets.UTF_8).length, Integer.valueOf(frame.getHeader("content-length")).intValue());
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.disconnect();
}

61. StompV11Test#testSendAndReceive()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendAndReceive() throws Exception {
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World 1!");
    ClientStompFrame response = connV11.sendFrame(frame);
    assertNull(response);
    frame.addHeader("receipt", "1234");
    frame.setBody("Hello World 2!");
    response = connV11.sendFrame(frame);
    assertNotNull(response);
    assertEquals("RECEIPT", response.getCommand());
    assertEquals("1234", response.getHeader("receipt-id"));
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    assertEquals("MESSAGE", frame.getCommand());
    assertEquals("a-sub", frame.getHeader("subscription"));
    assertNotNull(frame.getHeader("message-id"));
    assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader("destination"));
    assertEquals("Hello World 1!", frame.getBody());
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.sendFrame(unsubFrame);
    newConn.disconnect();
}

62. StompV12Test#testSendAndReceive()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendAndReceive() throws Exception {
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World 1!");
    ClientStompFrame response = connV12.sendFrame(frame);
    Assert.assertNull(response);
    frame.addHeader("receipt", "1234");
    frame.setBody("Hello World 2!");
    response = connV12.sendFrame(frame);
    Assert.assertNotNull(response);
    Assert.assertEquals("RECEIPT", response.getCommand());
    Assert.assertEquals("1234", response.getHeader("receipt-id"));
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    Assert.assertEquals("MESSAGE", frame.getCommand());
    Assert.assertEquals("a-sub", frame.getHeader("subscription"));
    //'auto' ack mode doesn't require 'ack' header
    Assert.assertNull(frame.getHeader("ack"));
    Assert.assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader("destination"));
    Assert.assertEquals("Hello World 1!", frame.getBody());
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.sendFrame(unsubFrame);
    newConn.disconnect();
}

63. StompV11Test#testHeaderEncoding()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testHeaderEncoding() throws Exception {
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    String body = "Hello World 1!";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "application/xml");
    frame.addHeader("content-length", cLen);
    String hKey = "special-header\\\\\\n\\c";
    String hVal = "\\c\\\\\\ngood";
    frame.addHeader(hKey, hVal);
    System.out.println("key: |" + hKey + "| val: |" + hVal + "|");
    frame.setBody(body);
    connV11.sendFrame(frame);
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    assertEquals("MESSAGE", frame.getCommand());
    String value = frame.getHeader("special-header" + "\\" + "\n" + ":");
    assertEquals(":" + "\\" + "\n" + "good", value);
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.disconnect();
}

64. StompV12Test#testHeaderEncoding()

Project: activemq-artemis
Source File: StompV12Test.java
View license
/**
    * Since 1.2 the CR ('\r') needs to be escaped.
    */
@Test
public void testHeaderEncoding() throws Exception {
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    String body = "Hello World 1!";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "application/xml");
    frame.addHeader("content-length", cLen);
    String hKey = "\\rspecial-header\\\\\\n\\c\\r\\n";
    String hVal = "\\c\\\\\\ngood\\n\\r";
    frame.addHeader(hKey, hVal);
    System.out.println("key: |" + hKey + "| val: |" + hVal + "|");
    frame.setBody(body);
    connV12.sendFrame(frame);
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    Assert.assertEquals("MESSAGE", frame.getCommand());
    String value = frame.getHeader("\r" + "special-header" + "\\" + "\n" + ":" + "\r\n");
    Assert.assertEquals(":" + "\\" + "\n" + "good\n\r", value);
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.disconnect();
}

65. StompV11Test#testHeaderContentLength()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testHeaderContentLength() throws Exception {
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    String body = "Hello World 1!";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "application/xml");
    frame.addHeader("content-length", cLen);
    frame.setBody(body + "extra");
    connV11.sendFrame(frame);
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    assertEquals("MESSAGE", frame.getCommand());
    assertEquals(cLen, frame.getHeader("content-length"));
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.disconnect();
}

66. StompV11Test#testSendAndReceiveWithEscapedCharactersInSenderId()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendAndReceiveWithEscapedCharactersInSenderId() throws Exception {
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World 1!");
    ClientStompFrame response = connV11.sendFrame(frame);
    assertNull(response);
    //subscribe
    ClientStompFrame subFrame = connV11.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "ID\\cMYMACHINE-50616-635482262727823605-1\\c1\\c1\\c1");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    connV11.sendFrame(subFrame);
    frame = connV11.receiveFrame();
    System.out.println("Received: " + frame);
    assertEquals("MESSAGE", frame.getCommand());
    assertEquals("ID:MYMACHINE-50616-635482262727823605-1:1:1:1", frame.getHeader("subscription"));
    assertNotNull(frame.getHeader("message-id"));
    assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader("destination"));
    assertEquals("Hello World 1!", frame.getBody());
    //unsub
    ClientStompFrame unsubFrame = connV11.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "ID\\cMYMACHINE-50616-635482262727823605-1\\c1\\c1\\c1");
    connV11.sendFrame(unsubFrame);
    connV11.disconnect();
}

67. StompV12Test#testSendAndReceiveWithEscapedCharactersInSenderId()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendAndReceiveWithEscapedCharactersInSenderId() throws Exception {
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    frame.setBody("Hello World 1!");
    ClientStompFrame response = connV12.sendFrame(frame);
    Assert.assertNull(response);
    //subscribe
    ClientStompFrame subFrame = connV12.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "ID\\cMYMACHINE-50616-635482262727823605-1\\c1\\c1\\c1");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    connV12.sendFrame(subFrame);
    frame = connV12.receiveFrame();
    System.out.println("Received: " + frame);
    Assert.assertEquals("MESSAGE", frame.getCommand());
    Assert.assertEquals("ID:MYMACHINE-50616-635482262727823605-1:1:1:1", frame.getHeader("subscription"));
    Assert.assertNotNull(frame.getHeader("message-id"));
    Assert.assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader("destination"));
    Assert.assertEquals("Hello World 1!", frame.getBody());
    //unsub
    ClientStompFrame unsubFrame = connV12.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "ID\\cMYMACHINE-50616-635482262727823605-1\\c1\\c1\\c1");
    connV12.sendFrame(unsubFrame);
    connV12.disconnect();
}

68. StompV11Test#testHeaderContentType()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testHeaderContentType() throws Exception {
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "application/xml");
    frame.setBody("Hello World 1!");
    connV11.sendFrame(frame);
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    assertEquals("MESSAGE", frame.getCommand());
    assertEquals("application/xml", frame.getHeader("content-type"));
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.disconnect();
}

69. StompV11Test#testSendMessageWithStandardHeaders()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendMessageWithStandardHeaders() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("correlation-id", "c123");
    frame.addHeader("persistent", "true");
    frame.addHeader("priority", "3");
    frame.addHeader("type", "t345");
    frame.addHeader("JMSXGroupID", "abc");
    frame.addHeader("foo", "abc");
    frame.addHeader("bar", "123");
    frame.setBody("Hello World");
    frame = connV11.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("bar", "123", message.getStringProperty("bar"));
    Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
    connV11.disconnect();
}

70. StompV11Test#testSendMessageWithLongHeaders()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendMessageWithLongHeaders() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 2048; i++) {
        buffer.append("a");
    }
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("correlation-id", "c123");
    frame.addHeader("persistent", "true");
    frame.addHeader("priority", "3");
    frame.addHeader("type", "t345");
    frame.addHeader("JMSXGroupID", "abc");
    frame.addHeader("foo", "abc");
    frame.addHeader("longHeader", buffer.toString());
    frame.setBody("Hello World");
    frame = connV11.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("longHeader", 2048, message.getStringProperty("longHeader").length());
    Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
    connV11.disconnect();
}

71. StompV12Test#testConnectionAsInSpec()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testConnectionAsInSpec() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection("1.0", hostname, port);
    ClientStompFrame frame = conn.createFrame("CONNECT");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("accept-version", "1.2");
    frame.addHeader("host", "127.0.0.1");
    ClientStompFrame reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    Assert.assertEquals("1.2", reply.getHeader("version"));
    conn.disconnect();
    //need 1.2 client
    conn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
    frame = conn.createFrame("STOMP");
    frame.addHeader("login", this.defUser);
    frame.addHeader("passcode", this.defPass);
    frame.addHeader("accept-version", "1.2");
    frame.addHeader("host", "127.0.0.1");
    reply = conn.sendFrame(frame);
    Assert.assertEquals("CONNECTED", reply.getCommand());
    Assert.assertEquals("1.2", reply.getHeader("version"));
    conn.disconnect();
}

72. StompV12Test#testHeaderContentType()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testHeaderContentType() throws Exception {
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "application/xml");
    frame.setBody("Hello World 1!");
    connV12.sendFrame(frame);
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    newConn.connect(defUser, defPass);
    ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", "a-sub");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    newConn.sendFrame(subFrame);
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    Assert.assertEquals("MESSAGE", frame.getCommand());
    Assert.assertEquals("application/xml", frame.getHeader("content-type"));
    //unsub
    ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
    unsubFrame.addHeader("id", "a-sub");
    newConn.disconnect();
}

73. StompV12Test#testSendMessageWithStandardHeaders()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendMessageWithStandardHeaders() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("correlation-id", "c123");
    frame.addHeader("persistent", "true");
    frame.addHeader("priority", "3");
    frame.addHeader("type", "t345");
    frame.addHeader("JMSXGroupID", "abc");
    frame.addHeader("foo", "abc");
    frame.addHeader("bar", "123");
    frame.setBody("Hello World");
    frame = connV12.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("bar", "123", message.getStringProperty("bar"));
    Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
    connV12.disconnect();
}

74. StompV12Test#testSendMessageWithLongHeaders()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendMessageWithLongHeaders() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV12.connect(defUser, defPass);
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 2048; i++) {
        buffer.append("a");
    }
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("correlation-id", "c123");
    frame.addHeader("persistent", "true");
    frame.addHeader("priority", "3");
    frame.addHeader("type", "t345");
    frame.addHeader("JMSXGroupID", "abc");
    frame.addHeader("foo", "abc");
    frame.addHeader("very-very-long-stomp-message-header", buffer.toString());
    frame.setBody("Hello World");
    frame = connV12.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("very-very-long-stomp-message-header", 2048, message.getStringProperty("very-very-long-stomp-message-header").length());
    Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
    connV12.disconnect();
}

75. StompV11Test#testSuccessiveTransactionsWithSameID()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSuccessiveTransactionsWithSameID() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    // first tx
    this.beginTransaction(connV11, "tx1");
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    this.commitTransaction(connV11, "tx1");
    Message message = consumer.receive(1000);
    Assert.assertNotNull("Should have received a message", message);
    // 2nd tx with same tx ID
    this.beginTransaction(connV11, "tx1");
    frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    this.commitTransaction(connV11, "tx1");
    message = consumer.receive(1000);
    Assert.assertNotNull("Should have received a message", message);
    connV11.disconnect();
}

76. StompV11Test#testTransactionRollback()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testTransactionRollback() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    this.beginTransaction(connV11, "tx1");
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.setBody("first message");
    connV11.sendFrame(frame);
    // rollback first message
    this.abortTransaction(connV11, "tx1");
    this.beginTransaction(connV11, "tx1");
    frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.setBody("second message");
    connV11.sendFrame(frame);
    this.commitTransaction(connV11, "tx1", true);
    // only second msg should be received since first msg was rolled back
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("second message", message.getText());
    connV11.disconnect();
}

77. StompV12Test#testSuccessiveTransactionsWithSameID()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSuccessiveTransactionsWithSameID() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV12.connect(defUser, defPass);
    // first tx
    this.beginTransaction(connV12, "tx1");
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.setBody("Hello World");
    connV12.sendFrame(frame);
    this.commitTransaction(connV12, "tx1");
    Message message = consumer.receive(1000);
    Assert.assertNotNull("Should have received a message", message);
    // 2nd tx with same tx ID
    this.beginTransaction(connV12, "tx1");
    frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.setBody("Hello World");
    connV12.sendFrame(frame);
    this.commitTransaction(connV12, "tx1");
    message = consumer.receive(1000);
    Assert.assertNotNull("Should have received a message", message);
    connV12.disconnect();
}

78. StompV12Test#testTransactionRollback()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testTransactionRollback() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV12.connect(defUser, defPass);
    this.beginTransaction(connV12, "tx1");
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.setBody("first message");
    connV12.sendFrame(frame);
    // rollback first message
    this.abortTransaction(connV12, "tx1");
    this.beginTransaction(connV12, "tx1");
    frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.setBody("second message");
    connV12.sendFrame(frame);
    this.commitTransaction(connV12, "tx1", true);
    // only second msg should be received since first msg was rolled back
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("second message", message.getText());
    connV12.disconnect();
}

79. StompV11Test#testErrorWithReceipt()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testErrorWithReceipt() throws Exception {
    connV11.connect(defUser, defPass);
    subscribe(connV11, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    String messageID = frame.getHeader("message-id");
    ClientStompFrame ackFrame = connV11.createFrame("ACK");
    //give it a wrong sub id
    ackFrame.addHeader("subscription", "sub2");
    ackFrame.addHeader("message-id", messageID);
    ackFrame.addHeader("receipt", "answer-me");
    ClientStompFrame error = connV11.sendFrame(ackFrame);
    System.out.println("Receiver error: " + error);
    assertEquals("ERROR", error.getCommand());
    assertEquals("answer-me", error.getHeader("receipt-id"));
    unsubscribe(connV11, "sub1");
    connV11.disconnect();
    //message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
}

80. StompV11Test#testErrorWithReceipt2()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testErrorWithReceipt2() throws Exception {
    connV11.connect(defUser, defPass);
    subscribe(connV11, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    String messageID = frame.getHeader("message-id");
    ClientStompFrame ackFrame = connV11.createFrame("ACK");
    //give it a wrong sub id
    ackFrame.addHeader("subscription", "sub1");
    ackFrame.addHeader("message-id", String.valueOf(Long.valueOf(messageID) + 1));
    ackFrame.addHeader("receipt", "answer-me");
    ClientStompFrame error = connV11.sendFrame(ackFrame);
    System.out.println("Receiver error: " + error);
    assertEquals("ERROR", error.getCommand());
    assertEquals("answer-me", error.getHeader("receipt-id"));
    unsubscribe(connV11, "sub1");
    connV11.disconnect();
    //message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
}

81. StompV12Test#testErrorWithReceipt()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testErrorWithReceipt() throws Exception {
    connV12.connect(defUser, defPass);
    subscribe(connV12, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV12.receiveFrame();
    String messageID = frame.getHeader("message-id");
    ClientStompFrame ackFrame = connV12.createFrame("ACK");
    //give it a wrong sub id
    ackFrame.addHeader("subscription", "sub2");
    ackFrame.addHeader("message-id", messageID);
    ackFrame.addHeader("receipt", "answer-me");
    ClientStompFrame error = connV12.sendFrame(ackFrame);
    System.out.println("Receiver error: " + error);
    Assert.assertEquals("ERROR", error.getCommand());
    Assert.assertEquals("answer-me", error.getHeader("receipt-id"));
    waitDisconnect(connV12);
    Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", connV12.isConnected());
    //message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
}

82. StompV12Test#testErrorWithReceipt2()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testErrorWithReceipt2() throws Exception {
    connV12.connect(defUser, defPass);
    subscribe(connV12, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV12.receiveFrame();
    String messageID = frame.getHeader("message-id");
    ClientStompFrame ackFrame = connV12.createFrame("ACK");
    //give it a wrong sub id
    ackFrame.addHeader("subscription", "sub1");
    ackFrame.addHeader("message-id", String.valueOf(Long.valueOf(messageID) + 1));
    ackFrame.addHeader("receipt", "answer-me");
    ClientStompFrame error = connV12.sendFrame(ackFrame);
    System.out.println("Receiver error: " + error);
    Assert.assertEquals("ERROR", error.getCommand());
    Assert.assertEquals("answer-me", error.getHeader("receipt-id"));
    waitDisconnect(connV12);
    Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", connV12.isConnected());
    //message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
}

83. StompV11Test#testTransactionCommit()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testTransactionCommit() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    this.beginTransaction(connV11, "tx1");
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.addHeader("receipt", "123");
    frame.setBody("Hello World");
    frame = connV11.sendFrame(frame);
    assertEquals("123", frame.getHeader("receipt-id"));
    // check the message is not committed
    assertNull(consumer.receive(100));
    this.commitTransaction(connV11, "tx1", true);
    Message message = consumer.receive(1000);
    Assert.assertNotNull("Should have received a message", message);
    connV11.disconnect();
}

84. StompV12Test#testTransactionCommit()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testTransactionCommit() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV12.connect(defUser, defPass);
    this.beginTransaction(connV12, "tx1");
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("transaction", "tx1");
    frame.addHeader("receipt", "123");
    frame.setBody("Hello World");
    frame = connV12.sendFrame(frame);
    Assert.assertEquals("123", frame.getHeader("receipt-id"));
    // check the message is not committed
    Assert.assertNull(consumer.receive(100));
    this.commitTransaction(connV12, "tx1", true);
    Message message = consumer.receive(1000);
    Assert.assertNotNull("Should have received a message", message);
    connV12.disconnect();
}

85. StompV11Test#testSendMessageWithContentLength()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendMessageWithContentLength() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    byte[] data = new byte[] { 1, 0, 0, 4 };
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody(new String(data, StandardCharsets.UTF_8));
    frame.addHeader("content-length", String.valueOf(data.length));
    connV11.sendFrame(frame);
    BytesMessage message = (BytesMessage) consumer.receive(10000);
    Assert.assertNotNull(message);
    assertEquals(data.length, message.getBodyLength());
    assertEquals(data[0], message.readByte());
    assertEquals(data[1], message.readByte());
    assertEquals(data[2], message.readByte());
    assertEquals(data[3], message.readByte());
}

86. StompV11Test#testSendMessageWithReceipt()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendMessageWithReceipt() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("receipt", "1234");
    frame.setBody("Hello World");
    frame = connV11.sendFrame(frame);
    assertTrue(frame.getCommand().equals("RECEIPT"));
    assertEquals("1234", frame.getHeader("receipt-id"));
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    // Make sure that the timestamp is valid - should
    // be very close to the current time.
    long tnow = System.currentTimeMillis();
    long tmsg = message.getJMSTimestamp();
    Assert.assertTrue(Math.abs(tnow - tmsg) < 1000);
    connV11.disconnect();
}

87. StompV11Test#subscribeTopic()

Project: activemq-artemis
Source File: StompV11Test.java
View license
private void subscribeTopic(StompClientConnection conn, String subId, String ack, String durableId, boolean receipt, boolean noLocal) throws IOException, InterruptedException {
    ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", subId);
    subFrame.addHeader("destination", getTopicPrefix() + getTopicName());
    if (ack != null) {
        subFrame.addHeader("ack", ack);
    }
    if (durableId != null) {
        subFrame.addHeader("durable-subscriber-name", durableId);
    }
    if (receipt) {
        subFrame.addHeader("receipt", "1234");
    }
    if (noLocal) {
        subFrame.addHeader("no-local", "true");
    }
    ClientStompFrame frame = conn.sendFrame(subFrame);
    if (receipt) {
        assertTrue(frame.getHeader("receipt-id").equals("1234"));
    }
}

88. StompV12Test#testSendMessageWithContentLength()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendMessageWithContentLength() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV12.connect(defUser, defPass);
    byte[] data = new byte[] { 1, 0, 0, 4 };
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody(new String(data, StandardCharsets.UTF_8));
    frame.addHeader("content-length", String.valueOf(data.length));
    connV12.sendFrame(frame);
    BytesMessage message = (BytesMessage) consumer.receive(10000);
    Assert.assertNotNull(message);
    Assert.assertEquals(data.length, message.getBodyLength());
    Assert.assertEquals(data[0], message.readByte());
    Assert.assertEquals(data[1], message.readByte());
    Assert.assertEquals(data[2], message.readByte());
    Assert.assertEquals(data[3], message.readByte());
}

89. StompV12Test#testSendMessageWithReceipt()

Project: activemq-artemis
Source File: StompV12Test.java
View license
@Test
public void testSendMessageWithReceipt() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV12.connect(defUser, defPass);
    ClientStompFrame frame = connV12.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("receipt", "1234");
    frame.setBody("Hello World");
    frame = connV12.sendFrame(frame);
    Assert.assertTrue(frame.getCommand().equals("RECEIPT"));
    Assert.assertEquals("1234", frame.getHeader("receipt-id"));
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    // Make sure that the timestamp is valid - should
    // be very close to the current time.
    long tnow = System.currentTimeMillis();
    long tmsg = message.getJMSTimestamp();
    Assert.assertTrue(Math.abs(tnow - tmsg) < 1000);
    connV12.disconnect();
}

90. StompV12Test#subscribeTopic()

Project: activemq-artemis
Source File: StompV12Test.java
View license
private void subscribeTopic(StompClientConnection conn, String subId, String ack, String durableId, boolean receipt, boolean noLocal) throws IOException, InterruptedException {
    ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
    subFrame.addHeader("id", subId);
    subFrame.addHeader("destination", getTopicPrefix() + getTopicName());
    if (ack != null) {
        subFrame.addHeader("ack", ack);
    }
    if (durableId != null) {
        subFrame.addHeader("durable-subscriber-name", durableId);
    }
    if (receipt) {
        subFrame.addHeader("receipt", "1234");
    }
    if (noLocal) {
        subFrame.addHeader("no-local", "true");
    }
    ClientStompFrame frame = conn.sendFrame(subFrame);
    if (receipt) {
        Assert.assertTrue(frame.getHeader("receipt-id").equals("1234"));
    }
}

91. StompV11Test#testSendAndReceiveWithHeartBeats()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendAndReceiveWithHeartBeats() throws Exception {
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.addHeader("content-type", "text/plain");
    for (int i = 0; i < 10; i++) {
        frame.setBody("Hello World " + i + "!");
        connV11.sendFrame(frame);
        Thread.sleep(500);
    }
    //subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    try {
        frame = newConn.createFrame("CONNECT");
        frame.addHeader("host", "127.0.0.1");
        frame.addHeader("login", this.defUser);
        frame.addHeader("passcode", this.defPass);
        frame.addHeader("heart-beat", "500,1000");
        frame.addHeader("accept-version", "1.0,1.1");
        newConn.sendFrame(frame);
        newConn.startPinger(500);
        Thread.sleep(500);
        ClientStompFrame subFrame = newConn.createFrame("SUBSCRIBE");
        subFrame.addHeader("id", "a-sub");
        subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
        subFrame.addHeader("ack", "auto");
        newConn.sendFrame(subFrame);
        int cnt = 0;
        frame = newConn.receiveFrame();
        while (frame != null) {
            cnt++;
            Thread.sleep(500);
            frame = newConn.receiveFrame(5000);
        }
        assertEquals(10, cnt);
        // unsub
        ClientStompFrame unsubFrame = newConn.createFrame("UNSUBSCRIBE");
        unsubFrame.addHeader("id", "a-sub");
        newConn.sendFrame(unsubFrame);
    } finally {
        newConn.disconnect();
    }
}

92. StompV11Test#testNackWithWrongMessageId()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testNackWithWrongMessageId() throws Exception {
    connV11.connect(defUser, defPass);
    subscribe(connV11, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    frame.getHeader("message-id");
    nack(connV11, "sub2", "someother");
    ClientStompFrame error = connV11.receiveFrame();
    System.out.println("Receiver error: " + error);
    unsubscribe(connV11, "sub1");
    connV11.disconnect();
    //message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
}

93. StompV11Test#testAckWithWrongMessageId()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testAckWithWrongMessageId() throws Exception {
    connV11.connect(defUser, defPass);
    subscribe(connV11, "sub1", "client");
    sendMessage(getName());
    ClientStompFrame frame = connV11.receiveFrame();
    frame.getHeader("message-id");
    ack(connV11, "sub2", "someother", null);
    ClientStompFrame error = connV11.receiveFrame();
    System.out.println("Receiver error: " + error);
    unsubscribe(connV11, "sub1");
    connV11.disconnect();
    //message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
}

94. StompV11Test#testTwoSubscribers()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testTwoSubscribers() throws Exception {
    connV11.connect(defUser, defPass, "myclientid");
    this.subscribeTopic(connV11, "sub1", "auto", null);
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    newConn.connect(defUser, defPass, "myclientid2");
    this.subscribeTopic(newConn, "sub2", "auto", null);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getTopicPrefix() + getTopicName());
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    // receive message from socket
    frame = connV11.receiveFrame(1000);
    System.out.println("received frame : " + frame);
    assertEquals("Hello World", frame.getBody());
    assertEquals("sub1", frame.getHeader("subscription"));
    frame = newConn.receiveFrame(1000);
    System.out.println("received 2 frame : " + frame);
    assertEquals("Hello World", frame.getBody());
    assertEquals("sub2", frame.getHeader("subscription"));
    // remove suscription
    this.unsubscribe(connV11, "sub1", true);
    this.unsubscribe(newConn, "sub2", true);
    connV11.disconnect();
    newConn.disconnect();
}

95. StompV11Test#testDisconnectAndError()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testDisconnectAndError() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribe(connV11, getName(), "client");
    ClientStompFrame frame = connV11.createFrame("DISCONNECT");
    frame.addHeader("receipt", "1");
    ClientStompFrame result = connV11.sendFrame(frame);
    if (result == null || (!"RECEIPT".equals(result.getCommand())) || (!"1".equals(result.getHeader("receipt-id")))) {
        fail("Disconnect failed! " + result);
    }
    final CountDownLatch latch = new CountDownLatch(1);
    Thread thr = new Thread() {

        @Override
        public void run() {
            ClientStompFrame sendFrame = connV11.createFrame("SEND");
            sendFrame.addHeader("destination", getQueuePrefix() + getQueueName());
            sendFrame.setBody("Hello World");
            while (latch.getCount() != 0) {
                try {
                    connV11.sendFrame(sendFrame);
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                } catch (ClosedChannelException e) {
                    latch.countDown();
                    break;
                } catch (IOException e) {
                    latch.countDown();
                    break;
                } finally {
                    connV11.destroy();
                }
            }
        }
    };
    thr.start();
    latch.await(10, TimeUnit.SECONDS);
    long count = latch.getCount();
    if (count != 0) {
        latch.countDown();
    }
    thr.join();
    assertTrue("Server failed to disconnect.", count == 0);
}

96. StompV11Test#testDurableSubscriberWithReconnection()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testDurableSubscriberWithReconnection() throws Exception {
    connV11.connect(defUser, defPass, "myclientid");
    this.subscribeTopic(connV11, "sub1", "auto", getName());
    ClientStompFrame frame = connV11.createFrame("DISCONNECT");
    frame.addHeader("receipt", "1");
    ClientStompFrame result = connV11.sendFrame(frame);
    if (result == null || (!"RECEIPT".equals(result.getCommand())) || (!"1".equals(result.getHeader("receipt-id")))) {
        fail("Disconnect failed! " + result);
    }
    // send the message when the durable subscriber is disconnected
    sendMessage(getName(), topic);
    connV11.destroy();
    connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
    connV11.connect(defUser, defPass, "myclientid");
    this.subscribeTopic(connV11, "sub1", "auto", getName());
    // we must have received the message
    frame = connV11.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
    Assert.assertNotNull(frame.getHeader("destination"));
    Assert.assertEquals(getName(), frame.getBody());
    this.unsubscribe(connV11, "sub1");
    connV11.disconnect();
}

97. StompV11Test#testSendManyMessages()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendManyMessages() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    int count = 1000;
    final CountDownLatch latch = new CountDownLatch(count);
    consumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message arg0) {
            latch.countDown();
        }
    });
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World");
    for (int i = 1; i <= count; i++) {
        connV11.sendFrame(frame);
    }
    assertTrue(latch.await(60, TimeUnit.SECONDS));
    connV11.disconnect();
}

98. StompV11Test#testSendMessageWithLeadingNewLine()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSendMessageWithLeadingNewLine() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    connV11.connect(defUser, defPass);
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World");
    connV11.sendWickedFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    // Make sure that the timestamp is valid - should
    // be very close to the current time.
    long tnow = System.currentTimeMillis();
    long tmsg = message.getJMSTimestamp();
    Assert.assertTrue(Math.abs(tnow - tmsg) < 1000);
    assertNull(consumer.receive(1000));
    connV11.disconnect();
}

99. StompV11Test#testSubscribeToTopicWithNoLocal()

Project: activemq-artemis
Source File: StompV11Test.java
View license
@Test
public void testSubscribeToTopicWithNoLocal() throws Exception {
    connV11.connect(defUser, defPass);
    this.subscribeTopic(connV11, "sub1", null, null, true, true);
    // send a message on the same connection => it should not be received
    ClientStompFrame frame = connV11.createFrame("SEND");
    frame.addHeader("destination", getTopicPrefix() + getTopicName());
    frame.setBody("Hello World");
    connV11.sendFrame(frame);
    frame = connV11.receiveFrame(2000);
    assertNull(frame);
    // send message on another JMS connection => it should be received
    sendMessage(getName(), topic);
    frame = connV11.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
    Assert.assertTrue(frame.getHeader("destination").equals(getTopicPrefix() + getTopicName()));
    Assert.assertTrue(frame.getBody().equals(getName()));
    this.unsubscribe(connV11, "sub1");
    connV11.disconnect();
}

100. StompV11Test#nack()

Project: activemq-artemis
Source File: StompV11Test.java
View license
private void nack(StompClientConnection conn, String subId, String mid) throws IOException, InterruptedException {
    ClientStompFrame ackFrame = conn.createFrame("NACK");
    ackFrame.addHeader("subscription", subId);
    ackFrame.addHeader("message-id", mid);
    conn.sendFrame(ackFrame);
}