activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michaelpea...@apache.org
Subject [activemq-nms-amqp] branch master updated: AMQNET-612: ObjectMessage shouldn't have jms-msg-type set
Date Fri, 13 Sep 2019 19:28:31 GMT
This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-nms-amqp.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e0f0ba  AMQNET-612: ObjectMessage shouldn't have jms-msg-type set
     new ab1cb2e  Merge pull request #31 from Havret/do_not_add_jms_msg_type_to_dot_net_serializable_object_msg
3e0f0ba is described below

commit 3e0f0baf2f3952c7d5037c6b66a1d49b1f4a6848
Author: Havret <h4vret@gmail.com>
AuthorDate: Wed Sep 11 23:51:44 2019 +0200

    AMQNET-612: ObjectMessage shouldn't have jms-msg-type set
---
 src/NMS.AMQP/Message/Facade/INmsMessageFacade.cs   |  2 +-
 src/NMS.AMQP/Provider/Amqp/Message/AmqpCodec.cs    | 24 +++++++++++++---------
 .../Amqp/Message/AmqpNmsBytesMessageFacade.cs      |  2 +-
 .../Amqp/Message/AmqpNmsMapMessageFacade.cs        |  2 +-
 .../Provider/Amqp/Message/AmqpNmsMessageFacade.cs  |  2 +-
 .../Amqp/Message/AmqpNmsObjectMessageFacade.cs     |  2 +-
 .../Amqp/Message/AmqpNmsStreamMessageFacade.cs     |  2 +-
 .../Amqp/Message/AmqpNmsTextMessageFacade.cs       |  2 +-
 .../Message/Facade/NmsTestMessageFacade.cs         |  2 +-
 .../Provider/Amqp/AmqpCodecTest.cs                 |  1 -
 .../Provider/Amqp/AmqpMessageFactoryTest.cs        |  4 ++--
 .../Amqp/AmqpNmsObjectMessageFacadeTest.cs         |  2 +-
 12 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/src/NMS.AMQP/Message/Facade/INmsMessageFacade.cs b/src/NMS.AMQP/Message/Facade/INmsMessageFacade.cs
index 4b855ff..f6e7a94 100644
--- a/src/NMS.AMQP/Message/Facade/INmsMessageFacade.cs
+++ b/src/NMS.AMQP/Message/Facade/INmsMessageFacade.cs
@@ -38,7 +38,7 @@ namespace Apache.NMS.AMQP.Message.Facade
         string GroupId { get; set; }
         uint GroupSequence { get; set; }
         DateTime? Expiration { get; set; }
-        sbyte JmsMsgType { get; }
+        sbyte? JmsMsgType { get; }
         
         /// <summary>
         /// True if this message is tagged as being persistent
diff --git a/src/NMS.AMQP/Provider/Amqp/Message/AmqpCodec.cs b/src/NMS.AMQP/Provider/Amqp/Message/AmqpCodec.cs
index f371610..299657f 100644
--- a/src/NMS.AMQP/Provider/Amqp/Message/AmqpCodec.cs
+++ b/src/NMS.AMQP/Provider/Amqp/Message/AmqpCodec.cs
@@ -28,7 +28,7 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
         public static INmsMessageFacade DecodeMessage(IAmqpConsumer consumer, global::Amqp.Message
amqpMessage)
         {
             // First we try the easy way, if the annotation is there we don't have to work
hard.
-            AmqpNmsMessageFacade result = CreateFromMsgAnnotation(amqpMessage.MessageAnnotations);
+            AmqpNmsMessageFacade result = CreateFromMsgAnnotation(amqpMessage);
             if (result == null)
             {
                 // Next, match specific section structures and content types
@@ -44,9 +44,9 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
             throw new NMSException("Could not create a NMS message from incoming message");
         }
 
-        private static AmqpNmsMessageFacade CreateFromMsgAnnotation(MessageAnnotations messageAnnotations)
+        private static AmqpNmsMessageFacade CreateFromMsgAnnotation(global::Amqp.Message
message)
         {
-            object annotation = messageAnnotations?[SymbolUtil.JMSX_OPT_MSG_TYPE];
+            object annotation = message.MessageAnnotations?[SymbolUtil.JMSX_OPT_MSG_TYPE];
 
             if (annotation != null)
             {
@@ -55,16 +55,19 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
                 {
                     case MessageSupport.JMS_TYPE_MSG:
                         return new AmqpNmsMessageFacade();
-                    case MessageSupport.JMS_TYPE_BYTE:
-                        return new AmqpNmsBytesMessageFacade();
                     case MessageSupport.JMS_TYPE_TXT:
                         return new AmqpNmsTextMessageFacade();
-                    case MessageSupport.JMS_TYPE_OBJ:
-                        return new AmqpNmsObjectMessageFacade();
                     case MessageSupport.JMS_TYPE_STRM:
                         return new AmqpNmsStreamMessageFacade();
                     case MessageSupport.JMS_TYPE_MAP:
                         return new AmqpNmsMapMessageFacade();
+                    case MessageSupport.JMS_TYPE_BYTE:
+                    // Java serialized objects should be treated as bytes messages
+                    // as we cannot deserialize them in .NET world
+                    case MessageSupport.JMS_TYPE_OBJ when IsContentType(SymbolUtil.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE,
GetContentType(message.Properties)):
+                        return new AmqpNmsBytesMessageFacade();
+                    case MessageSupport.JMS_TYPE_OBJ:
+                        return new AmqpNmsObjectMessageFacade();
                     default:
                         throw new NMSException("Invalid Message Type annotation value found
in message: " + annotation);
                 }
@@ -130,9 +133,10 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
         {
             if (messageFacade.Message.MessageAnnotations == null) 
                 messageFacade.Message.MessageAnnotations = new MessageAnnotations();
-            
-            messageFacade.Message.MessageAnnotations[SymbolUtil.JMSX_OPT_MSG_TYPE] = messageFacade.JmsMsgType;
-            
+
+            if (messageFacade.JmsMsgType.HasValue) 
+                messageFacade.Message.MessageAnnotations[SymbolUtil.JMSX_OPT_MSG_TYPE] =
messageFacade.JmsMsgType.Value;
+
             AmqpDestinationHelper.SetToAnnotationFromDestination(messageFacade.NMSDestination,
messageFacade.Message.MessageAnnotations);
             AmqpDestinationHelper.SetReplyToAnnotationFromDestination(messageFacade.NMSReplyTo,
messageFacade.Message.MessageAnnotations);
         }
diff --git a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsBytesMessageFacade.cs b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsBytesMessageFacade.cs
index 84e167e..e61ddfb 100644
--- a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsBytesMessageFacade.cs
+++ b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsBytesMessageFacade.cs
@@ -33,7 +33,7 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
 
         private static readonly Data EMPTY_DATA = new Data { Binary = new byte[0] };
 
-        public override sbyte JmsMsgType => MessageSupport.JMS_TYPE_BYTE;
+        public override sbyte? JmsMsgType => MessageSupport.JMS_TYPE_BYTE;
         public long BodyLength => GetBinaryFromBody().Binary.LongLength;
 
         public BinaryReader GetDataReader()
diff --git a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsMapMessageFacade.cs b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsMapMessageFacade.cs
index 8be31cf..ae09084 100644
--- a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsMapMessageFacade.cs
+++ b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsMapMessageFacade.cs
@@ -29,7 +29,7 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
         private AMQPValueMap map;
         public IPrimitiveMap Map => map;
 
-        public override sbyte JmsMsgType => MessageSupport.JMS_TYPE_MAP;
+        public override sbyte? JmsMsgType => MessageSupport.JMS_TYPE_MAP;
 
         protected override void InitializeEmptyBody()
         {
diff --git a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsMessageFacade.cs b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsMessageFacade.cs
index 6766602..183f215 100644
--- a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsMessageFacade.cs
+++ b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsMessageFacade.cs
@@ -333,7 +333,7 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
         }
 
         public MessageAnnotations MessageAnnotations => Message.MessageAnnotations;
-        public virtual sbyte JmsMsgType => MessageSupport.JMS_TYPE_MSG;
+        public virtual sbyte? JmsMsgType => MessageSupport.JMS_TYPE_MSG;
 
         /// <summary>
         /// The annotation value for the JMS Message content type.  For a generic JMS message
this
diff --git a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsObjectMessageFacade.cs b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsObjectMessageFacade.cs
index 115521c..3e64d71 100644
--- a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsObjectMessageFacade.cs
+++ b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsObjectMessageFacade.cs
@@ -35,7 +35,7 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
             set => Delegate.Object = value;
         }
 
-        public override sbyte JmsMsgType => MessageSupport.JMS_TYPE_OBJ;
+        public override sbyte? JmsMsgType => typeDelegate is AmqpTypedObjectDelegate ?
(sbyte?) MessageSupport.JMS_TYPE_OBJ : null;
 
         public override void OnSend(TimeSpan producerTtl)
         {
diff --git a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsStreamMessageFacade.cs b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsStreamMessageFacade.cs
index 509f7ef..18fc051 100644
--- a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsStreamMessageFacade.cs
+++ b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsStreamMessageFacade.cs
@@ -30,7 +30,7 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
         private IList list;
         private int position = 0;
         
-        public override sbyte JmsMsgType => MessageSupport.JMS_TYPE_STRM;
+        public override sbyte? JmsMsgType => MessageSupport.JMS_TYPE_STRM;
 
         public object Peek()
         {
diff --git a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsTextMessageFacade.cs b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsTextMessageFacade.cs
index 01610d6..dd3cf81 100644
--- a/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsTextMessageFacade.cs
+++ b/src/NMS.AMQP/Provider/Amqp/Message/AmqpNmsTextMessageFacade.cs
@@ -83,7 +83,7 @@ namespace Apache.NMS.AMQP.Provider.Amqp.Message
             }
         }
 
-        public override sbyte JmsMsgType => MessageSupport.JMS_TYPE_TXT;
+        public override sbyte? JmsMsgType => MessageSupport.JMS_TYPE_TXT;
 
         private static string DecodeBinaryBody(byte[] body)
         {
diff --git a/test/Apache-NMS-AMQP-Test/Message/Facade/NmsTestMessageFacade.cs b/test/Apache-NMS-AMQP-Test/Message/Facade/NmsTestMessageFacade.cs
index b1d017d..cc3a697 100644
--- a/test/Apache-NMS-AMQP-Test/Message/Facade/NmsTestMessageFacade.cs
+++ b/test/Apache-NMS-AMQP-Test/Message/Facade/NmsTestMessageFacade.cs
@@ -75,7 +75,7 @@ namespace NMS.AMQP.Test.Message.Facade
         public string GroupId { get; set; }
         public uint GroupSequence { get; set; }
         public DateTime? Expiration { get; set; }
-        public sbyte JmsMsgType { get; }
+        public sbyte? JmsMsgType { get; }
         public bool IsPersistent { get; set; }
 
         public INmsMessageFacade Copy()
diff --git a/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpCodecTest.cs b/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpCodecTest.cs
index ffeb404..5677366 100644
--- a/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpCodecTest.cs
+++ b/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpCodecTest.cs
@@ -458,7 +458,6 @@ namespace NMS.AMQP.Test.Provider.Amqp
             DoTestNMSMessageEncodingAddsProperMessageAnnotations(MessageSupport.JMS_TYPE_MAP,
null, MessageSupport.JMS_DEST_TYPE_TEMP_QUEUE);
             DoTestNMSMessageEncodingAddsProperMessageAnnotations(MessageSupport.JMS_TYPE_TXT,
MessageSupport.JMS_DEST_TYPE_TOPIC, MessageSupport.JMS_DEST_TYPE_TEMP_QUEUE);
             DoTestNMSMessageEncodingAddsProperMessageAnnotations(MessageSupport.JMS_TYPE_STRM,
MessageSupport.JMS_DEST_TYPE_QUEUE, MessageSupport.JMS_DEST_TYPE_TEMP_QUEUE);
-            DoTestNMSMessageEncodingAddsProperMessageAnnotations(MessageSupport.JMS_TYPE_OBJ,
MessageSupport.JMS_DEST_TYPE_QUEUE, MessageSupport.JMS_DEST_TYPE_TEMP_QUEUE);
         }
 
         private void DoTestNMSMessageEncodingAddsProperMessageAnnotations(sbyte msgType,
byte? toType, byte? replyToType)
diff --git a/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpMessageFactoryTest.cs b/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpMessageFactoryTest.cs
index 450963a..562048f 100644
--- a/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpMessageFactoryTest.cs
+++ b/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpMessageFactoryTest.cs
@@ -121,7 +121,7 @@ namespace NMS.AMQP.Test.Provider.Amqp
 
             Assert.IsInstanceOf<NmsObjectMessage>(message);
             Assert.IsInstanceOf<AmqpNmsObjectMessageFacade>(facade);
-            Assert.AreEqual(MessageSupport.JMS_TYPE_OBJ, facade.JmsMsgType);
+            Assert.IsNull(facade.JmsMsgType);
 
             Assert.IsNull(((AmqpNmsObjectMessageFacade) facade).Body);
         }
@@ -137,7 +137,7 @@ namespace NMS.AMQP.Test.Provider.Amqp
 
             Assert.IsInstanceOf<NmsObjectMessage>(message);
             Assert.IsInstanceOf<AmqpNmsObjectMessageFacade>(facade);
-            Assert.AreEqual(MessageSupport.JMS_TYPE_OBJ, facade.JmsMsgType);
+            Assert.IsNull(facade.JmsMsgType);
 
             AmqpNmsObjectMessageFacade objectMessageFacade = (AmqpNmsObjectMessageFacade)
facade;
 
diff --git a/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpNmsObjectMessageFacadeTest.cs b/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpNmsObjectMessageFacadeTest.cs
index 015b64b..29a077f 100644
--- a/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpNmsObjectMessageFacadeTest.cs
+++ b/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpNmsObjectMessageFacadeTest.cs
@@ -39,7 +39,7 @@ namespace NMS.AMQP.Test.Provider.Amqp
             AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(false);
             Assert.Null(amqpObjectMessageFacade.MessageAnnotations);
 
-            Assert.AreEqual(MessageSupport.JMS_TYPE_OBJ, amqpObjectMessageFacade.JmsMsgType);
+            Assert.IsNull(amqpObjectMessageFacade.JmsMsgType);
         }
 
         [Test]


Mime
View raw message