Repository: activemq Updated Branches: refs/heads/activemq-5.9 48a9edc8c -> 687aa9265
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/fcc773a0 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/fcc773a0 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/fcc773a0 Branch: refs/heads/activemq-5.9 Commit: fcc773a05bc55b74d4d09cbd48dd66ea1a764e2d Parents: 48a9edc Author: Timothy Bish <[email protected]> Authored: Mon Nov 25 14:48:38 2013 -0500 Committer: Hadrian Zbarcea <[email protected]> Committed: Wed Mar 12 13:07:48 2014 -0400 ---------------------------------------------------------------------- .../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/fcc773a0/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/fcc773a0/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/fcc773a0/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
