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 2012/04/15 17:07:10 UTC

svn commit: r1326358 [1/2] - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/xml/ camel-core/src/main/java/org/apache/camel/component/dataset/ camel-core/src/main/java/org/apache/camel/compo...

Author: davsclaus
Date: Sun Apr 15 15:07:08 2012
New Revision: 1326358

URL: http://svn.apache.org/viewvc?rev=1326358&view=rev
Log:
CAMEL-5172: Fixed and improved TypeConverter to fail faster by throwing TypeConversionException to the caller. Use the new tryConvertTo API for the old behavior. This would also be more in line what people would expect that exceptions to be propated back as is to the caller.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConversionException.java
      - copied, changed from r1325597, camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverterLoaderException.java
    camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/FallbackTypeConverterShouldThrowExceptionTest.java
      - copied, changed from r1326087, camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/FallbackTypeConverterShouldNotThrowExceptionTest.java
    camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/SplitterAndExceptionRouteTwistIssueTest.java
Removed:
    camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/FallbackTypeConverterShouldNotThrowExceptionTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadException.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetSupport.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ArrayTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AsyncProcessorTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/EnumTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/FutureTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodFallbackTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/LazyLoadingTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/PropertyEditorTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodFallbackTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/NoXmlBodyValidationException.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidValueTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/MyMessageToProcessorConverter.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/EnumConverterTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryMissesThenAddTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimulatorTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWrappedExceptionTest.java
    camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java
    camel/trunk/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverter.java
    camel/trunk/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java
    camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
    camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
    camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/JAXBConvertTest.java
    camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMessageTypeTest.java
    camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
    camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPredicateFilterTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadException.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadException.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadException.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadException.java Sun Apr 15 15:07:08 2012
@@ -19,9 +19,14 @@ package org.apache.camel;
 /**
  * Is thrown if the payload from the exchange could not be retrieved because of being null, wrong class type etc.
  *
+ * @deprecated will be removed in Camel 3.0
  * @version 
  */
+@Deprecated
 public class InvalidPayloadException extends CamelExchangeException {
+
+    // TODO: We should remove this class in Camel 3.0, and just rely on the other exceptions for type conversion issues
+
     private static final long serialVersionUID = -1689157578733908632L;
     private final transient Class<?> type;
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java Sun Apr 15 15:07:08 2012
@@ -94,7 +94,8 @@ public interface Message {
      * @param name the name of the header
      * @param type the type of the header
      * @return the value of the given header or <tt>null</tt> if there is no header for
-     *         the given name or <tt>null</tt> if it cannot be converted to the given type
+     *         the given name
+     * @throws TypeConversionException is thrown if error during type conversion
      */
     <T> T getHeader(String name, Class<T> type);
 
@@ -192,7 +193,8 @@ public interface Message {
      * Returns the body as the specified type
      *
      * @param type the type that the body
-     * @return the body of the message as the specified type, or <tt>null</tt> if not possible to convert
+     * @return the body of the message as the specified type, or <tt>null</tt> if no body exists
+     * @throws TypeConversionException is thrown if error during type conversion
      */
     <T> T getBody(Class<T> type);
 

Copied: camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConversionException.java (from r1325597, camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverterLoaderException.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConversionException.java?p2=camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConversionException.java&p1=camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverterLoaderException.java&r1=1325597&r2=1326358&rev=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverterLoaderException.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConversionException.java Sun Apr 15 15:07:08 2012
@@ -17,20 +17,56 @@
 package org.apache.camel;
 
 /**
- * Exception when failing to load type converters.
+ * Exception when failing during type conversion.
  *
  * @version 
  */
-public class TypeConverterLoaderException extends CamelException {
-    private static final long serialVersionUID = -6118520819865759887L;
+public class TypeConversionException extends RuntimeCamelException {
+    private static final long serialVersionUID = -6118520819865759886L;
 
-    public TypeConverterLoaderException(String message) {
-        super("Failed to load type converters because of: " + message);
+    private final transient Object value;
+    private final transient Class<?> type;
+
+    public TypeConversionException(Object value, Class<?> type, Throwable cause) {
+        super(createMessage(value, type, cause), cause);
+        this.value = value;
+        this.type = type;
+    }
+
+    /**
+     * Returns the value which could not be converted
+     */
+    public Object getValue() {
+        return value;
+    }
+
+    /**
+     * Returns the required <tt>to</tt> type
+     */
+    public Class<?> getToType() {
+        return type;
+    }
+
+    /**
+     * Returns the required <tt>from</tt> type.
+     * Returns <tt>null</tt> if the provided value was null.
+     */
+    public Class<?> getFromType() {
+        if (value != null) {
+            return value.getClass();
+        } else {
+            return null;
+        }
     }
 
-    public TypeConverterLoaderException(String message, Throwable cause) {
-        super("Failed to load type converters because of: " + message, cause);
+    /**
+     * Returns an error message for type conversion failed.
+     */
+    public static String createMessage(Object value, Class<?> type, Throwable cause) {
+        return "Error during type conversion from type: " + (value != null ? value.getClass().getCanonicalName() : null)
+                + " to the required type: " + type.getCanonicalName() + " with value " + value + " due " + cause.getMessage();
     }
+
 }
 
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverter.java Sun Apr 15 15:07:08 2012
@@ -29,12 +29,13 @@ public interface TypeConverter {
 
     /**
      * Converts the value to the specified type
-     * 
+     *
      * @param type the requested type
      * @param value the value to be converted
      * @return the converted value, or <tt>null</tt> if not possible to convert
+     * @throws TypeConversionException is thrown if error during type conversion
      */
-    <T> T convertTo(Class<T> type, Object value);
+    <T> T convertTo(Class<T> type, Object value) throws TypeConversionException;
 
     /**
      * Converts the value to the specified type in the context of an exchange
@@ -46,8 +47,9 @@ public interface TypeConverter {
      * @param exchange the current exchange
      * @param value the value to be converted
      * @return the converted value, or <tt>null</tt> if not possible to convert
+     * @throws TypeConversionException is thrown if error during type conversion
      */
-    <T> T convertTo(Class<T> type, Exchange exchange, Object value);
+    <T> T convertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException;
 
     /**
      * Converts the value to the specified type
@@ -55,9 +57,10 @@ public interface TypeConverter {
      * @param type the requested type
      * @param value the value to be converted
      * @return the converted value, is never <tt>null</tt>
-     * @throws NoTypeConversionAvailableException if conversion not possible
+     * @throws TypeConversionException is thrown if error during type conversion
+     * @throws NoTypeConversionAvailableException} if no type converters exists to convert to the given type
      */
-    <T> T mandatoryConvertTo(Class<T> type, Object value) throws NoTypeConversionAvailableException;
+    <T> T mandatoryConvertTo(Class<T> type, Object value) throws TypeConversionException, NoTypeConversionAvailableException;
 
     /**
      * Converts the value to the specified type in the context of an exchange
@@ -69,8 +72,38 @@ public interface TypeConverter {
      * @param exchange the current exchange
      * @param value the value to be converted
      * @return the converted value, is never <tt>null</tt>
-     * @throws NoTypeConversionAvailableException} if conversion not possible
+     * @throws TypeConversionException is thrown if error during type conversion
+     * @throws NoTypeConversionAvailableException} if no type converters exists to convert to the given type
+     */
+    <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException, NoTypeConversionAvailableException;
+
+    /**
+     * Tries to converts the value to the specified type,
+     * returning <tt>null</tt> if not possible to convert.
+     * <p/>
+     * This method will <b>not</b> throw an exception if an exception occurred during conversion.
+     *
+     * @param type the requested type
+     * @param value the value to be converted
+     * @return the converted value, or <tt>null</tt> if not possible to convert
+     */
+    <T> T tryConvertTo(Class<T> type, Object value);
+
+    /**
+     * Tries to converts the value to the specified type in the context of an exchange,
+     * returning <tt>null</tt> if not possible to convert.
+     * <p/>
+     * This method will <b>not</b> throw an exception if an exception occurred during conversion.
+     * Converts the value to the specified type in the context of an exchange
+     * <p/>
+     * Used when conversion requires extra information from the current
+     * exchange (such as encoding).
+     *
+     * @param type the requested type
+     * @param exchange the current exchange
+     * @param value the value to be converted
+     * @return the converted value, or <tt>null</tt> if not possible to convert
      */
-    <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) throws NoTypeConversionAvailableException;
+    <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value);
 
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java Sun Apr 15 15:07:08 2012
@@ -47,6 +47,7 @@ import org.xml.sax.InputSource;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
+import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Predicate;
 import org.apache.camel.RuntimeExpressionException;
 import org.apache.camel.Service;
@@ -161,12 +162,13 @@ public class XPathBuilder implements Exp
         Exchange dummy = new DefaultExchange(context);
         dummy.getIn().setBody(body);
 
-        boolean answer = matches(dummy);
-
-        // remove the dummy from the thread local after usage
-        variableResolver.remove();
-        exchange.remove();
-        return answer;
+        try {
+            return matches(dummy);
+        } finally {
+            // remove the dummy from the thread local after usage
+            variableResolver.remove();
+            exchange.remove();
+        }
     }
 
     /**
@@ -184,12 +186,13 @@ public class XPathBuilder implements Exp
         Exchange dummy = new DefaultExchange(context);
         dummy.getIn().setBody(body);
 
-        T answer = evaluate(dummy, type);
-
-        // remove the dummy from the thread local after usage
-        variableResolver.remove();
-        exchange.remove();
-        return answer;
+        try {
+            return evaluate(dummy, type);
+        } finally {
+            // remove the dummy from the thread local after usage
+            variableResolver.remove();
+            exchange.remove();
+        }
     }
 
     /**
@@ -207,12 +210,13 @@ public class XPathBuilder implements Exp
         dummy.getIn().setBody(body);
 
         setResultQName(XPathConstants.STRING);
-        String answer = evaluate(dummy, String.class);
-
-        // remove the dummy from the thread local after usage
-        variableResolver.remove();
-        exchange.remove();
-        return answer;
+        try {
+            return evaluate(dummy, String.class);
+        } finally {
+            // remove the dummy from the thread local after usage
+            variableResolver.remove();
+            exchange.remove();
+        }
     }
 
     // Builder methods
@@ -938,36 +942,66 @@ public class XPathBuilder implements Exp
      * Strategy method to extract the document from the exchange.
      */
     protected Object getDocument(Exchange exchange, Object body) {
+        try {
+            return doGetDocument(exchange, body);
+        } catch (Exception e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        } finally {
+            // call the reset if the in message body is StreamCache
+            MessageHelper.resetStreamCache(exchange.getIn());
+        }
+    }
+
+    protected Object doGetDocument(Exchange exchange, Object body) throws Exception {
+        if (body == null) {
+            return null;
+        }
+
         Object answer = null;
 
         Class<?> type = getDocumentType();
+        Exception cause = null;
         if (type != null) {
             // try to get the body as the desired type
-            answer = exchange.getContext().getTypeConverter().convertTo(type, exchange, body);
+            try {
+                answer = exchange.getContext().getTypeConverter().convertTo(type, exchange, body);
+            } catch (Exception e) {
+                // we want to store the caused exception, if we could not convert
+                cause = e;
+            }
         }
-        // fallback to get the body as is
+
+        // okay we can try to remedy the failed conversion by some special types
         if (answer == null) {
-            answer = body;
+            // let's try coercing some common types into something JAXP work with the best for special types
+            if (body instanceof WrappedFile) {
+                // special for files so we can work with them out of the box
+                InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, body);
+                answer = new InputSource(is);
+            } else if (body instanceof BeanInvocation) {
+                // if its a null bean invocation then handle that specially
+                BeanInvocation bi = exchange.getContext().getTypeConverter().convertTo(BeanInvocation.class, body);
+                if (bi.getArgs() != null && bi.getArgs().length == 1 && bi.getArgs()[0] == null) {
+                    // its a null argument from the bean invocation so use null as answer
+                    answer = null;
+                }
+            } else if (body instanceof String) {
+                answer = new InputSource(new StringReader((String) body));
+            }
         }
 
-        // let's try coercing some common types into something JAXP can work with
-        if (answer instanceof WrappedFile) {
-            // special for files so we can work with them out of the box
-            InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, answer);
-            answer = new InputSource(is);
-        } else if (answer instanceof BeanInvocation) {
-            // if its a null bean invocation then handle that
-            BeanInvocation bi = exchange.getContext().getTypeConverter().convertTo(BeanInvocation.class, answer);
-            if (bi.getArgs() != null && bi.getArgs().length == 1 && bi.getArgs()[0] == null) {
-                // its a null argument from the bean invocation so use null as answer
-                answer = null;
+        if (type == null && answer == null) {
+            // fallback to get the body as is
+            answer = body;
+        } else if (answer == null) {
+            // there was a type, and we could not convert to it, then fail
+            if (cause != null) {
+                throw cause;
+            } else {
+                throw new NoTypeConversionAvailableException(body, type);
             }
-        } else if (answer instanceof String) {
-            answer = new InputSource(new StringReader(answer.toString()));
         }
 
-        // call the reset if the in message body is StreamCache
-        MessageHelper.resetStreamCache(exchange.getIn());
         return answer;
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java Sun Apr 15 15:07:08 2012
@@ -414,19 +414,19 @@ public class XsltBuilder implements Proc
 
         Source source = null;
         if (isAllowStAX()) {
-            source = exchange.getContext().getTypeConverter().convertTo(StAXSource.class, exchange, body);
+            source = exchange.getContext().getTypeConverter().tryConvertTo(StAXSource.class, exchange, body);
         }
         if (source == null) {
             // then try SAX
-            source = exchange.getContext().getTypeConverter().convertTo(SAXSource.class, exchange, body);
+            source = exchange.getContext().getTypeConverter().tryConvertTo(SAXSource.class, exchange, body);
         }
         if (source == null) {
             // then try stream
-            source = exchange.getContext().getTypeConverter().convertTo(StreamSource.class, exchange, body);
+            source = exchange.getContext().getTypeConverter().tryConvertTo(StreamSource.class, exchange, body);
         }
         if (source == null) {
             // and fallback to DOM
-            source = exchange.getContext().getTypeConverter().convertTo(DOMSource.class, exchange, body);
+            source = exchange.getContext().getTypeConverter().tryConvertTo(DOMSource.class, exchange, body);
         }
         if (source == null) {
             if (isFailOnNullBody()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetSupport.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetSupport.java Sun Apr 15 15:07:08 2012
@@ -22,7 +22,6 @@ import java.util.Map;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
-import org.apache.camel.util.ExchangeHelper;
 
 /**
  * Base class for DataSet
@@ -58,7 +57,7 @@ public abstract class DataSetSupport imp
         Object actualBody = actual.getIn().getBody();
         if (expectedBody != null) {
             // let's coerce to the correct type
-            actualBody = ExchangeHelper.getMandatoryInBody(actual, expectedBody.getClass());
+            actualBody = actual.getIn().getMandatoryBody(expectedBody.getClass());
         }
         DataSetEndpoint.assertEquals("message body", expectedBody, actualBody, actual);
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java Sun Apr 15 15:07:08 2012
@@ -29,7 +29,6 @@ import java.util.List;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
@@ -207,7 +206,7 @@ public class FileOperations implements G
             }
 
             // fallback and use stream based
-            InputStream in = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
+            InputStream in = exchange.getIn().getMandatoryBody(InputStream.class);
             writeFileByStream(in, file);
             // try to keep last modified timestamp if configured to do so
             keepLastModified(exchange, file);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java Sun Apr 15 15:07:08 2012
@@ -24,7 +24,6 @@ import java.util.zip.GZIPOutputStream;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.DataFormat;
-import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.IOHelper;
 
 public class GzipDataFormat implements DataFormat {
@@ -41,7 +40,7 @@ public class GzipDataFormat implements D
     }
 
     public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
-        InputStream is = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
+        InputStream is = exchange.getIn().getMandatoryBody(InputStream.class);
         GZIPInputStream unzipInput = new GZIPInputStream(is);
         
         // Create an expandable byte array to hold the inflated data

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java Sun Apr 15 15:07:08 2012
@@ -68,15 +68,14 @@ public abstract class MessageSupport imp
 
             // lets first try converting the body itself first
             // as for some types like InputStream v Reader its more efficient to do the transformation
-            // from the body itself as its got efficient implementations of them, before trying the
-            // message
-            T answer = converter.convertTo(type, getExchange(), body);
+            // from the body itself as its got efficient implementations of them, before trying the message
+            T answer = converter.convertTo(type, e, body);
             if (answer != null) {
                 return answer;
             }
 
-            // fallback to the message itself (e.g. used in camel-http)
-            answer = converter.convertTo(type, getExchange(), this);
+            // fallback and try the message itself (e.g. used in camel-http)
+            answer = converter.tryConvertTo(type, e, this);
             if (answer != null) {
                 return answer;
             }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java Sun Apr 15 15:07:08 2012
@@ -25,7 +25,6 @@ import java.util.zip.InflaterInputStream
 
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.DataFormat;
-import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.IOHelper;
 
 public class ZipDataFormat implements DataFormat {
@@ -53,7 +52,7 @@ public class ZipDataFormat implements Da
     }
 
     public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
-        InputStream is = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
+        InputStream is = exchange.getIn().getMandatoryBody(InputStream.class);
         InflaterInputStream unzipInput = new InflaterInputStream(is);
         
         // Create an expandable byte array to hold the inflated data

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ArrayTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ArrayTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ArrayTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ArrayTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -88,4 +88,22 @@ public class ArrayTypeConverter implemen
     public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
         return convertTo(type, value);
     }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            return convertTo(type, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AsyncProcessorTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AsyncProcessorTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AsyncProcessorTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AsyncProcessorTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -58,11 +58,27 @@ public class AsyncProcessorTypeConverter
     public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) throws NoTypeConversionAvailableException {
         return convertTo(type, exchange, value);
     }
-    
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, exchange, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            return convertTo(type, null, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
     /**
      * @deprecated use AnycProcessorConverter.convert instead
-     * @param value
-     * @return
      */
     @Deprecated
     public static AsyncProcessor convert(Processor value) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java Sun Apr 15 15:07:08 2012
@@ -31,6 +31,7 @@ import org.apache.camel.CamelExecutionEx
 import org.apache.camel.Exchange;
 import org.apache.camel.NoFactoryAvailableException;
 import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.TypeConversionException;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.Injector;
@@ -101,20 +102,18 @@ public abstract class BaseTypeConverterR
 
         Object answer;
         try {
-            answer = doConvertTo(type, exchange, value);
+            answer = doConvertTo(type, exchange, value, false);
         } catch (Exception e) {
             // if its a ExecutionException then we have rethrow it as its not due to failed conversion
+            // this is special for FutureTypeConverter
             boolean execution = ObjectHelper.getException(ExecutionException.class, e) != null
                     || ObjectHelper.getException(CamelExecutionException.class, e) != null;
             if (execution) {
                 throw ObjectHelper.wrapCamelExecutionException(exchange, e);
             }
 
-            // we cannot convert so return null
-            if (log.isDebugEnabled()) {
-                log.debug("{} Caused by: {}. Will ignore this and continue.", NoTypeConversionAvailableException.createMessage(value, type), e.getMessage());
-            }
-            return null;
+            // error occurred during type conversion
+            throw new TypeConversionException(value, type, e);
         }
         if (answer == Void.TYPE) {
             // Could not find suitable conversion
@@ -138,9 +137,10 @@ public abstract class BaseTypeConverterR
 
         Object answer;
         try {
-            answer = doConvertTo(type, exchange, value);
+            answer = doConvertTo(type, exchange, value, false);
         } catch (Exception e) {
-            throw new NoTypeConversionAvailableException(value, type, e);
+            // error occurred during type conversion
+            throw new TypeConversionException(value, type, e);
         }
         if (answer == Void.TYPE || value == null) {
             // Could not find suitable conversion
@@ -150,7 +150,32 @@ public abstract class BaseTypeConverterR
         }
     }
 
-    protected Object doConvertTo(final Class<?> type, final Exchange exchange, final Object value) {
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        return tryConvertTo(type, null, value);
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        if (!isRunAllowed()) {
+            return null;
+        }
+
+        Object answer;
+        try {
+            answer = doConvertTo(type, exchange, value, true);
+        } catch (Exception e) {
+            return null;
+        }
+        if (answer == Void.TYPE) {
+            // Could not find suitable conversion
+            return null;
+        } else {
+            return (T) answer;
+        }
+    }
+
+    protected Object doConvertTo(final Class<?> type, final Exchange exchange, final Object value, final boolean tryConvert) {
         if (log.isTraceEnabled()) {
             log.trace("Converting {} -> {} with value: {}",
                     new Object[]{value == null ? "null" : value.getClass().getCanonicalName(), 
@@ -177,7 +202,7 @@ public abstract class BaseTypeConverterR
             return Void.TYPE;
         }
         
-        // special for NaN numbers, which we can only convert for flating numbers
+        // special for NaN numbers, which we can only convert for floating numbers
         if (ObjectHelper.isNaN(value)) {
             if (Float.class.isAssignableFrom(type)) {
                 return Float.NaN;
@@ -238,8 +263,11 @@ public abstract class BaseTypeConverterR
             }
         }
 
-        // Could not find suitable conversion, so remember it
-        misses.put(key, key);
+        if (!tryConvert) {
+            // Could not find suitable conversion, so remember it
+            // do not register misses for try conversions
+            misses.put(key, key);
+        }
 
         // Could not find suitable conversion, so return Void to indicate not found
         return Void.TYPE;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/EnumTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/EnumTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/EnumTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/EnumTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -64,4 +64,23 @@ public class EnumTypeConverter implement
         // ignore exchange
         return convertTo(type, value);
     }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            // ignore exchange
+            return convertTo(type, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }
\ No newline at end of file

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/FutureTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/FutureTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/FutureTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/FutureTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -79,7 +79,7 @@ public final class FutureTypeConverter i
                 body = ExchangeHelper.extractResultBody(result, result.getPattern());
             }
 
-            // no then try to lookup a type converter
+            // no then convert to the type
             return converter.convertTo(type, exchange, body);
         }
 
@@ -120,4 +120,22 @@ public final class FutureTypeConverter i
 
         return answer;
     }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, exchange, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            return convertTo(type, null, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodFallbackTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodFallbackTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodFallbackTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodFallbackTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -71,7 +71,25 @@ public class InstanceMethodFallbackTypeC
 
     @Override
     public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
-        return convertTo(type, null, value);
+        return convertTo(type, exchange, value);
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            return convertTo(type, null, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, exchange, value);
+        } catch (Exception e) {
+            return null;
+        }
     }
 
 }
\ No newline at end of file

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -32,7 +32,7 @@ import org.apache.camel.util.ObjectHelpe
  * @version 
  */
 public class InstanceMethodTypeConverter implements TypeConverter {
-    private final CachingInjector<?>injector;
+    private final CachingInjector<?> injector;
     private final Method method;
     private final boolean useExchange;
     private final TypeConverterRegistry registry;
@@ -79,6 +79,24 @@ public class InstanceMethodTypeConverter
 
     @Override   
     public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
-        return convertTo(type, null, value);
+        return convertTo(type, exchange, value);
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, exchange, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            return convertTo(type, null, value);
+        } catch (Exception e) {
+            return null;
+        }
     }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/LazyLoadingTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/LazyLoadingTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/LazyLoadingTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/LazyLoadingTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -45,12 +45,12 @@ public class LazyLoadingTypeConverter ex
     }
 
     @Override
-    protected Object doConvertTo(final Class<?> type, final Exchange exchange, final Object value) {
-        Object answer = super.doConvertTo(type, exchange, value);
+    protected Object doConvertTo(final Class<?> type, final Exchange exchange, final Object value, boolean tryConvert) {
+        Object answer = super.doConvertTo(type, exchange, value, tryConvert);
         if (answer == null && !loaded.get()) {
             // okay we could not convert, so try again, but load the converters up front
             ensureLoaded();
-            answer = super.doConvertTo(type, exchange, value);
+            answer = super.doConvertTo(type, exchange, value, tryConvert);
         }
         return answer;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/PropertyEditorTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/PropertyEditorTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/PropertyEditorTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/PropertyEditorTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -32,8 +32,11 @@ import org.slf4j.LoggerFactory;
  * Uses the {@link java.beans.PropertyEditor} conversion system to convert Objects to
  * and from String values.
  *
+ * @deprecated should be removed as it can cause side-effects when using 3rd party property editors
+ *
  * @version 
  */
+@Deprecated
 public class PropertyEditorTypeConverter implements TypeConverter {
 
     private static final Logger LOG = LoggerFactory.getLogger(PropertyEditorTypeConverter.class);
@@ -122,4 +125,22 @@ public class PropertyEditorTypeConverter
     public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
         return convertTo(type, value);
     }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, exchange, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            return convertTo(type, null, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodFallbackTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodFallbackTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodFallbackTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodFallbackTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -63,7 +63,24 @@ public class StaticMethodFallbackTypeCon
 
     @Override
     public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
-        return convertTo(type, null, value);
+        return convertTo(type, exchange, value);
     }
 
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, exchange, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            return convertTo(type, null, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }
\ No newline at end of file

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -59,7 +59,24 @@ public class StaticMethodTypeConverter i
 
     @Override
     public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
-        return convertTo(type, null, value);
+        return convertTo(type, exchange, value);
     }
 
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, exchange, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            return convertTo(type, null, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java Sun Apr 15 15:07:08 2012
@@ -79,4 +79,21 @@ public class ToStringTypeConverter imple
         return convertTo(type, value);
     }
 
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        try {
+            return convertTo(type, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        try {
+            return convertTo(type, value);
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java Sun Apr 15 15:07:08 2012
@@ -284,7 +284,7 @@ public class BeanExpression implements E
             }
 
             // special for list is last keyword
-            Integer num = exchange.getContext().getTypeConverter().convertTo(Integer.class, key);
+            Integer num = exchange.getContext().getTypeConverter().tryConvertTo(Integer.class, key);
             boolean checkList = key.startsWith("last") || num != null;
 
             if (checkList) {
@@ -296,7 +296,7 @@ public class BeanExpression implements E
                         // maybe its an expression to subtract a number after last
                         String after = ObjectHelper.after(key, "-");
                         if (after != null) {
-                            Integer redux = exchange.getContext().getTypeConverter().convertTo(Integer.class, after.trim());
+                            Integer redux = exchange.getContext().getTypeConverter().tryConvertTo(Integer.class, after.trim());
                             if (redux != null) {
                                 num -= redux;
                             } else {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/UnmarshalProcessor.java Sun Apr 15 15:07:08 2012
@@ -27,7 +27,6 @@ import org.apache.camel.RuntimeCamelExce
 import org.apache.camel.Traceable;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.support.ServiceSupport;
-import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
@@ -49,7 +48,7 @@ public class UnmarshalProcessor extends 
     public void process(Exchange exchange) throws Exception {
         ObjectHelper.notNull(dataFormat, "dataFormat");
 
-        InputStream stream = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
+        InputStream stream = exchange.getIn().getMandatoryBody(InputStream.class);
         try {
             // lets setup the out message before we invoke the dataFormat so that it can mutate it if necessary
             Message out = exchange.getOut();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/NoXmlBodyValidationException.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/NoXmlBodyValidationException.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/NoXmlBodyValidationException.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/NoXmlBodyValidationException.java Sun Apr 15 15:07:08 2012
@@ -30,4 +30,8 @@ public class NoXmlBodyValidationExceptio
     public NoXmlBodyValidationException(Exchange exchange) {
         super(exchange, "No XML body could be found on the input message");
     }
+
+    public NoXmlBodyValidationException(Exchange exchange, Throwable cause) {
+        super("No XML body could be found on the input message", exchange, cause);
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java Sun Apr 15 15:07:08 2012
@@ -71,12 +71,16 @@ public class ValidatingProcessor impleme
 
         Source source;
         Result result;
-        if (useDom) {
-            source = exchange.getIn().getBody(DOMSource.class);
-            result = new DOMResult();
-        } else {
-            source = exchange.getIn().getBody(SAXSource.class);
-            result = new SAXResult();
+        try {
+            if (useDom) {
+                source = exchange.getIn().getBody(DOMSource.class);
+                result = new DOMResult();
+            } else {
+                source = exchange.getIn().getBody(SAXSource.class);
+                result = new SAXResult();
+            }
+        } catch (Exception e) {
+            throw new NoXmlBodyValidationException(exchange, e);
         }
         if (source == null) {
             throw new NoXmlBodyValidationException(exchange);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Sun Apr 15 15:07:08 2012
@@ -37,6 +37,7 @@ import org.apache.camel.NoSuchEndpointEx
 import org.apache.camel.NoSuchHeaderException;
 import org.apache.camel.NoSuchPropertyException;
 import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.TypeConversionException;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.spi.UnitOfWork;
@@ -86,6 +87,16 @@ public final class ExchangeHelper {
         return endpoint;
     }
 
+    /**
+     * Gets the mandatory property of the exchange of the correct type
+     *
+     * @param exchange      the exchange
+     * @param propertyName  the property name
+     * @param type          the type
+     * @return the property value
+     * @throws TypeConversionException is thrown if error during type conversion
+     * @throws NoSuchPropertyException is thrown if no property exists
+     */
     public static <T> T getMandatoryProperty(Exchange exchange, String propertyName, Class<T> type) throws NoSuchPropertyException {
         T result = exchange.getProperty(propertyName, type);
         if (result != null) {
@@ -94,7 +105,17 @@ public final class ExchangeHelper {
         throw new NoSuchPropertyException(exchange, propertyName, type);
     }
 
-    public static <T> T getMandatoryHeader(Exchange exchange, String headerName, Class<T> type) throws NoSuchHeaderException {
+    /**
+     * Gets the mandatory inbound header of the correct type
+     *
+     * @param exchange      the exchange
+     * @param headerName    the header name
+     * @param type          the type
+     * @return the header value
+     * @throws TypeConversionException is thrown if error during type conversion
+     * @throws NoSuchHeaderException is thrown if no headers exists
+     */
+    public static <T> T getMandatoryHeader(Exchange exchange, String headerName, Class<T> type) throws TypeConversionException, NoSuchHeaderException {
         T answer = exchange.getIn().getHeader(headerName, type);
         if (answer == null) {
             throw new NoSuchHeaderException(exchange, headerName, type);
@@ -105,7 +126,13 @@ public final class ExchangeHelper {
     /**
      * Returns the mandatory inbound message body of the correct type or throws
      * an exception if it is not present
+     *
+     * @param exchange the exchange
+     * @return the body, is never <tt>null</tt>
+     * @throws InvalidPayloadException Is thrown if the body being <tt>null</tt> or wrong class type
+     * @deprecated use {@link org.apache.camel.Message#getMandatoryBody()}
      */
+    @Deprecated
     public static Object getMandatoryInBody(Exchange exchange) throws InvalidPayloadException {
         return exchange.getIn().getMandatoryBody();
     }
@@ -113,7 +140,9 @@ public final class ExchangeHelper {
     /**
      * Returns the mandatory inbound message body of the correct type or throws
      * an exception if it is not present
+     * @deprecated use {@link org.apache.camel.Message#getMandatoryBody(Class)}
      */
+    @Deprecated
     public static <T> T getMandatoryInBody(Exchange exchange, Class<T> type) throws InvalidPayloadException {
         return exchange.getIn().getMandatoryBody(type);
     }
@@ -121,7 +150,9 @@ public final class ExchangeHelper {
     /**
      * Returns the mandatory outbound message body of the correct type or throws
      * an exception if it is not present
+     * @deprecated use {@link org.apache.camel.Message#getMandatoryBody()}
      */
+    @Deprecated
     public static Object getMandatoryOutBody(Exchange exchange) throws InvalidPayloadException {
         return exchange.getOut().getMandatoryBody();
     }
@@ -129,15 +160,22 @@ public final class ExchangeHelper {
     /**
      * Returns the mandatory outbound message body of the correct type or throws
      * an exception if it is not present
+     * @deprecated use {@link org.apache.camel.Message#getMandatoryBody(Class)}
      */
+    @Deprecated
     public static <T> T getMandatoryOutBody(Exchange exchange, Class<T> type) throws InvalidPayloadException {
         return exchange.getOut().getMandatoryBody(type);
     }
 
     /**
      * Converts the value to the given expected type or throws an exception
+     *
+     * @return the converted value
+     * @throws TypeConversionException is thrown if error during type conversion
+     * @throws NoTypeConversionAvailableException} if no type converters exists to convert to the given type
      */
-    public static <T> T convertToMandatoryType(Exchange exchange, Class<T> type, Object value) throws NoTypeConversionAvailableException {
+    public static <T> T convertToMandatoryType(Exchange exchange, Class<T> type, Object value)
+        throws TypeConversionException, NoTypeConversionAvailableException {
         CamelContext camelContext = exchange.getContext();
         ObjectHelper.notNull(camelContext, "CamelContext of Exchange");
         TypeConverter converter = camelContext.getTypeConverter();
@@ -148,10 +186,12 @@ public final class ExchangeHelper {
     }
 
     /**
-     * Converts the value to the given expected type returning null if it could
-     * not be converted
+     * Converts the value to the given expected type
+     *
+     * @return the converted value
+     * @throws org.apache.camel.TypeConversionException is thrown if error during type conversion
      */
-    public static <T> T convertToType(Exchange exchange, Class<T> type, Object value) {
+    public static <T> T convertToType(Exchange exchange, Class<T> type, Object value) throws TypeConversionException {
         CamelContext camelContext = exchange.getContext();
         ObjectHelper.notNull(camelContext, "CamelContext of Exchange");
         TypeConverter converter = camelContext.getTypeConverter();
@@ -333,6 +373,10 @@ public final class ExchangeHelper {
 
     /**
      * Creates a new instance of the given type from the injector
+     *
+     * @param exchange the exchange
+     * @param type     the given type
+     * @return the created instance of the given type
      */
     public static <T> T newInstance(Exchange exchange, Class<T> type) {
         return exchange.getContext().getInjector().newInstance(type);
@@ -376,6 +420,9 @@ public final class ExchangeHelper {
 
     /**
      * Returns the MIME content type on the input message or null if one is not defined
+     *
+     * @param exchange the exchange
+     * @return the MIME content type
      */
     public static String getContentType(Exchange exchange) {
         return MessageHelper.getContentType(exchange.getIn());
@@ -383,6 +430,9 @@ public final class ExchangeHelper {
 
     /**
      * Returns the MIME content encoding on the input message or null if one is not defined
+     *
+     * @param exchange the exchange
+     * @return the MIME content encoding
      */
     public static String getContentEncoding(Exchange exchange) {
         return MessageHelper.getContentEncoding(exchange.getIn());
@@ -390,8 +440,13 @@ public final class ExchangeHelper {
 
     /**
      * Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found
+     *
+     * @param exchange the exchange
+     * @param name     the bean name
+     * @return the bean
+     * @throws NoSuchBeanException if no bean could be found in the registry
      */
-    public static Object lookupMandatoryBean(Exchange exchange, String name) {
+    public static Object lookupMandatoryBean(Exchange exchange, String name) throws NoSuchBeanException {
         Object value = lookupBean(exchange, name);
         if (value == null) {
             throw new NoSuchBeanException(name);
@@ -401,6 +456,12 @@ public final class ExchangeHelper {
 
     /**
      * Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found
+     *
+     * @param exchange the exchange
+     * @param name     the bean name
+     * @param type     the expected bean type
+     * @return the bean
+     * @throws NoSuchBeanException if no bean could be found in the registry
      */
     public static <T> T lookupMandatoryBean(Exchange exchange, String name, Class<T> type) {
         T value = lookupBean(exchange, name, type);
@@ -412,6 +473,10 @@ public final class ExchangeHelper {
 
     /**
      * Performs a lookup in the registry of the bean name
+     *
+     * @param exchange the exchange
+     * @param name     the bean name
+     * @return the bean, or <tt>null</tt> if no bean could be found
      */
     public static Object lookupBean(Exchange exchange, String name) {
         return exchange.getContext().getRegistry().lookup(name);
@@ -419,6 +484,11 @@ public final class ExchangeHelper {
 
     /**
      * Performs a lookup in the registry of the bean name and type
+     *
+     * @param exchange the exchange
+     * @param name     the bean name
+     * @param type     the expected bean type
+     * @return the bean, or <tt>null</tt> if no bean could be found
      */
     public static <T> T lookupBean(Exchange exchange, String name, Class<T> type) {
         return exchange.getContext().getRegistry().lookup(name, type);
@@ -427,6 +497,10 @@ public final class ExchangeHelper {
     /**
      * Returns the first exchange in the given collection of exchanges which has the same exchange ID as the one given
      * or null if none could be found
+     *
+     * @param exchanges  the exchanges
+     * @param exchangeId the exchangeId to find
+     * @return matching exchange, or <tt>null</tt> if none found
      */
     public static Exchange getExchangeById(Iterable<Exchange> exchanges, String exchangeId) {
         for (Exchange exchange : exchanges) {
@@ -464,28 +538,63 @@ public final class ExchangeHelper {
         }
     }
 
+    /**
+     * Checks whether the exchange has been failure handed
+     *
+     * @param exchange  the exchange
+     * @return <tt>true</tt> if failure handled, <tt>false</tt> otherwise
+     */
     public static boolean isFailureHandled(Exchange exchange) {
         return exchange.getProperty(Exchange.FAILURE_HANDLED, false, Boolean.class);
     }
 
+    /**
+     * Checks whether the exchange {@link UnitOfWork} is exhausted
+     *
+     * @param exchange  the exchange
+     * @return <tt>true</tt> if exhausted, <tt>false</tt> otherwise
+     */
     public static boolean isUnitOfWorkExhausted(Exchange exchange) {
         return exchange.getProperty(Exchange.UNIT_OF_WORK_EXHAUSTED, false, Boolean.class);
     }
 
+    /**
+     * Sets the exchange to be failure handled.
+     *
+     * @param exchange  the exchange
+     */
     public static void setFailureHandled(Exchange exchange) {
         exchange.setProperty(Exchange.FAILURE_HANDLED, Boolean.TRUE);
         // clear exception since its failure handled
         exchange.setException(null);
     }
 
+    /**
+     * Checks whether the exchange is redelivery exhausted
+     *
+     * @param exchange  the exchange
+     * @return <tt>true</tt> if exhausted, <tt>false</tt> otherwise
+     */
     public static boolean isRedeliveryExhausted(Exchange exchange) {
         return exchange.getProperty(Exchange.REDELIVERY_EXHAUSTED, false, Boolean.class);
     }
 
+    /**
+     * Checks whether the exchange {@link UnitOfWork} is redelivered
+     *
+     * @param exchange  the exchange
+     * @return <tt>true</tt> if redelivered, <tt>false</tt> otherwise
+     */
     public static boolean isRedelivered(Exchange exchange) {
         return exchange.getIn().hasHeaders() && exchange.getIn().getHeader(Exchange.REDELIVERED, false, Boolean.class);
     }
 
+    /**
+     * Checks whether the exchange {@link UnitOfWork} has been interrupted during processing
+     *
+     * @param exchange  the exchange
+     * @return <tt>true</tt> if interrupted, <tt>false</tt> otherwise
+     */
     public static boolean isInterrupted(Exchange exchange) {
         return exchange.getException(InterruptedException.class) != null;
     }
@@ -592,8 +701,7 @@ public final class ExchangeHelper {
      * @param type    the expected body response type
      * @return the result body, can be <tt>null</tt>.
      * @throws CamelExecutionException is thrown if the processing of the exchange failed
-     * @throws java.util.concurrent.TimeoutException
-     *                                 is thrown if a timeout triggered
+     * @throws java.util.concurrent.TimeoutException is thrown if a timeout triggered
      */
     public static <T> T extractFutureBody(CamelContext context, Future<Object> future, long timeout, TimeUnit unit, Class<T> type) throws TimeoutException {
         try {
@@ -668,6 +776,13 @@ public final class ExchangeHelper {
         return "(MessageId: " + msgId + " on ExchangeId: " + exchange.getExchangeId()  + ")";
     }
 
+    /**
+     * Copies the exchange but the copy will be tied to the given context
+     *
+     * @param exchange  the source exchange
+     * @param context   the camel context
+     * @return a copy with the given camel context
+     */
     public static Exchange copyExchangeAndSetCamelContext(Exchange exchange, CamelContext context) {
         DefaultExchange answer = new DefaultExchange(context, exchange.getPattern());
         if (exchange.hasProperties()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java Sun Apr 15 15:07:08 2012
@@ -97,14 +97,14 @@ public final class ObjectHelper {
         }
 
         // convert left to right
-        Object value = converter.convertTo(rightValue.getClass(), leftValue);
+        Object value = converter.tryConvertTo(rightValue.getClass(), leftValue);
         answer = equal(value, rightValue);
         if (answer) {
             return true;
         }
 
         // convert right to left
-        value = converter.convertTo(leftValue.getClass(), rightValue);
+        value = converter.tryConvertTo(leftValue.getClass(), rightValue);
         answer = equal(leftValue, value);
         return answer;
     }
@@ -127,15 +127,15 @@ public final class ObjectHelper {
     public static int typeCoerceCompare(TypeConverter converter, Object leftValue, Object rightValue) {
 
         // if both values is numeric then compare using numeric
-        Long leftNum = converter.convertTo(Long.class, leftValue);
-        Long rightNum = converter.convertTo(Long.class, rightValue);
+        Long leftNum = converter.tryConvertTo(Long.class, leftValue);
+        Long rightNum = converter.tryConvertTo(Long.class, rightValue);
         if (leftNum != null && rightNum != null) {
             return leftNum.compareTo(rightNum);
         }
 
         // also try with floating point numbers
-        Double leftDouble = converter.convertTo(Double.class, leftValue);
-        Double rightDouble = converter.convertTo(Double.class, rightValue);
+        Double leftDouble = converter.tryConvertTo(Double.class, leftValue);
+        Double rightDouble = converter.tryConvertTo(Double.class, rightValue);
         if (leftDouble != null && rightDouble != null) {
             return leftDouble.compareTo(rightDouble);
         }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java Sun Apr 15 15:07:08 2012
@@ -182,10 +182,10 @@ public abstract class TestSupport extend
 
         Object actual;
         if (expected == null) {
-            actual = ExchangeHelper.getMandatoryInBody(exchange);
+            actual = exchange.getIn().getMandatoryBody();
             assertEquals("in body of: " + exchange, expected, actual);
         } else {
-            actual = ExchangeHelper.getMandatoryInBody(exchange, expected.getClass());
+            actual = exchange.getIn().getMandatoryBody(expected.getClass());
         }
         assertEquals("in body of: " + exchange, expected, actual);
 
@@ -204,10 +204,10 @@ public abstract class TestSupport extend
 
         Object actual;
         if (expected == null) {
-            actual = ExchangeHelper.getMandatoryOutBody(exchange);
+            actual = exchange.getOut().getMandatoryBody();
             assertEquals("output body of: " + exchange, expected, actual);
         } else {
-            actual = ExchangeHelper.getMandatoryOutBody(exchange, expected.getClass());
+            actual = exchange.getOut().getMandatoryBody(expected.getClass());
         }
         assertEquals("output body of: " + exchange, expected, actual);
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java Sun Apr 15 15:07:08 2012
@@ -18,6 +18,7 @@ package org.apache.camel.builder;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.TestSupport;
+import org.apache.camel.TypeConversionException;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultExchange;
 
@@ -47,8 +48,13 @@ public class SimpleBuilderTest extends T
         exchange.getIn().setHeader("cool", true);
 
         assertEquals("foo", SimpleBuilder.simple("${body}", String.class).evaluate(exchange, Object.class));
-        // not possible
-        assertEquals(null, SimpleBuilder.simple("${body}", int.class).evaluate(exchange, Object.class));
+        try {
+            // error during conversion
+            SimpleBuilder.simple("${body}", int.class).evaluate(exchange, Object.class);
+            fail("Should have thrown exception");
+        } catch (TypeConversionException e) {
+            assertIsInstanceOf(NumberFormatException.class, e.getCause());
+        }
 
         assertEquals(true, SimpleBuilder.simple("${header.cool}", boolean.class).evaluate(exchange, Object.class));
         assertEquals("true", SimpleBuilder.simple("${header.cool}", String.class).evaluate(exchange, Object.class));

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidValueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidValueTest.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidValueTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidValueTest.java Sun Apr 15 15:07:08 2012
@@ -21,7 +21,7 @@ import java.util.Map;
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.ExpressionEvaluationException;
-import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.TypeConversionException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.JndiRegistry;
 
@@ -37,7 +37,7 @@ public class BeanParameterInvalidValueTe
             template.sendBody("direct:a", "World");
             fail("Should have thrown exception");
         } catch (CamelExecutionException e) {
-            NoTypeConversionAvailableException cause = assertIsInstanceOf(NoTypeConversionAvailableException.class, e.getCause());
+            TypeConversionException cause = assertIsInstanceOf(TypeConversionException.class, e.getCause());
             assertEquals(String.class, cause.getFromType());
             assertEquals(int.class, cause.getToType());
             assertEquals("A", cause.getValue());
@@ -53,7 +53,7 @@ public class BeanParameterInvalidValueTe
             template.sendBody("direct:b", "World");
             fail("Should have thrown exception");
         } catch (CamelExecutionException e) {
-            NoTypeConversionAvailableException cause = assertIsInstanceOf(NoTypeConversionAvailableException.class, e.getCause());
+            TypeConversionException cause = assertIsInstanceOf(TypeConversionException.class, e.getCause());
             assertEquals(String.class, cause.getFromType());
             assertEquals(int.class, cause.getToType());
             assertEquals("true", cause.getValue());

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/MyMessageToProcessorConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/MyMessageToProcessorConverter.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/MyMessageToProcessorConverter.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/MyMessageToProcessorConverter.java Sun Apr 15 15:07:08 2012
@@ -47,4 +47,12 @@ public class MyMessageToProcessorConvert
         return convertTo(type, value);
     }
 
+    public <T> T tryConvertTo(Class<T> type, Object value) {
+        return convertTo(type, value);
+    }
+
+    public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, value);
+    }
+
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java Sun Apr 15 15:07:08 2012
@@ -30,6 +30,7 @@ import junit.framework.TestCase;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.TypeConversionException;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultClassResolver;
@@ -240,7 +241,7 @@ public class ConverterTest extends TestC
         try {
             converter.mandatoryConvertTo(char.class, "ABC");
             fail("Should have thrown an exception");
-        } catch (NoTypeConversionAvailableException e) {
+        } catch (TypeConversionException e) {
             assertEquals("java.lang.IllegalArgumentException: String must have exactly a length of 1: ABC", e.getCause().getMessage());
         }
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/EnumConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/EnumConverterTest.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/EnumConverterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/EnumConverterTest.java Sun Apr 15 15:07:08 2012
@@ -19,7 +19,7 @@ package org.apache.camel.converter;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.LoggingLevel;
-import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.TypeConversionException;
 import org.apache.camel.impl.DefaultExchange;
 
 /**
@@ -42,7 +42,7 @@ public class EnumConverterTest extends C
         try {
             context.getTypeConverter().mandatoryConvertTo(LoggingLevel.class, "XXX");
             fail("Should have thrown an exception");
-        } catch (NoTypeConversionAvailableException e) {
+        } catch (TypeConversionException e) {
             // expected
         }
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java Sun Apr 15 15:07:08 2012
@@ -24,6 +24,7 @@ import org.apache.camel.ExchangeTestSupp
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.TypeConversionException;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -45,7 +46,12 @@ public class DefaultExchangeTest extends
         assertNotNull(exchange.getIn().getBody());
 
         assertEquals("<hello id='m123'>world!</hello>", exchange.getIn().getBody());
-        assertEquals(null, exchange.getIn().getBody(Integer.class));
+        try {
+            assertEquals(null, exchange.getIn().getBody(Integer.class));
+            fail("Should have thrown a TypeConversionException");
+        } catch (TypeConversionException e) {
+            // expected
+        }
 
         assertEquals("<hello id='m123'>world!</hello>", exchange.getIn().getMandatoryBody());
         try {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryMissesThenAddTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryMissesThenAddTest.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryMissesThenAddTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryMissesThenAddTest.java Sun Apr 15 15:07:08 2012
@@ -76,6 +76,14 @@ public class TypeConverterRegistryMisses
         public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
             return convertTo(type, value);
         }
+
+        public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+            return convertTo(type, value);
+        }
+
+        public <T> T tryConvertTo(Class<T> type, Object value) {
+            return convertTo(type, value);
+        }
     }
 
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryTest.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/TypeConverterRegistryTest.java Sun Apr 15 15:07:08 2012
@@ -90,6 +90,22 @@ public class TypeConverterRegistryTest e
         public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
             return convertTo(type, value);
         }
+
+        public <T> T tryConvertTo(Class<T> type, Object value) {
+            try {
+                return convertTo(type, null, value);
+            } catch (Exception e) {
+                return null;
+            }
+        }
+
+        public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+            try {
+                return convertTo(type, exchange, value);
+            } catch (Exception e) {
+                return null;
+            }
+        }
     }
     // END SNIPPET: e2
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimulatorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimulatorTest.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimulatorTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimulatorTest.java Sun Apr 15 15:07:08 2012
@@ -24,7 +24,6 @@ import org.apache.camel.InvalidPayloadEx
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.jndi.JndiContext;
 
 /**
@@ -59,7 +58,7 @@ public class SimulatorTest extends Conte
 
         assertNotNull("Should receive a response!", response);
 
-        String text = ExchangeHelper.getMandatoryOutBody(response, String.class);
+        String text = response.getOut().getMandatoryBody(String.class);
         assertStringContains(text, containedText);
     }
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWrappedExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWrappedExceptionTest.java?rev=1326358&r1=1326357&r2=1326358&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWrappedExceptionTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWrappedExceptionTest.java Sun Apr 15 15:07:08 2012
@@ -74,6 +74,14 @@ public class OnExceptionWrappedException
         public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
             return convertTo(type, value);
         }
+
+        public <T> T tryConvertTo(Class<T> type, Object value) {
+            return convertTo(type, value);
+        }
+
+        public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value) {
+            return convertTo(type, value);
+        }
     }
 
 }
\ No newline at end of file