Modified: 
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java?rev=680645&r1=680644&r2=680645&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
 (original)
+++ 
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
 Tue Jul 29 01:34:12 2008
@@ -17,7 +17,6 @@
 package org.apache.camel.component.jms;
 
 import java.io.File;
-import java.util.Enumeration;
 import java.util.Map;
 
 import javax.jms.Destination;
@@ -155,45 +154,8 @@
 
     @Override
     protected void populateInitialHeaders(Map<String, Object> map) {
-        if (jmsMessage != null) {
-            // lets populate the standard JMS message headers
-            try {
-                map.put("JMSCorrelationID", jmsMessage.getJMSCorrelationID());
-                map.put("JMSDeliveryMode", jmsMessage.getJMSDeliveryMode());
-                map.put("JMSDestination", jmsMessage.getJMSDestination());
-                map.put("JMSExpiration", jmsMessage.getJMSExpiration());
-                map.put("JMSMessageID", jmsMessage.getJMSMessageID());
-                map.put("JMSPriority", jmsMessage.getJMSPriority());
-                map.put("JMSRedelivered", jmsMessage.getJMSRedelivered());
-                map.put("JMSReplyTo", jmsMessage.getJMSReplyTo());
-                map.put("JMSTimestamp", jmsMessage.getJMSTimestamp());
-                map.put("JMSType", jmsMessage.getJMSType());
-
-                // TODO this works around a bug in the ActiveMQ property 
handling
-                map.put("JMSXGroupID", 
jmsMessage.getStringProperty("JMSXGroupID"));
-            } catch (JMSException e) {
-                throw new MessageJMSPropertyAccessException(e);
-            }
-
-            Enumeration names;
-            try {
-                names = jmsMessage.getPropertyNames();
-            } catch (JMSException e) {
-                throw new MessagePropertyNamesAccessException(e);
-            }
-            while (names.hasMoreElements()) {
-                String name = names.nextElement().toString();
-                try {
-                    Object value = jmsMessage.getObjectProperty(name);
-
-                    // must decode back from safe JMS header name to original 
header name
-                    // when storing on this Camel JmsMessage object.
-                    String key = JmsBinding.decodeFromSafeJmsHeaderName(name);
-                    map.put(key, value);
-                } catch (JMSException e) {
-                    throw new MessagePropertyAccessException(name, e);
-                }
-            }
+        if (jmsMessage != null && map != null) {
+            map.putAll(getBinding().extractHeadersFromJms(jmsMessage));
         }
     }
 

Added: 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java?rev=680645&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
 Tue Jul 29 01:34:12 2008
@@ -0,0 +1,148 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jms;
+
+import static 
org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.jms.ConnectionFactory;
+
+import junit.framework.AssertionFailedError;
+
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultHeaderFilterStrategy;
+
+/**
+ *
+ * @version $Revision$
+ */
+public class JmsHeaderFilteringTest extends ContextTestSupport {
+    
+    private static final String IN_FILTER_PATTERN = 
"(org_apache_camel)[_|a-z|A-Z|0-9]*(test)[_|a-z|A-Z|0-9]*";
+    
+    private static final String componentName = "jms";
+    private static final String testQueueEndpointA = componentName + 
":queue:test.a";
+    private static final String testQueueEndpointB = componentName + 
":queue:test.b";
+    private static final String assertionReceiver = "mock:errors";
+    private CountDownLatch latch = new CountDownLatch(2);
+
+    public void testHeaderFilters() throws Exception {
+        MockEndpoint errors = this.resolveMandatoryEndpoint(assertionReceiver, 
MockEndpoint.class);
+        errors.expectedMessageCount(0);
+        
+        Exchange exchange = template.send(testQueueEndpointA, 
ExchangePattern.InOnly, new Processor() {    
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader("org.apache.camel.jms", 10000);
+                exchange.getIn().setHeader("org.apache.camel.test.jms", 20000);
+                exchange.getIn().setHeader("testheader", 1020);
+                exchange.getIn().setHeader("anotherheader", 1030);
+            }
+
+        });
+        
+        latch.await(2, TimeUnit.SECONDS);
+        errors.assertIsSatisfied();
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {        
+        CamelContext camelContext = super.createCamelContext();
+        ConnectionFactory connectionFactory = new 
ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        camelContext.addComponent(componentName, 
jmsComponentClientAcknowledge(connectionFactory));
+        
+        // add "testheader" to in filter set
+        ((DefaultHeaderFilterStrategy)camelContext.getComponent(componentName)
+                .getHeaderFilterStrategy()).getInFilter().add("testheader");
+        // add "anotherheader" to out filter set
+        ((DefaultHeaderFilterStrategy)camelContext.getComponent(componentName)
+                
.getHeaderFilterStrategy()).getOutFilter().add("anotherheader");
+        // add a regular expression pattern filter 
+        // notice that dots are encoded to underscores in jms headers
+        ((DefaultHeaderFilterStrategy)camelContext.getComponent(componentName)
+                
.getHeaderFilterStrategy()).setInFilterPattern(IN_FILTER_PATTERN);
+        
+        return camelContext;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+
+                
exception(AssertionFailedError.class).maximumRedeliveries(1).to(assertionReceiver);
+
+                from(testQueueEndpointA).process(new 
OutHeaderChecker()).to(testQueueEndpointB);
+                from(testQueueEndpointB).process(new InHeaderChecker());
+            }
+        };
+    }
+    
+    class OutHeaderChecker implements Processor {
+
+        public void process(Exchange exchange) throws Exception {
+            JmsMessage message = (JmsMessage) exchange.getIn();
+            
+            // testheader not filtered out until it is copied back to camel
+            assertEquals(1020, 
message.getJmsMessage().getObjectProperty("testheader"));
+            
+            // anotherheader has been filtered out
+            
assertNull(message.getJmsMessage().getObjectProperty("anotherheader"));
+            
+            // notice dots are replaced by underscores when it is copied to 
jms message properties
+            assertEquals(10000, 
message.getJmsMessage().getObjectProperty("org_apache_camel_jms"));
+
+            // like testheader, org.apache.camel.test.jms will be filtered 
"in" filter
+            assertEquals(20000, 
message.getJmsMessage().getObjectProperty("org_apache_camel_test_jms"));
+            
+            latch.countDown();
+        }
+        
+    }
+    
+    class InHeaderChecker implements Processor {
+
+        public void process(Exchange exchange) throws Exception {
+            
+            // filtered out by "in" filter
+            assertNull(exchange.getIn().getHeader("testheader"));
+            
+            // it has been filtered out by "out" filter
+            assertNull(exchange.getIn().getHeader("anotherheader"));
+            
+            // it should not been filtered out
+            assertEquals(10000, 
exchange.getIn().getHeader("org.apache.camel.jms"));
+            
+            // filtered out by "in" filter
+            
assertNull(exchange.getIn().getHeader("org.apache.camel.test.jms"));
+           
+            latch.countDown();
+        }
+        
+    }
+
+}

Propchange: 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringWithSpringTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringWithSpringTest.java?rev=680645&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringWithSpringTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringWithSpringTest.java
 Tue Jul 29 01:34:12 2008
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jms;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.SpringCamelContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ *
+ * @version $Revision$
+ */
+public class JmsHeaderFilteringWithSpringTest extends JmsHeaderFilteringTest {
+    
+    private ClassPathXmlApplicationContext applicationContext;
+
+   
+    @Override
+    protected CamelContext createCamelContext() throws Exception {   
+        applicationContext = createApplicationContext();
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }    
+    
+    private ClassPathXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/component/jms/jmsHeaderFilteringWithSpring.xml");
+    }
+
+    
+    @Override
+    protected void tearDown() throws Exception {
+        if (applicationContext != null) {
+            applicationContext.close();
+        }
+        super.tearDown();
+    }
+    
+}
+

Propchange: 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringWithSpringTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringWithSpringTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteUsingSpringTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteUsingSpringTest.java?rev=680645&r1=680644&r2=680645&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteUsingSpringTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteUsingSpringTest.java
 Tue Jul 29 01:34:12 2008
@@ -25,12 +25,14 @@
  */
 public class JmsRouteUsingSpringTest extends JmsRouteTest {
     private ClassPathXmlApplicationContext applicationContext;
-
+    
+    @Override
     protected CamelContext createCamelContext() throws Exception {
         applicationContext = createApplicationContext();
         return SpringCamelContext.springCamelContext(applicationContext);
+        
     }
-
+    
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new 
ClassPathXmlApplicationContext("org/apache/camel/component/jms/jmsRouteUsingSpring.xml");
     }

Added: 
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsHeaderFilteringWithSpring.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsHeaderFilteringWithSpring.xml?rev=680645&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsHeaderFilteringWithSpring.xml
 (added)
+++ 
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsHeaderFilteringWithSpring.xml
 Tue Jul 29 01:34:12 2008
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+    
+    http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+    xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://activemq.apache.org/camel/schema/spring 
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+    <camelContext id="camel"
+        xmlns="http://activemq.apache.org/camel/schema/spring";>
+    </camelContext>
+
+    <bean id="jms"
+        class="org.apache.camel.component.jms.JmsComponent">
+        <property name="connectionFactory">
+            <bean
+                class="org.apache.activemq.ActiveMQConnectionFactory">
+                <property name="brokerURL"
+                    value="vm://localhost?broker.persistent=false" />
+            </bean>
+        </property>
+
+        <property name="headerFilterStrategy">
+            <bean
+                class="org.apache.camel.component.jms.JmsHeaderFilterStrategy">
+                <property name="outFilter">
+                    <set>
+                        <value>JMSXUserID</value>
+                        <value>JMSXAppID</value>
+                        <value>JMSXDeliveryCount</value>
+                        <value>JMSXProducerTXID</value>
+                        <value>JMSXConsumerTXID</value>
+                        <value>JMSXRcvTimestamp</value>
+                        <value>JMSXRecvTimestamp</value>
+                        <value>JMSXState</value>
+                        <value>anotherheader</value>
+                    </set>
+                </property>
+                <property name="inFilter">
+                    <set>
+                        <value>testheader</value>
+                    </set>
+                </property>
+                <property name="inFilterPattern" 
value="(org_apache_camel)[_|a-z|A-Z|0-9]*(test)[_|a-z|A-Z|0-9]*"/>              
  
+            </bean>
+
+        </property>
+    </bean>
+
+</beans>

Propchange: 
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsHeaderFilteringWithSpring.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsHeaderFilteringWithSpring.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsHeaderFilteringWithSpring.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to