Search in sources :

Example 31 with ClientStompFrame

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

the class StompTestBase method subscribeTopic.

public static ClientStompFrame subscribeTopic(StompClientConnection conn, String subscriptionId, String ack, String durableId, String durableIdHeader, boolean receipt, boolean noLocal) throws IOException, InterruptedException {
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SUBSCRIBE).addHeader(Stomp.Headers.Subscribe.SUBSCRIPTION_TYPE, RoutingType.MULTICAST.toString()).addHeader(Stomp.Headers.Subscribe.DESTINATION, getTopicPrefix() + getTopicName());
    if (subscriptionId != null) {
        frame.addHeader(Stomp.Headers.Subscribe.ID, subscriptionId);
    }
    if (ack != null) {
        frame.addHeader(Stomp.Headers.Subscribe.ACK_MODE, ack);
    }
    if (durableId != null) {
        frame.addHeader(durableIdHeader, durableId);
    }
    String uuid = UUID.randomUUID().toString();
    if (receipt) {
        frame.addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
    }
    if (noLocal) {
        frame.addHeader(Stomp.Headers.Subscribe.NO_LOCAL, "true");
    }
    frame = conn.sendFrame(frame);
    if (frame.getCommand().equals("ERROR")) {
        return frame;
    }
    if (receipt) {
        assertNotNull("Requested receipt, but response is null", frame);
        assertTrue(frame.getHeader(Stomp.Headers.Response.RECEIPT_ID).equals(uuid));
    }
    return frame;
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)

Example 32 with ClientStompFrame

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

the class StompTestBase method abortTransaction.

public static void abortTransaction(StompClientConnection conn, String txID) throws IOException, InterruptedException {
    ClientStompFrame abortFrame = conn.createFrame(Stomp.Commands.ABORT).addHeader(Stomp.Headers.TRANSACTION, txID);
    conn.sendFrame(abortFrame);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)

Example 33 with ClientStompFrame

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

the class StompTestBase method unsubscribe.

public static ClientStompFrame unsubscribe(StompClientConnection conn, String subscriptionId, String subscriptionIdHeader, String destination, boolean receipt, boolean durable) throws IOException, InterruptedException {
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.UNSUBSCRIBE);
    if (durable && subscriptionId != null) {
        frame.addHeader(subscriptionIdHeader, subscriptionId);
    } else if (!durable && subscriptionId != null) {
        frame.addHeader(Stomp.Headers.Unsubscribe.ID, subscriptionId);
    }
    if (destination != null) {
        frame.addHeader(Stomp.Headers.Unsubscribe.DESTINATION, destination);
    }
    String uuid = UUID.randomUUID().toString();
    if (receipt) {
        frame.addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
    }
    frame = conn.sendFrame(frame);
    if (receipt) {
        assertEquals(Stomp.Responses.RECEIPT, frame.getCommand());
        assertEquals(uuid, frame.getHeader(Stomp.Headers.Response.RECEIPT_ID));
    }
    return frame;
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)

Example 34 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame 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 35 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame 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)

Aggregations

ClientStompFrame (org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)195 Test (org.junit.Test)173 MessageConsumer (javax.jms.MessageConsumer)67 TextMessage (javax.jms.TextMessage)62 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)51 BytesMessage (javax.jms.BytesMessage)43 StompClientConnection (org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection)41 Message (javax.jms.Message)37 IOException (java.io.IOException)7 URI (java.net.URI)5 MessageProducer (javax.jms.MessageProducer)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)4 ClosedChannelException (java.nio.channels.ClosedChannelException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 LargeMessageTestBase (org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1