qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lqu...@apache.org
Subject [1/4] qpid-broker-j git commit: QPID-7434: [Java Broker] Fix AMQP 0-10 to 1.0 correlationId conversion
Date Wed, 23 Aug 2017 15:36:46 GMT
Repository: qpid-broker-j
Updated Branches:
  refs/heads/master a10f3063b -> d12b40a4d


QPID-7434: [Java Broker] Fix AMQP 0-10 to 1.0 correlationId conversion


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/d12b40a4
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/d12b40a4
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/d12b40a4

Branch: refs/heads/master
Commit: d12b40a4d066d79e5dc38b7b137a73b776817f0a
Parents: a7e4a71
Author: Lorenz Quack <lquack@apache.org>
Authored: Wed Aug 23 15:30:22 2017 +0100
Committer: Lorenz Quack <lquack@apache.org>
Committed: Wed Aug 23 16:36:38 2017 +0100

----------------------------------------------------------------------
 .../MessageConverter_0_10_to_1_0.java           | 25 ++++++++++++++++----
 .../PropertyConverter_0_10_to_1_0Test.java      | 23 ++++++++++++++----
 2 files changed, 39 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d12b40a4/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_0_10_to_1_0.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_0_10_to_1_0.java
b/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_0_10_to_1_0.java
index 5bdfbf5..af4bd9a 100644
--- a/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_0_10_to_1_0.java
+++ b/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/main/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_0_10_to_1_0.java
@@ -21,6 +21,11 @@
 
 package org.apache.qpid.server.protocol.converter.v0_10_v1_0;
 
+import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -28,6 +33,9 @@ import java.util.Map;
 import org.apache.qpid.server.plugin.PluggableService;
 import org.apache.qpid.server.protocol.converter.MessageConversionException;
 import org.apache.qpid.server.protocol.v0_10.MessageTransferMessage;
+import org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties;
+import org.apache.qpid.server.protocol.v0_10.transport.MessageDeliveryMode;
+import org.apache.qpid.server.protocol.v0_10.transport.MessageProperties;
 import org.apache.qpid.server.protocol.v0_10.transport.ReplyTo;
 import org.apache.qpid.server.protocol.v1_0.MessageConverter_to_1_0;
 import org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0;
@@ -37,15 +45,11 @@ import org.apache.qpid.server.protocol.v1_0.type.Symbol;
 import org.apache.qpid.server.protocol.v1_0.type.UnsignedByte;
 import org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger;
 import org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties;
-import org.apache.qpid.server.protocol.v1_0.type.messaging.Data;
 import org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection;
 import org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection;
 import org.apache.qpid.server.protocol.v1_0.type.messaging.Header;
 import org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations;
 import org.apache.qpid.server.protocol.v1_0.type.messaging.Properties;
-import org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties;
-import org.apache.qpid.server.protocol.v0_10.transport.MessageDeliveryMode;
-import org.apache.qpid.server.protocol.v0_10.transport.MessageProperties;
 import org.apache.qpid.server.util.GZIPUtils;
 
 @PluggableService
@@ -123,7 +127,18 @@ public class MessageConverter_0_10_to_1_0  extends MessageConverter_to_1_0<Messa
 
             if(msgProps.hasCorrelationId())
             {
-                props.setCorrelationId(new Binary(msgProps.getCorrelationId()));
+                CharsetDecoder charsetDecoder = StandardCharsets.UTF_8.newDecoder()
+                                                                      .onMalformedInput(CodingErrorAction.REPORT)
+                                                                      .onUnmappableCharacter(CodingErrorAction.REPORT);
+                try
+                {
+                    String correlationIdAsString = charsetDecoder.decode(ByteBuffer.wrap(msgProps.getCorrelationId())).toString();
+                    props.setCorrelationId(correlationIdAsString);
+                }
+                catch (CharacterCodingException e)
+                {
+                    props.setCorrelationId(new Binary(msgProps.getCorrelationId()));
+                }
             }
 
             if(msgProps.hasMessageId())

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d12b40a4/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/PropertyConverter_0_10_to_1_0Test.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/PropertyConverter_0_10_to_1_0Test.java
b/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/PropertyConverter_0_10_to_1_0Test.java
index 30eed53..f9b90f6 100644
--- a/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/PropertyConverter_0_10_to_1_0Test.java
+++ b/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/PropertyConverter_0_10_to_1_0Test.java
@@ -22,6 +22,7 @@
 package org.apache.qpid.server.protocol.converter.v0_10_v1_0;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertArrayEquals;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -178,15 +179,29 @@ public class PropertyConverter_0_10_to_1_0Test extends QpidTestCase
     {
         final String correlationId = "testCorrelationId";
         final MessageProperties messageProperties = new MessageProperties();
-        messageProperties.setCorrelationId(correlationId.getBytes());
+        messageProperties.setCorrelationId(correlationId.getBytes(UTF_8));
         MessageTransferMessage message = createTestMessage(messageProperties);
 
         final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
 
         Properties properties = convertedMessage.getPropertiesSection().getValue();
-        assertEquals("Unexpected correlationId",
-                     correlationId,
-                     new String(((Binary) properties.getCorrelationId()).getArray(), UTF_8));
+        assertEquals("Unexpected correlationId", correlationId, properties.getCorrelationId());
+    }
+
+    public void testBinaryCorrelationIdConversion()
+    {
+        final byte[] correlationId = new byte[]{0x00, (byte) 0xff, (byte) 0xc3};
+        final MessageProperties messageProperties = new MessageProperties();
+        messageProperties.setCorrelationId(correlationId);
+        MessageTransferMessage message = createTestMessage(messageProperties);
+
+        final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
+
+        Properties properties = convertedMessage.getPropertiesSection().getValue();
+        assertTrue(String.format("Unexpected correlationId type. expected 'Binary' actual
'%s'",
+                                 properties.getCorrelationId().getClass().getSimpleName()),
+                   properties.getCorrelationId() instanceof Binary);
+        assertArrayEquals("Unexpected correlationId", correlationId, ((Binary) properties.getCorrelationId()).getArray());
     }
 
     public void testReplyToConversionWhenExchangeAndRoutingKeySpecified()


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


Mime
View raw message