use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompV12Test method testSendWithHeartBeatsAndReceiveWithHeartBeats.
@Test
public void testSendWithHeartBeatsAndReceiveWithHeartBeats() throws Exception {
StompClientConnection newConn = null;
try {
ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT).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);
frame = newConn.createFrame(Stomp.Commands.CONNECT).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");
newConn.sendFrame(frame);
newConn.startPinger(500);
Thread.sleep(500);
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 StompV11Test 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.Send.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();
IntegrationTestLogger.LOGGER.info("received " + frame);
assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
assertEquals(cLen, frame.getHeader(Stomp.Headers.CONTENT_LENGTH));
// 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 StompV11Test method testSendWithHeartBeatsAndReceiveWithHeartBeats.
@Test
public void testSendWithHeartBeatsAndReceiveWithHeartBeats() throws Exception {
StompClientConnection newConn = null;
try {
ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT).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.Connect.ACCEPT_VERSION, "1.0,1.1");
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);
frame = newConn.createFrame(Stomp.Commands.CONNECT).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.Connect.ACCEPT_VERSION, "1.0,1.1");
newConn.sendFrame(frame);
newConn.startPinger(500);
Thread.sleep(500);
subscribe(newConn, "a-sub");
int cnt = 0;
frame = newConn.receiveFrame();
while (frame != null) {
cnt++;
Thread.sleep(500);
frame = newConn.receiveFrame(5000);
}
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 StompV11Test method testHeartBeatToConnectionTTLModifier.
@Test
public void testHeartBeatToConnectionTTLModifier() throws Exception {
ClientStompFrame frame;
ClientStompFrame reply;
StompClientConnection connection;
int port = 61614;
server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://127.0.0.1:" + port + "?heartBeatToConnectionTtlModifier=1").start();
connection = StompClientConnectionFactory.createClientConnection(uri);
frame = connection.createFrame(Stomp.Commands.CONNECT).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, "5000,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
reply = connection.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
assertEquals("0,5000", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
Thread.sleep(6000);
try {
assertFalse(connection.isConnected());
} finally {
connection.closeTransport();
}
server.getActiveMQServer().getRemotingService().destroyAcceptor("test");
server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://127.0.0.1:" + port + "?heartBeatToConnectionTtlModifier=1.5").start();
connection = StompClientConnectionFactory.createClientConnection(uri);
frame = connection.createFrame(Stomp.Commands.CONNECT).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, "5000,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
reply = connection.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
assertEquals("0,5000", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
Thread.sleep(6000);
connection.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompV11Test method testConnection.
@Test
public void testConnection() throws Exception {
server.getActiveMQServer().getConfiguration().setSecurityEnabled(true);
StompClientConnection connection = StompClientConnectionFactory.createClientConnection(v10Uri);
connection.connect(defUser, defPass);
assertTrue(connection.isConnected());
assertEquals("1.0", connection.getVersion());
connection.disconnect();
connection = StompClientConnectionFactory.createClientConnection(uri);
connection.connect(defUser, defPass);
assertTrue(connection.isConnected());
assertEquals("1.1", connection.getVersion());
connection.disconnect();
connection = StompClientConnectionFactory.createClientConnection(uri);
connection.connect();
assertFalse(connection.isConnected());
// new way of connection
StompClientConnectionV11 conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection(uri);
conn.connect1(defUser, defPass);
assertTrue(conn.isConnected());
conn.disconnect();
// invalid user
conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection(uri);
ClientStompFrame frame = conn.connect("invaliduser", defPass);
assertFalse(conn.isConnected());
assertTrue(Stomp.Responses.ERROR.equals(frame.getCommand()));
assertTrue(frame.getBody().contains("Security Error occurred"));
}
Aggregations