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

@ -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 {
@ -961,8 +957,6 @@ public class StompTest extends CombinationTestSupport {
sendMessage("message 4");
sendMessage("message 5");
StompFrame frame = stompConnection.receive();
assertEquals(frame.getBody(), "message 1");
@ -1006,7 +1000,6 @@ public class StompTest extends CombinationTestSupport {
stompConnection.commit("tx3");
stompDisconnect();
}
public void testTransactionsWithMultipleDestinations() throws Exception {
@ -1032,10 +1025,8 @@ public class StompTest extends CombinationTestSupport {
stompConnection.send("/queue/test1", "another message");
StompFrame frame = stompConnection.receive(500);
System.out.println(frame);
assertNotNull(frame);
stompConnection.disconnect();
}
@ -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);
}
}