This closes #178

This commit is contained in:
Clebert Suconic 2015-09-28 15:35:44 -04:00
commit da17f039a5
3 changed files with 55 additions and 5 deletions

View File

@ -71,6 +71,8 @@ public interface Message {
SimpleString HDR_LAST_VALUE_NAME = new SimpleString("_AMQ_LVQ_NAME");
SimpleString HDR_CONTENT_TYPE = new SimpleString("_AMQ_CONTENT_TYPE");
byte DEFAULT_TYPE = 0;
byte OBJECT_TYPE = 2;

View File

@ -59,6 +59,10 @@ public class StompUtils {
if (groupID != null) {
msg.putStringProperty(Message.HDR_GROUP_ID, SimpleString.toSimpleString(groupID));
}
String contentType = headers.remove(Stomp.Headers.CONTENT_TYPE);
if (contentType != null) {
msg.putStringProperty(Message.HDR_CONTENT_TYPE, SimpleString.toSimpleString(contentType));
}
Object replyTo = headers.remove(Stomp.Headers.Send.REPLY_TO);
if (replyTo != null) {
msg.putStringProperty(ClientMessageImpl.REPLYTO_HEADER_NAME, SimpleString.toSimpleString((String) replyTo));
@ -96,12 +100,16 @@ public class StompUtils {
if (message.getObjectProperty("JMSType") != null) {
command.addHeader(Stomp.Headers.Message.TYPE, message.getObjectProperty("JMSType").toString());
}
if (message.getStringProperty(Message.HDR_CONTENT_TYPE.toString()) != null) {
command.addHeader(Stomp.Headers.CONTENT_TYPE, message.getStringProperty(Message.HDR_CONTENT_TYPE.toString()));
}
// now let's add all the message headers
Set<SimpleString> names = message.getPropertyNames();
for (SimpleString name : names) {
String value = name.toString();
if (name.equals(ClientMessageImpl.REPLYTO_HEADER_NAME) ||
name.equals(Message.HDR_CONTENT_TYPE) ||
value.equals("JMSType") ||
value.equals("JMSCorrelationID") ||
value.equals(Stomp.Headers.Message.DESTINATION)) {

View File

@ -35,6 +35,7 @@ import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame
import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionV11;
import org.apache.activemq.artemis.core.protocol.stomp.Stomp;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.junit.After;
import org.junit.Assert;
@ -2312,9 +2313,48 @@ public class StompV11Test extends StompV11TestBase {
connV11.disconnect();
}
@Test
public void testReceiveContentType() throws Exception {
MessageConsumer consumer = session.createConsumer(queue);
connV11.connect(defUser, defPass);
ClientStompFrame frame = connV11.createFrame("SEND");
frame.addHeader("destination", getQueuePrefix() + getQueueName());
frame.addHeader(Stomp.Headers.CONTENT_TYPE, "text/plain");
frame.setBody("Hello World");
connV11.sendFrame(frame);
TextMessage message = (TextMessage) consumer.receive(1000);
Assert.assertNotNull(message);
Assert.assertEquals(
"text/plain",
message.getStringProperty(
org.apache.activemq.artemis.api.core.Message.HDR_CONTENT_TYPE.toString()));
}
@Test
public void testSendContentType() throws Exception {
connV11.connect(defUser, defPass);
this.subscribe(connV11, "sub1", "auto");
MessageProducer producer = session.createProducer(queue);
BytesMessage message = session.createBytesMessage();
message.setStringProperty(
org.apache.activemq.artemis.api.core.Message.HDR_CONTENT_TYPE.toString(),
"text/plain");
message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
producer.send(message);
ClientStompFrame frame = connV11.receiveFrame();
Assert.assertNotNull(frame);
Assert.assertEquals("text/plain", frame.getHeader(Stomp.Headers.CONTENT_TYPE));
connV11.disconnect();
}
}