Search in sources :

Example 6 with StompClientConnection

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

the class StompWithInterceptorsTest method stompFrameInterceptor.

@Test
public void stompFrameInterceptor() throws Exception {
    IncomingStompInterceptor.interceptedFrames.clear();
    OutgoingStompInterceptor.interceptedFrames.clear();
    // wait for the SESS_START which is the last packet for the test's JMS connection
    assertTrue(Wait.waitFor(() -> {
        for (Packet packet : new ArrayList<>(CoreInterceptor.incomingInterceptedFrames)) {
            if (packet.getType() == (byte) 67) {
                return true;
            }
        }
        return false;
    }, 2000, 50));
    CoreInterceptor.incomingInterceptedFrames.clear();
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    conn.connect(defUser, defPass);
    ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
    subFrame.addHeader("subscription-type", "ANYCAST");
    subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
    subFrame.addHeader("ack", "auto");
    conn.sendFrame(subFrame);
    assertEquals(0, CoreInterceptor.incomingInterceptedFrames.size());
    sendJmsMessage(getName());
    // Something was supposed to be called on sendMessages
    assertTrue("core interceptor is not working", CoreInterceptor.incomingInterceptedFrames.size() > 0);
    conn.receiveFrame(10000);
    ClientStompFrame frame = conn.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World");
    conn.sendFrame(frame);
    assertTrue(Wait.waitFor(() -> OutgoingStompInterceptor.interceptedFrames.size() == 3, 2000, 50));
    conn.disconnect();
    assertTrue(Wait.waitFor(() -> IncomingStompInterceptor.interceptedFrames.size() == 4, 2000, 50));
    List<String> incomingCommands = new ArrayList<>(4);
    incomingCommands.add("CONNECT");
    incomingCommands.add("SUBSCRIBE");
    incomingCommands.add("SEND");
    incomingCommands.add("DISCONNECT");
    for (int i = 0; i < IncomingStompInterceptor.interceptedFrames.size(); i++) {
        Assert.assertEquals(incomingCommands.get(i), IncomingStompInterceptor.interceptedFrames.get(i).getCommand());
        Assert.assertEquals("incomingInterceptedVal", IncomingStompInterceptor.interceptedFrames.get(i).getHeader("incomingInterceptedProp"));
    }
    List<String> outgoingCommands = new ArrayList<>(3);
    outgoingCommands.add("CONNECTED");
    outgoingCommands.add("MESSAGE");
    outgoingCommands.add("MESSAGE");
    for (int i = 0; i < OutgoingStompInterceptor.interceptedFrames.size(); i++) {
        Assert.assertEquals(outgoingCommands.get(i), OutgoingStompInterceptor.interceptedFrames.get(i).getCommand());
    }
    Assert.assertEquals("incomingInterceptedVal", OutgoingStompInterceptor.interceptedFrames.get(2).getHeader("incomingInterceptedProp"));
    Assert.assertEquals("outgoingInterceptedVal", OutgoingStompInterceptor.interceptedFrames.get(2).getHeader("outgoingInterceptedProp"));
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Packet(org.apache.activemq.artemis.core.protocol.core.Packet) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with StompClientConnection

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

the class StompWithMessageIDTest method testEnableMessageID.

@Test
public void testEnableMessageID() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    conn.connect(defUser, defPass);
    ClientStompFrame frame = conn.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World 1");
    conn.sendFrame(frame);
    frame = conn.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World 2");
    conn.sendFrame(frame);
    QueueBrowser browser = session.createBrowser(queue);
    Enumeration enu = browser.getEnumeration();
    while (enu.hasMoreElements()) {
        Message msg = (Message) enu.nextElement();
        String msgId = msg.getStringProperty("amqMessageId");
        assertNotNull(msgId);
        assertTrue(msgId.indexOf("STOMP") == 0);
    }
    browser.close();
    MessageConsumer consumer = session.createConsumer(queue);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    message = (TextMessage) consumer.receive(2000);
    Assert.assertNull(message);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) Enumeration(java.util.Enumeration) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) QueueBrowser(javax.jms.QueueBrowser) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 8 with StompClientConnection

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

the class StompV12Test method testConnection.

@Test
public void testConnection() throws Exception {
    server.getActiveMQServer().getConfiguration().setSecurityEnabled(true);
    StompClientConnection connection = StompClientConnectionFactory.createClientConnection(v10Uri);
    connection.connect(defUser, defPass);
    Assert.assertTrue(connection.isConnected());
    Assert.assertEquals("1.0", connection.getVersion());
    connection.disconnect();
    connection = StompClientConnectionFactory.createClientConnection(uri);
    connection.connect(defUser, defPass);
    Assert.assertTrue(connection.isConnected());
    Assert.assertEquals("1.2", connection.getVersion());
    connection.disconnect();
    connection = StompClientConnectionFactory.createClientConnection(uri);
    connection.connect();
    Assert.assertFalse(connection.isConnected());
    // new way of connection
    StompClientConnectionV11 conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection(v11Uri);
    conn.connect1(defUser, defPass);
    Assert.assertTrue(conn.isConnected());
    conn.disconnect();
}
Also used : StompClientConnectionV11(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionV11) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) Test(org.junit.Test)

Example 9 with StompClientConnection

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

the class StompV12Test method testSendAndReceive.

@Test
public void testSendAndReceive() throws Exception {
    conn.connect(defUser, defPass);
    ClientStompFrame response = send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World 1!");
    Assert.assertNull(response);
    send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World 2!", true);
    // subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
    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("a-sub", frame.getHeader(Stomp.Headers.Message.SUBSCRIPTION));
    // 'auto' ack mode doesn't require 'ack' header
    Assert.assertNull(frame.getHeader(Stomp.Headers.Subscribe.ACK_MODE));
    Assert.assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader(Stomp.Headers.Subscribe.DESTINATION));
    Assert.assertEquals("Hello World 1!", frame.getBody());
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    // 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 10 with StompClientConnection

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

the class StompV12Test method testSendAndReceiveOnDifferentConnections.

@Test
public void testSendAndReceiveOnDifferentConnections() throws Exception {
    conn.connect(defUser, defPass);
    send(conn, getQueuePrefix() + getQueueName(), null, "Hello World");
    StompClientConnection connV12_2 = StompClientConnectionFactory.createClientConnection(v11Uri);
    connV12_2.connect(defUser, defPass);
    subscribe(connV12_2, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
    ClientStompFrame frame = connV12_2.receiveFrame(2000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals("Hello World", frame.getBody());
    conn.disconnect();
    connV12_2.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