Search in sources :

Example 11 with StompClientConnection

use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.

the class StompV12Test method testHeartBeat.

@Test
public void testHeartBeat() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    // no heart beat at all if heat-beat absent
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    ClientStompFrame reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    Thread.sleep(5000);
    Assert.assertEquals(0, conn.getFrameQueueSize());
    conn.disconnect();
    // no heart beat for (0,0)
    conn = StompClientConnectionFactory.createClientConnection(uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "0,0").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    Assert.assertEquals("0,30000", reply.getHeader(Stomp.Headers.Connect.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(uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "1,0").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.2");
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    Assert.assertEquals("0,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    Thread.sleep(2000);
    // send will fail
    try {
        send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World");
        Assert.fail("connection should have been destroyed by now");
    } catch (IOException e) {
    // ignore
    }
    // heart-beat (1,0), start a ping, then send a message, should be ok.
    conn = StompClientConnectionFactory.createClientConnection(uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "1,0").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    Assert.assertEquals("0,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    conn.startPinger(500);
    Thread.sleep(2000);
    // send will be ok
    send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World");
    conn.stopPinger();
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with StompClientConnection

use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.

the class StompV12Test method testHeaderContentType.

@Test
public void testHeaderContentType() throws Exception {
    conn.connect(defUser, defPass);
    send(conn, getQueuePrefix() + getQueueName(), "application/xml", "Hello World 1!");
    // subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(v11Uri);
    newConn.connect(defUser, defPass);
    subscribe(newConn, "a-sub");
    ClientStompFrame frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals("application/xml", frame.getHeader(Stomp.Headers.CONTENT_TYPE));
    // unsub
    unsubscribe(newConn, "a-sub");
    newConn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) Test(org.junit.Test)

Example 13 with StompClientConnection

use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.

the class StompV12Test method testHeadersPadding.

// padding shouldn't be trimmed
@Test
public void testHeadersPadding() throws Exception {
    conn.connect(defUser, defPass);
    String body = "<p>Hello World!</p>";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml").addHeader(Stomp.Headers.CONTENT_LENGTH, cLen).addHeader(" header1", "value1 ").addHeader("  header2", "value2   ").addHeader("header3 ", " value3").addHeader(" header4 ", " value4 ").addHeader(" header 5  ", " value 5 ").addHeader("header6", "\t value\t 6 \t").setBody(body);
    conn.sendFrame(frame);
    // subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
    newConn.connect(defUser, defPass);
    subscribe(newConn, "a-sub");
    frame = newConn.receiveFrame();
    Assert.assertEquals(Stomp.Responses.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
    unsubscribe(newConn, "a-sub");
    newConn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 14 with StompClientConnection

use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.

the class StompV12Test method testNegotiation.

@Test
public void testNegotiation() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(v10Uri);
    // case 1 accept-version absent. It is a 1.0 connect
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    ClientStompFrame reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    Assert.assertEquals(null, reply.getHeader(Stomp.Headers.Error.VERSION));
    conn.disconnect();
    // case 2 accept-version=1.0, result: 1.0
    conn = StompClientConnectionFactory.createClientConnection(v11Uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0");
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    Assert.assertEquals("1.0", reply.getHeader(Stomp.Headers.Error.VERSION));
    conn.disconnect();
    // case 3 accept-version=1.1, result: 1.1
    conn = StompClientConnectionFactory.createClientConnection(v11Uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.1");
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    Assert.assertEquals("1.1", reply.getHeader(Stomp.Headers.Error.VERSION));
    conn.disconnect();
    // case 4 accept-version=1.0,1.1,1.3, result 1.2
    conn = StompClientConnectionFactory.createClientConnection(v11Uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.3");
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    Assert.assertEquals("1.1", reply.getHeader(Stomp.Headers.Error.VERSION));
    conn.disconnect();
    // case 5 accept-version=1.3, result error
    conn = StompClientConnectionFactory.createClientConnection(v11Uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.3");
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.ERROR, reply.getCommand());
    conn.disconnect();
    System.out.println("Got error frame " + reply);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) Test(org.junit.Test)

Example 15 with StompClientConnection

use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.

the class StompV12Test method testTwoSubscribers.

@Test
public void testTwoSubscribers() throws Exception {
    conn.connect(defUser, defPass, CLIENT_ID);
    subscribeTopic(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO, null);
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(v11Uri);
    newConn.connect(defUser, defPass, "myclientid2");
    subscribeTopic(newConn, "sub2", Stomp.Headers.Subscribe.AckModeValues.AUTO, null);
    send(conn, getTopicPrefix() + getTopicName(), null, "Hello World");
    // receive message from socket
    ClientStompFrame frame = conn.receiveFrame(1000);
    System.out.println("received frame : " + frame);
    Assert.assertEquals("Hello World", frame.getBody());
    Assert.assertEquals("sub1", frame.getHeader(Stomp.Headers.Message.SUBSCRIPTION));
    frame = newConn.receiveFrame(1000);
    System.out.println("received 2 frame : " + frame);
    Assert.assertEquals("Hello World", frame.getBody());
    Assert.assertEquals("sub2", frame.getHeader(Stomp.Headers.Message.SUBSCRIPTION));
    // remove suscription
    unsubscribe(conn, "sub1", true);
    unsubscribe(newConn, "sub2", true);
    conn.disconnect();
    newConn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) Test(org.junit.Test)

Aggregations

StompClientConnection (org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection)44 Test (org.junit.Test)42 ClientStompFrame (org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)41 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)14 URI (java.net.URI)7 IOException (java.io.IOException)2 MessageConsumer (javax.jms.MessageConsumer)2 TextMessage (javax.jms.TextMessage)2 LargeMessageTestBase (org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase)2 StompClientConnectionV11 (org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionV11)2 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 Message (javax.jms.Message)1 QueueBrowser (javax.jms.QueueBrowser)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)1 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)1 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)1