This is an automated email from the ASF dual-hosted git repository. robbie pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/qpid-jms.git
The following commit(s) were added to refs/heads/master by this push: new a39599e QPIDJMS-485: move bytes message facade content-type handling to onSend, have copy simply copy a39599e is described below commit a39599e376c82421e3e200188f46d3a652c4f63d Author: Robbie Gemmell <rob...@apache.org> AuthorDate: Wed Feb 12 17:16:12 2020 +0000 QPIDJMS-485: move bytes message facade content-type handling to onSend, have copy simply copy --- .../amqp/message/AmqpJmsBytesMessageFacade.java | 6 ++-- .../amqp/message/AmqpJmsMessageFacade.java | 2 +- .../message/AmqpJmsBytesMessageFacadeTest.java | 42 +++++++++++++++------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsBytesMessageFacade.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsBytesMessageFacade.java index b84d492..2ca21c4 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsBytesMessageFacade.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsBytesMessageFacade.java @@ -52,7 +52,6 @@ public class AmqpJmsBytesMessageFacade extends AmqpJmsMessageFacade implements J @Override protected void initializeEmptyBody() { - setContentType(OCTET_STREAM_CONTENT_TYPE); setBody(EMPTY_BODY); } @@ -63,7 +62,6 @@ public class AmqpJmsBytesMessageFacade extends AmqpJmsMessageFacade implements J copyInto(copy); Binary payload = getBinaryFromBody(); - copy.setContentType(OCTET_STREAM_CONTENT_TYPE); if (payload.getLength() > 0) { copy.setBody(new Data(payload)); } else { @@ -220,6 +218,10 @@ public class AmqpJmsBytesMessageFacade extends AmqpJmsMessageFacade implements J public void onSend(long producerTtl) throws JMSException { super.onSend(producerTtl); + if(getContentType() == null) { + setContentType(OCTET_STREAM_CONTENT_TYPE); + } + reset(); } } diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java index 5362416..5051c5e 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java @@ -140,7 +140,7 @@ public class AmqpJmsMessageFacade implements JmsMessageFacade { * @return a Symbol value indicating the message content type. */ public Symbol getContentType() { - if (properties != null && properties.getContentType() != null) { + if (properties != null) { return properties.getContentType(); } diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsBytesMessageFacadeTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsBytesMessageFacadeTest.java index e982bed..e4196c8 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsBytesMessageFacadeTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsBytesMessageFacadeTest.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.Arrays; import org.apache.qpid.proton.amqp.Binary; +import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.messaging.AmqpSequence; import org.apache.qpid.proton.amqp.messaging.AmqpValue; import org.apache.qpid.proton.amqp.messaging.Data; @@ -85,19 +86,6 @@ public class AmqpJmsBytesMessageFacadeTest extends AmqpJmsMessageTypesTestCase { assertEquals("Message reports unexpected length", 0, amqpBytesMessageFacade.getBodyLength()); } - @Test - public void testNewMessageHasContentType() throws Exception { - AmqpJmsBytesMessageFacade amqpBytesMessageFacade = createNewBytesMessageFacade(); - - Properties properties = amqpBytesMessageFacade.getProperties(); - assertNotNull(properties); - assertNotNull(properties.getContentType()); - - String contentType = properties.getContentType().toString(); - assertNotNull("content type should be set", contentType); - assertEquals("application/octet-stream", contentType); - } - // ---------- test for normal message operations -------------------------// @Test @@ -171,6 +159,34 @@ public class AmqpJmsBytesMessageFacadeTest extends AmqpJmsMessageTypesTestCase { assertDataBodyAsExpected(copy.getBody(), 0); } + @Test + public void testCopyOfContentType() throws Exception { + AmqpJmsBytesMessageFacade amqpBytesMessageFacade1 = createNewBytesMessageFacade(); + AmqpJmsBytesMessageFacade copy1 = amqpBytesMessageFacade1.copy(); + assertNull(copy1.getContentType()); + + AmqpJmsBytesMessageFacade amqpBytesMessageFacade2 = createNewBytesMessageFacade(); + Symbol contentType = Symbol.valueOf("content-type"); + amqpBytesMessageFacade2.setContentType(contentType); + + AmqpJmsBytesMessageFacade copy2 = amqpBytesMessageFacade2.copy(); + assertEquals(contentType, copy2.getContentType()); + } + + @Test + public void testMessageToSendHasContentTypeSet() throws Exception { + AmqpJmsBytesMessageFacade amqpBytesMessageFacade = createNewBytesMessageFacade(); + amqpBytesMessageFacade.onSend(0); + + Properties properties = amqpBytesMessageFacade.getProperties(); + assertNotNull(properties); + assertNotNull(properties.getContentType()); + + String contentType = properties.getContentType().toString(); + assertNotNull("content type should be set", contentType); + assertEquals("application/octet-stream", contentType); + } + /** * Test that copying a new messages which has a body and the copy has getOutputStream * called which clears the message body doesn't affect the original. --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org