Author: tross
Date: Fri Nov 30 21:42:36 2012
New Revision: 1415859
URL: http://svn.apache.org/viewvc?rev=1415859&view=rev
Log:
PROTON-174 - Patch contributed by Hiram Chirino
Modified:
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java
Modified:
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java?rev=1415859&r1=1415858&r2=1415859&view=diff
==============================================================================
---
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java
(original)
+++
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/InboundTransformer.java
Fri Nov 30 21:42:36 2012
@@ -16,7 +16,6 @@
*/
package org.apache.qpid.proton.jms;
-import org.apache.qpid.proton.engine.Delivery;
import org.apache.qpid.proton.type.Binary;
import org.apache.qpid.proton.type.messaging.ApplicationProperties;
import org.apache.qpid.proton.type.messaging.DeliveryAnnotations;
@@ -25,9 +24,12 @@ import org.apache.qpid.proton.type.messa
import org.apache.qpid.proton.type.messaging.MessageAnnotations;
import org.apache.qpid.proton.type.messaging.Properties;
-import javax.jms.DeliveryMode;
+import javax.jms.*;
import javax.jms.JMSException;
import javax.jms.Message;
+import javax.jms.Queue;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -133,18 +135,41 @@ public abstract class InboundTransformer
}
}
+ Class<? extends Destination> toAttributes = Destination.class;
+ Class<? extends Destination> replyToAttributes = Destination.class;
+
final MessageAnnotations ma = amqp.getMessageAnnotations();
if( ma!=null ) {
for (Map.Entry entry : (Set<Map.Entry>)ma.getValue().entrySet()) {
String key = entry.getKey().toString();
if( "x-opt-jms-type".equals(key) ) {
jms.setJMSType(entry.getValue().toString());
+ } else if( "x-opt-to-type".equals(key) ) {
+ toAttributes =
toClassFromAttributes(entry.getValue().toString());
+ } else if( "x-opt-reply-type".equals(key) ) {
+ replyToAttributes =
toClassFromAttributes(entry.getValue().toString());
} else {
setProperty(jms, prefixVendor + prefixMessageAnnotations +
key, entry.getValue());
}
}
}
+ final ApplicationProperties ap = amqp.getApplicationProperties();
+ if( ap !=null ) {
+ for (Map.Entry entry : (Set<Map.Entry>)ap.getValue().entrySet()) {
+ String key = entry.getKey().toString();
+ if( "JMSXGroupID".equals(key) ) {
+ vendor.setJMSXGroupID(jms, entry.getValue().toString());
+ } else if( "JMSXGroupSequence".equals(key) ) {
+ vendor.setJMSXGroupSequence(jms,
((Number)entry.getValue()).intValue());
+ } else if( "JMSXUserID".equals(key) ) {
+ vendor.setJMSXUserID(jms, entry.getValue().toString());
+ } else {
+ setProperty(jms, key, entry.getValue());
+ }
+ }
+ }
+
final Properties properties = amqp.getProperties();
if( properties!=null ) {
if( properties.getMessageId()!=null ) {
@@ -155,13 +180,13 @@ public abstract class InboundTransformer
vendor.setJMSXUserID(jms, new String(userId.getArray(),
userId.getArrayOffset(), userId.getLength(), "UTF-8"));
}
if( properties.getTo()!=null ) {
-
jms.setJMSDestination(vendor.createDestination(properties.getTo()));
+
jms.setJMSDestination(vendor.createDestination(properties.getTo(),
toAttributes));
}
if( properties.getSubject()!=null ) {
jms.setStringProperty(prefixVendor + "Subject",
properties.getSubject());
}
if( properties.getReplyTo() !=null ) {
-
jms.setJMSReplyTo(vendor.createDestination(properties.getReplyTo()));
+
jms.setJMSReplyTo(vendor.createDestination(properties.getReplyTo(),
replyToAttributes));
}
if( properties.getCorrelationId() !=null ) {
jms.setJMSCorrelationID(properties.getCorrelationId().toString());
@@ -186,14 +211,6 @@ public abstract class InboundTransformer
}
}
- final ApplicationProperties ap = amqp.getApplicationProperties();
- if( ap !=null ) {
- for (Map.Entry entry : (Set<Map.Entry>)ap.getValue().entrySet()) {
- String key = entry.getKey().toString();
- setProperty(jms, key, entry.getValue());
- }
- }
-
final Footer fp = amqp.getFooter();
if( fp !=null ) {
for (Map.Entry entry : (Set<Map.Entry>)fp.getValue().entrySet()) {
@@ -203,6 +220,46 @@ public abstract class InboundTransformer
}
}
+ private static final Set<String> QUEUE_ATTRIBUTES = createSet("queue");
+ private static final Set<String> TOPIC_ATTRIBUTES = createSet("topic");
+ private static final Set<String> TEMP_QUEUE_ATTRIBUTES =
createSet("queue", "temporary");
+ private static final Set<String> TEMP_TOPIC_ATTRIBUTES =
createSet("topic", "temporary");
+
+ private static Set<String> createSet(String ... args) {
+ HashSet<String> s = new HashSet<String>();
+ for (String arg : args)
+ {
+ s.add(arg);
+ }
+ return Collections.unmodifiableSet(s);
+ }
+
+ Class<? extends Destination> toClassFromAttributes(String value)
+ {
+ if( value ==null ) {
+ return null;
+ }
+ HashSet<String> attributes = new HashSet<String>();
+ for( String x: value.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;
+ }
+
+
private void setProperty(Message msg, String key, Object value) throws
JMSException {
//TODO support all types
msg.setObjectProperty(key, value);
Modified:
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java?rev=1415859&r1=1415858&r2=1415859&view=diff
==============================================================================
---
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java
(original)
+++
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java
Fri Nov 30 21:42:36 2012
@@ -130,9 +130,13 @@ public class JMSMappingOutboundTransform
}
if( msg.getJMSDestination()!=null ) {
props.setTo(vendor.toAddress(msg.getJMSDestination()));
+ if( maMap==null ) maMap = new HashMap();
+ maMap.put("x-opt-to-type",
destinationAttributes(msg.getJMSDestination()));
}
if( msg.getJMSReplyTo()!=null ) {
- props.setReplyTo(vendor.toAddress(msg.getJMSDestination()));
+ props.setReplyTo(vendor.toAddress(msg.getJMSReplyTo()));
+ if( maMap==null ) maMap = new HashMap();
+ maMap.put("x-opt-reply-type",
destinationAttributes(msg.getJMSReplyTo()));
}
if( msg.getJMSCorrelationID()!=null ) {
props.setCorrelationId(msg.getJMSCorrelationID());
@@ -154,11 +158,18 @@ public class JMSMappingOutboundTransform
} else if( key.startsWith("JMSXDeliveryCount") ) {
header.setDeliveryCount(new
UnsignedInteger(msg.getIntProperty(key)));
} else if( key.startsWith("JMSXUserID") ) {
- props.setUserId(new
Binary(msg.getStringProperty(key).getBytes("UTF-8")));
+ String value = msg.getStringProperty(key);
+ props.setUserId(new Binary(value.getBytes("UTF-8")));
} else if( key.startsWith("JMSXGroupID") ) {
- props.setGroupId(msg.getStringProperty(key));
+ String value = msg.getStringProperty(key);
+ props.setGroupId(value);
+ if( apMap==null ) apMap = new HashMap();
+ apMap.put(key, value);
} else if( key.startsWith("JMSXGroupSeq") ) {
- props.setGroupSequence(new
UnsignedInteger(msg.getIntProperty(key)));
+ UnsignedInteger value = new
UnsignedInteger(msg.getIntProperty(key));
+ props.setGroupSequence(value);
+ if( apMap==null ) apMap = new HashMap();
+ apMap.put(key, value);
} else if( key.startsWith(prefixDeliveryAnnotationsKey) ) {
if( daMap == null ) daMap = new HashMap();
String name =
key.substring(prefixDeliveryAnnotationsKey.length());
@@ -207,4 +218,22 @@ public class JMSMappingOutboundTransform
return new EncodedMessage(messageFormat, buffer.array(), 0, c);
}
+
+ private static String destinationAttributes(Destination destination) {
+ 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 "";
+ }
}
Modified:
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java?rev=1415859&r1=1415858&r2=1415859&view=diff
==============================================================================
---
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java
(original)
+++
qpid/proton/trunk/proton-j/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java
Fri Nov 30 21:42:36 2012
@@ -1,6 +1,9 @@
package org.apache.qpid.proton.jms;
import javax.jms.*;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
/**
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
@@ -21,7 +24,15 @@ abstract public class JMSVendor {
public abstract void setJMSXUserID(Message msg, String value);
- public abstract Destination createDestination(String name);
+ @Deprecated
+ public Destination createDestination(String name) {
+ return null;
+ }
+
+ @SuppressWarnings("deprecation")
+ public <T extends Destination> T createDestination(String name, Class<T>
kind) {
+ return kind.cast(createDestination(name));
+ }
public abstract void setJMSXGroupID(Message msg, String groupId);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]