activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r534342 - /activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
Date Wed, 02 May 2007 07:56:33 GMT
Author: rajdavies
Date: Wed May  2 00:56:32 2007
New Revision: 534342

URL: http://svn.apache.org/viewvc?view=rev&rev=534342
Log:
Added an id to the Message

Modified:
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java?view=diff&rev=534342&r1=534341&r2=534342
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
Wed May  2 00:56:32 2007
@@ -17,12 +17,19 @@
  */
 package org.apache.camel.component.jms;
 
-import org.apache.camel.impl.DefaultMessage;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
+import java.beans.DesignMode;
+import java.io.File;
 import java.util.Enumeration;
 import java.util.Map;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.TemporaryTopic;
+import javax.jms.Topic;
+import org.apache.camel.impl.DefaultMessage;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Represents a {@link org.apache.camel.Message} for working with JMS
@@ -30,13 +37,14 @@
  * @version $Revision:520964 $
  */
 public class JmsMessage extends DefaultMessage {
+    private static final transient Log log = LogFactory.getLog(JmsMessage.class);
     private Message jmsMessage;
 
     public JmsMessage() {
     }
 
     public JmsMessage(Message jmsMessage) {
-        this.jmsMessage = jmsMessage;
+        setJmsMessage(jmsMessage);
     }
 
     @Override
@@ -59,8 +67,15 @@
         return jmsMessage;
     }
 
-    public void setJmsMessage(Message jmsMessage) {
-        this.jmsMessage = jmsMessage;
+    public void setJmsMessage(Message jmsMessage){
+        this.jmsMessage=jmsMessage;
+        try{
+            String id=getDestinationAsString(jmsMessage.getJMSDestination());
+            id+=getSanitizedString(jmsMessage.getJMSMessageID());
+            setMessageId(id);
+        }catch(JMSException e){
+            log.error("Failed to get message id from message "+jmsMessage,e);
+        }
     }
 
     public Object getHeader(String name) {
@@ -114,6 +129,20 @@
                 }
             }
         }
+    }
+    
+    private String getDestinationAsString(Destination destination) throws JMSException {
+        String result = "";
+        if (destination instanceof Topic) {
+            result += "topic" + File.separator + getSanitizedString(((Topic)destination).getTopicName());
+        }else {
+            result += "queue" + File.separator + getSanitizedString(((Queue)destination).getQueueName());
+        }
+        result += File.separator;
+        return result;
+    }
+    private String getSanitizedString(Object value) {
+        return value != null ? value.toString().replaceAll("[^a-zA-Z0-9\\.\\_\\-]", "_")
: "";
     }
 }
 



Mime
View raw message