Search in sources :

Example 16 with StompClientConnection

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

the class StompV12Test method testSendWithHeartBeatsAndReceiveWithHeartBeats.

@Test
public void testSendWithHeartBeatsAndReceiveWithHeartBeats() throws Exception {
    StompClientConnection newConn = null;
    try {
        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).addHeader(Stomp.Headers.Connect.HEART_BEAT, "500,1000").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
        conn.sendFrame(frame);
        conn.startPinger(500);
        for (int i = 0; i < 10; i++) {
            send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World " + i + "!");
            Thread.sleep(500);
        }
        // subscribe
        newConn = StompClientConnectionFactory.createClientConnection(uri);
        frame = newConn.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, "500,1000").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
        newConn.sendFrame(frame);
        newConn.startPinger(500);
        Thread.sleep(500);
        subscribe(newConn, "a-sub");
        int cnt = 0;
        frame = newConn.receiveFrame();
        while (frame != null) {
            cnt++;
            Thread.sleep(500);
            frame = newConn.receiveFrame(5000);
        }
        Assert.assertEquals(10, cnt);
        // unsub
        unsubscribe(newConn, "a-sub");
    } finally {
        if (newConn != null)
            newConn.disconnect();
        conn.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 17 with StompClientConnection

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

the class StompV11Test method testHeaderContentLength.

@Test
public void testHeaderContentLength() throws Exception {
    conn.connect(defUser, defPass);
    String body = "Hello World 1!";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml").addHeader(Stomp.Headers.CONTENT_LENGTH, cLen).setBody(body + "extra");
    conn.sendFrame(frame);
    // subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
    newConn.connect(defUser, defPass);
    subscribe(newConn, "a-sub");
    frame = newConn.receiveFrame();
    IntegrationTestLogger.LOGGER.info("received " + frame);
    assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    assertEquals(cLen, frame.getHeader(Stomp.Headers.CONTENT_LENGTH));
    // 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 18 with StompClientConnection

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

the class StompV11Test method testSendWithHeartBeatsAndReceiveWithHeartBeats.

@Test
public void testSendWithHeartBeatsAndReceiveWithHeartBeats() throws Exception {
    StompClientConnection newConn = null;
    try {
        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).addHeader(Stomp.Headers.Connect.HEART_BEAT, "500,1000").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
        conn.sendFrame(frame);
        conn.startPinger(500);
        for (int i = 0; i < 10; i++) {
            send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World " + i + "!");
            Thread.sleep(500);
        }
        // subscribe
        newConn = StompClientConnectionFactory.createClientConnection(uri);
        frame = newConn.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, "500,1000").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
        newConn.sendFrame(frame);
        newConn.startPinger(500);
        Thread.sleep(500);
        subscribe(newConn, "a-sub");
        int cnt = 0;
        frame = newConn.receiveFrame();
        while (frame != null) {
            cnt++;
            Thread.sleep(500);
            frame = newConn.receiveFrame(5000);
        }
        assertEquals(10, cnt);
        // unsub
        unsubscribe(newConn, "a-sub");
    } finally {
        if (newConn != null)
            newConn.disconnect();
        conn.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 19 with StompClientConnection

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

the class StompV11Test method testHeartBeatToConnectionTTLModifier.

@Test
public void testHeartBeatToConnectionTTLModifier() throws Exception {
    ClientStompFrame frame;
    ClientStompFrame reply;
    StompClientConnection connection;
    int port = 61614;
    server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://127.0.0.1:" + port + "?heartBeatToConnectionTtlModifier=1").start();
    connection = StompClientConnectionFactory.createClientConnection(uri);
    frame = connection.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, "5000,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
    reply = connection.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    assertEquals("0,5000", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    Thread.sleep(6000);
    try {
        assertFalse(connection.isConnected());
    } finally {
        connection.closeTransport();
    }
    server.getActiveMQServer().getRemotingService().destroyAcceptor("test");
    server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://127.0.0.1:" + port + "?heartBeatToConnectionTtlModifier=1.5").start();
    connection = StompClientConnectionFactory.createClientConnection(uri);
    frame = connection.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, "5000,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
    reply = connection.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    assertEquals("0,5000", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    Thread.sleep(6000);
    connection.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 20 with StompClientConnection

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

the class StompV11Test method testConnection.

@Test
public void testConnection() throws Exception {
    server.getActiveMQServer().getConfiguration().setSecurityEnabled(true);
    StompClientConnection connection = StompClientConnectionFactory.createClientConnection(v10Uri);
    connection.connect(defUser, defPass);
    assertTrue(connection.isConnected());
    assertEquals("1.0", connection.getVersion());
    connection.disconnect();
    connection = StompClientConnectionFactory.createClientConnection(uri);
    connection.connect(defUser, defPass);
    assertTrue(connection.isConnected());
    assertEquals("1.1", connection.getVersion());
    connection.disconnect();
    connection = StompClientConnectionFactory.createClientConnection(uri);
    connection.connect();
    assertFalse(connection.isConnected());
    // new way of connection
    StompClientConnectionV11 conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection(uri);
    conn.connect1(defUser, defPass);
    assertTrue(conn.isConnected());
    conn.disconnect();
    // invalid user
    conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection(uri);
    ClientStompFrame frame = conn.connect("invaliduser", defPass);
    assertFalse(conn.isConnected());
    assertTrue(Stomp.Responses.ERROR.equals(frame.getCommand()));
    assertTrue(frame.getBody().contains("Security Error occurred"));
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnectionV11(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionV11) 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