camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r821290 - in /camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/JmsBinding.java test/java/org/apache/camel/component/jms/issues/JmsMQSpecialHeaderTest.java
Date Sat, 03 Oct 2009 10:30:23 GMT
Author: davsclaus
Date: Sat Oct  3 10:30:23 2009
New Revision: 821290

URL: http://svn.apache.org/viewvc?rev=821290&view=rev
Log:
CAMEL-2050: Fix to allow using JMS_IBM to set custom IBM headers when sending to WebSphere
MQ.

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

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java?rev=821290&r1=821289&r2=821290&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
(original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
Sat Oct  3 10:30:23 2009
@@ -301,7 +301,7 @@
 
     public void appendJmsProperty(Message jmsMessage, Exchange exchange, org.apache.camel.Message
in,
                                   String headerName, Object headerValue) throws JMSException
{
-        if (headerName.startsWith("JMS") && !headerName.startsWith("JMSX")) {
+        if (isStandardJMSHeader(headerName)) {
             if (headerName.equals("JMSCorrelationID")) {
                 jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class,
headerValue));
             } else if (headerName.equals("JMSReplyTo") && headerValue != null) {
@@ -341,6 +341,34 @@
     }
 
     /**
+     * Is the given header a standard JMS header
+     * @param headerName the header name
+     * @return <tt>true</tt> if its a standard JMS header
+     */
+    protected boolean isStandardJMSHeader(String headerName) {
+        if (!headerName.startsWith("JMS")) {
+            return false;
+        }
+        if (headerName.startsWith("JMSX")) {
+            return false;
+        }
+        // IBM WebSphereMQ uses JMS_IBM as special headers
+        if (headerName.startsWith("JMS_")) {
+            return false;
+        }
+
+        // the 4th char must be a letter to be a standard JMS header
+        if (headerName.length() > 3) {
+            Character fourth = headerName.charAt(3);
+            if (Character.isLetter(fourth)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
      * Strategy to test if the given header is valid according to the JMS spec to be set
as a property
      * on the JMS message.
      * <p/>

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMQSpecialHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMQSpecialHeaderTest.java?rev=821290&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMQSpecialHeaderTest.java
(added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsMQSpecialHeaderTest.java
Sat Oct  3 10:30:23 2009
@@ -0,0 +1,82 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+
+/**
+ * @version $Revision$
+ */
+public class JmsMQSpecialHeaderTest extends CamelTestSupport {
+
+    @Test
+    public void testUsingSpecialIBMJMSHeader() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello IBM");
+        mock.message(0).header("JMS_IBM_Character_Set").isEqualTo("ISO8859_1");
+
+        template.sendBodyAndHeader("activemq:queue:ibm", "Hello IBM", "JMS_IBM_Character_Set",
"ISO8859_1");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testUsingSpecialIBMJMSHeaderAndStandardJMSHeader() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello IBM");
+        mock.message(0).header("JMS_IBM_Character_Set").isEqualTo("ISO8859_1");
+        
+        Map headers = new HashMap();
+        headers.put("JMSPriority", 3);
+        headers.put("JMS_IBM_Character_Set", "ISO8859_1");
+
+        template.sendBodyAndHeaders("activemq:queue:ibm", "Hello IBM", headers);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    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;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("activemq:queue:ibm").to("mock:result");
+            }
+        };
+    }
+
+}

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

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



Mime
View raw message