PROTON-711: add support (disabled by default) for using a byte value for destination type annotations during inbound transformation
git-svn-id: https://svn.apache.org/repos/asf/qpid/proton/trunk@1631795 13f79535-47bb-0310-9956-ffa450edef68 Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/960eeff9 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/960eeff9 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/960eeff9 Branch: refs/heads/examples Commit: 960eeff9eefa5b8dc52de356d1118ae0b017a319 Parents: 72b7beb Author: Robert Gemmell <[email protected]> Authored: Tue Oct 14 15:33:50 2014 +0000 Committer: Robert Gemmell <[email protected]> Committed: Tue Oct 14 15:33:50 2014 +0000 ---------------------------------------------------------------------- .../qpid/proton/jms/InboundTransformer.java | 84 ++++++++++++----- .../jms/JMSMappingInboundTransformerTest.java | 97 +++++++++++++++++--- 2 files changed, 146 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/960eeff9/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java ---------------------------------------------------------------------- diff --git a/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java b/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java index 0374e6a..cef10c4 100644 --- a/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java +++ b/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java @@ -53,12 +53,22 @@ public abstract class InboundTransformer { int defaultPriority = javax.jms.Message.DEFAULT_PRIORITY; long defaultTtl = javax.jms.Message.DEFAULT_TIME_TO_LIVE; + private boolean useByteDestinationTypeAnnotations = false; + public InboundTransformer(JMSVendor vendor) { this.vendor = vendor; } abstract public Message transform(EncodedMessage amqpMessage) throws Exception; + public boolean isUseByteDestinationTypeAnnotations() { + return useByteDestinationTypeAnnotations; + } + + public void setUseByteDestinationTypeAnnotations(boolean useByteDestinationTypeAnnotations) { + this.useByteDestinationTypeAnnotations = useByteDestinationTypeAnnotations; + } + public int getDefaultDeliveryMode() { return defaultDeliveryMode; } @@ -130,8 +140,16 @@ public abstract class InboundTransformer { } } - Class<? extends Destination> toAttributes = Destination.class; - Class<? extends Destination> replyToAttributes = Destination.class; + Class<? extends Destination> toAttributes = null; + Class<? extends Destination> replyToAttributes = null; + + if (isUseByteDestinationTypeAnnotations()){ + toAttributes = Queue.class; + replyToAttributes = Queue.class; + } else { + toAttributes = Destination.class; + replyToAttributes = Destination.class; + } final MessageAnnotations ma = amqp.getMessageAnnotations(); if( ma!=null ) { @@ -140,9 +158,9 @@ public abstract class InboundTransformer { if( "x-opt-jms-type".equals(key.toString()) && entry.getValue() != null ) { jms.setJMSType(entry.getValue().toString()); } else if( "x-opt-to-type".equals(key.toString()) ) { - toAttributes = toClassFromAttributes(entry.getValue().toString()); + toAttributes = toClassFromAttributes(entry.getValue()); } else if( "x-opt-reply-type".equals(key.toString()) ) { - replyToAttributes = toClassFromAttributes(entry.getValue().toString()); + replyToAttributes = toClassFromAttributes(entry.getValue()); } else { setProperty(jms, prefixVendor + prefixMessageAnnotations + key, entry.getValue()); } @@ -246,29 +264,49 @@ public abstract class InboundTransformer { return Collections.unmodifiableSet(s); } - Class<? extends Destination> toClassFromAttributes(String value) + Class<? extends Destination> toClassFromAttributes(Object value) { - if( value ==null ) { - return null; - } - HashSet<String> attributes = new HashSet<String>(); - for( String x: value.split("\\s*,\\s*") ) { - attributes.add(x); - } + if(isUseByteDestinationTypeAnnotations()) { + if(value instanceof Byte) { + switch ((Byte) value) { + case JMSVendor.QUEUE_TYPE: + return Queue.class; + case JMSVendor.TOPIC_TYPE: + return Topic.class; + case JMSVendor.TEMP_QUEUE_TYPE: + return TemporaryQueue.class; + case JMSVendor.TEMP_TOPIC_TYPE: + return TemporaryTopic.class; + default: + return Queue.class; + } + } - if( QUEUE_ATTRIBUTES.equals(attributes) ) { return Queue.class; + } else { + if( value == null ) { + return null; + } + String valueString = value.toString(); + HashSet<String> attributes = new HashSet<String>(); + for( String x: valueString.split("\\s*,\\s*") ) { + attributes.add(x); + } + + if( QUEUE_ATTRIBUTES.equals(attributes) ) { + return Queue.class; + } + if( TOPIC_ATTRIBUTES.equals(attributes) ) { + return Topic.class; + } + if( TEMP_QUEUE_ATTRIBUTES.equals(attributes) ) { + return TemporaryQueue.class; + } + if( TEMP_TOPIC_ATTRIBUTES.equals(attributes) ) { + return TemporaryTopic.class; + } + return Destination.class; } - if( TOPIC_ATTRIBUTES.equals(attributes) ) { - return Topic.class; - } - if( TEMP_QUEUE_ATTRIBUTES.equals(attributes) ) { - return TemporaryQueue.class; - } - if( TEMP_TOPIC_ATTRIBUTES.equals(attributes) ) { - return TemporaryTopic.class; - } - return Destination.class; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/960eeff9/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java ---------------------------------------------------------------------- diff --git a/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java b/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java index 42a99ca..2413310 100644 --- a/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java +++ b/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java @@ -60,41 +60,78 @@ public class JMSMappingInboundTransformerTest // ======= JMSDestination Handling ========= // ========================================= + // --- String type annotation --- @Test public void testTransformWithNoToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl(null, Destination.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl(null, Destination.class, false); } @Test public void testTransformWithQueueStringToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue", Queue.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue", Queue.class, false); } @Test public void testTransformWithTemporaryQueueStringToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue,temporary", TemporaryQueue.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue,temporary", TemporaryQueue.class, false); } @Test public void testTransformWithTopicStringToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic", Topic.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic", Topic.class, false); } @Test public void testTransformWithTemporaryTopicStringToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic,temporary", TemporaryTopic.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic,temporary", TemporaryTopic.class, false); } - private void doTransformWithToTypeDestinationTypeAnnotationTestImpl(Object toTypeAnnotationValue, Class<? extends Destination> expectedClass) throws Exception + // --- byte type annotation --- + + @Test + public void testTransformWithNoToTypeDestinationTypeAnnotationUsingByteAnnotation() throws Exception + { + doTransformWithToTypeDestinationTypeAnnotationTestImpl(null, Queue.class, true); + } + + @Test + public void testTransformWithQueueByteToTypeDestinationTypeAnnotation() throws Exception + { + doTransformWithToTypeDestinationTypeAnnotationTestImpl(JMSVendor.QUEUE_TYPE, Queue.class, true); + } + + @Test + public void testTransformWithTemporaryQueueByteToTypeDestinationTypeAnnotation() throws Exception + { + doTransformWithToTypeDestinationTypeAnnotationTestImpl(JMSVendor.TEMP_QUEUE_TYPE, TemporaryQueue.class, true); + } + + @Test + public void testTransformWithTopicByteToTypeDestinationTypeAnnotation() throws Exception + { + doTransformWithToTypeDestinationTypeAnnotationTestImpl(JMSVendor.TOPIC_TYPE, Topic.class, true); + } + + @Test + public void testTransformWithTemporaryTopicByteToTypeDestinationTypeAnnotation() throws Exception + { + doTransformWithToTypeDestinationTypeAnnotationTestImpl(JMSVendor.TEMP_TOPIC_TYPE, TemporaryTopic.class, true); + } + + private void doTransformWithToTypeDestinationTypeAnnotationTestImpl(Object toTypeAnnotationValue, Class<? extends Destination> expectedClass, boolean byteType) throws Exception { TextMessage mockTextMessage = createMockTextMessage(); JMSVendor mockVendor = createMockVendor(mockTextMessage); JMSMappingInboundTransformer transformer = new JMSMappingInboundTransformer(mockVendor); + if(byteType) + { + transformer.setUseByteDestinationTypeAnnotations(true); + } String toAddress = "toAddress"; Message amqp = Message.Factory.create(); @@ -120,41 +157,77 @@ public class JMSMappingInboundTransformerTest // ======= JMSReplyTo Handling ========= // ===================================== + // --- String type annotation --- @Test public void testTransformWithNoReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(null,Destination.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(null,Destination.class, false); } @Test public void testTransformWithQueueStringReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue", Queue.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue", Queue.class, false); } @Test public void testTransformWithTemporaryQueueStringReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue,temporary", TemporaryQueue.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue,temporary", TemporaryQueue.class, false); } @Test public void testTransformWithTopicStringReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic", Topic.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic", Topic.class, false); } @Test public void testTransformWithTemporaryTopicStringReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic,temporary", TemporaryTopic.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic,temporary", TemporaryTopic.class, false); } - private void doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(Object replyToTypeAnnotationValue, Class<? extends Destination> expectedClass) throws Exception + // --- byte type annotation --- + @Test + public void testTransformWithNoReplyToTypeDestinationTypeAnnotationUsingByteAnnotation() throws Exception + { + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(null,Queue.class, true); + } + + @Test + public void testTransformWithQueueByteReplyToTypeDestinationTypeAnnotation() throws Exception + { + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(JMSVendor.QUEUE_TYPE, Queue.class, true); + } + + @Test + public void testTransformWithTemporaryQueueByteReplyToTypeDestinationTypeAnnotation() throws Exception + { + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(JMSVendor.TEMP_QUEUE_TYPE, TemporaryQueue.class, true); + } + + @Test + public void testTransformWithTopicByteReplyToTypeDestinationTypeAnnotation() throws Exception + { + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(JMSVendor.TOPIC_TYPE, Topic.class, true); + } + + @Test + public void testTransformWithTemporaryTopicByteReplyToTypeDestinationTypeAnnotation() throws Exception + { + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(JMSVendor.TEMP_TOPIC_TYPE, TemporaryTopic.class, true); + } + + private void doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(Object replyToTypeAnnotationValue, Class<? extends Destination> expectedClass, boolean byteType) throws Exception { TextMessage mockTextMessage = createMockTextMessage(); JMSVendor mockVendor = createMockVendor(mockTextMessage); JMSMappingInboundTransformer transformer = new JMSMappingInboundTransformer(mockVendor); + if(byteType) + { + transformer.setUseByteDestinationTypeAnnotations(true); + } String replyToAddress = "replyToAddress"; Message amqp = Message.Factory.create(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
