Search in sources :

Example 36 with StompClientConnection

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

the class StompWithLargeMessagesTest method testReceiveLargeCompressedToLargePersistentMessagesFromCore.

// //core sender -> large (compressed regular) -> stomp v12 receiver
// @Test
// public void testReceiveLargeCompressedToRegularPersistentMessagesFromCoreV12() throws Exception {
// LargeMessageTestBase.TestLargeMessageInputStream input = new LargeMessageTestBase.TestLargeMessageInputStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, true);
// LargeMessageTestBase.adjustLargeCompression(true, input, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
// 
// char[] contents = input.toArray();
// String msg = new String(contents);
// 
// int count = 10;
// for (int i = 0; i < count; i++) {
// this.sendJmsMessage(msg);
// }
// 
// StompClientConnection connV12 = StompClientConnectionFactory.createClientConnection("1.2", "localhost", port);
// connV12.connect(defUser, defPass);
// 
// ClientStompFrame subFrame = connV12.createFrame("SUBSCRIBE");
// subFrame.addHeader("id", "a-sub");
// subFrame.addHeader("subscription-type", "ANYCAST");
// subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
// subFrame.addHeader("ack", "auto");
// 
// connV12.sendFrame(subFrame);
// 
// for (int i = 0; i < count; i++) {
// ClientStompFrame receiveFrame = connV12.receiveFrame(30000);
// 
// Assert.assertNotNull(receiveFrame);
// System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 20));
// Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
// Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
// assertEquals(contents.length, receiveFrame.getBody().length());
// }
// 
// // remove susbcription
// ClientStompFrame unsubFrame = connV12.createFrame("UNSUBSCRIBE");
// unsubFrame.addHeader("id", "a-sub");
// connV12.sendFrame(unsubFrame);
// 
// connV12.disconnect();
// }
// 
// //core sender -> large (compressed large) -> stomp v12 receiver
// @Test
// public void testReceiveLargeCompressedToLargePersistentMessagesFromCoreV12() throws Exception {
// LargeMessageTestBase.TestLargeMessageInputStream input = new LargeMessageTestBase.TestLargeMessageInputStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, true);
// input.setSize(10 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
// LargeMessageTestBase.adjustLargeCompression(false, input, 10 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
// 
// char[] contents = input.toArray();
// String msg = new String(contents);
// 
// int count = 10;
// for (int i = 0; i < count; i++) {
// this.sendJmsMessage(msg);
// }
// 
// IntegrationTestLogger.LOGGER.info("Message count for " + getQueueName() + ": " + server.getActiveMQServer().locateQueue(SimpleString.toSimpleString(getQueueName())).getMessageCount());
// 
// StompClientConnection connV12 = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
// connV12.connect(defUser, defPass);
// 
// ClientStompFrame subFrame = connV12.createFrame("SUBSCRIBE");
// subFrame.addHeader("id", "a-sub");
// subFrame.addHeader("subscription-type", "ANYCAST");
// subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
// subFrame.addHeader("ack", "auto");
// 
// connV12.sendFrame(subFrame);
// 
// for (int i = 0; i < count; i++) {
// ClientStompFrame receiveFrame = connV12.receiveFrame(30000);
// 
// Assert.assertNotNull(receiveFrame);
// System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 20));
// Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
// Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
// assertEquals(contents.length, receiveFrame.getBody().length());
// }
// 
// // remove susbcription
// ClientStompFrame unsubFrame = connV12.createFrame("UNSUBSCRIBE");
// unsubFrame.addHeader("id", "a-sub");
// connV12.sendFrame(unsubFrame);
// 
// connV12.disconnect();
// }
// core sender -> large (compressed large) -> stomp v10 receiver
@Test
public void testReceiveLargeCompressedToLargePersistentMessagesFromCore() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    try {
        LargeMessageTestBase.TestLargeMessageInputStream input = new LargeMessageTestBase.TestLargeMessageInputStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, true);
        input.setSize(10 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
        LargeMessageTestBase.adjustLargeCompression(false, input, 10 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
        char[] contents = input.toArray();
        String msg = new String(contents);
        String leadingPart = msg.substring(0, 100);
        int count = 10;
        for (int i = 0; i < count; i++) {
            this.sendJmsMessage(msg);
        }
        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);
        for (int i = 0; i < count; i++) {
            ClientStompFrame frame = conn.receiveFrame(60000);
            Assert.assertNotNull(frame);
            System.out.println(frame.toString());
            System.out.println("part of frame: " + frame.getBody().substring(0, 250));
            Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
            Assert.assertTrue(frame.getHeader("destination").equals(getQueuePrefix() + getQueueName()));
            int index = frame.getBody().toString().indexOf(leadingPart);
            assertEquals(msg.length(), (frame.getBody().toString().length() - index));
        }
        ClientStompFrame unsubFrame = conn.createFrame("UNSUBSCRIBE");
        unsubFrame.addHeader("destination", getQueuePrefix() + getQueueName());
        unsubFrame.addHeader("receipt", "567");
        conn.sendFrame(unsubFrame);
    } finally {
        conn.disconnect();
        conn.closeTransport();
    }
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) LargeMessageTestBase(org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 37 with StompClientConnection

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

the class StompWithSecurityTest method testJMSXUserID.

@Test
public void testJMSXUserID() throws Exception {
    server.getActiveMQServer().getConfiguration().setPopulateValidatedUser(true);
    MessageConsumer consumer = session.createConsumer(queue);
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
    conn.connect(defUser, defPass);
    ClientStompFrame frame = conn.createFrame("SEND");
    frame.addHeader("destination", getQueuePrefix() + getQueueName());
    frame.setBody("Hello World");
    conn.sendFrame(frame);
    conn.disconnect();
    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());
    Assert.assertEquals("JMSXUserID", "brianm", message.getStringProperty("JMSXUserID"));
    // 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);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 38 with StompClientConnection

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

the class StompV11Test 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(uri);
    newConn.connect(defUser, defPass);
    subscribe(newConn, "a-sub");
    ClientStompFrame frame = newConn.receiveFrame();
    IntegrationTestLogger.LOGGER.info("received " + frame);
    assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    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 39 with StompClientConnection

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

the class StompV11Test 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(uri);
    newConn.connect(defUser, defPass, "myclientid2");
    subscribeTopic(newConn, "sub2", Stomp.Headers.Subscribe.AckModeValues.AUTO, null);
    send(newConn, getTopicPrefix() + getTopicName(), null, "Hello World");
    // receive message from socket
    ClientStompFrame frame = conn.receiveFrame(5000);
    IntegrationTestLogger.LOGGER.info("received frame : " + frame);
    assertEquals("Hello World", frame.getBody());
    assertEquals("sub1", frame.getHeader(Stomp.Headers.Message.SUBSCRIPTION));
    frame = newConn.receiveFrame(5000);
    IntegrationTestLogger.LOGGER.info("received 2 frame : " + frame);
    assertEquals("Hello World", frame.getBody());
    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)

Example 40 with StompClientConnection

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

the class StompV11Test method testHeaderEncoding.

@Test
public void testHeaderEncoding() throws Exception {
    conn.connect(defUser, defPass);
    String body = "Hello World 1!";
    String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
    String hKey = "special-header\\\\\\n\\c";
    String hVal = "\\c\\\\\\ngood";
    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).addHeader(hKey, hVal);
    IntegrationTestLogger.LOGGER.info("key: |" + hKey + "| val: |" + hVal + "|");
    frame.setBody(body);
    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());
    String value = frame.getHeader("special-header" + "\\" + "\n" + ":");
    assertEquals(":" + "\\" + "\n" + "good", value);
    // 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)

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