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"));
}
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();
}
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();
}
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();
}
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();
}
Aggregations