mirror of https://github.com/apache/activemq.git
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@906071 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5170a8bba3
commit
caabb6cb3d
|
@ -74,6 +74,10 @@ public interface FrameTranslator {
|
||||||
headers.put(Stomp.Headers.Message.TYPE, message.getJMSType());
|
headers.put(Stomp.Headers.Message.TYPE, message.getJMSType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.getUserID() != null) {
|
||||||
|
headers.put(Stomp.Headers.Message.USERID, message.getUserID());
|
||||||
|
}
|
||||||
|
|
||||||
// now lets add all the message headers
|
// now lets add all the message headers
|
||||||
final Map<String, Object> properties = message.getProperties();
|
final Map<String, Object> properties = message.getProperties();
|
||||||
if (properties != null) {
|
if (properties != null) {
|
||||||
|
|
|
@ -76,6 +76,7 @@ public interface Stomp {
|
||||||
String TIMESTAMP = "timestamp";
|
String TIMESTAMP = "timestamp";
|
||||||
String TYPE = "type";
|
String TYPE = "type";
|
||||||
String SUBSCRIPTION = "subscription";
|
String SUBSCRIPTION = "subscription";
|
||||||
|
String USERID = "JMSXUserID";
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Subscribe {
|
public interface Subscribe {
|
||||||
|
|
|
@ -133,14 +133,14 @@ public class StompTest extends CombinationTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
try {
|
try {
|
||||||
connection.close();
|
connection.close();
|
||||||
stompDisconnect();
|
stompDisconnect();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
// Some tests explicitly disconnect from stomp so can ignore
|
// Some tests explicitly disconnect from stomp so can ignore
|
||||||
} finally {
|
} finally {
|
||||||
broker.stop();
|
broker.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stompDisconnect() throws IOException {
|
private void stompDisconnect() throws IOException {
|
||||||
|
@ -470,9 +470,7 @@ public class StompTest extends CombinationTestSupport {
|
||||||
LOG.info("Received frame: " + frame);
|
LOG.info("Received frame: " + frame);
|
||||||
fail("No message should have been received since subscription was removed");
|
fail("No message should have been received since subscription was removed");
|
||||||
} catch (SocketTimeoutException e) {
|
} catch (SocketTimeoutException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTransactionCommit() throws Exception {
|
public void testTransactionCommit() throws Exception {
|
||||||
|
@ -563,7 +561,6 @@ public class StompTest extends CombinationTestSupport {
|
||||||
|
|
||||||
assertTrue(f.startsWith("ERROR"));
|
assertTrue(f.startsWith("ERROR"));
|
||||||
assertClients(1);
|
assertClients(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConnectNotAuthenticatedWrongPassword() throws Exception {
|
public void testConnectNotAuthenticatedWrongPassword() throws Exception {
|
||||||
|
@ -590,7 +587,6 @@ public class StompTest extends CombinationTestSupport {
|
||||||
stompConnection.sendFrame(frame);
|
stompConnection.sendFrame(frame);
|
||||||
String f = stompConnection.receiveFrame();
|
String f = stompConnection.receiveFrame();
|
||||||
assertTrue(f.startsWith("ERROR"));
|
assertTrue(f.startsWith("ERROR"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSubscribeNotAuthorized() throws Exception {
|
public void testSubscribeNotAuthorized() throws Exception {
|
||||||
|
@ -885,14 +881,14 @@ public class StompTest extends CombinationTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDurableUnsub() throws Exception {
|
public void testDurableUnsub() throws Exception {
|
||||||
// get broker JMX view
|
// get broker JMX view
|
||||||
|
|
||||||
String domain = "org.apache.activemq";
|
String domain = "org.apache.activemq";
|
||||||
ObjectName brokerName = new ObjectName(domain + ":Type=Broker,BrokerName=localhost");
|
ObjectName brokerName = new ObjectName(domain + ":Type=Broker,BrokerName=localhost");
|
||||||
|
|
||||||
BrokerViewMBean view = (BrokerViewMBean)broker.getManagementContext().newProxyInstance(brokerName, BrokerViewMBean.class, true);
|
BrokerViewMBean view = (BrokerViewMBean)broker.getManagementContext().newProxyInstance(brokerName, BrokerViewMBean.class, true);
|
||||||
|
|
||||||
// connect
|
// connect
|
||||||
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\nclient-id:test\n\n" + Stomp.NULL;
|
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\nclient-id:test\n\n" + Stomp.NULL;
|
||||||
stompConnection.sendFrame(frame);
|
stompConnection.sendFrame(frame);
|
||||||
|
|
||||||
|
@ -905,7 +901,7 @@ public class StompTest extends CombinationTestSupport {
|
||||||
stompConnection.sendFrame(frame);
|
stompConnection.sendFrame(frame);
|
||||||
// wait a bit for MBean to get refreshed
|
// wait a bit for MBean to get refreshed
|
||||||
try {
|
try {
|
||||||
Thread.sleep(400);
|
Thread.sleep(400);
|
||||||
} catch (InterruptedException e){}
|
} catch (InterruptedException e){}
|
||||||
|
|
||||||
assertEquals(view.getDurableTopicSubscribers().length, 1);
|
assertEquals(view.getDurableTopicSubscribers().length, 1);
|
||||||
|
@ -913,12 +909,12 @@ public class StompTest extends CombinationTestSupport {
|
||||||
frame = "DISCONNECT\nclient-id:test\n\n" + Stomp.NULL;
|
frame = "DISCONNECT\nclient-id:test\n\n" + Stomp.NULL;
|
||||||
stompConnection.sendFrame(frame);
|
stompConnection.sendFrame(frame);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(400);
|
Thread.sleep(400);
|
||||||
} catch (InterruptedException e){}
|
} catch (InterruptedException e){}
|
||||||
|
|
||||||
//reconnect
|
//reconnect
|
||||||
stompConnect();
|
stompConnect();
|
||||||
// connect
|
// connect
|
||||||
frame = "CONNECT\n" + "login: system\n" + "passcode: manager\nclient-id:test\n\n" + Stomp.NULL;
|
frame = "CONNECT\n" + "login: system\n" + "passcode: manager\nclient-id:test\n\n" + Stomp.NULL;
|
||||||
stompConnection.sendFrame(frame);
|
stompConnection.sendFrame(frame);
|
||||||
frame = stompConnection.receiveFrame();
|
frame = stompConnection.receiveFrame();
|
||||||
|
@ -930,7 +926,7 @@ public class StompTest extends CombinationTestSupport {
|
||||||
frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
|
frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
|
||||||
stompConnection.sendFrame(frame);
|
stompConnection.sendFrame(frame);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(400);
|
Thread.sleep(400);
|
||||||
} catch (InterruptedException e){}
|
} catch (InterruptedException e){}
|
||||||
assertEquals(view.getDurableTopicSubscribers().length, 0);
|
assertEquals(view.getDurableTopicSubscribers().length, 0);
|
||||||
}
|
}
|
||||||
|
@ -961,8 +957,6 @@ public class StompTest extends CombinationTestSupport {
|
||||||
sendMessage("message 4");
|
sendMessage("message 4");
|
||||||
sendMessage("message 5");
|
sendMessage("message 5");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
StompFrame frame = stompConnection.receive();
|
StompFrame frame = stompConnection.receive();
|
||||||
assertEquals(frame.getBody(), "message 1");
|
assertEquals(frame.getBody(), "message 1");
|
||||||
|
|
||||||
|
@ -973,10 +967,10 @@ public class StompTest extends CombinationTestSupport {
|
||||||
assertEquals(frame1.getBody(), "message 2");
|
assertEquals(frame1.getBody(), "message 2");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
StompFrame frame2 = stompConnection.receive(500);
|
StompFrame frame2 = stompConnection.receive(500);
|
||||||
if (frame2 != null) {
|
if (frame2 != null) {
|
||||||
fail("Should not have received the second message");
|
fail("Should not have received the second message");
|
||||||
}
|
}
|
||||||
} catch (SocketTimeoutException soe) {}
|
} catch (SocketTimeoutException soe) {}
|
||||||
|
|
||||||
stompConnection.ack(frame1, "tx1");
|
stompConnection.ack(frame1, "tx1");
|
||||||
|
@ -1006,37 +1000,34 @@ public class StompTest extends CombinationTestSupport {
|
||||||
stompConnection.commit("tx3");
|
stompConnection.commit("tx3");
|
||||||
|
|
||||||
stompDisconnect();
|
stompDisconnect();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTransactionsWithMultipleDestinations() throws Exception {
|
public void testTransactionsWithMultipleDestinations() throws Exception {
|
||||||
|
|
||||||
stompConnection.connect("system", "manager");
|
stompConnection.connect("system", "manager");
|
||||||
|
|
||||||
HashMap<String, String> headers = new HashMap<String, String>();
|
HashMap<String, String> headers = new HashMap<String, String>();
|
||||||
headers.put("activemq.prefetchSize", "1");
|
headers.put("activemq.prefetchSize", "1");
|
||||||
headers.put("activemq.exclusive", "true");
|
headers.put("activemq.exclusive", "true");
|
||||||
|
|
||||||
stompConnection.subscribe("/queue/test1", "client", headers);
|
stompConnection.subscribe("/queue/test1", "client", headers);
|
||||||
|
|
||||||
stompConnection.begin("ID:tx1");
|
stompConnection.begin("ID:tx1");
|
||||||
|
|
||||||
headers.clear();
|
headers.clear();
|
||||||
headers.put("receipt", "ID:msg1");
|
headers.put("receipt", "ID:msg1");
|
||||||
stompConnection.send("/queue/test2", "test message", "ID:tx1", headers);
|
stompConnection.send("/queue/test2", "test message", "ID:tx1", headers);
|
||||||
|
|
||||||
stompConnection.commit("ID:tx1");
|
stompConnection.commit("ID:tx1");
|
||||||
|
|
||||||
// make sure connection is active after commit
|
// make sure connection is active after commit
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
stompConnection.send("/queue/test1", "another message");
|
stompConnection.send("/queue/test1", "another message");
|
||||||
|
|
||||||
StompFrame frame = stompConnection.receive(500);
|
StompFrame frame = stompConnection.receive(500);
|
||||||
System.out.println(frame);
|
assertNotNull(frame);
|
||||||
assertNotNull(frame);
|
|
||||||
|
|
||||||
|
stompConnection.disconnect();
|
||||||
stompConnection.disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTempDestination() throws Exception {
|
public void testTempDestination() throws Exception {
|
||||||
|
@ -1057,6 +1048,44 @@ public class StompTest extends CombinationTestSupport {
|
||||||
assertEquals("Hello World", message.getBody());
|
assertEquals("Hello World", message.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testJMSXUserIDIsSetInMessage() throws Exception {
|
||||||
|
|
||||||
|
MessageConsumer consumer = session.createConsumer(queue);
|
||||||
|
|
||||||
|
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
|
||||||
|
stompConnection.sendFrame(frame);
|
||||||
|
|
||||||
|
frame = stompConnection.receiveFrame();
|
||||||
|
assertTrue(frame.startsWith("CONNECTED"));
|
||||||
|
|
||||||
|
frame = "SEND\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World" + Stomp.NULL;
|
||||||
|
|
||||||
|
stompConnection.sendFrame(frame);
|
||||||
|
|
||||||
|
TextMessage message = (TextMessage)consumer.receive(1000);
|
||||||
|
assertNotNull(message);
|
||||||
|
assertEquals("system", message.getStringProperty(Stomp.Headers.Message.USERID));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testJMSXUserIDIsSetInStompMessage() throws Exception {
|
||||||
|
|
||||||
|
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
|
||||||
|
stompConnection.sendFrame(frame);
|
||||||
|
|
||||||
|
frame = stompConnection.receiveFrame();
|
||||||
|
assertTrue(frame.startsWith("CONNECTED"));
|
||||||
|
|
||||||
|
frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "ack:auto\n\n" + Stomp.NULL;
|
||||||
|
stompConnection.sendFrame(frame);
|
||||||
|
|
||||||
|
frame = "SEND\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World" + Stomp.NULL;
|
||||||
|
stompConnection.sendFrame(frame);
|
||||||
|
|
||||||
|
StompFrame message = stompConnection.receive(1000);
|
||||||
|
assertEquals("system", message.getHeaders().get(Stomp.Headers.Message.USERID));
|
||||||
|
}
|
||||||
|
|
||||||
protected void assertClients(int expected) throws Exception {
|
protected void assertClients(int expected) throws Exception {
|
||||||
org.apache.activemq.broker.Connection[] clients = broker.getBroker().getClients();
|
org.apache.activemq.broker.Connection[] clients = broker.getBroker().getClients();
|
||||||
int actual = clients.length;
|
int actual = clients.length;
|
||||||
|
@ -1071,5 +1100,3 @@ public class StompTest extends CombinationTestSupport {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue