Author: davsclaus
Date: Sat Jan 29 12:54:32 2011
New Revision: 1065012
URL: http://svn.apache.org/viewvc?rev=1065012&view=rev
Log:
CAMEL-3254: Added test for using multiple route policies. Reworked a bit to
only use one RoutePolicyProcessor.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesRefTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRoutePoliciesTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRoutePoliciesTest.xml
- copied, changed from r1064979,
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/choice.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutePolicyProcessor.java
camel/trunk/components/camel-quartz/pom.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java?rev=1065012&r1=1065011&r2=1065012&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
Sat Jan 29 12:54:32 2011
@@ -146,35 +146,28 @@ public class DefaultRouteContext impleme
public void commit() {
// now lets turn all of the event driven consumer processors into a
single route
if (!eventDrivenProcessors.isEmpty()) {
- Processor processor = Pipeline.newInstance(getCamelContext(),
eventDrivenProcessors);
+ Processor target = Pipeline.newInstance(getCamelContext(),
eventDrivenProcessors);
// and wrap it in a unit of work so the UoW is on the top, so the
entire route will be in the same UoW
- UnitOfWorkProcessor unitOfWorkProcessor = new
UnitOfWorkProcessor(this, processor);
- Processor target = unitOfWorkProcessor;
+ UnitOfWorkProcessor unitOfWorkProcessor = new
UnitOfWorkProcessor(this, target);
// and then optionally add route policy processor if a custom
policy is set
RoutePolicyProcessor routePolicyProcessor = null;
- List<RoutePolicy> policyList = getRoutePolicyList();
- if (!policyList.isEmpty()) {
- boolean firstPolicy = true;
- for (RoutePolicy policy : policyList) {
- if (firstPolicy) {
- routePolicyProcessor = new
RoutePolicyProcessor(unitOfWorkProcessor, policy);
- firstPolicy = false;
- } else {
- routePolicyProcessor = new
RoutePolicyProcessor(routePolicyProcessor, policy);
- }
-
- // add it as service if we have not already done that (eg
possible if two routes have the same service)
- if (!camelContext.hasService(policy)) {
- try {
- camelContext.addService(policy);
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
+ List<RoutePolicy> routePolicyList = getRoutePolicyList();
+ if (routePolicyList != null && !routePolicyList.isEmpty()) {
+ routePolicyProcessor = new
RoutePolicyProcessor(unitOfWorkProcessor, routePolicyList);
+
+ // add it as service if we have not already done that (eg
possible if two routes have the same service)
+ if (!camelContext.hasService(routePolicyProcessor)) {
+ try {
+ camelContext.addService(routePolicyProcessor);
+ } catch (Exception e) {
+ throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
target = routePolicyProcessor;
+ } else {
+ target = unitOfWorkProcessor;
}
// and wrap it by a instrumentation processor that is to be used
for performance stats
@@ -199,8 +192,8 @@ public class DefaultRouteContext impleme
}
// invoke init on route policy
- if (!policyList.isEmpty()) {
- for (RoutePolicy policy : policyList) {
+ if (routePolicyList != null && !routePolicyList.isEmpty()) {
+ for (RoutePolicy policy : routePolicyList) {
policy.onInit(edcr);
}
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java?rev=1065012&r1=1065011&r2=1065012&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
Sat Jan 29 12:54:32 2011
@@ -56,7 +56,7 @@ import org.apache.camel.util.ObjectHelpe
* @version $Revision$
*/
@XmlRootElement(name = "route")
-@XmlType(propOrder = {"inputs", "outputs" })
+@XmlType(propOrder = {"inputs", "outputs"})
@XmlAccessorType(XmlAccessType.PROPERTY)
public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
private final AtomicBoolean prepared = new AtomicBoolean(false);
@@ -69,7 +69,7 @@ public class RouteDefinition extends Pro
private String delayer;
private String autoStartup;
private Integer startupOrder;
- private RoutePolicy routePolicy;
+ private List<RoutePolicy> routePolicies;
private String routePolicyRef;
private ShutdownRoute shutdownRoute;
private ShutdownRunningTask shutdownRunningTask;
@@ -146,7 +146,7 @@ public class RouteDefinition extends Pro
return status.isStoppable();
}
}
-
+
public List<RouteContext> addRoutes(CamelContext camelContext,
Collection<Route> routes) throws Exception {
List<RouteContext> answer = new ArrayList<RouteContext>();
@@ -186,8 +186,8 @@ public class RouteDefinition extends Pro
* <p/>
* Will stop and remove the old route from camel context and add and start
this new advised route.
*
- * @param camelContext the camel context
- * @param builder the route builder
+ * @param camelContext the camel context
+ * @param builder the route builder
* @return a new route which is this route merged with the route builder
* @throws Exception can be thrown from the route builder
*/
@@ -224,7 +224,7 @@ public class RouteDefinition extends Pro
/**
* Creates an input to the route
*
- * @param uri the from uri
+ * @param uri the from uri
* @return the builder
*/
public RouteDefinition from(String uri) {
@@ -235,7 +235,7 @@ public class RouteDefinition extends Pro
/**
* Creates an input to the route
*
- * @param endpoint the from endpoint
+ * @param endpoint the from endpoint
* @return the builder
*/
public RouteDefinition from(Endpoint endpoint) {
@@ -246,7 +246,7 @@ public class RouteDefinition extends Pro
/**
* Creates inputs to the route
*
- * @param uris the from uris
+ * @param uris the from uris
* @return the builder
*/
public RouteDefinition from(String... uris) {
@@ -259,7 +259,7 @@ public class RouteDefinition extends Pro
/**
* Creates inputs to the route
*
- * @param endpoints the from endpoints
+ * @param endpoints the from endpoints
* @return the builder
*/
public RouteDefinition from(Endpoint... endpoints) {
@@ -272,7 +272,7 @@ public class RouteDefinition extends Pro
/**
* Set the group name for this route
*
- * @param name the group name
+ * @param name the group name
* @return the builder
*/
public RouteDefinition group(String name) {
@@ -283,7 +283,7 @@ public class RouteDefinition extends Pro
/**
* Set the route id for this route
*
- * @param id the route id
+ * @param id the route id
* @return the builder
*/
public RouteDefinition routeId(String id) {
@@ -293,7 +293,7 @@ public class RouteDefinition extends Pro
/**
* Disable stream caching for this route.
- *
+ *
* @return the builder
*/
public RouteDefinition noStreamCaching() {
@@ -304,7 +304,7 @@ public class RouteDefinition extends Pro
/**
* Enable stream caching for this route.
- *
+ *
* @return the builder
*/
public RouteDefinition streamCaching() {
@@ -320,7 +320,7 @@ public class RouteDefinition extends Pro
/**
* Disable tracing for this route.
- *
+ *
* @return the builder
*/
public RouteDefinition noTracing() {
@@ -330,7 +330,7 @@ public class RouteDefinition extends Pro
/**
* Enable tracing for this route.
- *
+ *
* @return the builder
*/
public RouteDefinition tracing() {
@@ -340,7 +340,7 @@ public class RouteDefinition extends Pro
/**
* Disable handle fault for this route.
- *
+ *
* @return the builder
*/
public RouteDefinition noHandleFault() {
@@ -350,7 +350,7 @@ public class RouteDefinition extends Pro
/**
* Enable handle fault for this route.
- *
+ *
* @return the builder
*/
public RouteDefinition handleFault() {
@@ -360,7 +360,7 @@ public class RouteDefinition extends Pro
/**
* Disable delayer for this route.
- *
+ *
* @return the builder
*/
public RouteDefinition noDelayer() {
@@ -392,7 +392,7 @@ public class RouteDefinition extends Pro
/**
* Disables this route from being auto started when Camel starts.
- *
+ *
* @return the builder
*/
public RouteDefinition noAutoStartup() {
@@ -415,13 +415,18 @@ public class RouteDefinition extends Pro
}
/**
- * Configures a route policy for this route
+ * Configures route policies for this route
*
- * @param routePolicy the route policy
+ * @param policies the route policies
* @return the builder
- */
- public RouteDefinition routePolicy(RoutePolicy routePolicy) {
- setRoutePolicy(routePolicy);
+ */
+ public RouteDefinition routePolicy(RoutePolicy... policies) {
+ if (routePolicies == null) {
+ routePolicies = new ArrayList<RoutePolicy>();
+ }
+ for (RoutePolicy policy : policies) {
+ routePolicies.add(policy);
+ }
return this;
}
@@ -429,6 +434,7 @@ public class RouteDefinition extends Pro
* Configures a route policy for this route
*
* @param routePolicyRef reference to a {@link RoutePolicy} to lookup and
use.
+ * You can specify multiple references by separating
using comma.
* @return the builder
*/
public RouteDefinition routePolicyRef(String routePolicyRef) {
@@ -488,7 +494,7 @@ public class RouteDefinition extends Pro
/**
* The group that this route belongs to; could be the name of the
RouteBuilder class
* or be explicitly configured in the XML.
- *
+ * <p/>
* May be null.
*/
public String getGroup() {
@@ -596,13 +602,13 @@ public class RouteDefinition extends Pro
return routePolicyRef;
}
- @XmlTransient
- public void setRoutePolicy(RoutePolicy routePolicy) {
- this.routePolicy = routePolicy;
+ public List<RoutePolicy> getRoutePolicies() {
+ return routePolicies;
}
- public RoutePolicy getRoutePolicy() {
- return routePolicy;
+ @XmlTransient
+ public void setRoutePolicies(List<RoutePolicy> routePolicies) {
+ this.routePolicies = routePolicies;
}
public ShutdownRoute getShutdownRoute() {
@@ -636,7 +642,7 @@ public class RouteDefinition extends Pro
routeContext.setTracing(isTrace);
if (isTrace) {
if (log.isDebugEnabled()) {
- log.debug("Tracing is enabled on route: " + this);
+ log.debug("Tracing is enabled on route: " + getId());
}
// tracing is added in the DefaultChannel so we can enable
it on the fly
}
@@ -650,7 +656,7 @@ public class RouteDefinition extends Pro
routeContext.setStreamCaching(isStreamCache);
if (isStreamCache) {
if (log.isDebugEnabled()) {
- log.debug("StreamCaching is enabled on route: " +
this);
+ log.debug("StreamCaching is enabled on route: " +
getId());
}
// only add a new stream cache if not already a global
configured on camel context
if (StreamCaching.getStreamCaching(camelContext) == null) {
@@ -667,7 +673,7 @@ public class RouteDefinition extends Pro
routeContext.setHandleFault(isHandleFault);
if (isHandleFault) {
if (log.isDebugEnabled()) {
- log.debug("HandleFault is enabled on route: " + this);
+ log.debug("HandleFault is enabled on route: " +
getId());
}
// only add a new handle fault if not already a global
configured on camel context
if (HandleFault.getHandleFault(camelContext) == null) {
@@ -684,29 +690,33 @@ public class RouteDefinition extends Pro
routeContext.setDelayer(delayer);
if (delayer > 0) {
if (log.isDebugEnabled()) {
- log.debug("Delayer is enabled with: " + delayer + "
ms. on route: " + this);
+ log.debug("Delayer is enabled with: " + delayer + "
ms. on route: " + getId());
}
addInterceptStrategy(new Delayer(delayer));
} else {
if (log.isDebugEnabled()) {
- log.debug("Delayer is disabled on route: " + this);
+ log.debug("Delayer is disabled on route: " + getId());
}
}
}
}
// configure route policy
- if (routePolicy != null) {
- if (log.isDebugEnabled()) {
- log.debug("RoutePolicy is enabled: " + routePolicy + " on
route: " + this);
+ if (routePolicies != null && !routePolicies.isEmpty()) {
+ for (RoutePolicy policy : routePolicies) {
+ if (log.isDebugEnabled()) {
+ log.debug("RoutePolicy is enabled: " + policy + " on
route: " + getId());
+ }
+ routeContext.getRoutePolicyList().add(policy);
}
- routeContext.getRoutePolicyList().add(getRoutePolicy());
- } else if (routePolicyRef != null) {
+ }
+ if (routePolicyRef != null) {
StringTokenizer policyTokens = new StringTokenizer(routePolicyRef,
",");
while (policyTokens.hasMoreTokens()) {
- RoutePolicy policy =
CamelContextHelper.mandatoryLookup(camelContext,
policyTokens.nextToken().trim(), RoutePolicy.class);
+ String ref = policyTokens.nextToken().trim();
+ RoutePolicy policy =
CamelContextHelper.mandatoryLookup(camelContext, ref, RoutePolicy.class);
if (log.isDebugEnabled()) {
- log.debug("RoutePolicy is enabled: " + policy + " on
route: " + this);
+ log.debug("RoutePolicy is enabled: " + policy + " on
route: " + getId());
}
routeContext.getRoutePolicyList().add(policy);
}
@@ -716,7 +726,7 @@ public class RouteDefinition extends Pro
Boolean isAutoStartup = CamelContextHelper.parseBoolean(camelContext,
getAutoStartup());
if (isAutoStartup != null) {
if (log.isDebugEnabled()) {
- log.debug("Using AutoStartup " + isAutoStartup + " on route: "
+ this);
+ log.debug("Using AutoStartup " + isAutoStartup + " on route: "
+ getId());
}
routeContext.setAutoStartup(isAutoStartup);
}
@@ -724,13 +734,13 @@ public class RouteDefinition extends Pro
// configure shutdown
if (shutdownRoute != null) {
if (log.isDebugEnabled()) {
- log.debug("Using ShutdownRoute " + getShutdownRoute() + " on
route: " + this);
+ log.debug("Using ShutdownRoute " + getShutdownRoute() + " on
route: " + getId());
}
routeContext.setShutdownRoute(getShutdownRoute());
}
if (shutdownRunningTask != null) {
if (log.isDebugEnabled()) {
- log.debug("Using ShutdownRunningTask " +
getShutdownRunningTask() + " on route: " + this);
+ log.debug("Using ShutdownRunningTask " +
getShutdownRunningTask() + " on route: " + getId());
}
routeContext.setShutdownRunningTask(getShutdownRunningTask());
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutePolicyProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutePolicyProcessor.java?rev=1065012&r1=1065011&r2=1065012&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutePolicyProcessor.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutePolicyProcessor.java
Sat Jan 29 12:54:32 2011
@@ -16,6 +16,8 @@
*/
package org.apache.camel.processor;
+import java.util.List;
+
import org.apache.camel.AsyncCallback;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
@@ -24,61 +26,101 @@ import org.apache.camel.Route;
import org.apache.camel.impl.ServiceSupport;
import org.apache.camel.impl.SynchronizationAdapter;
import org.apache.camel.spi.RoutePolicy;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
+ * {@link Processor} which instruments the {@link RoutePolicy}.
+ *
* @version $Revision$
*/
public class RoutePolicyProcessor extends DelegateAsyncProcessor {
- private final RoutePolicy routePolicy;
+ private final Log LOG = LogFactory.getLog(RoutePolicyProcessor.class);
+ private final List<RoutePolicy> routePolicies;
private Route route;
- public RoutePolicyProcessor(Processor processor, RoutePolicy routePolicy) {
+ public RoutePolicyProcessor(Processor processor, List<RoutePolicy>
routePolicies) {
super(processor);
- this.routePolicy = routePolicy;
+ this.routePolicies = routePolicies;
}
@Override
public String toString() {
- return "RoutePolicy[" + routePolicy + "]";
+ return "RoutePolicy[" + routePolicies + "]";
}
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
- // check whether the policy is enabled
- if (isRoutePolicyRunAllowed()) {
- // invoke begin
- routePolicy.onExchangeBegin(route, exchange);
+ // invoke begin
+ for (RoutePolicy policy : routePolicies) {
+ try {
+ if (isRoutePolicyRunAllowed(policy)) {
+ policy.onExchangeBegin(route, exchange);
+ }
+ } catch (Exception e) {
+ LOG.warn("Error occurred during onExchangeBegin on
RoutePolicy: " + policy
+ + ". This exception will be ignored", e);
+ }
+ }
- // add on completion that invokes the policy callback on complete
- // as the Exchange can be routed async and thus we need the
callback to
- // invoke when the route is completed
- exchange.addOnCompletion(new SynchronizationAdapter() {
- @Override
- public void onDone(Exchange exchange) {
- // do not invoke it if Camel is stopping as we don't want
- // the policy to start a consumer during Camel is stopping
- if (isCamelStopping(exchange.getContext())) {
- return;
- }
- routePolicy.onExchangeDone(route, exchange);
+ // add on completion that invokes the policy callback on complete
+ // as the Exchange can be routed async and thus we need the callback to
+ // invoke when the route is completed
+ exchange.addOnCompletion(new SynchronizationAdapter() {
+ @Override
+ public void onDone(Exchange exchange) {
+ // do not invoke it if Camel is stopping as we don't want
+ // the policy to start a consumer during Camel is stopping
+ if (isCamelStopping(exchange.getContext())) {
+ return;
}
- @Override
- public String toString() {
- return "RoutePolicy";
+ for (RoutePolicy policy : routePolicies) {
+ try {
+ if (isRoutePolicyRunAllowed(policy)) {
+ policy.onExchangeDone(route, exchange);
+ }
+ } catch (Exception e) {
+ LOG.warn("Error occurred during onExchangeDone on
RoutePolicy: " + policy
+ + ". This exception will be ignored", e);
+ }
}
- });
- }
+ }
+
+ @Override
+ public String toString() {
+ return "RoutePolicyOnCompletion";
+ }
+ });
return super.process(exchange, callback);
}
+ /**
+ * Sets the route this policy applies.
+ *
+ * @param route the route
+ */
public void setRoute(Route route) {
this.route = route;
}
+ /**
+ * Strategy to determine if this policy is allowed to run
+ *
+ * @param policy the policy
+ * @return <tt>true</tt> to run
+ */
+ protected boolean isRoutePolicyRunAllowed(RoutePolicy policy) {
+ if (policy instanceof ServiceSupport) {
+ ServiceSupport ss = (ServiceSupport) policy;
+ return ss.isRunAllowed();
+ }
+ return true;
+ }
+
private static boolean isCamelStopping(CamelContext context) {
if (context instanceof ServiceSupport) {
ServiceSupport ss = (ServiceSupport) context;
@@ -87,12 +129,4 @@ public class RoutePolicyProcessor extend
return false;
}
- private boolean isRoutePolicyRunAllowed() {
- if (routePolicy instanceof ServiceSupport) {
- ServiceSupport ss = (ServiceSupport) routePolicy;
- return ss.isRunAllowed();
- }
- return true;
- }
-
}
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesRefTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesRefTest.java?rev=1065012&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesRefTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesRefTest.java
Sat Jan 29 12:54:32 2011
@@ -0,0 +1,81 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Route;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.impl.RoutePolicySupport;
+
+/**
+ * @version $Revision: 1043882 $
+ */
+public class RoutePoliciesRefTest extends ContextTestSupport {
+
+ private final MyCustomRoutePolicy policyA = new MyCustomRoutePolicy("A");
+ private final MyCustomRoutePolicy policyB = new MyCustomRoutePolicy("B");
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("policy-a", policyA);
+ jndi.bind("policy-b", policyB);
+ return jndi;
+ }
+
+ private class MyCustomRoutePolicy extends RoutePolicySupport {
+
+ private final String name;
+
+ private MyCustomRoutePolicy(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public void onExchangeBegin(Route route, Exchange exchange) {
+ exchange.getIn().setHeader(name, name);
+ }
+
+ }
+
+ public void testCustomPolicies() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+ mock.expectedHeaderReceived("A", "A");
+ mock.expectedHeaderReceived("B", "B");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .routePolicyRef("policy-a, policy-b")
+ .to("mock:result");
+ }
+ };
+ }
+}
+
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesTest.java?rev=1065012&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePoliciesTest.java
Sat Jan 29 12:54:32 2011
@@ -0,0 +1,72 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Route;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.RoutePolicySupport;
+
+/**
+ * @version $Revision: 1043882 $
+ */
+public class RoutePoliciesTest extends ContextTestSupport {
+
+ private final MyCustomRoutePolicy policyA = new MyCustomRoutePolicy("A");
+ private final MyCustomRoutePolicy policyB = new MyCustomRoutePolicy("B");
+
+ private class MyCustomRoutePolicy extends RoutePolicySupport {
+
+ private final String name;
+
+ private MyCustomRoutePolicy(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public void onExchangeBegin(Route route, Exchange exchange) {
+ exchange.getIn().setHeader(name, name);
+ }
+
+ }
+
+ public void testCustomPolicies() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+ mock.expectedHeaderReceived("A", "A");
+ mock.expectedHeaderReceived("B", "B");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .routePolicy(policyA, policyB)
+ .to("mock:result");
+ }
+ };
+ }
+}
+
Modified: camel/trunk/components/camel-quartz/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/pom.xml?rev=1065012&r1=1065011&r2=1065012&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/pom.xml (original)
+++ camel/trunk/components/camel-quartz/pom.xml Sat Jan 29 12:54:32 2011
@@ -73,11 +73,6 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-core-xml</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<scope>test</scope>
</dependency>
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRoutePoliciesTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRoutePoliciesTest.java?rev=1065012&view=auto
==============================================================================
---
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRoutePoliciesTest.java
(added)
+++
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRoutePoliciesTest.java
Sat Jan 29 12:54:32 2011
@@ -0,0 +1,64 @@
+/**
+ * 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.spring.processor;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Route;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.RoutePolicySupport;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class SpringRoutePoliciesTest extends SpringTestSupport {
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/spring/processor/SpringRoutePoliciesTest.xml");
+ }
+
+ public void testCustomPolicies() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+ mock.expectedHeaderReceived("A", "A");
+ mock.expectedHeaderReceived("B", "B");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public static class MyCustomRoutePolicy extends RoutePolicySupport {
+
+ private final String name;
+
+ private MyCustomRoutePolicy(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public void onExchangeBegin(Route route, Exchange exchange) {
+ exchange.getIn().setHeader(name, name);
+ }
+
+ }
+
+
+}
Copied:
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRoutePoliciesTest.xml
(from r1064979,
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/choice.xml)
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRoutePoliciesTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRoutePoliciesTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/choice.xml&r1=1064979&r2=1065012&rev=1065012&view=diff
==============================================================================
---
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/choice.xml
(original)
+++
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRoutePoliciesTest.xml
Sat Jan 29 12:54:32 2011
@@ -22,26 +22,19 @@
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
">
- <!-- START SNIPPET: example -->
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <choice>
- <when>
- <xpath>$foo = 'bar'</xpath>
- <to uri="mock:x"/>
- </when>
- <when>
- <xpath>$foo = 'cheese'</xpath>
- <to uri="mock:y"/>
- </when>
- <otherwise>
- <to uri="mock:z"/>
- </otherwise>
- </choice>
- <to uri="mock:end"/>
- </route>
- </camelContext>
- <!-- END SNIPPET: example -->
+ <bean id="policy-a"
class="org.apache.camel.spring.processor.SpringRoutePoliciesTest$MyCustomRoutePolicy">
+ <constructor-arg index="0" value="A"/>
+ </bean>
+
+ <bean id="policy-b"
class="org.apache.camel.spring.processor.SpringRoutePoliciesTest$MyCustomRoutePolicy">
+ <constructor-arg index="0" value="B"/>
+ </bean>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route routePolicyRef="policy-a, policy-b">
+ <from uri="direct:start"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
</beans>