You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/05/13 06:14:24 UTC
svn commit: r943792 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/model/ main/java/org/apache/camel/processor/
test/java/org/apache/camel/processor/routingslip/
Author: ningjiang
Date: Thu May 13 04:14:24 2010
New Revision: 943792
URL: http://svn.apache.org/viewvc?rev=943792&view=rev
Log:
CAMEL-2710, CAMEL-1717 Added ignoreInvalidEndpoints options on RoutingSlip
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutingSlipDefinition.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=943792&r1=943791&r2=943792&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Thu May 13 04:14:24 2010
@@ -1271,6 +1271,48 @@ public abstract class ProcessorDefinitio
addOutput(answer);
return (Type) this;
}
+
+ /**
+ * <a href="http://camel.apache.org/routing-slip.html">Routing Slip EIP:</a>
+ * Creates a routing slip allowing you to route a message consecutively through a series of processing
+ * steps where the sequence of steps is not known at design time and can vary for each message.
+ *
+ * @param header is the header that the {@link org.apache.camel.processor.RoutingSlip RoutingSlip}
+ * class will look in for the list of URIs to route the message to.
+ * @param uriDelimiter is the delimiter that will be used to split up
+ * the list of URIs in the routing slip.
+ * @param ignoreInvalidEndpoints if this parameter is true, routingSlip will ignore the endpoints which
+ * cannot be resolved or a producer cannot be created or started
+ * @return the builder
+ */
+ @SuppressWarnings("unchecked")
+ public Type routingSlip(String header, String uriDelimiter, boolean ignoreInvalidEndpoints) {
+ RoutingSlipDefinition answer = new RoutingSlipDefinition(header, uriDelimiter);
+ answer.setIgnoreInvalidEndpoints(ignoreInvalidEndpoints);
+ addOutput(answer);
+ return (Type) this;
+ }
+
+ /**
+ * <a href="http://camel.apache.org/routing-slip.html">Routing Slip EIP:</a>
+ * Creates a routing slip allowing you to route a message consecutively through a series of processing
+ * steps where the sequence of steps is not known at design time and can vary for each message.
+ * <p>
+ * The list of URIs will be split based on the default delimiter {@link RoutingSlipDefinition#DEFAULT_DELIMITER}
+ *
+ * @param header is the header that the {@link org.apache.camel.processor.RoutingSlip RoutingSlip}
+ * class will look in for the list of URIs to route the message to.
+ * @param ignoreInvalidEndpoints if this parameter is true, routingSlip will ignore the endpoints which
+ * cannot be resolved or a producer cannot be created or started
+ * @return the builder
+ */
+ @SuppressWarnings("unchecked")
+ public Type routingSlip(String header, boolean ignoreInvalidEndpoints) {
+ RoutingSlipDefinition answer = new RoutingSlipDefinition(header);
+ answer.setIgnoreInvalidEndpoints(ignoreInvalidEndpoints);
+ addOutput(answer);
+ return (Type) this;
+ }
/**
* <a href="http://camel.apache.org/sampling.html">Sampling Throttler</a>
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutingSlipDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutingSlipDefinition.java?rev=943792&r1=943791&r2=943792&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutingSlipDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutingSlipDefinition.java Thu May 13 04:14:24 2010
@@ -41,6 +41,8 @@ public class RoutingSlipDefinition exten
private String headerName;
@XmlAttribute
private String uriDelimiter;
+ @XmlAttribute
+ private Boolean ignoreInvalidEndpoints;
public RoutingSlipDefinition() {
this(null, DEFAULT_DELIMITER);
@@ -69,7 +71,11 @@ public class RoutingSlipDefinition exten
public Processor createProcessor(RouteContext routeContext) throws Exception {
ObjectHelper.notEmpty(getHeaderName(), "headerName", this);
ObjectHelper.notEmpty(getUriDelimiter(), "uriDelimiter", this);
- return new RoutingSlip(routeContext.getCamelContext(), getHeaderName(), getUriDelimiter());
+ RoutingSlip routingSlip = new RoutingSlip(routeContext.getCamelContext(), getHeaderName(), getUriDelimiter());
+ if (getIgnoreInvalidEndpoint() != null) {
+ routingSlip.setIgnoreInvalidEndpoints(getIgnoreInvalidEndpoint());
+ }
+ return routingSlip;
}
@Override
@@ -92,4 +98,12 @@ public class RoutingSlipDefinition exten
public String getUriDelimiter() {
return uriDelimiter;
}
+
+ public void setIgnoreInvalidEndpoints(Boolean ignoreInvalidEndpoints) {
+ this.ignoreInvalidEndpoints = ignoreInvalidEndpoints;
+ }
+
+ public Boolean getIgnoreInvalidEndpoint() {
+ return ignoreInvalidEndpoints;
+ }
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java?rev=943792&r1=943791&r2=943792&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java Thu May 13 04:14:24 2010
@@ -59,7 +59,7 @@ public abstract class RedeliveryErrorHan
Processor failureProcessor;
Processor onRedeliveryProcessor = redeliveryProcessor;
Predicate handledPredicate = handledPolicy;
- Predicate continuedPredicate = null;
+ Predicate continuedPredicate;
boolean useOriginalInMessage = useOriginalMessagePolicy;
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java?rev=943792&r1=943791&r2=943792&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java Thu May 13 04:14:24 2010
@@ -20,6 +20,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
+import org.apache.camel.FailedToCreateProducerException;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
@@ -44,6 +45,7 @@ import static org.apache.camel.util.Obje
public class RoutingSlip extends ServiceSupport implements Processor, Traceable {
private static final transient Log LOG = LogFactory.getLog(RoutingSlip.class);
private ProducerCache producerCache;
+ private boolean ignoreInvalidEndpoints;
private final String header;
private final String uriDelimiter;
private final CamelContext camelContext;
@@ -61,6 +63,14 @@ public class RoutingSlip extends Service
this.header = header;
this.uriDelimiter = uriDelimiter;
}
+
+ public boolean isIgnoreInvalidEndpoints() {
+ return ignoreInvalidEndpoints;
+ }
+
+ public void setIgnoreInvalidEndpoints(boolean ignoreInvalidEndpoints) {
+ this.ignoreInvalidEndpoints = ignoreInvalidEndpoints;
+ }
@Override
public String toString() {
@@ -81,7 +91,17 @@ public class RoutingSlip extends Service
Exchange current = exchange;
for (String nextRecipient : recipients) {
- Endpoint endpoint = resolveEndpoint(exchange, nextRecipient);
+ Endpoint endpoint = null;
+ try {
+ endpoint = resolveEndpoint(exchange, nextRecipient.trim());
+ } catch (Exception ex) {
+ if (isIgnoreInvalidEndpoints()) {
+ LOG.info("Cannot resolve the endpoint with " + nextRecipient, ex);
+ continue;
+ } else {
+ throw ex;
+ }
+ }
Exchange copy = new DefaultExchange(current);
updateRoutingSlip(current);
@@ -97,8 +117,14 @@ public class RoutingSlip extends Service
}
});
} catch (Exception e) {
- // catch exception so we can decide if we want to continue or not
- copy.setException(e);
+ // Need to check the if the exception is thrown when camel try to create and start the producer
+ if (e instanceof FailedToCreateProducerException && isIgnoreInvalidEndpoints()) {
+ LOG.info("An Invalid endpoint with " + nextRecipient, e);
+ continue;
+ } else {
+ // catch exception so we can decide if we want to continue or not
+ copy.setException(e);
+ }
} finally {
current = copy;
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java?rev=943792&r1=943791&r2=943792&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java Thu May 13 04:14:24 2010
@@ -23,13 +23,10 @@ import org.apache.camel.ContextTestSuppo
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.util.jndi.JndiContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
public class RoutingSlipDataModificationTest extends ContextTestSupport {
protected static final String ANSWER = "answer";
protected static final String ROUTING_SLIP_HEADER = "routingSlipHeader";
- private static final transient Log LOG = LogFactory.getLog(RoutingSlipDataModificationTest.class);
protected MyBean myBean = new MyBean();
public void testModificationOfDataAlongRoute()
@@ -47,7 +44,7 @@ public class RoutingSlipDataModification
protected void sendBody() {
template.sendBodyAndHeader("direct:a", ANSWER, ROUTING_SLIP_HEADER,
- "mock:x,bean:myBean?method=modifyData");
+ "mock:x , bean:myBean?method=modifyData");
}
@Override
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java?rev=943792&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java Thu May 13 04:14:24 2010
@@ -0,0 +1,65 @@
+/**
+ * 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.routingslip;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class RoutingSlipIgnoreInvalidEndpointsTest extends ContextTestSupport {
+
+ public void testEndpontResolvedFailedWithIgnoreInvalidEndpoints() throws Exception {
+ MockEndpoint result = getMockEndpoint("mock:result");
+ result.expectedBodiesReceived("Hello World");
+ MockEndpoint end = getMockEndpoint("mock:end");
+ end.expectedBodiesReceived("Hello World");
+
+ template.sendBodyAndHeader("direct:a", "Hello", "myHeader", "direct:start ,fail:endpoint, mock:result");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testEndpointResolvedFailedWithoutIgnoreInvalidEndpoints() throws Exception {
+ MockEndpoint result = getMockEndpoint("mock:result");
+ result.expectedMessageCount(0);
+ MockEndpoint end = getMockEndpoint("mock:end");
+ end.expectedMessageCount(0);
+ try {
+ template.sendBodyAndHeader("direct:b", "Hello", "myHeader", "direct:start,fail:endpoint,mock:result");
+ fail("Expect the exception here.");
+ } catch (Exception ex) {
+ assertTrue("Get a wrong cause of the exception", ex.getCause() instanceof ResolveEndpointFailedException);
+ }
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:a").routingSlip("myHeader", true).to("mock:end");
+
+ from("direct:b").routingSlip("myHeader").to("mock:end");
+
+ from("direct:start").transform(constant("Hello World"));
+ }
+
+ };
+ }
+
+}
+
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipIgnoreInvalidEndpointsTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date