git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@906071 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2010-02-03 14:42:33 +00:00
parent 5170a8bba3
commit caabb6cb3d
3 changed files with 178 additions and 146 deletions

View File

@ -74,6 +74,10 @@ public interface FrameTranslator {
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
final Map<String, Object> properties = message.getProperties();
if (properties != null) {

View File

@ -76,6 +76,7 @@ public interface Stomp {
String TIMESTAMP = "timestamp";
String TYPE = "type";
String SUBSCRIPTION = "subscription";
String USERID = "JMSXUserID";
}
public interface Subscribe {

View File

@ -133,14 +133,14 @@ public class StompTest extends CombinationTestSupport {
}
protected void tearDown() throws Exception {
try {
connection.close();
stompDisconnect();
} catch(Exception e) {
// Some tests explicitly disconnect from stomp so can ignore
} finally {
broker.stop();
}
try {
connection.close();
stompDisconnect();
} catch(Exception e) {
// Some tests explicitly disconnect from stomp so can ignore
} finally {
broker.stop();
}
}
private void stompDisconnect() throws IOException {
@ -470,9 +470,7 @@ public class StompTest extends CombinationTestSupport {
LOG.info("Received frame: " + frame);
fail("No message should have been received since subscription was removed");
} catch (SocketTimeoutException e) {
}
}
public void testTransactionCommit() throws Exception {
@ -563,7 +561,6 @@ public class StompTest extends CombinationTestSupport {
assertTrue(f.startsWith("ERROR"));
assertClients(1);
}
public void testConnectNotAuthenticatedWrongPassword() throws Exception {
@ -590,7 +587,6 @@ public class StompTest extends CombinationTestSupport {
stompConnection.sendFrame(frame);
String f = stompConnection.receiveFrame();
assertTrue(f.startsWith("ERROR"));
}
public void testSubscribeNotAuthorized() throws Exception {
@ -885,14 +881,14 @@ public class StompTest extends CombinationTestSupport {
}
public void testDurableUnsub() throws Exception {
// get broker JMX view
// get broker JMX view
String domain = "org.apache.activemq";
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;
stompConnection.sendFrame(frame);
@ -905,7 +901,7 @@ public class StompTest extends CombinationTestSupport {
stompConnection.sendFrame(frame);
// wait a bit for MBean to get refreshed
try {
Thread.sleep(400);
Thread.sleep(400);
} catch (InterruptedException e){}
assertEquals(view.getDurableTopicSubscribers().length, 1);
@ -913,12 +909,12 @@ public class StompTest extends CombinationTestSupport {
frame = "DISCONNECT\nclient-id:test\n\n" + Stomp.NULL;
stompConnection.sendFrame(frame);
try {
Thread.sleep(400);
Thread.sleep(400);
} catch (InterruptedException e){}
//reconnect
stompConnect();
// connect
// connect
frame = "CONNECT\n" + "login: system\n" + "passcode: manager\nclient-id:test\n\n" + Stomp.NULL;
stompConnection.sendFrame(frame);
frame = stompConnection.receiveFrame();
@ -930,7 +926,7 @@ public class StompTest extends CombinationTestSupport {
frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
stompConnection.sendFrame(frame);
try {
Thread.sleep(400);
Thread.sleep(400);
} catch (InterruptedException e){}
assertEquals(view.getDurableTopicSubscribers().length, 0);
}
@ -961,8 +957,6 @@ public class StompTest extends CombinationTestSupport {
sendMessage("message 4");
sendMessage("message 5");
StompFrame frame = stompConnection.receive();
assertEquals(frame.getBody(), "message 1");
@ -973,10 +967,10 @@ public class StompTest extends CombinationTestSupport {
assertEquals(frame1.getBody(), "message 2");
try {
StompFrame frame2 = stompConnection.receive(500);
if (frame2 != null) {
fail("Should not have received the second message");
}
StompFrame frame2 = stompConnection.receive(500);
if (frame2 != null) {
fail("Should not have received the second message");
}
} catch (SocketTimeoutException soe) {}
stompConnection.ack(frame1, "tx1");
@ -1006,37 +1000,34 @@ public class StompTest extends CombinationTestSupport {
stompConnection.commit("tx3");
stompDisconnect();
}
public void testTransactionsWithMultipleDestinations() throws Exception {
stompConnection.connect("system", "manager");
stompConnection.connect("system", "manager");
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("activemq.prefetchSize", "1");
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.put("receipt", "ID:msg1");
stompConnection.send("/queue/test2", "test message", "ID:tx1", headers);
headers.clear();
headers.put("receipt", "ID:msg1");
stompConnection.send("/queue/test2", "test message", "ID:tx1", headers);
stompConnection.commit("ID:tx1");
stompConnection.commit("ID:tx1");
// make sure connection is active after commit
Thread.sleep(1000);
stompConnection.send("/queue/test1", "another message");
// make sure connection is active after commit
Thread.sleep(1000);
stompConnection.send("/queue/test1", "another message");
StompFrame frame = stompConnection.receive(500);
System.out.println(frame);
assertNotNull(frame);
StompFrame frame = stompConnection.receive(500);
assertNotNull(frame);
stompConnection.disconnect();
stompConnection.disconnect();
}
public void testTempDestination() throws Exception {
@ -1057,6 +1048,44 @@ public class StompTest extends CombinationTestSupport {
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 {
org.apache.activemq.broker.Connection[] clients = broker.getBroker().getClients();
int actual = clients.length;
@ -1071,5 +1100,3 @@ public class StompTest extends CombinationTestSupport {
Thread.sleep(2000);
}
}