Author: davsclaus
Date: Fri Mar 15 10:12:32 2013
New Revision: 1456858
URL: http://svn.apache.org/r1456858
Log:
CAMEL-6166: Make it easier to configure jmsKeyFormatStrategy in camel-jms
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndpointTest.java
- copied, changed from r1456803,
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyTest.java
Modified:
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/PassThroughJmsKeyFormatStrategy.java
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyTest.java
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=1456858&r1=1456857&r2=1456858&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 15 10:12:32 2013
@@ -18,7 +18,6 @@ package org.apache.camel.component.jms;
import java.util.Map;
import java.util.concurrent.ExecutorService;
-
import javax.jms.ConnectionFactory;
import javax.jms.ExceptionListener;
import javax.jms.Session;
@@ -386,6 +385,20 @@ public class JmsComponent extends Defaul
getConfiguration().setDefaultTaskExecutorType(type);
}
+ public void setJmsKeyFormatStrategy(JmsKeyFormatStrategy
jmsKeyFormatStrategy) {
+ getConfiguration().setJmsKeyFormatStrategy(jmsKeyFormatStrategy);
+ }
+
+ public void setJmsKeyFormatStrategy(String jmsKeyFormatStrategyName) {
+ // allow to configure a standard by its name, which is simpler
+ JmsKeyFormatStrategy strategy =
resolveStandardJmsKeyFormatStrategy(jmsKeyFormatStrategyName);
+ if (strategy == null) {
+ throw new IllegalArgumentException("JmsKeyFormatStrategy with name
" + jmsKeyFormatStrategyName + " is not a standard supported name");
+ } else {
+ getConfiguration().setJmsKeyFormatStrategy(strategy);
+ }
+ }
+
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
}
@@ -497,18 +510,18 @@ public class JmsComponent extends Defaul
// jms header strategy
String strategyVal = getAndRemoveParameter(parameters,
KEY_FORMAT_STRATEGY_PARAM, String.class);
- if ("default".equalsIgnoreCase(strategyVal)) {
- endpoint.setJmsKeyFormatStrategy(new
DefaultJmsKeyFormatStrategy());
- } else if ("passthrough".equalsIgnoreCase(strategyVal)) {
- endpoint.setJmsKeyFormatStrategy(new
PassThroughJmsKeyFormatStrategy());
- } else { // a reference
+ JmsKeyFormatStrategy strategy =
resolveStandardJmsKeyFormatStrategy(strategyVal);
+ if (strategy != null) {
+ endpoint.setJmsKeyFormatStrategy(strategy);
+ } else {
+ // its not a standard, but a reference
parameters.put(KEY_FORMAT_STRATEGY_PARAM, strategyVal);
endpoint.setJmsKeyFormatStrategy(resolveAndRemoveReferenceParameter(
parameters, KEY_FORMAT_STRATEGY_PARAM,
JmsKeyFormatStrategy.class));
}
- messageListenerContainerFactory =
resolveAndRemoveReferenceParameter(parameters,
"messageListenerContainerFactoryRef",
- MessageListenerContainerFactory.class);
+ messageListenerContainerFactory =
resolveAndRemoveReferenceParameter(parameters,
+ "messageListenerContainerFactoryRef",
MessageListenerContainerFactory.class);
if (messageListenerContainerFactory != null) {
endpoint.setMessageListenerContainerFactory(messageListenerContainerFactory);
}
@@ -520,6 +533,26 @@ public class JmsComponent extends Defaul
}
/**
+ * Resolves the standard supported {@link JmsKeyFormatStrategy} by a name
which can be:
+ * <ul>
+ * <li>default - to use the default strategy</li>
+ * <li>passthrough - to use the passthrough strategy</li>
+ * </ul>
+ *
+ * @param name the name
+ * @return the strategy, or <tt>null</tt> if not a standard name.
+ */
+ private static JmsKeyFormatStrategy
resolveStandardJmsKeyFormatStrategy(String name) {
+ if ("default".equalsIgnoreCase(name)) {
+ return new DefaultJmsKeyFormatStrategy();
+ } else if ("passthrough".equalsIgnoreCase(name)) {
+ return new PassThroughJmsKeyFormatStrategy();
+ } else {
+ return null;
+ }
+ }
+
+ /**
* A strategy method allowing the URI destination to be translated into the
* actual JMS destination name (say by looking up in JNDI or something)
*/
Modified:
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=1456858&r1=1456857&r2=1456858&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategy.java
(original)
+++
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/PassThroughJmsKeyFormatStrategy.java
Fri Mar 15 10:12:32 2013
@@ -17,7 +17,7 @@
package org.apache.camel.component.jms;
/**
- * A strategy that does not do any encoding or decoding, eg. the keys is
passed throught as is.
+ * A strategy that does not do any encoding or decoding, eg. the keys is
passed through as is.
*
* @version
*/
Copied:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndpointTest.java
(from r1456803,
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndpointTest.java?p2=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndpointTest.java&p1=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyTest.java&r1=1456803&r2=1456858&rev=1456858&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyTest.java
(original)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyEndpointTest.java
Fri Mar 15 10:12:32 2013
@@ -26,7 +26,6 @@ import org.apache.camel.builder.RouteBui
import org.apache.camel.component.jms.CamelJmsTestHelper;
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.jmsComponentAutoAcknowledge;
@@ -34,7 +33,7 @@ import static org.apache.camel.component
/**
* @version
*/
-public class JmsPassThroughtJmsKeyFormatStrategyTest extends CamelTestSupport {
+public class JmsPassThroughtJmsKeyFormatStrategyEndpointTest extends
CamelTestSupport {
private String uri =
"activemq:queue:hello?jmsKeyFormatStrategy=passthrough";
Modified:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyTest.java?rev=1456858&r1=1456857&r2=1456858&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyTest.java
(original)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsPassThroughtJmsKeyFormatStrategyTest.java
Fri Mar 15 10:12:32 2013
@@ -24,9 +24,9 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.CamelJmsTestHelper;
+import org.apache.camel.component.jms.JmsComponent;
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.jmsComponentAutoAcknowledge;
@@ -36,7 +36,7 @@ import static org.apache.camel.component
*/
public class JmsPassThroughtJmsKeyFormatStrategyTest extends CamelTestSupport {
- private String uri =
"activemq:queue:hello?jmsKeyFormatStrategy=passthrough";
+ private String uri = "activemq:queue:hello";
@Test
public void testSendWithHeaders() throws Exception {
@@ -60,7 +60,13 @@ public class JmsPassThroughtJmsKeyFormat
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
ConnectionFactory connectionFactory =
CamelJmsTestHelper.createConnectionFactory();
- camelContext.addComponent("activemq",
jmsComponentAutoAcknowledge(connectionFactory));
+
+ // configure to use passthrough
+ JmsComponent activemq = jmsComponentAutoAcknowledge(connectionFactory);
+ activemq.setJmsKeyFormatStrategy("passthrough");
+
+ camelContext.addComponent("activemq", activemq);
+
return camelContext;
}