You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/03/13 15:36:51 UTC
svn commit: r753284 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/builder/
main/java/org/apache/camel/component/bean/
main/java/org/apache/camel/model/ main/java/org/apache/camel/processor/
test/java/org/apache/camel/component/bean/ test...
Author: davsclaus
Date: Fri Mar 13 14:36:50 2009
New Revision: 753284
URL: http://svn.apache.org/viewvc?rev=753284&view=rev
Log:
CAMEL-1446, CAMEL-1457: Added TypeConverter as parameter Camel Bean Binding can bind out-of-the-box. Better method selection for methods with exception. Added disableRedelivery to DLC as its more readable than maximumRedeliveries(0).
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoSelectMethodTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExchangeAsReturnTypeNotAllowedTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java Fri Mar 13 14:36:50 2009
@@ -99,6 +99,11 @@
return this;
}
+ public DeadLetterChannelBuilder disableRedelivery() {
+ getRedeliveryPolicy().maximumRedeliveries(0);
+ return this;
+ }
+
public DeadLetterChannelBuilder maximumRedeliveryDelay(long maximumRedeliveryDelay) {
getRedeliveryPolicy().maximumRedeliveryDelay(maximumRedeliveryDelay);
return this;
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java Fri Mar 13 14:36:50 2009
@@ -148,9 +148,9 @@
public static Expression exchangeExceptionExpression() {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
- Throwable exception = exchange.getException();
+ Exception exception = exchange.getException();
if (exception == null) {
- exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
+ exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
}
return exception;
}
@@ -163,6 +163,24 @@
}
/**
+ * Returns an expression for the type converter
+ *
+ * @return an expression object which will return the type converter
+ */
+ public static Expression typeConverterExpression() {
+ return new ExpressionAdapter() {
+ public Object evaluate(Exchange exchange) {
+ return exchange.getContext().getTypeConverter();
+ }
+
+ @Override
+ public String toString() {
+ return "typeConverter";
+ }
+ };
+ }
+
+ /**
* Returns an expression for an exception message set on the exchange
*
* @see <tt>Exchange.getException().getMessage()</tt>
@@ -171,9 +189,9 @@
public static Expression exchangeExceptionMessageExpression() {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
- Throwable exception = exchange.getException();
+ Exception exception = exchange.getException();
if (exception == null) {
- exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
+ exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
}
return exception != null ? exception.getMessage() : null;
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Fri Mar 13 14:36:50 2009
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.bean;
-
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -60,13 +58,13 @@
public class BeanInfo {
private static final transient Log LOG = LogFactory.getLog(BeanInfo.class);
private final CamelContext camelContext;
- private Class type;
- private ParameterMappingStrategy strategy;
- private Map<String, MethodInfo> operations = new ConcurrentHashMap<String, MethodInfo>();
+ private final Class type;
+ private final ParameterMappingStrategy strategy;
+ private final Map<String, MethodInfo> operations = new ConcurrentHashMap<String, MethodInfo>();
+ private final List<MethodInfo> operationsWithBody = new ArrayList<MethodInfo>();
+ private final List<MethodInfo> operationsWithCustomAnnotation = new ArrayList<MethodInfo>();
+ private final Map<Method, MethodInfo> methodMap = new ConcurrentHashMap<Method, MethodInfo>();
private MethodInfo defaultMethod;
- private List<MethodInfo> operationsWithBody = new ArrayList<MethodInfo>();
- private List<MethodInfo> operationsWithCustomAnnotation = new ArrayList<MethodInfo>();
- private Map<Method, MethodInfo> methodMap = new HashMap<Method, MethodInfo>();
private BeanInfo superBeanInfo;
public BeanInfo(CamelContext camelContext, Class type) {
@@ -94,8 +92,20 @@
return camelContext;
}
- public MethodInvocation createInvocation(Method method, Object pojo, Exchange exchange)
- throws RuntimeCamelException {
+ public static ParameterMappingStrategy createParameterMappingStrategy(CamelContext camelContext) {
+ // lookup in registry first if there is a strategy defined
+ Registry registry = camelContext.getRegistry();
+ ParameterMappingStrategy answer = registry.lookup(ParameterMappingStrategy.class.getName(),
+ ParameterMappingStrategy.class);
+ if (answer == null) {
+ // no then use the default one
+ answer = new DefaultParameterMappingStrategy();
+ }
+
+ return answer;
+ }
+
+ public MethodInvocation createInvocation(Method method, Object pojo, Exchange exchange) throws RuntimeCamelException {
MethodInfo methodInfo = introspect(type, method);
if (methodInfo != null) {
return methodInfo.createMethodInvocation(pojo, exchange);
@@ -103,11 +113,9 @@
return null;
}
- public MethodInvocation createInvocation(Object pojo, Exchange exchange) throws RuntimeCamelException,
- AmbiguousMethodCallException {
+ public MethodInvocation createInvocation(Object pojo, Exchange exchange) throws RuntimeCamelException, AmbiguousMethodCallException {
MethodInfo methodInfo = null;
- // TODO use some other mechanism?
String name = exchange.getIn().getHeader(Exchange.BEAN_METHOD_NAME, String.class);
if (name != null) {
methodInfo = operations.get(name);
@@ -121,9 +129,15 @@
if (methodInfo != null) {
return methodInfo.createMethodInvocation(pojo, exchange);
}
+
return null;
}
+ /**
+ * Introspects the given class
+ *
+ * @param clazz the class
+ */
protected void introspect(Class clazz) {
if (LOG.isTraceEnabled()) {
LOG.trace("Introspecting class: " + clazz);
@@ -140,6 +154,12 @@
}
}
+ /**
+ * Introspects the given method
+ *
+ * @param clazz the class
+ * @param method the method
+ */
protected MethodInfo introspect(Class clazz, Method method) {
if (LOG.isTraceEnabled()) {
LOG.trace("Introspecting class: " + clazz + ", method: " + method);
@@ -178,39 +198,6 @@
return methodInfo;
}
- /**
- * Does the given method info override an existing method registered before (from a subclass)
- *
- * @param methodInfo the method to test
- * @return the already registered method to use, null if not overriding any
- */
- private MethodInfo overridesExistingMethod(MethodInfo methodInfo) {
- for (MethodInfo info : methodMap.values()) {
-
- // name test
- if (!info.getMethod().getName().equals(methodInfo.getMethod().getName())) {
- continue;
- }
-
- // parameter types
- if (info.getMethod().getParameterTypes().length != methodInfo.getMethod().getParameterTypes().length) {
- continue;
- }
-
- for (int i = 0; i < info.getMethod().getParameterTypes().length; i++) {
- Class type1 = info.getMethod().getParameterTypes()[i];
- Class type2 = methodInfo.getMethod().getParameterTypes()[i];
- if (!type1.equals(type2)) {
- continue;
- }
- }
-
- // same name, same parameters, then its overrides an existing class
- return info;
- }
-
- return null;
- }
/**
* Returns the {@link MethodInfo} for the given method if it exists or null
@@ -243,21 +230,20 @@
for (int i = 0; i < parameterTypes.length; i++) {
Class parameterType = parameterTypes[i];
Annotation[] parameterAnnotations = parametersAnnotations[i];
- Expression expression = createParameterUnmarshalExpression(clazz, method, parameterType,
- parameterAnnotations);
+ Expression expression = createParameterUnmarshalExpression(clazz, method, parameterType, parameterAnnotations);
hasCustomAnnotation |= expression != null;
- ParameterInfo parameterInfo = new ParameterInfo(i, parameterType, parameterAnnotations,
- expression);
+ ParameterInfo parameterInfo = new ParameterInfo(i, parameterType, parameterAnnotations, expression);
parameters.add(parameterInfo);
if (expression == null) {
hasCustomAnnotation |= ObjectHelper.hasAnnotation(parameterAnnotations, Body.class);
if (bodyParameters.isEmpty()) {
- // lets assume its the body
if (Exchange.class.isAssignableFrom(parameterType)) {
+ // use exchange
expression = ExpressionBuilder.exchangeExpression();
} else {
+ // lets assume its the body
expression = ExpressionBuilder.bodyExpression(parameterType);
}
parameterInfo.setExpression(expression);
@@ -270,12 +256,6 @@
}
// now lets add the method to the repository
-
- // TODO allow an annotation to expose the operation name to use
- /* if (method.getAnnotation(Operation.class) != null) { String name =
- * method.getAnnotation(Operation.class).name(); if (name != null &&
- * name.length() > 0) { opName = name; } }
- */
MethodInfo methodInfo = new MethodInfo(clazz, method, parameters, bodyParameters, hasCustomAnnotation);
return methodInfo;
}
@@ -288,20 +268,25 @@
* @param exchange the message exchange
* @return the method to invoke or null if no definitive method could be
* matched
+ * @throws AmbiguousMethodCallException is thrown if cannot chose method due to ambiguous
*/
protected MethodInfo chooseMethod(Object pojo, Exchange exchange) throws AmbiguousMethodCallException {
if (operationsWithBody.size() == 1) {
+ // only one body possible so we got a hit
return operationsWithBody.get(0);
} else if (!operationsWithBody.isEmpty()) {
+ // multiple operations so find the best suited if possible
return chooseMethodWithMatchingBody(exchange, operationsWithBody);
} else if (operationsWithCustomAnnotation.size() == 1) {
+ // if there is one method with an annotation then use that one
return operationsWithCustomAnnotation.get(0);
}
+ // no we could not find a method to invoke, so either there are none or there are ambigiuous methods.
return null;
}
@SuppressWarnings("unchecked")
- protected MethodInfo chooseMethodWithMatchingBody(Exchange exchange, Collection<MethodInfo> operationList) throws AmbiguousMethodCallException {
+ private MethodInfo chooseMethodWithMatchingBody(Exchange exchange, Collection<MethodInfo> operationList) throws AmbiguousMethodCallException {
// lets see if we can find a method who's body param type matches the message body
Message in = exchange.getIn();
Object body = in.getBody();
@@ -312,6 +297,7 @@
}
List<MethodInfo> possibles = new ArrayList<MethodInfo>();
+ List<MethodInfo> possiblesWithException = new ArrayList<MethodInfo>();
for (MethodInfo methodInfo : operationList) {
// TODO: AOP proxies have additional methods - consider having a static
// method exclude list to skip all known AOP proxy methods
@@ -326,17 +312,32 @@
// try to match the arguments
if (methodInfo.bodyParameterMatches(bodyType)) {
- possibles.add(methodInfo);
+ if (methodInfo.hasExceptionParameter()) {
+ // methods with accepts exceptions
+ possiblesWithException.add(methodInfo);
+ } else {
+ // regular methods with no exceptions
+ possibles.add(methodInfo);
+ }
}
}
- if (possibles.size() == 1) {
+
+ // TODO refactor below into a separate method
+
+ // find best suited method to use
+ Exception exception = ExpressionBuilder.exchangeExceptionExpression().evaluate(exchange, Exception.class);
+ if (exception != null && possiblesWithException.size() == 1) {
+ // prefer the method that accepts exception in case we have an exception also
+ return possiblesWithException.get(0);
+ } else if (possibles.size() == 1) {
return possibles.get(0);
} else if (possibles.isEmpty()) {
+ // TODO: Make sure this is properly unit tested
// lets try converting
Object newBody = null;
MethodInfo matched = null;
for (MethodInfo methodInfo : operationList) {
- Object value = null;
+ Object value;
try {
value = convertToType(exchange, methodInfo.getBodyParameterType(), body);
if (value != null) {
@@ -364,11 +365,67 @@
return chooseMethodWithCustomAnnotations(exchange, possibles);
}
}
+
// no match so return null
return null;
}
- protected MethodInfo chooseMethodWithCustomAnnotations(Exchange exchange, Collection<MethodInfo> possibles) throws AmbiguousMethodCallException {
+ /**
+ * Validates wheter the given method is a valid candidate for Camel Bean Binding.
+ *
+ * @param clazz the class
+ * @param method the method
+ * @return true if valid, false to skip the method
+ */
+ protected boolean isValidMethod(Class clazz, Method method) {
+ // must be a public method
+ if (!Modifier.isPublic(method.getModifiers())) {
+ return false;
+ }
+
+ // return type must not be an Exchange
+ if (method.getReturnType() != null && Exchange.class.isAssignableFrom(method.getReturnType())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Does the given method info override an existing method registered before (from a subclass)
+ *
+ * @param methodInfo the method to test
+ * @return the already registered method to use, null if not overriding any
+ */
+ private MethodInfo overridesExistingMethod(MethodInfo methodInfo) {
+ for (MethodInfo info : methodMap.values()) {
+
+ // name test
+ if (!info.getMethod().getName().equals(methodInfo.getMethod().getName())) {
+ continue;
+ }
+
+ // parameter types
+ if (info.getMethod().getParameterTypes().length != methodInfo.getMethod().getParameterTypes().length) {
+ continue;
+ }
+
+ for (int i = 0; i < info.getMethod().getParameterTypes().length; i++) {
+ Class type1 = info.getMethod().getParameterTypes()[i];
+ Class type2 = methodInfo.getMethod().getParameterTypes()[i];
+ if (!type1.equals(type2)) {
+ continue;
+ }
+ }
+
+ // same name, same parameters, then its overrides an existing class
+ return info;
+ }
+
+ return null;
+ }
+
+ private MethodInfo chooseMethodWithCustomAnnotations(Exchange exchange, Collection<MethodInfo> possibles) throws AmbiguousMethodCallException {
// if we have only one method with custom annotations lets choose that
MethodInfo chosen = null;
for (MethodInfo possible : possibles) {
@@ -393,41 +450,22 @@
* insufficient annotations or not fitting with the default type
* conventions.
*/
- protected Expression createParameterUnmarshalExpression(Class clazz, Method method, Class parameterType,
- Annotation[] parameterAnnotation) {
+ private Expression createParameterUnmarshalExpression(Class clazz, Method method, Class parameterType,
+ Annotation[] parameterAnnotation) {
- // TODO look for a parameter annotation that converts into an expression
+ // look for a parameter annotation that converts into an expression
for (Annotation annotation : parameterAnnotation) {
Expression answer = createParameterUnmarshalExpressionForAnnotation(clazz, method, parameterType, annotation);
if (answer != null) {
return answer;
}
}
+ // no annotations then try the default parameter mappings
return strategy.getDefaultParameterTypeExpression(parameterType);
}
- protected boolean isPossibleBodyParameter(Annotation[] annotations) {
- if (annotations != null) {
- for (Annotation annotation : annotations) {
- if ((annotation instanceof Property)
- || (annotation instanceof Header)
- || (annotation instanceof Headers)
- || (annotation instanceof OutHeaders)
- || (annotation instanceof Properties)) {
- return false;
- }
- LanguageAnnotation languageAnnotation = annotation.annotationType().getAnnotation(LanguageAnnotation.class);
- if (languageAnnotation != null) {
- return false;
- }
- }
- }
- return true;
- }
-
- protected Expression createParameterUnmarshalExpressionForAnnotation(Class clazz, Method method,
- Class parameterType,
- Annotation annotation) {
+ private Expression createParameterUnmarshalExpressionForAnnotation(Class clazz, Method method, Class parameterType,
+ Annotation annotation) {
if (annotation instanceof Property) {
Property propertyAnnotation = (Property)annotation;
return ExpressionBuilder.propertyExpression(propertyAnnotation.value());
@@ -461,27 +499,4 @@
return null;
}
- protected boolean isValidMethod(Class clazz, Method method) {
- // must be a public method
- if (!Modifier.isPublic(method.getModifiers())) {
- return false;
- }
-
- // return type must not be an Exchange
- if (method.getReturnType() != null && Exchange.class.isAssignableFrom(method.getReturnType())) {
- return false;
- }
-
- return true;
- }
-
- public static ParameterMappingStrategy createParameterMappingStrategy(CamelContext camelContext) {
- Registry registry = camelContext.getRegistry();
- ParameterMappingStrategy answer = registry.lookup(ParameterMappingStrategy.class.getName(),
- ParameterMappingStrategy.class);
- if (answer == null) {
- answer = new DefaultParameterMappingStrategy();
- }
- return answer;
- }
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java Fri Mar 13 14:36:50 2009
@@ -22,6 +22,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Message;
+import org.apache.camel.TypeConverter;
import org.apache.camel.builder.ExpressionBuilder;
/**
@@ -36,7 +37,7 @@
loadDefaultRegistry();
}
- public synchronized Expression getDefaultParameterTypeExpression(Class parameterType) {
+ public Expression getDefaultParameterTypeExpression(Class parameterType) {
Expression expression = parameterTypeToExpressionMap.get(parameterType);
return expression;
}
@@ -44,24 +45,15 @@
/**
* Adds a default parameter type mapping to an expression
*/
- public synchronized void addParameterMapping(Class parameterType, Expression expression) {
+ public void addParameterMapping(Class parameterType, Expression expression) {
parameterTypeToExpressionMap.put(parameterType, expression);
}
- /**
- * Creates an invocation on the given POJO using annotations to decide which method to invoke
- * and to figure out which parameters to use
- */
-/*
- public MethodInvocation createInvocation(Object pojo,
- BeanInfo beanInfo,
- Exchange messageExchange,
- Endpoint pojoEndpoint) throws RuntimeCamelException {
- return beanInfo.createInvocation(pojo, messageExchange);
- }
-*/
public void loadDefaultRegistry() {
addParameterMapping(Exchange.class, ExpressionBuilder.exchangeExpression());
addParameterMapping(Message.class, ExpressionBuilder.inMessageExpression());
+ addParameterMapping(Exception.class, ExpressionBuilder.exchangeExceptionExpression());
+ addParameterMapping(TypeConverter.class, ExpressionBuilder.typeConverterExpression());
}
+
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java Fri Mar 13 14:36:50 2009
@@ -314,5 +314,13 @@
return null;
}
+ protected boolean hasExceptionParameter() {
+ for (ParameterInfo parameter : parameters) {
+ if (Exception.class.isAssignableFrom(parameter.getType())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java Fri Mar 13 14:36:50 2009
@@ -56,6 +56,8 @@
private LoggingLevel retryAttemptedLogLevel;
@XmlAttribute
private Boolean logStackTrace;
+ @XmlAttribute
+ private Boolean disableRedelivery;
public RedeliveryPolicy createRedeliveryPolicy(CamelContext context, RedeliveryPolicy parentPolicy) {
if (ref != null) {
@@ -96,6 +98,10 @@
if (logStackTrace != null) {
answer.setLogStackTrace(logStackTrace);
}
+ if (disableRedelivery != null && disableRedelivery) {
+ answer.setMaximumRedeliveries(0);
+ }
+
return answer;
}
@@ -332,4 +338,12 @@
public void setLogStackTrace(Boolean logStackTrace) {
this.logStackTrace = logStackTrace;
}
+
+ public Boolean getDisableRedelivery() {
+ return disableRedelivery;
+ }
+
+ public void setDisableRedelivery(Boolean disableRedelivery) {
+ this.disableRedelivery = disableRedelivery;
+ }
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java Fri Mar 13 14:36:50 2009
@@ -300,6 +300,14 @@
return this;
}
+ /**
+ * Disables redelivery by setting maximum redeliveries to 0.
+ */
+ public RedeliveryPolicy disableRedelivery() {
+ setMaximumRedeliveries(0);
+ return this;
+ }
+
// Properties
// -------------------------------------------------------------------------
public double getBackOffMultiplier() {
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExchangeAsReturnTypeNotAllowedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExchangeAsReturnTypeNotAllowedTest.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExchangeAsReturnTypeNotAllowedTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExchangeAsReturnTypeNotAllowedTest.java Fri Mar 13 14:36:50 2009
@@ -58,7 +58,8 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- errorHandler(deadLetterChannel("mock:dead"));
+ // no redelivery for faster unit test
+ errorHandler(deadLetterChannel("mock:dead").disableRedelivery());
from("direct:in")
.to("bean:myBean")
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoSelectMethodTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoSelectMethodTest.java?rev=753284&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoSelectMethodTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoSelectMethodTest.java Fri Mar 13 14:36:50 2009
@@ -0,0 +1,87 @@
+/**
+ * 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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * @version $Revision$
+ */
+public class BeanInfoSelectMethodTest extends ContextTestSupport {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("foo", new MyFooBean());
+ return jndi;
+ }
+
+ public void testOrder() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Order");
+ template.sendBody("direct:a", "Hello");
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testFailure() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Failure");
+ template.send("direct:b", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody("Hello");
+ exchange.setException(new IllegalArgumentException("Forced by unit test"));
+ }
+ });
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ errorHandler(deadLetterChannel().logStackTrace(false).disableRedelivery());
+
+ onException(Exception.class).handled(true).beanRef("foo").to("mock:result");
+
+ from("direct:a").beanRef("foo").to("mock:result");
+
+ from("direct:b").to("mock:foo");
+ }
+ };
+ }
+
+
+
+ public static class MyFooBean {
+
+ public String handleException(Exception e) {
+ fail("Should not call this method as it is not intended for Camel");
+ return "Exception";
+ }
+
+ public String handleFailure(String order, Exception e) {
+ return "Failure";
+ }
+
+ public String handleOrder(String order) {
+ return "Order";
+ }
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoSelectMethodTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoSelectMethodTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java Fri Mar 13 14:36:50 2009
@@ -46,6 +46,9 @@
return new RouteBuilder() {
@Override
public void configure() throws Exception {
+ // for faster unit testing
+ errorHandler(noErrorHandler());
+
from("direct:start")
.to("bean:myBean?method=a")
.bean(beanMock, "b")
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java?rev=753284&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java Fri Mar 13 14:36:50 2009
@@ -0,0 +1,118 @@
+/**
+ * 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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * @version $Revision$
+ */
+public class DefaultParameterMappingStrategyTest extends ContextTestSupport {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("foo", new MyFooBean());
+ return jndi;
+ }
+
+ public void testExchange() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Exchange");
+ template.sendBody("direct:a", "Hello");
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testMessage() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Message");
+ template.sendBody("direct:b", "Hello");
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testException() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Exception");
+ template.send("direct:c", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody("Hello");
+ exchange.setException(new IllegalArgumentException("Forced by unit test"));
+ }
+ });
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testTypeConverter() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("TypeConverter");
+ template.sendBody("direct:d", "Hello");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ errorHandler(deadLetterChannel().logStackTrace(false).disableRedelivery());
+
+ onException(Exception.class).handled(true).beanRef("foo", "withException").to("mock:result");
+
+ from("direct:a").beanRef("foo", "withExchange").to("mock:result");
+
+ from("direct:b").beanRef("foo", "withMessage").to("mock:result");
+
+ from("direct:c").to("mock:foo");
+
+ from("direct:d").beanRef("foo", "withTypeConverter").to("mock:result");
+ }
+ };
+ }
+
+ public static class MyFooBean {
+
+ public String withExchange(Exchange exchange) {
+ assertNotNull(exchange);
+ assertEquals("Hello", exchange.getIn().getBody(String.class));
+ return "Exchange";
+ }
+
+ public String withMessage(Message message) {
+ assertNotNull(message);
+ assertEquals("Hello", message.getBody(String.class));
+ return "Message";
+ }
+
+ public String withException(Message in, Exception cause) {
+ assertNotNull(in);
+ assertNotNull(cause);
+ assertEquals("Hello", in.getBody(String.class));
+ return "Exception";
+ }
+
+ public String withTypeConverter(String body, TypeConverter converter) {
+ assertNotNull(body);
+ assertNotNull(converter);
+ assertEquals("Hello", body);
+ assertEquals(new Integer(123), converter.convertTo(Integer.class, "123"));
+ return "TypeConverter";
+ }
+
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java?rev=753284&r1=753283&r2=753284&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java Fri Mar 13 14:36:50 2009
@@ -28,8 +28,8 @@
*/
public class FromFilePollThirdTimeOkTest extends ContextTestSupport {
- private String body = "Hello World this file will be deleted";
private static int counter;
+ private String body = "Hello World this file will be deleted";
@Override
protected void setUp() throws Exception {