You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2013/11/25 20:48:48 UTC

git commit: fix for: https://issues.apache.org/jira/browse/AMQ-4893

Updated Branches:
  refs/heads/trunk b0e91d47f -> a6e306437


fix for: https://issues.apache.org/jira/browse/AMQ-4893

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/a6e30643
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/a6e30643
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/a6e30643

Branch: refs/heads/trunk
Commit: a6e306437efafc13cf2c2e9d681d5685fdfbcfce
Parents: b0e91d4
Author: Timothy Bish <ta...@gmai.com>
Authored: Mon Nov 25 14:48:38 2013 -0500
Committer: Timothy Bish <ta...@gmai.com>
Committed: Mon Nov 25 14:48:38 2013 -0500

----------------------------------------------------------------------
 .../activemq/command/ActiveMQMessage.java       |  5 ++
 activemq-unit-tests/.gitignore                  |  3 +
 .../org/apache/activemq/bugs/AMQ4893Test.java   | 69 ++++++++++++++++++++
 3 files changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/a6e30643/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
index e673d96..eef6c11 100755
--- a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
+++ b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
@@ -38,6 +38,7 @@ import org.apache.activemq.state.CommandVisitor;
 import org.apache.activemq.util.Callback;
 import org.apache.activemq.util.JMSExceptionSupport;
 import org.apache.activemq.util.TypeConversionSupport;
+import org.fusesource.hawtbuf.UTF8Buffer;
 
 /**
  *
@@ -484,6 +485,10 @@ public class ActiveMQMessage extends Message implements org.apache.activemq.Mess
             throw new IllegalArgumentException("Property name cannot be empty or null");
         }
 
+        if (value instanceof UTF8Buffer) {
+            value = value.toString();
+        }
+
         checkValidObject(value);
         value = convertScheduled(name, value);
         PropertySetter setter = JMS_PROPERTY_SETERS.get(name);

http://git-wip-us.apache.org/repos/asf/activemq/blob/a6e30643/activemq-unit-tests/.gitignore
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/.gitignore b/activemq-unit-tests/.gitignore
new file mode 100644
index 0000000..d2b46e9
--- /dev/null
+++ b/activemq-unit-tests/.gitignore
@@ -0,0 +1,3 @@
+/createData
+/derbydb_15
+/testJdbcConfig

http://git-wip-us.apache.org/repos/asf/activemq/blob/a6e30643/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4893Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4893Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4893Test.java
new file mode 100644
index 0000000..d78000d
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4893Test.java
@@ -0,0 +1,69 @@
+package org.apache.activemq.bugs;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.jms.JMSException;
+
+import org.apache.activemq.command.ActiveMQObjectMessage;
+import org.apache.activemq.openwire.OpenWireFormat;
+import org.apache.activemq.util.ByteSequence;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AMQ4893Test {
+
+    private static final transient Logger LOG = LoggerFactory.getLogger(AMQ4893Test.class);
+
+    @Test
+    public void testPropertiesInt() throws Exception {
+        ActiveMQObjectMessage message = new ActiveMQObjectMessage();
+        message.setIntProperty("TestProp", 333);
+        fakeUnmarshal(message);
+        roundTripProperties(message);
+    }
+
+    @Test
+    public void testPropertiesString() throws Exception {
+        ActiveMQObjectMessage message = new ActiveMQObjectMessage();
+        message.setStringProperty("TestProp", "Value");
+        fakeUnmarshal(message);
+        roundTripProperties(message);
+    }
+
+    @Test
+    public void testPropertiesObject() throws Exception {
+        ActiveMQObjectMessage message = new ActiveMQObjectMessage();
+        message.setObjectProperty("TestProp", "Value");
+        fakeUnmarshal(message);
+        roundTripProperties(message);
+    }
+
+    @Test
+    public void testPropertiesObjectNoMarshalling() throws Exception {
+        ActiveMQObjectMessage message = new ActiveMQObjectMessage();
+        message.setObjectProperty("TestProp", "Value");
+        roundTripProperties(message);
+    }
+
+    private void roundTripProperties(ActiveMQObjectMessage message) throws IOException, JMSException {
+        ActiveMQObjectMessage copy = new ActiveMQObjectMessage();
+        for (Map.Entry<String, Object> prop : message.getProperties().entrySet()) {
+            LOG.debug("{} -> {}", prop.getKey(), prop.getValue().getClass());
+            copy.setObjectProperty(prop.getKey(), prop.getValue());
+        }
+    }
+
+    private void fakeUnmarshal(ActiveMQObjectMessage message) throws IOException {
+        // we need to force the unmarshalled property field to be set so it
+        // gives us a hawtbuffer for the string
+        OpenWireFormat format = new OpenWireFormat();
+        message.beforeMarshall(format);
+        message.afterMarshall(format);
+
+        ByteSequence seq = message.getMarshalledProperties();
+        message.clearProperties();
+        message.setMarshalledProperties(seq);
+    }
+}
\ No newline at end of file