Author: robbie
Date: Tue Oct 14 15:33:50 2014
New Revision: 1631795
URL: http://svn.apache.org/r1631795
Log:
PROTON-711: add support (disabled by default) for using a byte value for
destination type annotations during inbound transformation
Modified:
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java
qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java
Modified:
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java?rev=1631795&r1=1631794&r2=1631795&view=diff
==============================================================================
---
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java
(original)
+++
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java
Tue Oct 14 15:33:50 2014
@@ -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;
}
Modified:
qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java?rev=1631795&r1=1631794&r2=1631795&view=diff
==============================================================================
---
qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java
(original)
+++
qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java
Tue Oct 14 15:33:50 2014
@@ -60,41 +60,78 @@ public class JMSMappingInboundTransforme
// ======= 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 JMSMappingInboundTransforme
// ======= 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]