You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/08/09 18:39:55 UTC
svn commit: r564272 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/builder/ main/java/org/apache/camel/impl/
main/java/org/apache/camel/model/ main/java/org/apache/camel/processor/
main/resources/org/apache/camel/model/ test/java...
Author: jstrachan
Date: Thu Aug 9 09:39:53 2007
New Revision: 564272
URL: http://svn.apache.org/viewvc?view=rev&rev=564272
Log:
initial implementation of interceptor routes; allowing interceptors to be implemented easily in the DSL for CAMEL-92
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java (contents, props changed)
- copied, changed from r564133, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OtherwiseType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorType.java (with props)
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java (with props)
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java (with props)
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ProceedProcessor.java (with props)
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java (contents, props changed)
- copied, changed from r564133, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java (with props)
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java (with props)
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java (with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteContext.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorRef.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ResequencerType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrottlerType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ToType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java Thu Aug 9 09:39:53 2007
@@ -72,6 +72,23 @@
}
/**
+ * A helper method to return the logical not of the given predicate
+ */
+ public static <E extends Exchange> Predicate<E> not(final Predicate<E> predicate) {
+ notNull(predicate, "predicate");
+ return new PredicateSupport<E>() {
+ public boolean matches(E exchange) {
+ return !predicate.matches(exchange);
+ }
+
+ @Override
+ public String toString() {
+ return "not " + predicate;
+ }
+ };
+ }
+
+ /**
* A helper method to combine multiple predicates by a logical AND
*/
public static <E extends Exchange> Predicate<E> and(final Predicate<E> left, final Predicate<E> right) {
@@ -285,5 +302,4 @@
};
}
-
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java Thu Aug 9 09:39:53 2007
@@ -16,18 +16,22 @@
*/
package org.apache.camel.builder;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
+import org.apache.camel.Predicate;
import org.apache.camel.Route;
import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.InterceptType;
+import org.apache.camel.model.OtherwiseType;
+import org.apache.camel.model.ProcessorType;
import org.apache.camel.model.RouteType;
import org.apache.camel.model.RoutesType;
import org.apache.camel.processor.DelegateProcessor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
/**
* A <a href="http://activemq.apache.org/camel/dsl.html">Java DSL</a> which is
* used to build {@link Route} instances in a
@@ -54,10 +58,16 @@
*/
public abstract void configure() throws Exception;
+ /**
+ * Creates a new route from the given URI input
+ */
public RouteType from(String uri) {
return routeCollection.from(uri);
}
+ /**
+ * Creates a new route from the given endpoint
+ */
public RouteType from(Endpoint endpoint) {
return routeCollection.from(endpoint);
}
@@ -87,9 +97,30 @@
return this;
}
+ /**
+ * Adds the given interceptor to this route
+ */
public RouteBuilder intercept(DelegateProcessor interceptor) {
routeCollection.intercept(interceptor);
return this;
+ }
+
+ /**
+ * Adds a route for an interceptor; use the {@link ProcessorType#proceed()} method
+ * to continue processing the underying route being intercepted.
+ *
+ * @return
+ */
+ public InterceptType intercept() {
+ return routeCollection.intercept();
+ }
+
+ /**
+ * Applies a route for an interceptor if the given predicate is true
+ * otherwise the interceptor route is not applied
+ */
+ public OtherwiseType intercept(Predicate predicate) {
+ return routeCollection.intercept(predicate);
}
// Properties
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteContext.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteContext.java Thu Aug 9 09:39:53 2007
@@ -28,7 +28,9 @@
import org.apache.camel.model.FromType;
import org.apache.camel.model.ProcessorType;
import org.apache.camel.model.RouteType;
+import org.apache.camel.processor.Interceptor;
import org.apache.camel.processor.Pipeline;
+import org.apache.camel.processor.ProceedProcessor;
/**
* The context used to activate new routing rules
@@ -41,6 +43,7 @@
private final Collection<Route> routes;
private Endpoint endpoint;
private List<Processor> eventDrivenProcessors = new ArrayList<Processor>();
+ private Interceptor lastInterceptor;
public RouteContext(RouteType route, FromType from, Collection<Route> routes) {
this.route = route;
@@ -121,5 +124,19 @@
public void addEventDrivenProcessor(Processor processor) {
eventDrivenProcessors.add(processor);
+ }
+
+ public void intercept(Interceptor interceptor) {
+ getRoute().intercept(interceptor);
+ lastInterceptor = interceptor;
+ }
+
+ public Processor createProceedProcessor() {
+ if (lastInterceptor == null) {
+ throw new IllegalArgumentException("Cannot proceed() from outside of an interceptor!");
+ }
+ else {
+ return new ProceedProcessor(lastInterceptor);
+ }
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java Thu Aug 9 09:39:53 2007
@@ -16,25 +16,31 @@
*/
package org.apache.camel.impl;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import org.apache.camel.Service;
+import org.apache.camel.util.ServiceHelper;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* A useful base class which ensures that a service is only initialized once and
* provides some helper methods for enquiring of its status
- *
+ *
* @version $Revision$
*/
public abstract class ServiceSupport implements Service {
private static int threadCounter;
-
private AtomicBoolean started = new AtomicBoolean(false);
private AtomicBoolean stopping = new AtomicBoolean(false);
private AtomicBoolean stopped = new AtomicBoolean(false);
+ private Collection childServices;
public void start() throws Exception {
if (started.compareAndSet(false, true)) {
+ if (childServices != null) {
+ ServiceHelper.startServices(childServices);
+ }
doStart();
}
}
@@ -43,7 +49,11 @@
if (started.get() && stopping.compareAndSet(false, true)) {
try {
doStop();
- } finally {
+ }
+ finally {
+ if (childServices != null) {
+ ServiceHelper.stopServices(childServices);
+ }
stopped.set(true);
started.set(false);
stopping.set(false);
@@ -85,5 +95,21 @@
protected static synchronized int nextThreadCounter() {
return ++threadCounter;
+ }
+
+ protected void addChildService(Object childService) {
+ if (childServices == null) {
+ childServices = new ArrayList();
+ }
+ childServices.add(childService);
+ }
+
+ protected boolean removeChildService(Object childService) {
+ if (childServices != null) {
+ return childServices.remove(childService);
+ }
+ else {
+ return false;
+ }
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchType.java Thu Aug 9 09:39:53 2007
@@ -37,8 +37,8 @@
@XmlRootElement(name = "catch")
@XmlAccessorType(XmlAccessType.FIELD)
public class CatchType extends ProcessorType {
- @XmlElement(required = false)
- private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
+ @XmlElementRef
+ private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
@XmlElement(name = "exception")
private List<String> exceptions = new ArrayList<String>();
@XmlElementRef
@@ -69,11 +69,11 @@
return new CatchProcessor(getExceptionClasses(), childProcessor);
}
- public List<InterceptorRef> getInterceptors() {
+ public List<InterceptorType> getInterceptors() {
return interceptors;
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
+ public void setInterceptors(List<InterceptorType> interceptors) {
this.interceptors = interceptors;
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java Thu Aug 9 09:39:53 2007
@@ -40,8 +40,8 @@
@XmlRootElement(name = "choice")
@XmlAccessorType(XmlAccessType.FIELD)
public class ChoiceType extends ProcessorType {
- @XmlElement(required = false)
- private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
+ @XmlElementRef
+ private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
@XmlElementRef
private List<WhenType> whenClauses = new ArrayList<WhenType>();
@XmlElement(required = false)
@@ -78,6 +78,11 @@
return answer;
}
+ public ChoiceType proceed() {
+ super.proceed();
+ return this;
+ }
+
public ChoiceType to(Endpoint endpoint) {
super.to(endpoint);
return this;
@@ -132,11 +137,11 @@
this.otherwise = otherwise;
}
- public List<InterceptorRef> getInterceptors() {
+ public List<InterceptorType> getInterceptors() {
return interceptors;
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
+ public void setInterceptors(List<InterceptorType> interceptors) {
this.interceptors = interceptors;
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java Thu Aug 9 09:39:53 2007
@@ -38,8 +38,8 @@
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class ExpressionNode extends ProcessorType {
- @XmlElement(required = false)
- private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
+ @XmlElementRef
+ private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
@XmlElementRef
private ExpressionType expression;
@XmlElementRef
@@ -60,11 +60,11 @@
setExpression(new ExpressionType(predicate));
}
- public List<InterceptorRef> getInterceptors() {
+ public List<InterceptorType> getInterceptors() {
return interceptors;
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
+ public void setInterceptors(List<InterceptorType> interceptors) {
this.interceptors = interceptors;
}
Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java (from r564133, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OtherwiseType.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java?view=diff&rev=564272&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OtherwiseType.java&r1=564133&p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OtherwiseType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java Thu Aug 9 09:39:53 2007
@@ -16,26 +16,42 @@
*/
package org.apache.camel.model;
+import org.apache.camel.Processor;
+import org.apache.camel.Route;
+import org.apache.camel.Predicate;
+import org.apache.camel.builder.PredicateBuilder;
+import org.apache.camel.impl.RouteContext;
+import org.apache.camel.processor.Interceptor;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
-
-import org.apache.camel.Processor;
-import org.apache.camel.impl.RouteContext;
+import java.util.Collection;
/**
* @version $Revision: 1.1 $
*/
-@XmlRootElement(name = "otherwise")
+@XmlRootElement(name = "intercept")
@XmlAccessorType(XmlAccessType.FIELD)
-public class OtherwiseType extends OutputType {
+public class InterceptType extends OutputType {
@Override
public String toString() {
- return "Otherwise[" + getOutputs() + "]";
+ return "Intercept[" + getOutputs() + "]";
}
- @Override
- public Processor createProcessor(RouteContext routeContext) throws Exception {
- return routeContext.createProcessor(this);
+ public void addRoutes(RouteContext routeContext, Collection<Route> routes) throws Exception {
+ Interceptor interceptor = new Interceptor();
+ routeContext.intercept(interceptor);
+
+ final Processor interceptRoute = routeContext.createProcessor(this);
+ interceptor.setInterceptorLogic(interceptRoute);
+ }
+
+ /**
+ * Applies this interceptor only if the given predicate is true
+ */
+ public OtherwiseType when(Predicate predicate) {
+ return choice().when(PredicateBuilder.not(predicate)).proceed().otherwise();
+
}
}
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorRef.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorRef.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorRef.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorRef.java Thu Aug 9 09:39:53 2007
@@ -30,7 +30,7 @@
*/
@XmlRootElement(name = "interceptor")
@XmlAccessorType(XmlAccessType.FIELD)
-public class InterceptorRef {
+public class InterceptorRef extends InterceptorType {
@XmlAttribute(required = true)
private String ref;
@XmlTransient
Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorType.java?view=auto&rev=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorType.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorType.java Thu Aug 9 09:39:53 2007
@@ -0,0 +1,31 @@
+/**
+ *
+ * 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 org.apache.camel.processor.DelegateProcessor;
+import org.apache.camel.impl.RouteContext;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@XmlType(name = "interceptorType")
+public abstract class InterceptorType {
+ public abstract DelegateProcessor createInterceptor(RouteContext routeContext) throws Exception;
+}
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptorType.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java Thu Aug 9 09:39:53 2007
@@ -22,6 +22,8 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAccessType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -32,12 +34,15 @@
* @version $Revision: 1.1 $
*/
@XmlType(name = "outputType")
+@XmlAccessorType(XmlAccessType.FIELD)
public class OutputType extends ProcessorType {
private static final transient Log LOG = LogFactory.getLog(OutputType.class);
- protected List<ProcessorType> outputs = new ArrayList<ProcessorType>();
- private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
@XmlElementRef
+ protected List<ProcessorType> outputs = new ArrayList<ProcessorType>();
+ @XmlElementRef
+ private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
+
public List<ProcessorType> getOutputs() {
return outputs;
}
@@ -51,12 +56,11 @@
}
}
- @XmlElement(required = false)
- public List<InterceptorRef> getInterceptors() {
+ public List<InterceptorType> getInterceptors() {
return interceptors;
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
+ public void setInterceptors(List<InterceptorType> interceptors) {
this.interceptors = interceptors;
}
@@ -67,7 +71,7 @@
}
// don't inherit interceptors by default
/*
- List<InterceptorRef> list = output.getInterceptors();
+ List<InterceptorType> list = output.getInterceptors();
if (list == null) {
log.warn("No interceptor collection: " + output);
}
Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java?view=auto&rev=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java Thu Aug 9 09:39:53 2007
@@ -0,0 +1,47 @@
+/**
+ *
+ * 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 org.apache.camel.Processor;
+import org.apache.camel.impl.RouteContext;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAccessType;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@XmlRootElement(name = "proceed")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ProceedType extends ProcessorType {
+
+ public List<ProcessorType> getOutputs() {
+ return Collections.EMPTY_LIST;
+ }
+
+ public List<InterceptorType> getInterceptors() {
+ return Collections.EMPTY_LIST;
+ }
+
+ public Processor createProcessor(RouteContext routeContext) throws Exception {
+ return routeContext.createProceedProcessor();
+ }
+}
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java Thu Aug 9 09:39:53 2007
@@ -16,14 +16,6 @@
*/
package org.apache.camel.model;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlTransient;
-
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
@@ -41,13 +33,23 @@
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.MulticastProcessor;
import org.apache.camel.processor.Pipeline;
+import org.apache.camel.processor.RecipientList;
import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.apache.camel.processor.idempotent.IdempotentConsumer;
import org.apache.camel.processor.idempotent.MessageIdRepository;
import org.apache.camel.spi.Policy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
/**
* @version $Revision: 1.1 $
*/
@@ -55,14 +57,15 @@
public static final String DEFAULT_TRACE_CATEGORY = "org.apache.camel.TRACE";
private ErrorHandlerBuilder errorHandlerBuilder;
private Boolean inheritErrorHandlerFlag = Boolean.TRUE; // TODO not sure how
- // else to use an
+ private DelegateProcessor lastInterceptor;
+ // else to use an
// optional
// attribute in
// JAXB2
public abstract List<ProcessorType> getOutputs();
- public abstract List<InterceptorRef> getInterceptors();
+ public abstract List<InterceptorType> getInterceptors();
public Processor createProcessor(RouteContext routeContext) throws Exception {
throw new UnsupportedOperationException("Not implemented yet for class: " + getClass().getName());
@@ -416,6 +419,26 @@
return this;
}
+ public InterceptType intercept() {
+ InterceptType answer = new InterceptType();
+ getOutputs().add(answer);
+ return answer;
+ }
+
+ public ProcessorType proceed() {
+ getOutputs().add(new ProceedType());
+ return this;
+ }
+
+ /**
+ * Apply an interceptor route if the predicate is true
+ */
+ public OtherwiseType intercept(Predicate predicate) {
+ InterceptType answer = new InterceptType();
+ getOutputs().add(answer);
+ return answer.when(predicate);
+ }
+
public ProcessorType interceptors(String... refs) {
for (String ref : refs) {
interceptor(ref);
@@ -476,6 +499,7 @@
public ProcessorType intercept(DelegateProcessor interceptor) {
getInterceptors().add(new InterceptorRef(interceptor));
+ lastInterceptor = interceptor;
return this;
}
@@ -638,7 +662,7 @@
* @param target the processor which can be wrapped
* @return the original processor or a new wrapped interceptor
*/
- protected Processor wrapProcessorInInterceptors(RouteContext routeContext, Processor target) {
+ protected Processor wrapProcessorInInterceptors(RouteContext routeContext, Processor target) throws Exception {
// The target is required.
if (target == null) {
throw new RuntimeCamelException("target provided.");
@@ -647,20 +671,23 @@
// Interceptors are optional
DelegateProcessor first = null;
DelegateProcessor last = null;
- List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>(routeContext.getRoute()
+ List<InterceptorType> interceptors = new ArrayList<InterceptorType>(routeContext.getRoute()
.getInterceptors());
- interceptors.addAll(getInterceptors());
- if (interceptors != null) {
- for (InterceptorRef interceptorRef : interceptors) {
- DelegateProcessor p = interceptorRef.createInterceptor(routeContext);
- if (first == null) {
- first = p;
- }
- if (last != null) {
- last.setProcessor(p);
- }
- last = p;
+ List<InterceptorType> list = getInterceptors();
+ for (InterceptorType interceptorType : list) {
+ if (!interceptors.contains(interceptorType)) {
+ interceptors.add(interceptorType);
+ }
+ }
+ for (InterceptorType interceptorRef : interceptors) {
+ DelegateProcessor p = interceptorRef.createInterceptor(routeContext);
+ if (first == null) {
+ first = p;
+ }
+ if (last != null) {
+ last.setProcessor(p);
}
+ last = p;
}
if (last != null) {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ResequencerType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ResequencerType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ResequencerType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ResequencerType.java Thu Aug 9 09:39:53 2007
@@ -39,8 +39,8 @@
*/
@XmlRootElement(name = "resequencer")
public class ResequencerType extends ProcessorType {
- @XmlElement(required = false)
- private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
+ @XmlElementRef
+ private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
@XmlElementRef
private List<ExpressionType> expressions = new ArrayList<ExpressionType>();
@XmlElementRef
@@ -64,11 +64,11 @@
return expressions;
}
- public List<InterceptorRef> getInterceptors() {
+ public List<InterceptorType> getInterceptors() {
return interceptors;
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
+ public void setInterceptors(List<InterceptorType> interceptors) {
this.interceptors = interceptors;
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteType.java Thu Aug 9 09:39:53 2007
@@ -48,8 +48,8 @@
@XmlAccessorType(XmlAccessType.FIELD)
public class RouteType extends ProcessorType implements CamelContextAware {
private static final transient Log LOG = LogFactory.getLog(RouteType.class);
- @XmlElement(required = false, name = "interceptor")
- private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
+ @XmlElementRef
+ private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
@XmlElementRef
private List<FromType> inputs = new ArrayList<FromType>();
@XmlElementRef
@@ -100,6 +100,10 @@
// Fluent API
// -----------------------------------------------------------------------
+
+ /**
+ * Creates an input to the route
+ */
public RouteType from(String uri) {
getInputs().add(new FromType(uri));
return this;
@@ -108,11 +112,11 @@
// Properties
// -----------------------------------------------------------------------
- public List<InterceptorRef> getInterceptors() {
+ public List<InterceptorType> getInterceptors() {
return interceptors;
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
+ public void setInterceptors(List<InterceptorType> interceptors) {
this.interceptors = interceptors;
}
@@ -165,7 +169,7 @@
if (isInheritErrorHandler()) {
output.setErrorHandlerBuilder(getErrorHandlerBuilder());
}
- List<InterceptorRef> list = output.getInterceptors();
+ List<InterceptorType> list = output.getInterceptors();
if (list == null) {
LOG.warn("No interceptor collection: " + output);
} else {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesType.java Thu Aug 9 09:39:53 2007
@@ -29,6 +29,7 @@
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Route;
+import org.apache.camel.Predicate;
import org.apache.camel.processor.DelegateProcessor;
/**
@@ -46,7 +47,9 @@
@XmlElementRef
private List<RouteType> routes = new ArrayList<RouteType>();
@XmlTransient
- private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
+ private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
+ @XmlTransient
+ private List<InterceptType> intercepts = new ArrayList<InterceptType>();
@XmlTransient
private CamelContext camelContext;
@@ -71,14 +74,22 @@
this.routes = routes;
}
- public List<InterceptorRef> getInterceptors() {
+ public List<InterceptorType> getInterceptors() {
return interceptors;
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
+ public void setInterceptors(List<InterceptorType> interceptors) {
this.interceptors = interceptors;
}
+ public List<InterceptType> getIntercepts() {
+ return intercepts;
+ }
+
+ public void setIntercepts(List<InterceptType> intercepts) {
+ this.intercepts = intercepts;
+ }
+
public CamelContext getCamelContext() {
return camelContext;
}
@@ -97,16 +108,26 @@
// Fluent API
//-------------------------------------------------------------------------
+
+ /**
+ * Creates a new route
+ */
public RouteType route() {
RouteType route = new RouteType();
return route(route);
}
+ /**
+ * Creates a new route from the given URI input
+ */
public RouteType from(String uri) {
RouteType route = new RouteType(uri);
return route(route);
}
+ /**
+ * Creates a new route from the given endpoint
+ */
public RouteType from(Endpoint endpoint) {
RouteType route = new RouteType(endpoint);
return route(route);
@@ -117,7 +138,7 @@
route.setCamelContext(getCamelContext());
route.setInheritErrorHandlerFlag(getInheritErrorHandlerFlag());
route.getInterceptors().addAll(getInterceptors());
-
+ route.getOutputs().addAll(getIntercepts());
getRoutes().add(route);
return route;
}
@@ -126,4 +147,17 @@
getInterceptors().add(new InterceptorRef(interceptor));
return this;
}
+
+ public InterceptType intercept() {
+ InterceptType answer = new InterceptType();
+ getIntercepts().add(answer);
+ return answer;
+ }
+
+ public OtherwiseType intercept(Predicate predicate) {
+ InterceptType answer = new InterceptType();
+ getIntercepts().add(answer);
+ return answer.when(predicate);
+ }
+
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrottlerType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrottlerType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrottlerType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrottlerType.java Thu Aug 9 09:39:53 2007
@@ -40,8 +40,8 @@
private Long maximumRequestsPerPeriod;
@XmlAttribute
private long timePeriodMillis = 1000;
- @XmlElement(required = false)
- private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
+ @XmlElementRef
+ private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
@XmlElementRef
private List<ProcessorType> outputs = new ArrayList<ProcessorType>();
@@ -94,11 +94,11 @@
this.timePeriodMillis = timePeriodMillis;
}
- public List<InterceptorRef> getInterceptors() {
+ public List<InterceptorType> getInterceptors() {
return interceptors;
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
+ public void setInterceptors(List<InterceptorType> interceptors) {
this.interceptors = interceptors;
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ToType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ToType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ToType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ToType.java Thu Aug 9 09:39:53 2007
@@ -26,6 +26,7 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlElementRef;
import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
@@ -44,8 +45,8 @@
private String uri;
@XmlAttribute
private String ref;
- @XmlElement(required = false)
- private List<InterceptorRef> interceptors = new ArrayList<InterceptorRef>();
+ @XmlElementRef
+ private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
@XmlTransient
private Endpoint endpoint;
@@ -119,11 +120,11 @@
return Collections.EMPTY_LIST;
}
- public List<InterceptorRef> getInterceptors() {
+ public List<InterceptorType> getInterceptors() {
return interceptors;
}
- public void setInterceptors(List<InterceptorRef> interceptors) {
+ public void setInterceptors(List<InterceptorType> interceptors) {
this.interceptors = interceptors;
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryType.java Thu Aug 9 09:39:53 2007
@@ -37,11 +37,6 @@
@XmlRootElement(name = "try")
@XmlAccessorType(XmlAccessType.FIELD)
public class TryType extends OutputType {
- /*
- * @XmlElement(required = false) private List<InterceptorRef> interceptors =
- * new ArrayList<InterceptorRef>(); @XmlElementRef private List<ProcessorType>
- * outputs = new ArrayList<ProcessorType>();
- */
@XmlTransient
private List<CatchType> catchClauses;
@XmlTransient
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java Thu Aug 9 09:39:53 2007
@@ -19,6 +19,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.impl.ServiceSupport;
+import org.apache.camel.spi.Policy;
import org.apache.camel.util.ServiceHelper;
/**
@@ -66,5 +67,12 @@
protected void doStop() throws Exception {
ServiceHelper.stopServices(processor);
+ }
+
+ /**
+ * Proceed with the underlying delegated processor
+ */
+ public void proceed(Exchange exchange) throws Exception {
+ processNext(exchange);
}
}
Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java?view=auto&rev=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java Thu Aug 9 09:39:53 2007
@@ -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.processor;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.processor.DelegateProcessor;
+import org.apache.camel.util.ServiceHelper;
+
+/**
+ * An interceptor which provides the processing logic as a pluggable processor
+ * which allows the {@link #proceed(Exchange)} method to be called at some point
+ *
+ * @version $Revision: 1.1 $
+ */
+public class Interceptor extends DelegateProcessor {
+ private Processor interceptorLogic;
+
+ public Interceptor() {
+ }
+
+ public Interceptor(Processor interceptorLogic) {
+ this.interceptorLogic = interceptorLogic;
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ interceptorLogic.process(exchange);
+ }
+
+ public Processor getInterceptorLogic() {
+ return interceptorLogic;
+ }
+
+ public void setInterceptorLogic(Processor interceptorLogic) {
+ this.interceptorLogic = interceptorLogic;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ ServiceHelper.startService(interceptorLogic);
+ super.doStart();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ ServiceHelper.stopService(interceptorLogic);
+ super.doStop();
+ }
+}
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ProceedProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ProceedProcessor.java?view=auto&rev=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ProceedProcessor.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ProceedProcessor.java Thu Aug 9 09:39:53 2007
@@ -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;
+
+import org.apache.camel.Processor;
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.Interceptor;
+
+/**
+ * A {@link Processor} which proceeds on an {@link Interceptor}
+ *
+ * @version $Revision: 1.1 $
+ */
+public class ProceedProcessor implements Processor {
+ private final Interceptor interceptor;
+
+ public ProceedProcessor(Interceptor interceptor) {
+ this.interceptor = interceptor;
+ }
+
+ public String toString() {
+ return "Proceed[" + interceptor + "]";
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ interceptor.proceed(exchange);
+ }
+}
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ProceedProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index (original)
+++ activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index Thu Aug 9 09:39:53 2007
@@ -23,9 +23,12 @@
FinallyType
FromType
IdempotentConsumerType
+InterceptType
+InterceptorRef
MulticastType
OtherwiseType
PolicyRef
+ProceedType
ProcessorRef
RecipientListType
ResequencerType
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java?view=diff&rev=564272&r1=564271&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java Thu Aug 9 09:39:53 2007
@@ -16,11 +16,10 @@
*/
package org.apache.camel.model;
-import java.util.List;
+import org.apache.camel.model.language.ExpressionType;
import javax.xml.bind.JAXBException;
-
-import org.apache.camel.model.language.ExpressionType;
+import java.util.List;
/**
* @version $Revision: 1.1 $
@@ -180,13 +179,13 @@
protected void assertInterceptorRefs(ProcessorType route, String... names) {
int idx = 0;
- List<InterceptorRef> interceptors = route.getInterceptors();
+ List<InterceptorType> interceptors = route.getInterceptors();
for (String name : names) {
int nextIdx = idx + 1;
assertTrue("Not enough interceptors! Expected: " + nextIdx + " but have: " + interceptors,
- nextIdx <= interceptors.size());
+ nextIdx <= interceptors.size());
- InterceptorRef interceptor = interceptors.get(idx++);
+ InterceptorRef interceptor = assertIsInstanceOf(InterceptorRef.class, interceptors.get(idx++));
assertEquals("Interceptor: " + idx, name, interceptor.getRef());
}
}
Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java (from r564133, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java?view=diff&rev=564272&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java&r1=564133&p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java&r2=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java Thu Aug 9 09:39:53 2007
@@ -19,37 +19,47 @@
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
/**
* @version $Revision: 1.1 $
*/
-public class FilterTest extends ContextTestSupport {
+public class InterceptRouteTest extends ContextTestSupport {
+ private MockEndpoint a;
+ private MockEndpoint b;
public void testSendMatchingMessage() throws Exception {
- MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
- resultEndpoint.expectedMessageCount(1);
+ b.expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
- resultEndpoint.assertIsSatisfied();
+ assertIsSatisfied(a, b);
}
public void testSendNotMatchingMessage() throws Exception {
- MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
- resultEndpoint.expectedMessageCount(0);
+ a.expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
- resultEndpoint.assertIsSatisfied();
+ assertIsSatisfied(a, b);
}
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ a = (MockEndpoint) resolveMandatoryEndpoint("mock:a");
+ b = (MockEndpoint) resolveMandatoryEndpoint("mock:b");
+ }
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
- from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+ intercept().choice().
+ when(header("foo").isEqualTo("bar")).to("mock:b").
+ otherwise().proceed();
+
+ from("direct:start").to("mock:a");
}
};
}
-
-}
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java?view=auto&rev=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java Thu Aug 9 09:39:53 2007
@@ -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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class InterceptWithPredicateAndProceedRouteTest extends ContextTestSupport {
+ private MockEndpoint a;
+ private MockEndpoint b;
+
+ public void testSendMatchingMessage() throws Exception {
+ a.expectedMessageCount(1);
+ b.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
+
+ assertIsSatisfied(a, b);
+ }
+
+ public void testSendNotMatchingMessage() throws Exception {
+ a.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ assertIsSatisfied(a, b);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ a = (MockEndpoint) resolveMandatoryEndpoint("mock:a");
+ b = (MockEndpoint) resolveMandatoryEndpoint("mock:b");
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ intercept(header("foo").isEqualTo("bar")).to("mock:b").proceed();
+
+ from("direct:start").to("mock:a");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java?view=auto&rev=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java Thu Aug 9 09:39:53 2007
@@ -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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class InterceptWithPredicateRouteTest extends ContextTestSupport {
+ private MockEndpoint a;
+ private MockEndpoint b;
+
+ public void testSendMatchingMessage() throws Exception {
+ b.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
+
+ assertIsSatisfied(a, b);
+ }
+
+ public void testSendNotMatchingMessage() throws Exception {
+ a.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ assertIsSatisfied(a, b);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ a = (MockEndpoint) resolveMandatoryEndpoint("mock:a");
+ b = (MockEndpoint) resolveMandatoryEndpoint("mock:b");
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ intercept(header("foo").isEqualTo("bar")).to("mock:b");
+
+ from("direct:start").to("mock:a");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java?view=auto&rev=564272
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java Thu Aug 9 09:39:53 2007
@@ -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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class InterceptWithoutProceedRouteTest extends ContextTestSupport {
+ private MockEndpoint a;
+ private MockEndpoint b;
+
+ public void testSendMatchingMessage() throws Exception {
+ b.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
+
+ assertIsSatisfied(a, b);
+ }
+
+ public void testSendNotMatchingMessage() throws Exception {
+
+ template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ assertIsSatisfied(a, b);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ a = (MockEndpoint) resolveMandatoryEndpoint("mock:a");
+ b = (MockEndpoint) resolveMandatoryEndpoint("mock:b");
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // we will disable the output to 'mock:a' since we never proceed()
+ intercept().filter(header("foo").isEqualTo("bar")).to("mock:b");
+
+ from("direct:start").to("mock:a");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native