Author: robbie
Date: Tue Oct 14 15:33:34 2014
New Revision: 1631794
URL: http://svn.apache.org/r1631794
Log:
PROTON-711: add support (disabled by default) for using a byte value for
destination type annotations during outbound transformation
Modified:
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/AutoOutboundTransformer.java
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/OutboundTransformer.java
qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformerTest.java
Modified:
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/AutoOutboundTransformer.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/AutoOutboundTransformer.java?rev=1631794&r1=1631793&r2=1631794&view=diff
==============================================================================
---
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/AutoOutboundTransformer.java
(original)
+++
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/AutoOutboundTransformer.java
Tue Oct 14 15:33:34 2014
@@ -46,4 +46,10 @@ public class AutoOutboundTransformer ext
}
}
+ @Override
+ public void setUseByteDestinationTypeAnnotations(boolean
useByteDestinationTypeAnnotations)
+ {
+
super.setUseByteDestinationTypeAnnotations(useByteDestinationTypeAnnotations);
+
transformer.setUseByteDestinationTypeAnnotations(useByteDestinationTypeAnnotations);
+ }
}
Modified:
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java?rev=1631794&r1=1631793&r2=1631794&view=diff
==============================================================================
---
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java
(original)
+++
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java
Tue Oct 14 15:33:34 2014
@@ -224,21 +224,39 @@ public class JMSMappingOutboundTransform
return (ProtonJMessage)
org.apache.qpid.proton.message.Message.Factory.create(header, da, ma, props,
ap, body, footer);
}
- private static String destinationAttributes(Destination destination) {
- if( destination instanceof Queue ) {
- if( destination instanceof TemporaryQueue ) {
- return "temporary,queue";
- } else {
- return "queue";
+ private Object destinationAttributes(Destination destination) {
+ if(isUseByteDestinationTypeAnnotations()) {
+ if( destination instanceof Queue ) {
+ if( destination instanceof TemporaryQueue ) {
+ return JMSVendor.TEMP_QUEUE_TYPE;
+ } else {
+ return JMSVendor.QUEUE_TYPE;
+ }
}
- }
- if( destination instanceof Topic ) {
- if( destination instanceof TemporaryTopic ) {
- return "temporary,topic";
- } else {
- return "topic";
+ if( destination instanceof Topic ) {
+ if( destination instanceof TemporaryTopic ) {
+ return JMSVendor.TEMP_TOPIC_TYPE;
+ } else {
+ return JMSVendor.TOPIC_TYPE;
+ }
+ }
+ return JMSVendor.QUEUE_TYPE;
+ } else {
+ if( destination instanceof Queue ) {
+ if( destination instanceof TemporaryQueue ) {
+ return "temporary,queue";
+ } else {
+ return "queue";
+ }
+ }
+ if( destination instanceof Topic ) {
+ if( destination instanceof TemporaryTopic ) {
+ return "temporary,topic";
+ } else {
+ return "topic";
+ }
}
+ return "";
}
- return "";
}
}
Modified:
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java?rev=1631794&r1=1631793&r2=1631794&view=diff
==============================================================================
---
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java
(original)
+++
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java
Tue Oct 14 15:33:34 2014
@@ -1,15 +1,23 @@
package org.apache.qpid.proton.jms;
-import javax.jms.*;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
+import javax.jms.BytesMessage;
+import javax.jms.Destination;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.StreamMessage;
+import javax.jms.TextMessage;
/**
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
abstract public class JMSVendor {
+ public static final byte QUEUE_TYPE = 0x00;
+ public static final byte TOPIC_TYPE = 0x01;
+ public static final byte TEMP_QUEUE_TYPE = 0x02;
+ public static final byte TEMP_TOPIC_TYPE = 0x03;
+
public abstract BytesMessage createBytesMessage();
public abstract StreamMessage createStreamMessage();
Modified:
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/OutboundTransformer.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/OutboundTransformer.java?rev=1631794&r1=1631793&r2=1631794&view=diff
==============================================================================
---
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/OutboundTransformer.java
(original)
+++
qpid/proton/trunk/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/OutboundTransformer.java
Tue Oct 14 15:33:34 2014
@@ -16,8 +16,6 @@
*/
package org.apache.qpid.proton.jms;
-import org.apache.qpid.proton.engine.Delivery;
-
import javax.jms.Message;
/**
@@ -43,7 +41,7 @@ public abstract class OutboundTransforme
String replyToGroupIDKey;
String prefixFooterKey;
-
+ private boolean useByteDestinationTypeAnnotations;
public OutboundTransformer(JMSVendor vendor) {
this.vendor = vendor;
@@ -52,6 +50,16 @@ public abstract class OutboundTransforme
public abstract EncodedMessage transform(Message jms) throws Exception;
+ public boolean isUseByteDestinationTypeAnnotations()
+ {
+ return useByteDestinationTypeAnnotations;
+ }
+
+ public void setUseByteDestinationTypeAnnotations(boolean
useByteDestinationTypeAnnotations)
+ {
+ this.useByteDestinationTypeAnnotations =
useByteDestinationTypeAnnotations;
+ }
+
public String getPrefixVendor() {
return prefixVendor;
}
Modified:
qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformerTest.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformerTest.java?rev=1631794&r1=1631793&r2=1631794&view=diff
==============================================================================
---
qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformerTest.java
(original)
+++
qpid/proton/trunk/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformerTest.java
Tue Oct 14 15:33:34 2014
@@ -54,13 +54,34 @@ public class JMSMappingOutboundTransform
assertEquals(contentString, ((AmqpValue) amqp.getBody()).getValue());
}
+ @Test
+ public void testDefaultsTolStringDestinationTypeAnnotationValues()
+ {
+ JMSVendor mockVendor = createMockVendor();
+ JMSMappingOutboundTransformer transformer = new
JMSMappingOutboundTransformer(mockVendor);
+
+ assertFalse("Expected the older string style annotation values to be
used by default", transformer.isUseByteDestinationTypeAnnotations());
+ }
+
+ @Test
+ public void testSetGetIsUseByteDestinationTypeAnnotations()
+ {
+ JMSVendor mockVendor = createMockVendor();
+ JMSMappingOutboundTransformer transformer = new
JMSMappingOutboundTransformer(mockVendor);
+
+ assertFalse(transformer.isUseByteDestinationTypeAnnotations());
+ transformer.setUseByteDestinationTypeAnnotations(true);
+ assertTrue(transformer.isUseByteDestinationTypeAnnotations());
+ }
+
// ======= JMSDestination Handling =========
// =========================================
+ // --- String type annotation ---
@Test
public void testConvertMessageWithJMSDestinationNull() throws Exception
{
- doTestConvertMessageWithJMSDestination(null, null);
+ doTestConvertMessageWithJMSDestination(null, null, false);
}
@Test
@@ -68,7 +89,7 @@ public class JMSMappingOutboundTransform
{
Queue mockDest = Mockito.mock(Queue.class);
- doTestConvertMessageWithJMSDestination(mockDest, "queue");
+ doTestConvertMessageWithJMSDestination(mockDest, "queue", false);
}
@Test
@@ -76,7 +97,7 @@ public class JMSMappingOutboundTransform
{
TemporaryQueue mockDest = Mockito.mock(TemporaryQueue.class);
- doTestConvertMessageWithJMSDestination(mockDest, "temporary,queue");
+ doTestConvertMessageWithJMSDestination(mockDest, "temporary,queue",
false);
}
@Test
@@ -84,7 +105,7 @@ public class JMSMappingOutboundTransform
{
Topic mockDest = Mockito.mock(Topic.class);
- doTestConvertMessageWithJMSDestination(mockDest, "topic");
+ doTestConvertMessageWithJMSDestination(mockDest, "topic", false);
}
@Test
@@ -92,10 +113,58 @@ public class JMSMappingOutboundTransform
{
TemporaryTopic mockDest = Mockito.mock(TemporaryTopic.class);
- doTestConvertMessageWithJMSDestination(mockDest, "temporary,topic");
+ doTestConvertMessageWithJMSDestination(mockDest, "temporary,topic",
false);
}
- private void doTestConvertMessageWithJMSDestination(Destination
jmsDestination, Object expectedAnnotationValue) throws Exception
+ // --- byte type annotation ---
+
+ @Test
+ public void testConvertMessageWithJMSDestinationNullUsingByteAnnotation()
throws Exception
+ {
+ doTestConvertMessageWithJMSDestination(null, null, true);
+ }
+
+ @Test
+ public void testConvertMessageWithJMSDestinationQueueUsingByteAnnotation()
throws Exception
+ {
+ Queue mockDest = Mockito.mock(Queue.class);
+
+ doTestConvertMessageWithJMSDestination(mockDest, JMSVendor.QUEUE_TYPE,
true);
+ }
+
+ @Test
+ public void
testConvertMessageWithJMSDestinationTemporaryQueueUsingByteAnnotation() throws
Exception
+ {
+ TemporaryQueue mockDest = Mockito.mock(TemporaryQueue.class);
+
+ doTestConvertMessageWithJMSDestination(mockDest,
JMSVendor.TEMP_QUEUE_TYPE, true);
+ }
+
+ @Test
+ public void testConvertMessageWithJMSDestinationTopicUsingByteAnnotation()
throws Exception
+ {
+ Topic mockDest = Mockito.mock(Topic.class);
+
+ doTestConvertMessageWithJMSDestination(mockDest, JMSVendor.TOPIC_TYPE,
true);
+ }
+
+ @Test
+ public void
testConvertMessageWithJMSDestinationTemporaryTopicUsingByteAnnotation() throws
Exception
+ {
+ TemporaryTopic mockDest = Mockito.mock(TemporaryTopic.class);
+
+ doTestConvertMessageWithJMSDestination(mockDest,
JMSVendor.TEMP_TOPIC_TYPE, true);
+ }
+
+ @Test
+ public void
testConvertMessageWithJMSDestinationUnkownUsingByteAnnotation() throws Exception
+ {
+ Destination mockDest = Mockito.mock(Destination.class);
+
+ doTestConvertMessageWithJMSDestination(mockDest, JMSVendor.QUEUE_TYPE,
true);
+ }
+
+ private void doTestConvertMessageWithJMSDestination(Destination
jmsDestination, Object expectedAnnotationValue, boolean byteType) throws
Exception
{
TextMessage mockTextMessage = createMockTextMessage();
Mockito.when(mockTextMessage.getText()).thenReturn("myTextMessageContent");
@@ -109,6 +178,10 @@ public class JMSMappingOutboundTransform
}
JMSMappingOutboundTransformer transformer = new
JMSMappingOutboundTransformer(mockVendor);
+ if(byteType)
+ {
+ transformer.setUseByteDestinationTypeAnnotations(true);
+ }
Message amqp = transformer.convert(mockTextMessage);
@@ -133,10 +206,11 @@ public class JMSMappingOutboundTransform
// ======= JMSReplyTo Handling =========
// =====================================
+ // --- String type annotation ---
@Test
public void testConvertMessageWithJMSReplyToNull() throws Exception
{
- doTestConvertMessageWithJMSReplyTo(null, null);
+ doTestConvertMessageWithJMSReplyTo(null, null, false);
}
@Test
@@ -144,7 +218,7 @@ public class JMSMappingOutboundTransform
{
Queue mockDest = Mockito.mock(Queue.class);
- doTestConvertMessageWithJMSReplyTo(mockDest, "queue");
+ doTestConvertMessageWithJMSReplyTo(mockDest, "queue", false);
}
@Test
@@ -152,7 +226,7 @@ public class JMSMappingOutboundTransform
{
TemporaryQueue mockDest = Mockito.mock(TemporaryQueue.class);
- doTestConvertMessageWithJMSReplyTo(mockDest, "temporary,queue");
+ doTestConvertMessageWithJMSReplyTo(mockDest, "temporary,queue", false);
}
@Test
@@ -160,7 +234,7 @@ public class JMSMappingOutboundTransform
{
Topic mockDest = Mockito.mock(Topic.class);
- doTestConvertMessageWithJMSReplyTo(mockDest, "topic");
+ doTestConvertMessageWithJMSReplyTo(mockDest, "topic", false);
}
@Test
@@ -168,10 +242,57 @@ public class JMSMappingOutboundTransform
{
TemporaryTopic mockDest = Mockito.mock(TemporaryTopic.class);
- doTestConvertMessageWithJMSReplyTo(mockDest, "temporary,topic");
+ doTestConvertMessageWithJMSReplyTo(mockDest, "temporary,topic", false);
+ }
+
+ // --- byte type annotation ---
+ @Test
+ public void testConvertMessageWithJMSReplyToNullUsingByteAnnotation()
throws Exception
+ {
+ doTestConvertMessageWithJMSReplyTo(null, null, true);
+ }
+
+ @Test
+ public void testConvertMessageWithJMSReplyToQueueUsingByteAnnotation()
throws Exception
+ {
+ Queue mockDest = Mockito.mock(Queue.class);
+
+ doTestConvertMessageWithJMSReplyTo(mockDest, JMSVendor.QUEUE_TYPE,
true);
+ }
+
+ @Test
+ public void
testConvertMessageWithJMSReplyToTemporaryQueueUsingByteAnnotation() throws
Exception
+ {
+ TemporaryQueue mockDest = Mockito.mock(TemporaryQueue.class);
+
+ doTestConvertMessageWithJMSReplyTo(mockDest,
JMSVendor.TEMP_QUEUE_TYPE, true);
+ }
+
+ @Test
+ public void testConvertMessageWithJMSReplyToTopicUsingByteAnnotation()
throws Exception
+ {
+ Topic mockDest = Mockito.mock(Topic.class);
+
+ doTestConvertMessageWithJMSReplyTo(mockDest, JMSVendor.TOPIC_TYPE,
true);
+ }
+
+ @Test
+ public void
testConvertMessageWithJMSReplyToTemporaryTopicUsingByteAnnotation() throws
Exception
+ {
+ TemporaryTopic mockDest = Mockito.mock(TemporaryTopic.class);
+
+ doTestConvertMessageWithJMSReplyTo(mockDest,
JMSVendor.TEMP_TOPIC_TYPE, true);
+ }
+
+ @Test
+ public void testConvertMessageWithJMSReplyToUnkownUsingByteAnnotation()
throws Exception
+ {
+ Destination mockDest = Mockito.mock(Destination.class);
+
+ doTestConvertMessageWithJMSReplyTo(mockDest, JMSVendor.QUEUE_TYPE,
true);
}
- private void doTestConvertMessageWithJMSReplyTo(Destination jmsReplyTo,
Object expectedAnnotationValue) throws Exception
+ private void doTestConvertMessageWithJMSReplyTo(Destination jmsReplyTo,
Object expectedAnnotationValue, boolean byteType) throws Exception
{
TextMessage mockTextMessage = createMockTextMessage();
Mockito.when(mockTextMessage.getText()).thenReturn("myTextMessageContent");
@@ -185,6 +306,10 @@ public class JMSMappingOutboundTransform
}
JMSMappingOutboundTransformer transformer = new
JMSMappingOutboundTransformer(mockVendor);
+ if(byteType)
+ {
+ transformer.setUseByteDestinationTypeAnnotations(true);
+ }
Message amqp = transformer.convert(mockTextMessage);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]