use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompV12Test method testHeaderEncoding.
/**
* Since 1.2 the CR ('\r') needs to be escaped.
*/
@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 = "\\rspecial-header\\\\\\n\\c\\r\\n";
String hVal = "\\c\\\\\\ngood\\n\\r";
ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml").addHeader(Stomp.Headers.CONTENT_LENGTH, cLen).addHeader(hKey, hVal).setBody(body);
System.out.println("key: |" + hKey + "| val: |" + hVal + "|");
conn.sendFrame(frame);
// subscribe
StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
newConn.connect(defUser, defPass);
subscribe(newConn, "a-sub");
frame = newConn.receiveFrame();
System.out.println("received " + frame);
Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
String value = frame.getHeader("\r" + "special-header" + "\\" + "\n" + ":" + "\r\n");
Assert.assertEquals(":" + "\\" + "\n" + "good\n\r", value);
// 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 testHeaderContentLength.
@Test
public void testHeaderContentLength() throws Exception {
conn.connect(defUser, defPass);
String body = "Hello World 1!";
String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml").addHeader(Stomp.Headers.CONTENT_LENGTH, cLen).setBody(body + "extra");
conn.sendFrame(frame);
// subscribe
StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
newConn.connect(defUser, defPass);
subscribe(newConn, "a-sub");
frame = newConn.receiveFrame();
Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
Assert.assertEquals(body, frame.getBody());
Assert.assertEquals(cLen, frame.getHeader(Stomp.Headers.CONTENT_LENGTH));
// send again without content-length header
frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml").setBody(body + "extra");
conn.sendFrame(frame);
// receive again. extra should received.
frame = newConn.receiveFrame();
Assert.assertEquals(body + "extra", frame.getBody());
// although sender didn't send the content-length header,
// the server should add it anyway
Assert.assertEquals((body + "extra").getBytes(StandardCharsets.UTF_8).length, Integer.valueOf(frame.getHeader(Stomp.Headers.CONTENT_LENGTH)).intValue());
// 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 testHeaderRepetitive.
// test that repetitive headers
@Test
public void testHeaderRepetitive() throws Exception {
AddressSettings addressSettings = new AddressSettings();
addressSettings.setAutoCreateQueues(false);
addressSettings.setAutoCreateAddresses(false);
server.getActiveMQServer().getAddressSettingsRepository().addMatch("#", addressSettings);
conn.connect(defUser, defPass);
String body = "Hello World!";
String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.Subscribe.DESTINATION, "aNonexistentQueue").addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml").addHeader(Stomp.Headers.CONTENT_LENGTH, cLen).addHeader("foo", "value1").addHeader("foo", "value2").addHeader("foo", "value3");
frame.setBody(body);
conn.sendFrame(frame);
// subscribe
StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
newConn.connect(defUser, defPass);
subscribe(newConn, "a-sub", null, null, true);
frame = newConn.receiveFrame();
Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
Assert.assertEquals(body, frame.getBody());
System.out.println("received: " + frame);
Assert.assertEquals("value1", frame.getHeader("foo"));
// unsub
unsubscribe(newConn, "a-sub", true);
newConn.disconnect();
// should get error
body = "Hello World!";
cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, "aNonexistentQueue").addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml").addHeader(Stomp.Headers.CONTENT_LENGTH, cLen).addHeader(Stomp.Headers.RECEIPT_REQUESTED, "1234").setBody(body);
ClientStompFrame reply = conn.sendFrame(frame);
// TODO this is broken because queue auto-creation is always on
Assert.assertEquals(Stomp.Responses.ERROR, reply.getCommand());
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompV12Test method testSendWithHeartBeatsAndReceive.
@Test
public void testSendWithHeartBeatsAndReceive() throws Exception {
StompClientConnection newConn = null;
try {
ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT);
frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "500,1000").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
conn.sendFrame(frame);
conn.startPinger(500);
for (int i = 0; i < 10; i++) {
send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World " + i + "!");
Thread.sleep(500);
}
// subscribe
newConn = StompClientConnectionFactory.createClientConnection(uri);
newConn.connect(defUser, defPass);
subscribe(newConn, "a-sub");
int cnt = 0;
frame = newConn.receiveFrame();
while (frame != null) {
cnt++;
Thread.sleep(500);
frame = newConn.receiveFrame(5000);
}
Assert.assertEquals(10, cnt);
// unsub
unsubscribe(newConn, "a-sub");
} finally {
if (newConn != null)
newConn.disconnect();
conn.disconnect();
}
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompV12Test method testConnectionAsInSpec.
@Test
public void testConnectionAsInSpec() throws Exception {
StompClientConnection conn = StompClientConnectionFactory.createClientConnection(v10Uri);
ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT);
frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.2");
frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
ClientStompFrame reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
Assert.assertEquals("1.2", reply.getHeader(Stomp.Headers.Error.VERSION));
conn.disconnect();
// need 1.2 client
conn = StompClientConnectionFactory.createClientConnection(uri);
frame = conn.createFrame(Stomp.Commands.STOMP);
frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.2");
frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
Assert.assertEquals("1.2", reply.getHeader(Stomp.Headers.Error.VERSION));
conn.disconnect();
}
Aggregations