qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject qpid-jms git commit: QPIDJMS-49: ensure messages with unknown content-type and Data sections are handled as BytesMessage, and those with no sections are handled as Message
Date Fri, 15 May 2015 13:37:31 GMT
Repository: qpid-jms
Updated Branches:
  refs/heads/master a3b319e1a -> 3637ec999


QPIDJMS-49: ensure messages with unknown content-type and Data sections are handled as BytesMessage,
and those with no sections are handled as Message


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/3637ec99
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/3637ec99
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/3637ec99

Branch: refs/heads/master
Commit: 3637ec99936082b377341827813ec2f76333ed2b
Parents: a3b319e
Author: Robert Gemmell <robbie@apache.org>
Authored: Fri May 15 13:02:14 2015 +0100
Committer: Robert Gemmell <robbie@apache.org>
Committed: Fri May 15 13:02:45 2015 +0100

----------------------------------------------------------------------
 .../amqp/message/AmqpJmsMessageBuilder.java     |  8 ++--
 .../amqp/message/AmqpJmsMessageBuilderTest.java | 50 ++++++++++++--------
 .../org/apache/qpid/jms/example/Receiver.java   |  4 +-
 3 files changed, 35 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3637ec99/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java
b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java
index ab9dc61..eb66b03 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java
@@ -117,6 +117,8 @@ public class AmqpJmsMessageBuilder {
                 return createObjectMessage(consumer, message);
             } else if (isContentType(OCTET_STREAM_CONTENT_TYPE, message) || isContentType(null,
message)) {
                 return createBytesMessage(consumer, message);
+            } else {
+                return createMessage(consumer, message);
             }
         } else if (body instanceof Data) {
             // TODO: accept textual content types other than strictly "text/plain"
@@ -126,11 +128,9 @@ public class AmqpJmsMessageBuilder {
                 return createBytesMessage(consumer, message);
             } else if (isContentType(SERIALIZED_JAVA_OBJECT_CONTENT_TYPE, message)) {
                 return createObjectMessage(consumer, message);
+            } else {
+                return createBytesMessage(consumer, message);
             }
-
-            // TODO: should this situation throw an exception, or just become a bytes message?
-            // Content type is set, but not to something we understand above.
-            // Falling through to return null.
         } else if (body instanceof AmqpValue) {
             Object value = ((AmqpValue) body).getValue();
 

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3637ec99/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java
index 71d35b9..569b456 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java
@@ -321,16 +321,20 @@ public class AmqpJmsMessageBuilderTest extends QpidJmsTestCase {
 
     /**
      * Test that a message with no body section, and with the content type set to
-     * an unknown value results in an exception when not otherwise annotated to
+     * an unknown value results in a plain Message when not otherwise annotated to
      * indicate the type of JMS message it is.
      */
-    @Test(expected = IOException.class)
-    public void testNoBodySectionAndUnknownContentTypeThrowsException() throws Exception
{
-        //TODO: decide if this should instead just be a plain Message
+    public void testCreateGenericMessageFromNoBodySectionAndUnknownContentType() throws Exception
{
         Message message = Proton.message();
         message.setContentType("unknown-content-type");
 
-        AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
+        JmsMessage jmsMessage = AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
+        assertNotNull("Message should not be null", jmsMessage);
+        assertEquals("Unexpected message class type", JmsMessage.class, jmsMessage.getClass());
+
+        JmsMessageFacade facade = jmsMessage.getFacade();
+        assertNotNull("Facade should not be null", facade);
+        assertEquals("Unexpected facade class type", AmqpJmsMessageFacade.class, facade.getClass());
     }
 
     // --------- Data Body Section ---------
@@ -357,6 +361,26 @@ public class AmqpJmsMessageBuilderTest extends QpidJmsTestCase {
     }
 
     /**
+     * Test that a message with an empty data body section, and with the content type
+     * set to an unknown value results in a BytesMessage when not otherwise annotated
+     * to indicate the type of JMS message it is.
+     */
+    public void testCreateBytesMessageFromDataWithUnknownContentType() throws Exception {
+        Message message = Proton.message();
+        Binary binary = new Binary(new byte[0]);
+        message.setBody(new Data(binary));
+        message.setContentType("unknown-content-type");
+
+        JmsMessage jmsMessage = AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
+        assertNotNull("Message should not be null", jmsMessage);
+        assertEquals("Unexpected message class type", JmsBytesMessage.class, jmsMessage.getClass());
+
+        JmsMessageFacade facade = jmsMessage.getFacade();
+        assertNotNull("Facade should not be null", facade);
+        assertEquals("Unexpected facade class type", AmqpJmsBytesMessageFacade.class, facade.getClass());
+    }
+
+    /**
      * Test that a receiving a data body containing nothing and no content type being set
      * results in a BytesMessage when not otherwise annotated to indicate the type of
      * JMS message it is.
@@ -423,22 +447,6 @@ public class AmqpJmsMessageBuilderTest extends QpidJmsTestCase {
         assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass());
     }
 
-    /**
-     * Test that a message with a data body section, and with the content type set
-     * to an unknown value results in an exception when not otherwise annotated to
-     * indicate the type of JMS message it is.
-     */
-    @Test(expected = IOException.class)
-    public void testDataWithUnknownContentTypeAndEmptyBinaryThrowsException() throws Exception
{
-        //TODO: decide if this should instead just be a plain Message or BytesMessage instead?
-        Message message = Proton.message();
-        Binary binary = new Binary(new byte[0]);
-        message.setBody(new Data(binary));
-        message.setContentType("unknown-content-type");
-
-        AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
-    }
-
     // --------- AmqpValue Body Section ---------
 
     /**

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/3637ec99/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Receiver.java
----------------------------------------------------------------------
diff --git a/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Receiver.java b/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Receiver.java
index c9e4997..a16dc11 100644
--- a/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Receiver.java
+++ b/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Receiver.java
@@ -25,9 +25,9 @@ import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
 import javax.jms.ExceptionListener;
 import javax.jms.JMSException;
+import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.Session;
-import javax.jms.TextMessage;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 
@@ -69,7 +69,7 @@ public class Receiver {
             boolean deductTimeout = false;
             int timeout = 1000;
             for (int i = 1; i <= count; i++, actualCount++) {
-                TextMessage message = (TextMessage) messageConsumer.receive(timeout);
+                Message message = messageConsumer.receive(timeout);
                 if (message == null) {
                     System.out.println("Message " + i + " not received within timeout, stopping.");
                     deductTimeout = true;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message