camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r594493 - in /activemq/camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/JmsBinding.java test/java/org/apache/camel/component/jms/issues/MQSeriesHeaderTest.java
Date Tue, 13 Nov 2007 11:42:05 GMT
Author: jstrachan
Date: Tue Nov 13 03:42:04 2007
New Revision: 594493

URL: http://svn.apache.org/viewvc?rev=594493&view=rev
Log:
added test case and fix for https://issues.apache.org/activemq/browse/CAMEL-213

Added:
    activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MQSeriesHeaderTest.java
  (with props)
Modified:
    activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java

Modified: activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java?rev=594493&r1=594492&r2=594493&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
(original)
+++ activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
Tue Nov 13 03:42:04 2007
@@ -35,6 +35,7 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.HashSet;
 
 /**
  * A Strategy used to convert between a Camel {@JmsExchange} and {@JmsMessage}
@@ -45,6 +46,8 @@
 public class JmsBinding {
     private static final transient Log LOG = LogFactory.getLog(JmsBinding.class);
 
+    private Set<String> ignoreJmsHeaders;
+
     /**
      * Extracts the body from the JMS message
      * 
@@ -152,10 +155,30 @@
         return answer;
     }
 
+    public Set<String> getIgnoreJmsHeaders() {
+        if (ignoreJmsHeaders == null) {
+            ignoreJmsHeaders = new HashSet<String>();
+            populateIgnoreJmsHeaders(ignoreJmsHeaders);
+        }
+        return ignoreJmsHeaders;
+    }
+
+    public void setIgnoreJmsHeaders(Set<String> ignoreJmsHeaders) {
+        this.ignoreJmsHeaders = ignoreJmsHeaders;
+    }
+
     /**
      * Strategy to allow filtering of headers which are put on the JMS message
      */
     protected boolean shouldOutputHeader(org.apache.camel.Message camelMessage, String headerName,
Object headerValue) {
-        return headerValue != null;
+        return headerValue != null && !getIgnoreJmsHeaders().contains(headerName);
+    }
+
+    /**
+     * Populate any JMS headers that should be excluded from being copied from an input message
+     * onto an outgoing message
+     */
+    protected void populateIgnoreJmsHeaders(Set<String> set) {
+        set.add("JMSXAppID"); // MQSeries really doesn't seem to like this being set
     }
 }

Added: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MQSeriesHeaderTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MQSeriesHeaderTest.java?rev=594493&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MQSeriesHeaderTest.java
(added)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MQSeriesHeaderTest.java
Tue Nov 13 03:42:04 2007
@@ -0,0 +1,77 @@
+/**
+ *
+ * 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.issues;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Lets test that a number of headers MQSeries doesn't like to be sent are excluded when
+ * forwarding a JMS message from one destination to another
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class MQSeriesHeaderTest extends ContextTestSupport {
+
+    public void testForwardingJmsMessageIgnoresHeadersMQDoesntLike() throws Exception {
+        MockEndpoint endpoint = getMockEndpoint("mock:result");
+        endpoint.expectedMessageCount(1);
+
+        Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("JMSXAppID", "ABC");
+
+        template.sendBodyAndHeaders("activemq:test.a", "Hello World!", headers);
+
+        endpoint.assertIsSatisfied();
+
+        Exchange exchange = endpoint.getReceivedExchanges().get(0);
+        Message in = exchange.getIn();
+        assertMessageHeader(in, "JMSXAppID", null);
+
+        log.info("Received message: " + in);
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
+
+        return camelContext;
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("activemq:test.a").to("activemq:test.b");
+                from("activemq:test.b").to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

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



Mime
View raw message