svn commit: r756479 - in /camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/ test/java/org/apache/camel/component/jms/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r756479 - in /camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/ test/java/org/apache/camel/component/jms/

davsclaus-2
Author: davsclaus
Date: Fri Mar 20 14:20:27 2009
New Revision: 756479

URL: http://svn.apache.org/viewvc?rev=756479&view=rev
Log:
CAMEL-1212: Introduced JmsKeyFormatStrategy for pluggable encoder/decoder for JMS keys.

Added:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultJmsKeyFormatStrategy.java   (with props)
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsKeyFormatStrategy.java   (with props)
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategy.java   (with props)
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/DefaultJmsHeaderKeyFormatStrategyTest.java   (with props)
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithCustomKeyFormatStrategyTest.java   (with props)
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithDefaultKeyFormatStrategyTest.java   (with props)
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithPassThroughKeyFormatStrategyTest.java   (with props)
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategyTest.java   (with props)
Modified:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java

Added: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultJmsKeyFormatStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultJmsKeyFormatStrategy.java?rev=756479&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultJmsKeyFormatStrategy.java (added)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultJmsKeyFormatStrategy.java Fri Mar 20 14:20:27 2009
@@ -0,0 +1,40 @@
+/**
+ * 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;
+
+/**
+ * Default strategy that handles dots and hyphens.
+ * <p/>
+ * This can be used for sending keys containg package names that is common by Java frameworks.
+ *
+ * @version $Revision$
+ */
+public class DefaultJmsKeyFormatStrategy implements JmsKeyFormatStrategy {
+
+    public String encodeKey(String key) {
+        String answer = key.replace(".", "_");
+        answer = answer.replaceAll("-", "_HYPHEN_");
+        return answer;
+    }
+
+    public String decodeKey(String key) {
+        String answer = key.replaceAll("_HYPHEN_", "-");
+        answer = answer.replace("_", ".");
+        return answer;
+    }
+
+}

Propchange: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultJmsKeyFormatStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultJmsKeyFormatStrategy.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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=756479&r1=756478&r2=756479&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 Fri Mar 20 14:20:27 2009
@@ -144,7 +144,7 @@
 
                     // must decode back from safe JMS header name to original header name
                     // when storing on this Camel JmsMessage object.
-                    String key = JmsBinding.decodeFromSafeJmsHeaderName(name);
+                    String key = endpoint.getJmsKeyFormatStrategy().decodeKey(name);
                     map.put(key, value);
                 } catch (JMSException e) {
                     throw new RuntimeCamelException(name, e);
@@ -224,28 +224,25 @@
                                   String headerName, Object headerValue) throws JMSException {
         if (headerName.startsWith("JMS") && !headerName.startsWith("JMSX")) {
             if (headerName.equals("JMSCorrelationID")) {
-                jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class,
-                    headerValue));
+                jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class, headerValue));
             } else if (headerName.equals("JMSReplyTo") && headerValue != null) {
-                jmsMessage.setJMSReplyTo(ExchangeHelper.convertToType(exchange, Destination.class,
-                    headerValue));
+                jmsMessage.setJMSReplyTo(ExchangeHelper.convertToType(exchange, Destination.class, headerValue));
             } else if (headerName.equals("JMSType")) {
                 jmsMessage.setJMSType(ExchangeHelper.convertToType(exchange, String.class, headerValue));
             } else if (LOG.isDebugEnabled()) {
-                // The following properties are set by the MessageProducer
-                // JMSDeliveryMode, JMSDestination, JMSExpiration,
-                // JMSPriority,
-                // The following are set on the underlying JMS provider
+                // The following properties are set by the MessageProducer:
+                // JMSDeliveryMode, JMSDestination, JMSExpiration, JMSPriorit
+                // The following are set on the underlying JMS provider:
                 // JMSMessageID, JMSTimestamp, JMSRedelivered
                 LOG.debug("Ignoring JMS header: " + headerName + " with value: " + headerValue);
             }
         } else if (shouldOutputHeader(in, headerName, headerValue)) {
-            // must encode to safe JMS header name before setting property on jmsMessage
-            String key = encodeToSafeJmsHeaderName(headerName);
             // only primitive headers and strings is allowed as properties
             // see message properties: http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html
             Object value = getValidJMSHeaderValue(headerName, headerValue);
             if (value != null) {
+                // must encode to safe JMS header name before setting property on jmsMessage
+                String key = endpoint.getJmsKeyFormatStrategy().encodeKey(headerName);
                 jmsMessage.setObjectProperty(key, value);
             } else if (LOG.isDebugEnabled()) {
                 // okay the value is not a primitive or string so we cannot sent it over the wire
@@ -398,29 +395,4 @@
             || !headerFilterStrategy.applyFilterToCamelHeaders(headerName, headerValue);
     }
 
-    /**
-     * Encoder to encode JMS header keys that is that can be sent over the JMS transport.
-     * <p/>
-     * For example: Sending dots is the key is not allowed. Especially the Bean component has
-     * this problem if you want to provide the method name to invoke on the bean.
-     * <p/>
-     * <b>Note</b>: Currently this encoder is simple as it only supports encoding dots to underscores.
-     *
-     * @param headerName the header name
-     * @return the key to use instead for storing properties and to be for lookup of the same property
-     */
-    public static String encodeToSafeJmsHeaderName(String headerName) {
-        return headerName.replace(".", "_");
-    }
-
-    /**
-     * Decode operation for the {@link #encodeToSafeJmsHeaderName(String)}.
-     *
-     * @param headerName the header name
-     * @return the original key
-     */
-    public static String decodeFromSafeJmsHeaderName(String headerName) {
-        return headerName.replace("_", ".");
-    }
-
 }

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?rev=756479&r1=756478&r2=756479&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java Fri Mar 20 14:20:27 2009
@@ -423,8 +423,26 @@
                 throw new IllegalArgumentException("The JmsComponent's username or password is null");
             }
         }
-        setProperties(endpoint.getConfiguration(), parameters);
 
+        // jms header strategy
+        String strategy = getAndRemoveParameter(parameters, "jmsKeyFormatStrategy", String.class);
+        if (strategy != null) {
+            if (isReferenceParameter(strategy)) {
+                String key = strategy.substring(1);
+                endpoint.setJmsKeyFormatStrategy(lookup(key, JmsKeyFormatStrategy.class));
+            } else {
+                // should be on of the default ones we support
+                if ("default".equalsIgnoreCase(strategy)) {
+                    endpoint.setJmsKeyFormatStrategy(new DefaultJmsKeyFormatStrategy());
+                } else if ("passthrough".equalsIgnoreCase(strategy)) {
+                    endpoint.setJmsKeyFormatStrategy(new PassThroughJmsKeyFormatStrategy());
+                } else {
+                    throw new IllegalArgumentException("Unknown jmsKeyFormatStrategy option: " + strategy);
+                }
+            }
+        }
+
+        setProperties(endpoint.getConfiguration(), parameters);
         endpoint.setHeaderFilterStrategy(getHeaderFilterStrategy());
 
         return endpoint;

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java?rev=756479&r1=756478&r2=756479&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java Fri Mar 20 14:20:27 2009
@@ -132,6 +132,7 @@
     private String replyToDestination;
     private String replyToDestinationSelectorName;
     private JmsMessageType jmsMessageType;
+    private JmsKeyFormatStrategy jmsKeyFormatStrategy;
 
     public JmsConfiguration() {
     }
@@ -1153,4 +1154,15 @@
     public void setJmsMessageType(JmsMessageType jmsMessageType) {
         this.jmsMessageType = jmsMessageType;
     }
+
+    public JmsKeyFormatStrategy getJmsKeyFormatStrategy() {
+        if (jmsKeyFormatStrategy == null) {
+            jmsKeyFormatStrategy = new DefaultJmsKeyFormatStrategy();
+        }
+        return jmsKeyFormatStrategy;
+    }
+
+    public void setJmsKeyFormatStrategy(JmsKeyFormatStrategy jmsKeyFormatStrategy) {
+        this.jmsKeyFormatStrategy = jmsKeyFormatStrategy;
+    }
 }

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java?rev=756479&r1=756478&r2=756479&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java Fri Mar 20 14:20:27 2009
@@ -771,6 +771,14 @@
         getConfiguration().setJmsMessageType(jmsMessageType);
     }
 
+    public JmsKeyFormatStrategy getJmsKeyFormatStrategy() {
+        return getConfiguration().getJmsKeyFormatStrategy();
+    }
+
+    public void setJmsKeyFormatStrategy(JmsKeyFormatStrategy jmsHeaderStrategy) {
+        getConfiguration().setJmsKeyFormatStrategy(jmsHeaderStrategy);
+    }
+
     // Implementation methods
     //-------------------------------------------------------------------------
 

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java?rev=756479&r1=756478&r2=756479&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHeaderFilterStrategy.java Fri Mar 20 14:20:27 2009
@@ -41,9 +41,4 @@
         getOutFilter().add("JMSXState");
     }
 
-    @Override
-    protected boolean extendedFilter(Direction direction, String key, Object value) {
-        return Direction.OUT == direction
-            && !ObjectHelper.isJavaIdentifier(JmsBinding.encodeToSafeJmsHeaderName(key));
-    }
 }

Added: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsKeyFormatStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsKeyFormatStrategy.java?rev=756479&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsKeyFormatStrategy.java (added)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsKeyFormatStrategy.java Fri Mar 20 14:20:27 2009
@@ -0,0 +1,41 @@
+/**
+ * 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;
+
+/**
+ * Strategy for applying encoding and decoding of JMS headers so they apply to the JMS spec.
+ *
+ * @version $Revision$
+ */
+public interface JmsKeyFormatStrategy {
+
+    /**
+     * Encodes the key before its sent as a {@link javax.jms.Message} message.
+     *
+     * @param key  the original key
+     * @return the encoded key
+     */
+    String encodeKey(String key);
+
+    /**
+     * Decodes the key after its received from a {@link javax.jms.Message} message.
+     *
+     * @param key the encoded key
+     * @return the decoded key as the original key
+     */
+    String decodeKey(String key);
+}

Propchange: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsKeyFormatStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsKeyFormatStrategy.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategy.java?rev=756479&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategy.java (added)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategy.java Fri Mar 20 14:20:27 2009
@@ -0,0 +1,33 @@
+/**
+ * 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;
+
+/**
+ * A strategy that does not do any encoding or decoding, eg. the keys is passed throught as is.
+ *
+ * @version $Revision$
+ */
+public class PassThroughJmsKeyFormatStrategy implements JmsKeyFormatStrategy {
+
+    public String encodeKey(String key) {
+        return key;
+    }
+
+    public String decodeKey(String key) {
+        return key;
+    }
+}

Propchange: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategy.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/DefaultJmsHeaderKeyFormatStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/DefaultJmsHeaderKeyFormatStrategyTest.java?rev=756479&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/DefaultJmsHeaderKeyFormatStrategyTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/DefaultJmsHeaderKeyFormatStrategyTest.java Fri Mar 20 14:20:27 2009
@@ -0,0 +1,45 @@
+/**
+ * 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 junit.framework.TestCase;
+
+/**
+ * @version $Revision$
+ */
+public class DefaultJmsHeaderKeyFormatStrategyTest extends TestCase {
+
+    private JmsKeyFormatStrategy strategy = new DefaultJmsKeyFormatStrategy();
+
+    public void testEncodeValidKeys() {
+        assertEquals("foo", strategy.encodeKey("foo"));
+        assertEquals("foo123bar", strategy.encodeKey("foo123bar"));
+        assertEquals("CamelFileName", strategy.encodeKey("CamelFileName"));
+        assertEquals("org_apache_camel_MyBean", strategy.encodeKey("org.apache.camel.MyBean"));
+        assertEquals("Content_HYPHEN_Type", strategy.encodeKey("Content-Type"));
+        assertEquals("My_HYPHEN_Header_You", strategy.encodeKey("My-Header.You"));
+    }
+
+    public void testDeccodeValidKeys() {
+        assertEquals("foo", strategy.decodeKey("foo"));
+        assertEquals("foo123bar", strategy.decodeKey("foo123bar"));
+        assertEquals("CamelFileName", strategy.decodeKey("CamelFileName"));
+        assertEquals("Content-Type", strategy.decodeKey("Content_HYPHEN_Type"));
+        assertEquals("My-Header.You", strategy.decodeKey("My_HYPHEN_Header_You"));
+    }
+
+}

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

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

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithCustomKeyFormatStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithCustomKeyFormatStrategyTest.java?rev=756479&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithCustomKeyFormatStrategyTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithCustomKeyFormatStrategyTest.java Fri Mar 20 14:20:27 2009
@@ -0,0 +1,63 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * With the passthrough option
+ *
+ * @version $Revision$
+ */
+public class JmsRouteWithCustomKeyFormatStrategyTest extends JmsRouteWithDefaultKeyFormatStrategyTest {
+
+    protected String getUri() {
+        return "activemq:queue:foo?jmsKeyFormatStrategy=#myJmsKeyStrategy";
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("myJmsKeyStrategy", new MyCustomKeyFormatStrategy());
+        return jndi;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to(getUri());
+
+                from(getUri()).to("mock:result");
+            }
+        };
+    }
+
+    private class MyCustomKeyFormatStrategy implements JmsKeyFormatStrategy {
+
+        public String encodeKey(String key) {
+            return "FOO" + key + "BAR";
+        }
+
+        public String decodeKey(String key) {
+            return ObjectHelper.between(key, "FOO", "BAR");
+        }
+    }
+}
\ No newline at end of file

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

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

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithDefaultKeyFormatStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithDefaultKeyFormatStrategyTest.java?rev=756479&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithDefaultKeyFormatStrategyTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithDefaultKeyFormatStrategyTest.java Fri Mar 20 14:20:27 2009
@@ -0,0 +1,105 @@
+/**
+ * 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.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+/**
+ * @version $Revision$
+ */
+public class JmsRouteWithDefaultKeyFormatStrategyTest extends ContextTestSupport {
+
+    protected String getUri() {
+        return "activemq:queue:foo?jmsKeyFormatStrategy=default";
+    }
+
+    public void testIllegalOption() throws Exception {
+        try {
+            context.getEndpoint("activemq:queue:bar?jmsHeaderStrategy=xxx");
+            fail("Should have thrown a ResolveEndpointFailedException");
+        } catch (ResolveEndpointFailedException e) {
+            // expected
+        }
+    }
+
+    public void testNoHeader() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testWithPlainHeader() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+        mock.expectedHeaderReceived("foo", "cheese");
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "cheese");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testWithMixedHeader() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+        mock.expectedHeaderReceived("foo", "cheese");
+        mock.expectedHeaderReceived("Content-Type", "text/plain");
+        mock.expectedHeaderReceived("org.apache.camel.MyKey", "foo");
+
+        Map headers = new HashMap();
+        headers.put("foo", "cheese");
+        headers.put("Content-Type", "text/plain");
+        headers.put("org.apache.camel.MyKey", "foo");
+
+        template.sendBodyAndHeaders("direct:start", "Hello World", 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() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to(getUri());
+
+                from(getUri()).to("mock:result");
+            }
+        };
+    }
+}

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

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

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithPassThroughKeyFormatStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithPassThroughKeyFormatStrategyTest.java?rev=756479&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithPassThroughKeyFormatStrategyTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithPassThroughKeyFormatStrategyTest.java Fri Mar 20 14:20:27 2009
@@ -0,0 +1,30 @@
+/**
+ * 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;
+
+/**
+ * With the passthrough option
+ *
+ * @version $Revision$
+ */
+public class JmsRouteWithPassThroughKeyFormatStrategyTest extends JmsRouteWithDefaultKeyFormatStrategyTest {
+
+    @Override
+    protected String getUri() {
+        return "activemq:queue:foo?jmsKeyFormatStrategy=passthrough";
+    }
+}
\ No newline at end of file

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

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

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategyTest.java?rev=756479&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategyTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategyTest.java Fri Mar 20 14:20:27 2009
@@ -0,0 +1,45 @@
+/**
+ * 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 junit.framework.TestCase;
+
+/**
+ * @version $Revision$
+ */
+public class PassThroughJmsKeyFormatStrategyTest extends TestCase {
+
+    private JmsKeyFormatStrategy strategy = new PassThroughJmsKeyFormatStrategy();
+
+    public void testEncodeValidKeys() {
+        assertEquals("foo", strategy.encodeKey("foo"));
+        assertEquals("foo123bar", strategy.encodeKey("foo123bar"));
+        assertEquals("CamelFileName", strategy.encodeKey("CamelFileName"));
+        assertEquals("org.apache.camel.MyBean", strategy.encodeKey("org.apache.camel.MyBean"));
+        assertEquals("Content-Type", strategy.encodeKey("Content-Type"));
+        assertEquals("My-Header.You", strategy.encodeKey("My-Header.You"));
+    }
+
+    public void testDeccodeValidKeys() {
+        assertEquals("foo", strategy.decodeKey("foo"));
+        assertEquals("foo123bar", strategy.decodeKey("foo123bar"));
+        assertEquals("CamelFileName", strategy.decodeKey("CamelFileName"));
+        assertEquals("Content-Type", strategy.decodeKey("Content-Type"));
+        assertEquals("My-Header.You", strategy.decodeKey("My-Header.You"));
+    }
+
+}
\ No newline at end of file

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

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