From 235380d5dffda4858b2fc363792e0998f17f0d46 Mon Sep 17 00:00:00 2001 From: Julian Scheid Date: Fri, 25 Sep 2015 18:08:57 +0200 Subject: [PATCH 1/2] ARTEMIS-230 Copy STOMP content-header back and forth --- .../org/apache/activemq/artemis/api/core/Message.java | 2 ++ .../activemq/artemis/core/protocol/stomp/StompUtils.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/Message.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/Message.java index 4c2d742604..30b8235a68 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/Message.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/Message.java @@ -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; diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompUtils.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompUtils.java index e676431707..d8468b175f 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompUtils.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompUtils.java @@ -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 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)) { From 7fb30547f4ad1d3cfbfbb6e1bc7f7c2f78105d92 Mon Sep 17 00:00:00 2001 From: Julian Scheid Date: Mon, 28 Sep 2015 20:09:25 +0200 Subject: [PATCH 2/2] Add tests for ARTEMIS-230 --- .../integration/stomp/v11/StompV11Test.java | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java index 945da81737..6c402714fa 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java @@ -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(); + } + } - - - - -