You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2009/02/11 19:26:22 UTC
svn commit: r743442 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/model/
camel-core/src/main/java/org/apache/camel/processor/
camel-core/src/main/java/org/apache/camel/util/
camel-core/src/main/resources/org/apache/camel/model/ camel-cor...
Author: janstey
Date: Wed Feb 11 18:26:22 2009
New Revision: 743442
URL: http://svn.apache.org/viewvc?rev=743442&view=rev
Log:
CAMEL-209 - Add content enrichment support to Java/Spring DSLs. Thanks to Martin Krasser for this patch!
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/EnricherType.java (with props)
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/FailureProcessor.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/SampleAggregator.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherTest.java (with props)
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/enricher.xml (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/EnricherType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/EnricherType.java?rev=743442&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/EnricherType.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/EnricherType.java Wed Feb 11 18:26:22 2009
@@ -0,0 +1,73 @@
+/**
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.Processor;
+import org.apache.camel.processor.Enricher;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ * @see Enricher
+ */
+@XmlRootElement(name = "enrich")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class EnricherType extends OutputType<EnricherType> {
+
+ @XmlAttribute(required = true)
+ private String resourceUri;
+
+ @XmlAttribute(required = false)
+ private String aggregationStrategyRef;
+
+ @XmlTransient
+ private AggregationStrategy aggregationStrategy;
+
+ public EnricherType() {
+ this(null, null);
+ }
+
+ public EnricherType(String resourceUri) {
+ this(null, resourceUri);
+ }
+
+ public EnricherType(AggregationStrategy aggregationStrategy, String resourceUri) {
+ this.aggregationStrategy = aggregationStrategy;
+ this.resourceUri = resourceUri;
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext) throws Exception {
+ Enricher enricher = new Enricher(null, resourceUri);
+ if (aggregationStrategyRef != null) {
+ aggregationStrategy = routeContext.lookup(aggregationStrategyRef, AggregationStrategy.class);
+ }
+ if (aggregationStrategy == null) {
+ enricher.setDefaultAggregationStrategy();
+ } else {
+ enricher.setAggregationStrategy(aggregationStrategy);
+ }
+ return enricher;
+ }
+
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/EnricherType.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=743442&r1=743441&r2=743442&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java Wed Feb 11 18:26:22 2009
@@ -52,6 +52,7 @@
import org.apache.camel.model.language.ExpressionType;
import org.apache.camel.model.language.LanguageExpression;
import org.apache.camel.processor.DelegateProcessor;
+import org.apache.camel.processor.Enricher;
import org.apache.camel.processor.Pipeline;
import org.apache.camel.processor.aggregate.AggregationCollection;
import org.apache.camel.processor.aggregate.AggregationStrategy;
@@ -1788,6 +1789,24 @@
return (Type) this;
}
+ /**
+ * Enriches an exchange with additional data obtained from a
+ * <code>resourceUri</code>.
+ *
+ * @param resourceUri
+ * URI of resource endpoint for obtaining additional data.
+ * @param aggregationStrategy
+ * aggregation strategy to aggregate input data and additional
+ * data.
+ * @return this processor type
+ * @see Enricher
+ *
+ */
+ public Type enrich(String resourceUri, AggregationStrategy aggregationStrategy) {
+ addOutput(new EnricherType(aggregationStrategy, resourceUri));
+ return (Type)this;
+ }
+
// DataFormat support
// -------------------------------------------------------------------------
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java?rev=743442&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java Wed Feb 11 18:26:22 2009
@@ -0,0 +1,153 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+
+import static org.apache.camel.util.ExchangeHelper.copyResultsPreservePattern;
+
+/**
+ * A content enricher that enriches input data by first obtaining additional
+ * data from a <i>resource</i> identified by an <code>resourceUri</code> and
+ * second by aggregating input data and additional data. Aggregation of input
+ * data and additional data is delegated to an {@link AggregationStrategy}
+ * object.
+ */
+public class Enricher implements Processor {
+
+ private String resourceUri;
+
+ private AggregationStrategy aggregationStrategy;
+
+ /**
+ * Creates a new {@link Enricher}. The default aggregation strategy is to
+ * copy the additional data obtained from the enricher's resource over the
+ * input data. When using the copy aggregation strategy the enricher
+ * degenerates to a normal transformer.
+ *
+ * @param resourceUri
+ * URI of resource endpoint for obtaining additional data.
+ */
+ public Enricher(String resourceUri) {
+ this(defaultAggregationStrategy(), resourceUri);
+ }
+
+ /**
+ * Creates a new {@link Enricher}.
+ *
+ * @param aggregationStrategy
+ * aggregation strategy to aggregate input data and additional
+ * data.
+ * @param resourceUri
+ * URI of resource endpoint for obtaining additional data.
+ */
+ public Enricher(AggregationStrategy aggregationStrategy, String resourceUri) {
+ this.aggregationStrategy = aggregationStrategy;
+ this.resourceUri = resourceUri;
+ }
+
+ /**
+ * Sets the aggregation strategy for this enricher.
+ *
+ * @param aggregationStrategy the aggregationStrategy to set
+ */
+ public void setAggregationStrategy(AggregationStrategy aggregationStrategy) {
+ this.aggregationStrategy = aggregationStrategy;
+ }
+
+ /**
+ * Sets the default aggregation strategy for this enricher.
+ *
+ * @param aggregationStrategy the aggregationStrategy to set
+ */
+ public void setDefaultAggregationStrategy() {
+ this.aggregationStrategy = defaultAggregationStrategy();
+ }
+
+ /**
+ * Enriches the input data (<code>exchange</code>) by first obtaining
+ * additional data from an endpoint identified by an
+ * <code>resourceUri</code> and second by aggregating input data and
+ * additional data. Aggregation of input data and additional data is
+ * delegated to an {@link AggregationStrategy} object set at construction
+ * time. If the message exchange with the resource endpoint fails then no
+ * aggregation will be done and the failed exchange content is copied over
+ * to the original message exchange.
+ *
+ * @param exchange
+ * input data.
+ */
+ public void process(Exchange exchange) throws Exception {
+ // create in-out exchange to obtain additional data from resource
+ Exchange resourceExchange = createResourceExchange(exchange, ExchangePattern.InOut);
+ // send created exchange to resource endpoint
+ resourceExchange = exchange.getContext().createProducerTemplate().send(resourceUri, resourceExchange);
+
+ if (resourceExchange.isFailed()) {
+ // copy resource exchange onto original exchange (preserving pattern)
+ copyResultsPreservePattern(exchange, resourceExchange);
+ } else {
+ prepareResult(exchange);
+ // aggregate original exchange and resource exchange
+ Exchange aggregatedExchange = aggregationStrategy.aggregate(exchange, resourceExchange);
+ // copy aggregation result onto original exchange (preserving pattern)
+ copyResultsPreservePattern(exchange, aggregatedExchange);
+ }
+ }
+
+ /**
+ * Creates a new {@link DefaultExchange} instance from the given
+ * <code>exchange</code>. The resulting exchange's pattern is defined by
+ * <code>pattern</code>.
+ *
+ * @param source
+ * exchange to copy from.
+ * @param pattern
+ * exchange pattern to set.
+ * @return created exchange.
+ */
+ protected Exchange createResourceExchange(Exchange source, ExchangePattern pattern) {
+ DefaultExchange target = new DefaultExchange(source.getContext());
+ target.copyFrom(source);
+ target.setPattern(pattern);
+ return target;
+ }
+
+ private static void prepareResult(Exchange exchange) {
+ if (exchange.getPattern().isOutCapable()) {
+ exchange.getOut().copyFrom(exchange.getIn());
+ }
+ }
+
+ private static AggregationStrategy defaultAggregationStrategy() {
+ return new CopyAggregationStrategy();
+ }
+
+ private static class CopyAggregationStrategy implements AggregationStrategy {
+
+ public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ copyResultsPreservePattern(oldExchange, newExchange);
+ return oldExchange;
+ }
+
+ }
+
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Enricher.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=743442&r1=743441&r2=743442&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Wed Feb 11 18:26:22 2009
@@ -188,6 +188,11 @@
* @param source the source exchange which is not modified
*/
public static void copyResults(Exchange result, Exchange source) {
+
+ // --------------------------------------------------------------------
+ // TODO: merge logic with that of copyResultsPreservePattern()
+ // --------------------------------------------------------------------
+
if (result != source) {
result.setException(source.getException());
Message fault = source.getFault(false);
@@ -217,6 +222,68 @@
}
/**
+ * Copies the <code>source</code> exchange to <code>target</code> exchange
+ * preserving the {@link ExchangePattern} of <code>target</code>.
+ *
+ * @param source source exchange.
+ * @param result target exchange.
+ *
+ * @see #resultMessage(Exchange)
+ * @see #faultMessage(Exchange)
+ */
+ public static void copyResultsPreservePattern(Exchange result, Exchange source) {
+
+ // --------------------------------------------------------------------
+ // TODO: merge logic with that of copyResults()
+ // --------------------------------------------------------------------
+
+ if (source == result) {
+ // no need to copy
+ return;
+ }
+
+ // copy in message
+ Message m = source.getIn();
+ result.getIn().copyFrom(m);
+
+ // copy out message
+ m = source.getOut(false);
+ if (m != null) {
+ // exchange pattern sensitive
+ getResultMessage(result).copyFrom(m);
+ }
+
+ // copy fault message
+ m = source.getFault(false);
+ if (m != null) {
+ result.getFault().copyFrom(m);
+ }
+
+ // copy exception
+ result.setException(source.getException());
+
+ // copy properties
+ result.getProperties().clear();
+ result.getProperties().putAll(source.getProperties());
+ }
+
+ /**
+ * Returns the message where to write results in an
+ * exchange-pattern-sensitive way.
+ *
+ * @param exchange
+ * message exchange.
+ * @return result message.
+ */
+ public static Message getResultMessage(Exchange exchange) {
+ if (exchange.getPattern().isOutCapable()) {
+ return exchange.getOut();
+ } else {
+ return exchange.getIn();
+ }
+ }
+
+ /**
* Returns true if the given exchange pattern (if defined) can support IN messagea
*
* @param exchange the exchange to interrogate
Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index?rev=743442&r1=743441&r2=743442&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index (original)
+++ camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index Wed Feb 11 18:26:22 2009
@@ -21,6 +21,7 @@
ConvertBodyType
DelayerType
Description
+EnricherType
ExceptionType
ExpressionSubElementType
FilterType
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherTest.java?rev=743442&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherTest.java Wed Feb 11 18:26:22 2009
@@ -0,0 +1,172 @@
+/**
+ * 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.enricher;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class EnricherTest extends ContextTestSupport {
+
+ private static SampleAggregator aggregationStrategy = new SampleAggregator();
+
+ protected MockEndpoint mock;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mock = getMockEndpoint("mock:mock");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // -------------------------------------------------------------
+ // InOnly routes
+ // -------------------------------------------------------------
+
+ public void testEnrichInOnly() throws InterruptedException {
+ mock.expectedBodiesReceived("test:blah");
+ template.sendBody("direct:enricher-test-1", "test");
+ mock.assertIsSatisfied();
+ }
+
+ public void testEnrichFaultInOnly() throws InterruptedException {
+ mock.expectedMessageCount(0);
+ Exchange exchange = template.send("direct:enricher-test-3", new Processor() {
+ public void process(Exchange exchange) {
+ exchange.getIn().setBody("test");
+ }
+ });
+ mock.assertIsSatisfied();
+ assertEquals("test", exchange.getIn().getBody());
+ assertEquals("failed", exchange.getFault(false).getBody());
+ assertNull(exchange.getOut(false));
+ assertNull(exchange.getException());
+ }
+
+ public void testEnrichErrorInOnly() throws InterruptedException {
+ mock.expectedMessageCount(0);
+ Exchange exchange = template.send("direct:enricher-test-4", new Processor() {
+ public void process(Exchange exchange) {
+ exchange.getIn().setBody("test");
+ }
+ });
+ mock.assertIsSatisfied();
+ assertEquals("test", exchange.getIn().getBody());
+ assertEquals("failed", exchange.getException().getMessage());
+ assertNull(exchange.getFault(false));
+ assertNull(exchange.getOut(false));
+ }
+
+ // -------------------------------------------------------------
+ // InOut routes
+ // -------------------------------------------------------------
+
+ public void testEnrichInOut() throws InterruptedException {
+ String result = (String) template.sendBody("direct:enricher-test-5", ExchangePattern.InOut, "test");
+ assertEquals("test:blah", result);
+ }
+
+ public void testEnrichInOutPlusHeader() throws InterruptedException {
+ Exchange exchange = template.send("direct:enricher-test-5", ExchangePattern.InOut, new Processor() {
+ public void process(Exchange exchange) {
+ exchange.getIn().setHeader("foo", "bar");
+ exchange.getIn().setBody("test");
+ }
+ });
+ assertEquals("bar", exchange.getIn().getHeader("foo"));
+ assertEquals("test", exchange.getIn().getBody());
+ assertEquals("bar", exchange.getOut().getHeader("foo"));
+ assertEquals("test:blah", exchange.getOut().getBody());
+ assertNull(exchange.getFault(false));
+ assertNull(exchange.getException());
+ }
+
+ public void testEnrichFaultInOut() throws InterruptedException {
+ Exchange exchange = template.send("direct:enricher-test-7", ExchangePattern.InOut, new Processor() {
+ public void process(Exchange exchange) {
+ exchange.getIn().setBody("test");
+ }
+ });
+ assertEquals("test", exchange.getIn().getBody());
+ assertEquals("failed", exchange.getFault(false).getBody());
+ assertNull(exchange.getOut(false));
+ assertNull(exchange.getException());
+ }
+
+ public void testEnrichErrorInOut() throws InterruptedException {
+ Exchange exchange = template.send("direct:enricher-test-8", ExchangePattern.InOut, new Processor() {
+ public void process(Exchange exchange) {
+ exchange.getIn().setBody("test");
+ }
+ });
+ assertEquals("test", exchange.getIn().getBody());
+ assertEquals("failed", exchange.getException().getMessage());
+ assertNull(exchange.getFault(false));
+ assertNull(exchange.getOut(false));
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // -------------------------------------------------------------
+ // InOnly routes
+ // -------------------------------------------------------------
+
+ from("direct:enricher-test-1")
+ .enrich("direct:enricher-constant-resource", aggregationStrategy)
+ .to("mock:mock");
+
+ from("direct:enricher-test-3")
+ .enrich("direct:enricher-fault-resource", aggregationStrategy)
+ .to("mock:mock");
+
+ from("direct:enricher-test-4").errorHandler(noErrorHandler()) // avoid re-deliveries
+ .enrich("direct:enricher-error-resource", aggregationStrategy).to("mock:mock");
+
+ // -------------------------------------------------------------
+ // InOut routes
+ // -------------------------------------------------------------
+
+ from("direct:enricher-test-5")
+ .enrich("direct:enricher-constant-resource", aggregationStrategy);
+
+ from("direct:enricher-test-7")
+ .enrich("direct:enricher-fault-resource", aggregationStrategy);
+
+ from("direct:enricher-test-8").errorHandler(noErrorHandler()) // avoid re-deliveries
+ .enrich("direct:enricher-error-resource", aggregationStrategy);
+
+ // -------------------------------------------------------------
+ // Enricher resources
+ // -------------------------------------------------------------
+
+ from("direct:enricher-constant-resource").transform().constant("blah");
+
+ from("direct:enricher-fault-resource").errorHandler(noErrorHandler()).process(new FailureProcessor(false));
+ from("direct:enricher-error-resource").errorHandler(noErrorHandler()).process(new FailureProcessor(true));
+ }
+ };
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/FailureProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/FailureProcessor.java?rev=743442&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/FailureProcessor.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/FailureProcessor.java Wed Feb 11 18:26:22 2009
@@ -0,0 +1,43 @@
+/**
+ * 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.enricher;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class FailureProcessor implements Processor {
+
+ private boolean error;
+
+ public FailureProcessor() {
+ this(false);
+ }
+
+ public FailureProcessor(boolean error) {
+ this.error = error;
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ if (error) {
+ throw new RuntimeException("failed");
+ } else {
+ exchange.getFault().setBody("failed");
+ }
+ }
+
+}
+
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/FailureProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/SampleAggregator.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/SampleAggregator.java?rev=743442&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/SampleAggregator.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/SampleAggregator.java Wed Feb 11 18:26:22 2009
@@ -0,0 +1,35 @@
+/**
+ * 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.enricher;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+
+public class SampleAggregator implements AggregationStrategy {
+
+ public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ Object oldBody = oldExchange.getIn().getBody();
+ Object newBody = newExchange.getOut().getBody();
+ if (oldExchange.getPattern().isOutCapable()) {
+ oldExchange.getOut().setBody(oldBody + ":" + newBody);
+ } else {
+ oldExchange.getIn().setBody(oldBody + ":" + newBody);
+ }
+ return oldExchange;
+ }
+
+}
\ No newline at end of file
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/enricher/SampleAggregator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherTest.java?rev=743442&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherTest.java Wed Feb 11 18:26:22 2009
@@ -0,0 +1,48 @@
+/**
+ * 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.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ * @author Martin Krasser
+ */
+public class SpringEnricherTest extends ContextTestSupport {
+
+ private MockEndpoint mock;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mock = getMockEndpoint("mock:result");
+ }
+
+ public void testEnrich() throws Exception {
+ mock.expectedBodiesReceived("test:blah");
+ template.sendBody("direct:start", "test");
+ mock.assertIsSatisfied();
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/spring/processor/enricher.xml");
+ }
+
+}
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/enricher.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/enricher.xml?rev=743442&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/enricher.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/enricher.xml Wed Feb 11 18:26:22 2009
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <enrich resourceUri="direct:resource" aggregationStrategyRef="sampleAggregator"/>
+ <to uri="mock:result"/>
+ </route>
+ <route>
+ <from uri="direct:resource"/>
+ <transform>
+ <constant>blah</constant>
+ </transform>
+ </route>
+ </camelContext>
+
+ <bean id="sampleAggregator" class="org.apache.camel.processor.enricher.SampleAggregator" />
+ <!-- END SNIPPET: example -->
+
+</beans>
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/enricher.xml
------------------------------------------------------------------------------
svn:eol-style = native