camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/4] git commit: CAMEL-6583: Added option includeAllJMSXProperties to camel-jms.
Date Sun, 28 Jul 2013 12:07:15 GMT
CAMEL-6583: Added option includeAllJMSXProperties to camel-jms.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/96270b36
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/96270b36
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/96270b36

Branch: refs/heads/master
Commit: 96270b365572bd2194b3d9551b422e15b3a69299
Parents: 9433bf1
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Jul 28 14:05:52 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jul 28 14:05:52 2013 +0200

----------------------------------------------------------------------
 .../apache/camel/component/jms/JmsBinding.java  |  4 +-
 .../camel/component/jms/JmsComponent.java       | 16 ++++-
 .../camel/component/jms/JmsConfiguration.java   | 16 +++++
 .../apache/camel/component/jms/JmsEndpoint.java | 12 +++-
 .../component/jms/JmsHeaderFilterStrategy.java  |  8 ++-
 .../component/jms/JmsHeaderFilteringTest.java   | 19 ++++--
 .../jms/JmsIncludeAllJMSXPropertiesTest.java    | 71 ++++++++++++++++++++
 .../jms/JmsNotIncludeAllJMSXPropertiesTest.java | 71 ++++++++++++++++++++
 8 files changed, 206 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/96270b36/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
index 4fca604..ed666df 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
@@ -77,7 +77,7 @@ public class JmsBinding {
 
     public JmsBinding() {
         this.endpoint = null;
-        headerFilterStrategy = new JmsHeaderFilterStrategy();
+        headerFilterStrategy = new JmsHeaderFilterStrategy(false);
         jmsKeyFormatStrategy = new DefaultJmsKeyFormatStrategy();
     }
 
@@ -86,7 +86,7 @@ public class JmsBinding {
         if (endpoint.getHeaderFilterStrategy() != null) {
             headerFilterStrategy = endpoint.getHeaderFilterStrategy();
         } else {
-            headerFilterStrategy = new JmsHeaderFilterStrategy();
+            headerFilterStrategy = new JmsHeaderFilterStrategy(endpoint.isIncludeAllJMSXProperties());
         }
         if (endpoint.getJmsKeyFormatStrategy() != null) {
             jmsKeyFormatStrategy = endpoint.getJmsKeyFormatStrategy();

http://git-wip-us.apache.org/repos/asf/camel/blob/96270b36/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
index b31d504..2576946 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
@@ -53,7 +53,7 @@ public class JmsComponent extends UriEndpointComponent implements ApplicationCon
     private JmsConfiguration configuration;
     private ApplicationContext applicationContext;
     private QueueBrowseStrategy queueBrowseStrategy;
-    private HeaderFilterStrategy headerFilterStrategy = new JmsHeaderFilterStrategy();
+    private HeaderFilterStrategy headerFilterStrategy;
     private ExecutorService asyncStartStopExecutorService;
     private MessageListenerContainerFactory messageListenerContainerFactory;
 
@@ -382,7 +382,11 @@ public class JmsComponent extends UriEndpointComponent implements ApplicationCon
     public void setIncludeSentJMSMessageID(boolean includeSentJMSMessageID) {
         getConfiguration().setIncludeSentJMSMessageID(includeSentJMSMessageID);
     }
-    
+
+    public void setIncludeAllJMSXProperties(boolean includeAllJMSXProperties) {
+        getConfiguration().setIncludeAllJMSXProperties(includeAllJMSXProperties);
+    }
+
     public void setDefaultTaskExecutorType(DefaultTaskExecutorType type) {
         getConfiguration().setDefaultTaskExecutorType(type);
     }
@@ -427,6 +431,14 @@ public class JmsComponent extends UriEndpointComponent implements ApplicationCon
     // Implementation methods
     // -------------------------------------------------------------------------
 
+
+    @Override
+    protected void doStart() throws Exception {
+        if (headerFilterStrategy == null) {
+            headerFilterStrategy = new JmsHeaderFilterStrategy(getConfiguration().isIncludeAllJMSXProperties());
+        }
+    }
+
     @Override
     protected void doShutdown() throws Exception {
         if (asyncStartStopExecutorService != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/96270b36/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
index ae22f94..1ae25fa 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
@@ -191,6 +191,8 @@ public class JmsConfiguration implements Cloneable {
     @UriParam
     private boolean includeSentJMSMessageID;
     private DefaultTaskExecutorType defaultTaskExecutorType;
+    @UriParam
+    private boolean includeAllJMSXProperties;
 
     public JmsConfiguration() {
     }
@@ -1379,4 +1381,18 @@ public class JmsConfiguration implements Cloneable {
     public void setDefaultTaskExecutorType(DefaultTaskExecutorType defaultTaskExecutorType)
{
         this.defaultTaskExecutorType = defaultTaskExecutorType;
     }
+
+    public boolean isIncludeAllJMSXProperties() {
+        return includeAllJMSXProperties;
+    }
+
+    /**
+     * Whether to include all <tt>JMSX</tt> properties as Camel headers when
binding from JMS to Camel Message.
+     * <p/>
+     * By default a number of properties is excluded accordingly to the table of JMS properties
in the JMS 1.1 spec,
+     * on page 39.
+     */
+    public void setIncludeAllJMSXProperties(boolean includeAllJMSXProperties) {
+        this.includeAllJMSXProperties = includeAllJMSXProperties;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/96270b36/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
index d941af7..0b1741a 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
@@ -313,7 +313,7 @@ public class JmsEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
 
     public HeaderFilterStrategy getHeaderFilterStrategy() {
         if (headerFilterStrategy == null) {
-            headerFilterStrategy = new JmsHeaderFilterStrategy();
+            headerFilterStrategy = new JmsHeaderFilterStrategy(isIncludeAllJMSXProperties());
         }
         return headerFilterStrategy;
     }
@@ -1083,6 +1083,16 @@ public class JmsEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
     }
 
     @ManagedAttribute
+    public boolean isIncludeAllJMSXProperties() {
+        return configuration.isIncludeAllJMSXProperties();
+    }
+
+    @ManagedAttribute
+    public void setIncludeAllJMSXProperties(boolean includeAllJMSXProperties) {
+        configuration.setIncludeAllJMSXProperties(includeAllJMSXProperties);
+    }
+
+    @ManagedAttribute
     public DefaultTaskExecutorType getDefaultTaskExecutorType() {
         return configuration.getDefaultTaskExecutorType();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/96270b36/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java
index 9f65159..12c7f04 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java
@@ -24,7 +24,13 @@ import org.apache.camel.impl.DefaultHeaderFilterStrategy;
 public class JmsHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
 
     public JmsHeaderFilterStrategy() {
-        initialize();
+        this(false);
+    }
+
+    public JmsHeaderFilterStrategy(boolean includeAllJMSXProperties) {
+        if (!includeAllJMSXProperties) {
+            initialize();
+        }
     }
 
     protected void initialize() {

http://git-wip-us.apache.org/repos/asf/camel/blob/96270b36/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
index 8ab24fe..fa7dc4f 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsHeaderFilteringTest.java
@@ -59,6 +59,7 @@ public class JmsHeaderFilteringTest extends CamelTestSupport {
                 exchange.getIn().setHeader("org.apache.camel.test.jms", 20000);
                 exchange.getIn().setHeader("testheader", 1020);
                 exchange.getIn().setHeader("anotherheader", 1030);
+                exchange.getIn().setHeader("JMSXAppID", "myApp");
             }
 
         });
@@ -75,13 +76,15 @@ public class JmsHeaderFilteringTest extends CamelTestSupport {
         ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory();
         camelContext.addComponent(componentName, jmsComponentAutoAcknowledge(connectionFactory));
 
-        // add "testheader" to in filter set
         JmsComponent component = camelContext.getComponent(componentName, JmsComponent.class);
-        ((DefaultHeaderFilterStrategy)component.getHeaderFilterStrategy()).getInFilter().add("testheader");
-        // add "anotherheader" to out filter set
-        ((DefaultHeaderFilterStrategy)component.getHeaderFilterStrategy()).getOutFilter().add("anotherheader");
+
+        JmsHeaderFilterStrategy filter = new JmsHeaderFilterStrategy();
+        filter.getInFilter().add("testheader");
+        filter.getOutFilter().add("anotherheader");
         // add a regular expression pattern filter, notice that dots are encoded to '_DOT_'
in jms headers
-        ((DefaultHeaderFilterStrategy)component.getHeaderFilterStrategy()).setInFilterPattern(IN_FILTER_PATTERN);
+        filter.setInFilterPattern(IN_FILTER_PATTERN);
+
+        component.setHeaderFilterStrategy(filter);
 
         return camelContext;
     }
@@ -116,6 +119,9 @@ public class JmsHeaderFilteringTest extends CamelTestSupport {
             // like testheader, org.apache.camel.test.jms will be filtered by the "in" filter
             assertEquals(20000, message.getJmsMessage().getObjectProperty("org_DOT_apache_DOT_camel_DOT_test_DOT_jms"));
 
+            // should be filtered by default
+            assertNull(message.getJmsMessage().getStringProperty("JMSXAppID"));
+
             latch.countDown();
         }
 
@@ -137,6 +143,9 @@ public class JmsHeaderFilteringTest extends CamelTestSupport {
             // filtered out by "in" filter
             assertNull(exchange.getIn().getHeader("org_DOT_apache_DOT_camel_DOT_test_DOT_jms"));
 
+            // should be filtered by default
+            assertNull(exchange.getIn().getHeader("JMSXAppID"));
+
             latch.countDown();
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/96270b36/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsIncludeAllJMSXPropertiesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsIncludeAllJMSXPropertiesTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsIncludeAllJMSXPropertiesTest.java
new file mode 100644
index 0000000..bd11175
--- /dev/null
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsIncludeAllJMSXPropertiesTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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 java.util.HashMap;
+import java.util.Map;
+import javax.jms.ConnectionFactory;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge;
+
+/**
+ *
+ * @version 
+ */
+public class JmsIncludeAllJMSXPropertiesTest extends CamelTestSupport {
+
+    @Test
+    public void testIncludeAll() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:result").expectedHeaderReceived("foo", "bar");
+        getMockEndpoint("mock:result").expectedHeaderReceived("JMSXUserID", "Donald");
+        getMockEndpoint("mock:result").expectedHeaderReceived("JMSXAppID", "MyApp");
+
+        Map headers = new HashMap();
+        headers.put("foo", "bar");
+        headers.put("JMSXUserID", "Donald");
+        headers.put("JMSXAppID", "MyApp");
+
+        template.sendBodyAndHeaders("activemq:queue:in", "Hello World", headers);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory();
+        JmsComponent jms = jmsComponentAutoAcknowledge(connectionFactory);
+        jms.setIncludeAllJMSXProperties(true);
+        camelContext.addComponent("activemq", jms);
+        return camelContext;
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("activemq:queue:in")
+                    .to("mock:result");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/96270b36/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsNotIncludeAllJMSXPropertiesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsNotIncludeAllJMSXPropertiesTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsNotIncludeAllJMSXPropertiesTest.java
new file mode 100644
index 0000000..4bb8695
--- /dev/null
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsNotIncludeAllJMSXPropertiesTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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 java.util.HashMap;
+import java.util.Map;
+import javax.jms.ConnectionFactory;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge;
+
+/**
+ *
+ * @version 
+ */
+public class JmsNotIncludeAllJMSXPropertiesTest extends CamelTestSupport {
+
+    @Test
+    public void testNotIncludeAll() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:result").expectedHeaderReceived("foo", "bar");
+        getMockEndpoint("mock:result").expectedHeaderReceived("JMSXUserID", null);
+        getMockEndpoint("mock:result").expectedHeaderReceived("JMSXAppID", null);
+
+        Map headers = new HashMap();
+        headers.put("foo", "bar");
+        headers.put("JMSXUserID", "Donald");
+        headers.put("JMSXAppID", "MyApp");
+
+        template.sendBodyAndHeaders("activemq:queue:in", "Hello World", headers);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory();
+        JmsComponent jms = jmsComponentAutoAcknowledge(connectionFactory);
+        jms.setIncludeAllJMSXProperties(false);
+        camelContext.addComponent("activemq", jms);
+        return camelContext;
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("activemq:queue:in")
+                    .to("mock:result");
+            }
+        };
+    }
+
+}


Mime
View raw message