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