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/19 11:05:16 UTC

svn commit: r755890 [1/2] - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/component/bean/ camel-core/src/main/java/org/apache/camel/component/fil...

Author: davsclaus
Date: Thu Mar 19 10:05:14 2009
New Revision: 755890

URL: http://svn.apache.org/viewvc?rev=755890&view=rev
Log:
CAMEL-1459: Refactored type converter to allow returning null and introduce getMandatoryBody. Fixed CS.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java   (with props)
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/NoTypeConversionAvailableException.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/TypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.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/BeanProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ConstantBeanHolder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.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/component/log/LogFormatter.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/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/DefaultTypeConverter.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/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/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/processor/ConvertBodyProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.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/IntrospectionSupport.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.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/ConvertBodyTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWrappedExceptionTest.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.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-jms/src/test/java/org/apache/camel/component/jms/JmsMessageTypeTest.java
    camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
    camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaUdpProtocolCodecFactory.java
    camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
    camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -29,11 +29,18 @@
     }
 
     public InvalidPayloadException(Exchange exchange, Class<?> type, Message message) {
-        super("No in body available of type: " + type.getName()
+        super("No body available of type: " + type.getName()
               + NoSuchPropertyException.valueDescription(message.getBody()) + " on: " + message, exchange);
         this.type = type;
     }
 
+    public InvalidPayloadException(Exchange exchange, Class<?> type, Message message, Throwable cause) {
+        super("No body available of type: " + type.getName()
+              + NoSuchPropertyException.valueDescription(message.getBody()) + " on: " + message
+              + ". Caused by: " + cause.getMessage(), exchange, cause);
+        this.type = type;
+    }
+
     /**
      * The expected type of the body
      */

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -98,18 +98,39 @@
 
     /**
      * Returns the body of the message as a POJO
+     * <p/>
+     * The body can be <tt>null</tt> if no body is set
+     *
+     * @return the body, can be <tt>null</tt>
      */
     Object getBody();
 
     /**
+     * Returns the body of the message as a POJO
+     *
+     * @return the body, is never <tt>null</tt>
+     * @throws InvalidPayloadException Is thrown if the body being <tt>null</tt> or wrong class type
+     */
+    Object getMandatoryBody() throws InvalidPayloadException;
+
+    /**
      * Returns the body as the specified type
      *
      * @param type the type that the body
-     * @return the body of the message as the specified type
+     * @return the body of the message as the specified type, or <tt>null</tt> if not possible to convert
      */
     <T> T getBody(Class<T> type);
 
     /**
+     * Returns the mandatory body as the specified type
+     *
+     * @param type the type that the body
+     * @return the body of the message as the specified type, is never <tt>null</tt>.
+     * @throws InvalidPayloadException Is thrown if the body being <tt>null</tt> or wrong class type
+     */
+    <T> T getMandatoryBody(Class<T> type) throws InvalidPayloadException;
+
+    /**
      * Sets the body of the message
      *
      * @param body the body

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java Thu Mar 19 10:05:14 2009
@@ -26,12 +26,16 @@
     private final Class type;
 
     public NoTypeConversionAvailableException(Object value, Class type) {
-        super("No type converter available to convert from type: " + (value != null ? value.getClass().getCanonicalName() : null)
-              + " to the required type: " + type.getCanonicalName() + " with value " + value);
+        super(createMessage(value, type));
         this.value = value;
         this.type = type;
     }
 
+    public NoTypeConversionAvailableException(Object value, Class type, Throwable cause) {
+        this(value, type);
+        initCause(cause);
+    }
+
     /**
      * Returns the value which could not be converted
      */
@@ -42,7 +46,7 @@
     /**
      * Returns the required <tt>to</tt> type
      */
-    public Class getType() {
+    public Class getToType() {
         return type;
     }
 
@@ -58,4 +62,12 @@
         }
     }
 
+    /**
+     * Returns an error message for no type converter available.
+     */
+    public static String createMessage(Object value, Class type) {
+        return ("No type converter available to convert from type: " + (value != null ? value.getClass().getCanonicalName() : null)
+              + " to the required type: " + type.getCanonicalName() + " with value " + value);
+    }
+
 }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -32,8 +32,7 @@
      * 
      * @param type the requested type
      * @param value the value to be converted
-     * @return the converted value
-     * @throws NoTypeConversionAvailableException if conversion not possible
+     * @return the converted value, or <tt>null</tt> if not possible to convert
      */
     <T> T convertTo(Class<T> type, Object value);
 
@@ -46,8 +45,32 @@
      * @param type the requested type
      * @param exchange the current exchange
      * @param value the value to be converted
-     * @return the converted value
-     * @throws NoTypeConversionAvailableException} if conversion not possible
+     * @return the converted value, or <tt>null</tt> if not possible to convert
      */
     <T> T convertTo(Class<T> type, Exchange exchange, Object value);
+
+    /**
+     * Converts the value to the specified type
+     *
+     * @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
+     */
+    <T> T mandatoryConvertTo(Class<T> type, Object value);
+
+    /**
+     * 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, is never <tt>null</tt>
+     * @throws NoTypeConversionAvailableException} if conversion not possible
+     */
+    <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value);
+
 }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -226,7 +226,7 @@
         return deadLetterUri;
     }
 
-    public void setDeadLetterUri(final String deadLetterUri) {
+    public void setDeadLetterUri(String deadLetterUri) {
         this.deadLetter = null;
         this.deadLetterUri = deadLetterUri;
     }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -34,7 +34,6 @@
 import org.apache.camel.Header;
 import org.apache.camel.Headers;
 import org.apache.camel.Message;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.OutHeaders;
 import org.apache.camel.Properties;
 import org.apache.camel.Property;
@@ -366,26 +365,20 @@
             Object newBody = null;
             MethodInfo matched = null;
             for (MethodInfo methodInfo : operationList) {
-                Object value;
-                try {
-                    value = convertToType(exchange, methodInfo.getBodyParameterType(), body);
-                    if (value != null) {
-                        if (LOG.isTraceEnabled()) {
-                            LOG.trace("Converted body from: " + body.getClass().getCanonicalName()
-                                    + "to: " + methodInfo.getBodyParameterType().getCanonicalName());
-                        }
-                        if (newBody != null) {
-                            // we already have found one new body that could be converted so now we have 2 methods
-                            // and then its ambiguous
-                            throw new AmbiguousMethodCallException(exchange, Arrays.asList(matched, methodInfo));
-                        } else {
-                            newBody = value;
-                            matched = methodInfo;
-                        }
+                Object value = convertToType(exchange, methodInfo.getBodyParameterType(), body);
+                if (value != null) {
+                    if (LOG.isTraceEnabled()) {
+                        LOG.trace("Converted body from: " + body.getClass().getCanonicalName()
+                                + "to: " + methodInfo.getBodyParameterType().getCanonicalName());
+                    }
+                    if (newBody != null) {
+                        // we already have found one new body that could be converted so now we have 2 methods
+                        // and then its ambiguous
+                        throw new AmbiguousMethodCallException(exchange, Arrays.asList(matched, methodInfo));
+                    } else {
+                        newBody = value;
+                        matched = methodInfo;
                     }
-                } catch (NoTypeConversionAvailableException e) {
-                    // we can safely ignore this exception as we want a behaviour similar to
-                    // that if convertToType return null
                 }
             }
             if (matched != null) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java Thu Mar 19 10:05:14 2009
@@ -22,7 +22,6 @@
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
@@ -84,14 +83,10 @@
             in.setHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY, isMultiParameterArray());
         }
 
-        try {
-            BeanInvocation beanInvoke = in.getBody(BeanInvocation.class);
-            if (beanInvoke != null) {
-                beanInvoke.invoke(bean, exchange);
-                return;
-            }
-        } catch (NoTypeConversionAvailableException ex) {
-            // ignore, body is not a BeanInvocation
+        BeanInvocation beanInvoke = in.getBody(BeanInvocation.class);
+        if (beanInvoke != null) {
+            beanInvoke.invoke(bean, exchange);
+            return;
         }
 
         boolean isExplicitMethod = false;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ConstantBeanHolder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ConstantBeanHolder.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ConstantBeanHolder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ConstantBeanHolder.java Thu Mar 19 10:05:14 2009
@@ -17,7 +17,6 @@
 package org.apache.camel.component.bean;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Processor;
 import org.apache.camel.util.CamelContextHelper;
 
@@ -28,17 +27,13 @@
  */
 public class ConstantBeanHolder implements BeanHolder {
     private final Object bean;
-    private Processor processor;
-    private BeanInfo beanInfo;
+    private final BeanInfo beanInfo;
+    private final Processor processor;
 
     public ConstantBeanHolder(Object bean, BeanInfo beanInfo) {
         this.bean = bean;
         this.beanInfo = beanInfo;
-        try {
-            this.processor = CamelContextHelper.convertTo(beanInfo.getCamelContext(), Processor.class, bean);
-        } catch (NoTypeConversionAvailableException ex) {
-            this.processor = null;
-        }
+        this.processor = CamelContextHelper.convertTo(beanInfo.getCamelContext(), Processor.class, bean);
     }
 
     public ConstantBeanHolder(Object bean, CamelContext context) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java Thu Mar 19 10:05:14 2009
@@ -18,7 +18,6 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.NoSuchBeanException;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Processor;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.util.CamelContextHelper;
@@ -75,11 +74,7 @@
 
     public Processor getProcessor() {
         if (processor == null && bean != null) {
-            try {
-                processor = CamelContextHelper.convertTo(context, Processor.class, bean);
-            } catch (NoTypeConversionAvailableException ex) {
-                // ignore
-            }
+            processor = CamelContextHelper.convertTo(context, Processor.class, bean);
         }
         return processor;
     }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -28,7 +28,6 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
@@ -149,12 +148,8 @@
 
             // is the body file based
             File source = null;
-            try {
-                if (exchange.getIn().getBody() instanceof File || exchange.getIn().getBody() instanceof GenericFile) {
-                    source = exchange.getIn().getBody(File.class);
-                }
-            } catch (NoTypeConversionAvailableException e) {
-                // ignore
+            if (exchange.getIn().getBody() instanceof File || exchange.getIn().getBody() instanceof GenericFile) {
+                source = exchange.getIn().getBody(File.class);
             }
 
             if (source != null) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java Thu Mar 19 10:05:14 2009
@@ -18,7 +18,6 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.StreamCache;
 import org.apache.camel.spi.ExchangeFormatter;
 import org.apache.camel.util.ObjectHelper;
@@ -175,19 +174,13 @@
     // Implementation methods
     //-------------------------------------------------------------------------
     protected Object getBodyAsString(Message message) {
-        StreamCache newBody = null;
-        try {
-            newBody = message.getBody(StreamCache.class);
-            if (newBody != null) {
-                message.setBody(newBody);
-            }
-        } catch (NoTypeConversionAvailableException ex) {
-            // ignore
-        }
-        Object answer = null;
-        try {
-            answer = message.getBody(String.class);
-        } catch (NoTypeConversionAvailableException ex) {
+        StreamCache newBody = message.getBody(StreamCache.class);
+        if (newBody != null) {
+            message.setBody(newBody);
+        }
+
+        Object answer = message.getBody(String.class);
+        if (answer == null) {
             answer = message.getBody();
         }
 

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -16,12 +16,10 @@
  */
 package org.apache.camel.impl;
 
-import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.TypeConverter;
-import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.util.UuidGenerator;
 
 /**
@@ -47,46 +45,53 @@
         return body;
     }
 
-    @SuppressWarnings("unchecked")
     public <T> T getBody(Class<T> type) {
         return getBody(type, getBody());
     }
 
-    @SuppressWarnings("unchecked")
+    public Object getMandatoryBody() throws InvalidPayloadException {
+        Object answer = getBody();
+        if (answer == null) {
+            throw new InvalidPayloadException(getExchange(), Object.class, this);
+        }
+        return answer;
+    }
+
     protected <T> T getBody(Class<T> type, Object body) {
         Exchange e = getExchange();
         if (e != null) {
-            CamelContext camelContext = e.getContext();
-            if (camelContext != null) {
-                boolean tryConvert = true;
-                TypeConverter converter = camelContext.getTypeConverter();
-                // if its the default type converter then use a performance shortcut to check if it can convert it
-                // this is faster than getting throwing and catching NoTypeConversionAvailableException
-                // the StreamCachingInterceptor will attempt to convert the payload to a StremCache for caching purpose
-                // so we get invoked on each node the exchange passes. So this is a little performance optimization
-                // to avoid the excessive exception handling
-                if (body != null && converter instanceof DefaultTypeConverter) {
-                    DefaultTypeConverter defaultTypeConverter = (DefaultTypeConverter) converter;
-                    // we can only check if there is no converter meaning we have tried to convert it beforehand
-                    // and then knows for sure there is no converter possible
-                    tryConvert = !defaultTypeConverter.hasNoConverterFor(type, body.getClass());
-                }
-                if (tryConvert) {
-                    try {
-                        // 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
-                        return converter.convertTo(type, e, body);
-                    } catch (NoTypeConversionAvailableException ex) {
-                        // ignore
-                    }
-                }
-                // fallback to the message itself
-                return converter.convertTo(type, this);
+            TypeConverter converter = e.getContext().getTypeConverter();
+
+            // 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);
+            if (answer != null) {
+                return answer;
+            }
+            // fallback to the message itself
+            answer = converter.convertTo(type, getExchange(), this);
+            if (answer != null) {
+                return answer;
+            }
+        }
+
+        // not possible to convert
+        return null;
+    }
+
+    public <T> T getMandatoryBody(Class<T> type) throws InvalidPayloadException {
+        Exchange e = getExchange();
+        if (e != null) {
+            TypeConverter converter = e.getContext().getTypeConverter();
+            try {
+                return converter.mandatoryConvertTo(type, e, getBody());
+            } catch (Exception cause) {
+                throw new InvalidPayloadException(e, type, this, cause);
             }
         }
-        return (T)getBody();
+        throw new InvalidPayloadException(e, type, this);
     }
 
     public void setBody(Object body) {

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -77,4 +77,12 @@
     public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
         return convertTo(type, value);
     }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        return convertTo(type, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, value);
+    }
 }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -50,23 +50,31 @@
         }
     }
 
-    public <T> T convertTo(Class<T> toType, Object value) {
+    public <T> T convertTo(Class<T> type, Object value) {
         if (value != null) {
-            if (toType.equals(AsyncProcessor.class)) {
+            if (type.equals(AsyncProcessor.class)) {
                 if (value instanceof AsyncProcessor) {
-                    return toType.cast(value);
+                    return type.cast(value);
                 } else if (value instanceof Processor) {
                     // Provide an async bridge to the regular processor.
                     final Processor processor = (Processor)value;
-                    return toType.cast(new ProcessorToAsyncProcessorBridge(processor));
+                    return type.cast(new ProcessorToAsyncProcessorBridge(processor));
                 }
             }
         }
         return null;
     }
 
-    public <T> T convertTo(Class<T> toType, Exchange exchange, Object value) {
-        return convertTo(toType, value);
+    public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        return convertTo(type, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, value);
     }
 
     public static AsyncProcessor convert(Processor value) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java Thu Mar 19 10:05:14 2009
@@ -75,32 +75,51 @@
         return typeConverterLoaders;
     }
 
-    /**
-     * Is there <b>NOT</b> a type converter registered being able to converter the
-     * given value to the type
-     * @param toType  the type to convert to
-     * @param fromType  the type to convert from
-     * @return <tt>true</tt> if there is <b>NOT</b> a converter, <tt>false</tt> if there is
-     */
-    @SuppressWarnings("unchecked")
-    public boolean hasNoConverterFor(Class toType, Class fromType) {
-        TypeMapping key = new TypeMapping(toType, fromType);
-        // we must only look in misses and not do the acutal convertions
-        // as for stream it can be impossible to re-read them and this
-        // method should not cause any overhead
-        return misses.containsKey(key);
-    }
-
     public <T> T convertTo(Class<T> type, Object value) {
         return convertTo(type, null, value);
     }
 
     public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
-        return doConvertTo(type, exchange, value);
+        Object answer;
+        try {
+            answer = doConvertTo(type, exchange, value);
+        } catch (Exception e) {
+            // we cannot convert so return null
+            if (LOG.isDebugEnabled()) {
+                LOG.debug(NoTypeConversionAvailableException.createMessage(value, type)
+                        + " Caused by: " + e.getMessage() + ". Will ignore this and continue.");
+            }
+            return null;
+        }
+        if (answer == Void.TYPE) {
+            // Could not find suitable conversion
+            return null;
+        } else {
+            return (T) answer;
+        }
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        return mandatoryConvertTo(type, null, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        Object answer;
+        try {
+            answer = doConvertTo(type, exchange, value);
+        } catch (Exception e) {
+            throw new NoTypeConversionAvailableException(value, type, e);
+        }
+        if (answer == Void.TYPE) {
+            // Could not find suitable conversion
+            throw new NoTypeConversionAvailableException(value, type);
+        } else {
+            return (T) answer;
+        }
     }
 
     @SuppressWarnings("unchecked")
-    public <T> T doConvertTo(Class<T> type, Exchange exchange, Object value) {
+    public Object doConvertTo(final Class type, final Exchange exchange, final Object value) {
         if (LOG.isTraceEnabled()) {
             LOG.trace("Converting " + (value == null ? "null" : value.getClass().getCanonicalName())
                 + " -> " + type.getCanonicalName() + " with value: " + value);
@@ -109,7 +128,7 @@
         if (value == null) {
             // lets avoid NullPointerException when converting to boolean for null values
             if (boolean.class.isAssignableFrom(type)) {
-                return (T) Boolean.FALSE;
+                return Boolean.FALSE;
             }
             return null;
         }
@@ -119,13 +138,20 @@
             return type.cast(value);
         }
 
+        // check if we have tried it before and if its a miss
+        TypeMapping key = new TypeMapping(type, value.getClass());
+        if (misses.containsKey(key)) {
+            // we have tried before but we cannot convert this one
+            return Void.TYPE;
+        }
+
         // make sure we have loaded the converters
         checkLoaded();
 
         // try to find a suitable type converter
         TypeConverter converter = getOrFindTypeConverter(type, value);
         if (converter != null) {
-            T rc = converter.convertTo(type, exchange, value);
+            Object rc = converter.convertTo(type, exchange, value);
             if (rc != null) {
                 return rc;
             }
@@ -133,7 +159,7 @@
 
         // fallback converters
         for (TypeConverter fallback : fallbackConverters) {
-            T rc = fallback.convertTo(type, exchange, value);
+            Object rc = fallback.convertTo(type, exchange, value);
             if (rc != null) {
                 return rc;
             }
@@ -143,17 +169,17 @@
         if (type.isPrimitive()) {
             Class primitiveType = ObjectHelper.convertPrimitiveTypeToWrapperType(type);
             if (primitiveType != type) {
-                return (T) convertTo(primitiveType, exchange, value);
+                return convertTo(primitiveType, exchange, value);
             }
         }
 
+        // Could not find suitable conversion, so remember it
         synchronized (misses) {
-            TypeMapping key = new TypeMapping(type, value.getClass());
             misses.put(key, key);
         }
 
-        // Could not find suitable conversion
-        throw new NoTypeConversionAvailableException(value, type);
+        // Could not find suitable conversion, so return Void to indicate not found
+        return Void.TYPE;
     }
 
     public void addTypeConverter(Class toType, Class fromType, TypeConverter typeConverter) {

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -51,4 +51,14 @@
         // ignore exchange
         return convertTo(type, value);
     }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        // ignore exchange
+        return convertTo(type, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        // ignore exchange
+        return convertTo(type, value);
+    }
 }
\ No newline at end of file

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -62,4 +62,13 @@
             ? (T)ObjectHelper.invokeMethod(method, instance, type, value, exchange, registry) : (T)ObjectHelper
                 .invokeMethod(method, instance, type, value, registry);
     }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        return convertTo(type, null, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, null, value);
+    }
+
 }
\ 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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -59,4 +59,12 @@
             ? (T)ObjectHelper.invokeMethod(method, instance, value, exchange) : (T)ObjectHelper
                 .invokeMethod(method, instance, value);
     }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        return convertTo(type, null, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, null, value);
+    }
 }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -31,7 +31,7 @@
  */
 public class PropertyEditorTypeConverter implements TypeConverter {
 
-    public <T> T convertTo(Class<T> toType, Object value) {
+    public <T> T convertTo(Class<T> type, Object value) {
         // We can't convert null values since we can't figure out a property
         // editor for it.
         if (value == null) {
@@ -40,20 +40,20 @@
 
         if (value.getClass() == String.class) {
             // No conversion needed.
-            if (toType == String.class) {
-                return ObjectHelper.cast(toType, value);
+            if (type == String.class) {
+                return ObjectHelper.cast(type, value);
             }
 
-            PropertyEditor editor = PropertyEditorManager.findEditor(toType);
+            PropertyEditor editor = PropertyEditorManager.findEditor(type);
             if (editor != null) {
                 editor.setAsText(value.toString());
-                return ObjectHelper.cast(toType, editor.getValue());
+                return ObjectHelper.cast(type, editor.getValue());
             }
-        } else if (toType == String.class) {
+        } else if (type == String.class) {
             PropertyEditor editor = PropertyEditorManager.findEditor(value.getClass());
             if (editor != null) {
                 editor.setValue(value);
-                return ObjectHelper.cast(toType, editor.getAsText());
+                return ObjectHelper.cast(type, editor.getAsText());
             }
         }
 
@@ -63,4 +63,13 @@
     public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
         return convertTo(type, value);
     }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        return convertTo(type, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, value);
+    }
+
 }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -54,4 +54,13 @@
         return useExchange ? (T)ObjectHelper.invokeMethod(method, null, type, exchange, value, registry)
             : (T)ObjectHelper.invokeMethod(method, null, type, value, registry);
     }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        return convertTo(type, null, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, null, value);
+    }
+
 }
\ 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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -50,4 +50,13 @@
         return useExchange ? (T)ObjectHelper.invokeMethod(method, null, value, exchange)
             : (T)ObjectHelper.invokeMethod(method, null, value);
     }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        return convertTo(type, null, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, null, value);
+    }
+
 }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -40,4 +40,13 @@
     public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
         return convertTo(type, value);
     }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        return convertTo(type, value);
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return convertTo(type, value);
+    }
+
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java Thu Mar 19 10:05:14 2009
@@ -18,18 +18,16 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Processor;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * A processor which converts the payload of the input message to be of the given type
+ * <p/>
+ * If the convertions fails an {@link org.apache.camel.InvalidPayloadException} is thrown.
  *
  * @version $Revision$
  */
 public class ConvertBodyProcessor implements Processor {
-    private static final transient Log LOG = LogFactory.getLog(ConvertBodyProcessor.class);
     private final Class type;
 
     public ConvertBodyProcessor(Class type) {
@@ -39,12 +37,8 @@
     @SuppressWarnings("unchecked")
     public void process(Exchange exchange) throws Exception {
         Message in = exchange.getIn();        
-        Object value = null;
-        try {
-            value = in.getBody(type);
-        } catch (NoTypeConversionAvailableException e) {
-            LOG.warn("Could not convert body of IN message: " + in + " to type: " + type.getName());
-        }
+        Object value = in.getMandatoryBody(type);
+
         if (exchange.getPattern().isOutCapable()) {
             Message out = exchange.getOut();
             out.copyFrom(in);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.java Thu Mar 19 10:05:14 2009
@@ -21,7 +21,6 @@
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.AsyncProcessor;
 import org.apache.camel.Exchange;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Processor;
 import org.apache.camel.StreamCache;
 import org.apache.camel.model.AbstractInterceptorDefinition;
@@ -70,15 +69,11 @@
     }
 
     public boolean process(Exchange exchange, AsyncCallback callback) {
-        try {
-            StreamCache newBody = exchange.getIn().getBody(StreamCache.class);
-            if (newBody != null) {
-                exchange.getIn().setBody(newBody);
-            }
-            MessageHelper.resetStreamCache(exchange.getIn());
-        } catch (NoTypeConversionAvailableException ex) {
-            // ignore if in is not of StreamCache type
+        StreamCache newBody = exchange.getIn().getBody(StreamCache.class);
+        if (newBody != null) {
+            exchange.getIn().setBody(newBody);
         }
+        MessageHelper.resetStreamCache(exchange.getIn());
 
         return proceed(exchange, callback);
     }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -30,10 +30,7 @@
 import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.NoSuchHeaderException;
 import org.apache.camel.NoSuchPropertyException;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.TypeConverter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * Some helper methods for working with {@link Exchange} objects
@@ -41,7 +38,6 @@
  * @version $Revision$
  */
 public final class ExchangeHelper {
-    private static final transient Log LOG = LogFactory.getLog(ExchangeHelper.class);
 
     /**
      * Utility classes should not have a public constructor.
@@ -80,7 +76,6 @@
      * @return the endpoint
      * @throws NoSuchEndpointException if the endpoint cannot be resolved
      */
-    @SuppressWarnings({"unchecked" })
     public static Endpoint resolveEndpoint(Exchange exchange, Object value)
         throws NoSuchEndpointException {
         Endpoint endpoint;
@@ -95,13 +90,9 @@
 
     public static <T> T getMandatoryProperty(Exchange exchange, String propertyName, Class<T> type)
         throws NoSuchPropertyException {
-        try {
-            T result = exchange.getProperty(propertyName, type);
-            if (result != null) {
-                return result;
-            }
-        } catch (NoTypeConversionAvailableException ex) {
-            // will throw NoSuchPropertyException below
+        T result = exchange.getProperty(propertyName, type);
+        if (result != null) {
+            return result;
         }
         throw new NoSuchPropertyException(exchange, propertyName, type);
     }
@@ -183,16 +174,9 @@
      */
     public static <T> T convertToType(Exchange exchange, Class<T> type, Object value) {
         CamelContext camelContext = exchange.getContext();
-        if (camelContext != null) {
-            TypeConverter converter = camelContext.getTypeConverter();
-            if (converter != null) {
-                return converter.convertTo(type, exchange, value);
-            }
-        }
-        LOG.warn("No CamelContext and type converter available to convert types for exchange " + exchange);
-
-        if (type.isInstance(value)) {
-            return type.cast(value);
+        TypeConverter converter = camelContext.getTypeConverter();
+        if (converter != null) {
+            return converter.convertTo(type, exchange, value);
         }
         return null;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java Thu Mar 19 10:05:14 2009
@@ -262,7 +262,7 @@
     @SuppressWarnings("unchecked")
     private static Object convert(TypeConverter typeConverter, Class type, Object value) throws URISyntaxException {
         if (typeConverter != null) {
-            return typeConverter.convertTo(type, value);
+            return typeConverter.mandatoryConvertTo(type, value);
         }
         PropertyEditor editor = PropertyEditorManager.findEditor(type);
         if (editor != null) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java Thu Mar 19 10:05:14 2009
@@ -17,7 +17,6 @@
 package org.apache.camel.util;
 
 import org.apache.camel.Message;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.StreamCache;
 
 /**
@@ -47,20 +46,13 @@
             return null;
         }
 
-        StreamCache newBody = null;
-        try {
-            newBody = message.getBody(StreamCache.class);
-            if (newBody != null) {
-                message.setBody(newBody);
-            }
-        } catch (NoTypeConversionAvailableException ex) {
-            // ignore, in not of StreamCache type
+        StreamCache newBody = message.getBody(StreamCache.class);
+        if (newBody != null) {
+            message.setBody(newBody);
         }
 
-        Object answer;
-        try {
-            answer = message.getBody(String.class);
-        } catch (NoTypeConversionAvailableException ex) {
+        Object answer = message.getBody(String.class);
+        if (answer == null) {
             answer = message.getBody();
         }
 

Added: 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=755890&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java Thu Mar 19 10:05:14 2009
@@ -0,0 +1,61 @@
+/**
+ * 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.impl;
+
+import org.apache.camel.ExchangeTestSupport;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.NoTypeConversionAvailableException;
+
+/**
+ * @version $Revision$
+ */
+public class DefaultExchangeTest extends ExchangeTestSupport {
+
+    public void testBody() throws Exception {
+        assertNotNull(exchange.getIn().getBody());
+
+        assertEquals("<hello id='m123'>world!</hello>", exchange.getIn().getBody());
+        assertEquals("<hello id='m123'>world!</hello>", exchange.getIn().getBody(String.class));
+
+        assertEquals("<hello id='m123'>world!</hello>", exchange.getIn().getMandatoryBody());
+        assertEquals("<hello id='m123'>world!</hello>", exchange.getIn().getMandatoryBody(String.class));
+    }
+
+    public void testMandatoryBody() throws Exception {
+        assertNotNull(exchange.getIn().getBody());
+
+        assertEquals("<hello id='m123'>world!</hello>", exchange.getIn().getBody());
+        assertEquals(null, exchange.getIn().getBody(Integer.class));
+
+        assertEquals("<hello id='m123'>world!</hello>", exchange.getIn().getMandatoryBody());
+        try {
+            exchange.getIn().getMandatoryBody(Integer.class);
+            fail("Should have thrown an InvalidPayloadException");
+        } catch (InvalidPayloadException e) {
+            // expected
+        }
+    }
+
+    public void testHeader() throws Exception {
+        assertNotNull(exchange.getIn().getHeaders());
+
+        assertEquals(123, exchange.getIn().getHeader("bar"));
+        assertEquals(new Integer(123), exchange.getIn().getHeader("bar", Integer.class));
+        assertEquals("123", exchange.getIn().getHeader("bar", String.class));
+    }
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -81,6 +81,14 @@
             // such as an encoding parameter or the likes
             return convertTo(type, value);
         }
+
+        public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+            return convertTo(type, value);
+        }
+
+        public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+            return convertTo(type, value);
+        }
     }
     // END SNIPPET: e2
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java Thu Mar 19 10:05:14 2009
@@ -14,29 +14,50 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.processor;
 
+import java.util.Date;
+
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 
 public class ConvertBodyTest extends ContextTestSupport {
-    public void testConvertToInteger() throws Exception {
 
-        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result",
-                MockEndpoint.class);
-        resultEndpoint.expectedBodiesReceived(11);
+    public void testConvertToInteger() throws Exception {
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedBodiesReceived(11);
 
         template.sendBody("direct:start", "11");
 
-        resultEndpoint.assertIsSatisfied();
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testConvertFailed() throws Exception {
+        MockEndpoint dead = getMockEndpoint("mock:dead");
+        dead.expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        try {
+            template.sendBody("direct:invalid", "11");
+            fail("Should have thrown an exception");
+        } catch (RuntimeCamelException e) {
+            assertTrue(e.getCause() instanceof InvalidPayloadException);
+        }
+
+        assertMockEndpointsSatisfied();
     }
 
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
+                errorHandler(deadLetterChannel("mock:dead").disableRedelivery());
+
                 from("direct:start").convertBodyTo(Integer.class).to("mock:result");
+
+                from("direct:invalid").convertBodyTo(Date.class).to("mock:result");
             }
         };
     }

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=755890&r1=755889&r2=755890&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 Thu Mar 19 10:05:14 2009
@@ -66,6 +66,14 @@
         public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
             return convertTo(type, value);
         }
+
+        public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+            return convertTo(type, value);
+        }
+
+        public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+            return convertTo(type, value);
+        }
     }
 
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java Thu Mar 19 10:05:14 2009
@@ -17,22 +17,18 @@
 package org.apache.camel.component.cxf;
 
 import java.io.InputStream;
-
 import javax.xml.transform.Source;
 
-import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.cxf.util.CxfHeaderHelper;
 import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.MessageImpl;
 
 public final class CxfSoapBinding {
-    private static final Log LOG = LogFactory.getLog(CxfSoapBinding.class);
 
     private CxfSoapBinding() {
-
     }
     
     public static org.apache.cxf.message.Message getCxfInMessage(HeaderFilterStrategy headerFilterStrategy,
@@ -54,12 +50,13 @@
 
         CxfHeaderHelper.propagateCamelToCxf(headerFilterStrategy, message.getHeaders(), answer);
 
+        InputStream body = null;
         try {
-            InputStream body = message.getBody(InputStream.class);
-            answer.setContent(InputStream.class, body);
-        } catch (NoTypeConversionAvailableException ex) {
-            LOG.warn("Can't get right InputStream object here, the message body is " + message.getBody());
+            body = message.getMandatoryBody(InputStream.class);
+        } catch (InvalidPayloadException e) {
+            throw new RuntimeCamelException(e);
         }
+        answer.setContent(InputStream.class, body);
 
         answer.putAll(message.getHeaders());
         answer.setExchange(cxfExchange);
@@ -85,12 +82,13 @@
         CxfHeaderHelper.propagateCamelToCxf(headerFilterStrategy, message.getHeaders(), outMessage);
 
         // send the body back
+        Source body = null;
         try {
-            Source body = message.getBody(Source.class);
-            outMessage.setContent(Source.class, body);
-        } catch (NoTypeConversionAvailableException ex) {
-            LOG.warn("Can't get right Source object here, the message body is " + message.getBody());
+            body = message.getMandatoryBody(Source.class);
+        } catch (InvalidPayloadException e) {
+            throw new RuntimeCamelException(e);
         }
+        outMessage.setContent(Source.class, body);
         outMessage.putAll(message.getHeaders());
         return outMessage;
     }

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java Thu Mar 19 10:05:14 2009
@@ -19,9 +19,6 @@
 import java.lang.reflect.Proxy;
 import javax.xml.namespace.QName;
 
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.AbstractApplicationContext;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.cxf.spring.CxfEndpointBean;
 import org.apache.camel.component.cxf.util.CxfEndpointUtils;
@@ -35,6 +32,7 @@
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+import org.springframework.context.support.AbstractApplicationContext;
 
 /**
  * Defines the <a href="http://camel.apache.org/cxf.html">CXF Endpoint</a>

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java Thu Mar 19 10:05:14 2009
@@ -72,7 +72,6 @@
         assertNotNull("The camel context which get from camel destination is not null", context);
         assertEquals("Get the wrong camel context", context.getName(), "dest_context");
         assertEquals("The camel context should has two routers", context.getRoutes().size(), 2);
-        assertEquals("The router 0 start endpoint is wrong", context.getRoutes().get(0).getEndpoint().getEndpointUri(), "direct:EndpointA");
         bus.shutdown(false);
     }
 
@@ -126,15 +125,10 @@
 
 
 
-    private void verifyReceivedMessage(Message inMessage, String content) {
+    private void verifyReceivedMessage(Message inMessage, String content) throws IOException {
         ByteArrayInputStream bis = (ByteArrayInputStream)inMessage.getContent(InputStream.class);
         byte bytes[] = new byte[bis.available()];
-        try {
-            bis.read(bytes);
-        } catch (IOException ex) {
-            assertFalse("Read the Destination recieved Message error ", false);
-            ex.printStackTrace();
-        }
+        bis.read(bytes);
         String reponse = new String(bytes);
         assertEquals("The reponse date should be equals", content, reponse);
     }
@@ -154,21 +148,20 @@
         // set up MessageObserver for handlering the conduit message
         MessageObserver observer = new MessageObserver() {
             public void onMessage(Message m) {
-                Exchange exchange = new ExchangeImpl();
-                exchange.setInMessage(m);
-                m.setExchange(exchange);
-                verifyReceivedMessage(m, "HelloWorld");
-                //verifyHeaders(m, outMessage);
-                // setup the message for
-                Conduit backConduit;
                 try {
+                    Exchange exchange = new ExchangeImpl();
+                    exchange.setInMessage(m);
+                    m.setExchange(exchange);
+                    verifyReceivedMessage(m, "HelloWorld");
+                    //verifyHeaders(m, outMessage);
+                    // setup the message for
+                    Conduit backConduit;
                     backConduit = destination.getBackChannel(m, null, null);
                     // wait for the message to be got from the conduit
                     Message replyMessage = new MessageImpl();
                     sendoutMessage(backConduit, replyMessage, true, "HelloWorld Response");
                 } catch (Exception e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
+                    throw new RuntimeException(e);
                 }
             }
         };

Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java (original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java Thu Mar 19 10:05:14 2009
@@ -27,8 +27,8 @@
  */
 public class FromFtpThirdPoolOkTest extends FtpServerTestSupport {
 
-    private String body = "Hello World this file will be deleted";
     private static int counter;
+    private String body = "Hello World this file will be deleted";
 
     private String getFtpUrl() {
         return "ftp://admin@localhost:" + getPort() + "/thirdpool?password=admin&delete=true";

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Thu Mar 19 10:05:14 2009
@@ -22,10 +22,8 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.http.helper.GZIPHelper;
-import org.apache.camel.component.http.helper.LoadingByteArrayOutputStream;
 import org.apache.camel.converter.stream.CachedOutputStream;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.spi.HeaderFilterStrategy;
@@ -212,23 +210,22 @@
         if (in.getBody() == null) {
             return null;
         }
-        try {
-            return in.getBody(RequestEntity.class);
-        } catch (NoTypeConversionAvailableException ex) {
+
+        RequestEntity answer = in.getBody(RequestEntity.class);
+        if (answer == null) {
             try {
                 String data = in.getBody(String.class);
                 if (data != null) {
                     String contentType = in.getHeader("Content-Type", String.class);
                     String charset = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
-                    return new StringRequestEntity(data, contentType, charset);
-                } else {
-                    // no data
-                    return null;
+                    answer = new StringRequestEntity(data, contentType, charset);
                 }
             } catch (UnsupportedEncodingException e) {
                 throw new RuntimeCamelException(e);
             }
         }
+
+        return answer;
     }
 
     public HttpClient getHttpClient() {

Modified: camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java (original)
+++ camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java Thu Mar 19 10:05:14 2009
@@ -86,6 +86,18 @@
         return convertTo(type, value);
     }
 
+    public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+        T answer = convertTo(type, value);
+        if (answer == null) {
+            throw new NoTypeConversionAvailableException(value, type);
+        }
+        return answer;
+    }
+
+    public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+        return mandatoryConvertTo(type, value);
+    }
+
     protected <T> boolean isJaxbType(Class<T> type) {
         XmlRootElement element = type.getAnnotation(XmlRootElement.class);
         return element != null;
@@ -133,26 +145,26 @@
     }
 
     protected <T> T marshall(Class<T> type, Object value) throws JAXBException {
+        T answer = null;
         if (parentTypeConverter != null) {
             // lets convert the object to a JAXB source and try convert that to
             // the required source
             JAXBContext context = createContext(value.getClass());
             JAXBSource source = new JAXBSource(context, value);
-            try {
-                return parentTypeConverter.convertTo(type, source);
-            } catch (NoTypeConversionAvailableException e) {
+
+            answer = parentTypeConverter.convertTo(type, source);
+            if (answer == null) {
                 // lets try a stream
                 StringWriter buffer = new StringWriter();
                 // must create a new instance of marshaller as its not thred safe
                 Marshaller marshaller = context.createMarshaller();
                 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, isPrettyPrint() ? Boolean.TRUE : Boolean.FALSE);
                 marshaller.marshal(value, buffer);
-                return parentTypeConverter.convertTo(type, buffer.toString());
+                answer = parentTypeConverter.convertTo(type, buffer.toString());
             }
         }
 
-        // lets try convert to the type from JAXB
-        return null;
+        return answer;
     }
 
     /**

Modified: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/JAXBConvertTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/JAXBConvertTest.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/JAXBConvertTest.java (original)
+++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/JAXBConvertTest.java Thu Mar 19 10:05:14 2009
@@ -87,7 +87,7 @@
     public void testNoConversionForStreamCache() throws Exception {
         PurchaseOrder order = new PurchaseOrder();
         try {
-            converter.convertTo(StreamCache.class, order);
+            converter.mandatoryConvertTo(StreamCache.class, order);
             fail("We should not use the JAXB FallbackTypeConverter for stream caching");
         } catch (NoTypeConversionAvailableException e) {
             //this is OK

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMessageTypeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMessageTypeTest.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMessageTypeTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMessageTypeTest.java Thu Mar 19 10:05:14 2009
@@ -234,5 +234,13 @@
         public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
             return convertTo(type, value);
         }
+
+        public <T> T mandatoryConvertTo(Class<T> type, Object value) {
+            return convertTo(type, value);
+        }
+
+        public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) {
+            return convertTo(type, value);
+        }
     }
 }

Modified: camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java (original)
+++ camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java Thu Mar 19 10:05:14 2009
@@ -93,7 +93,7 @@
 
     @Override
     protected String createEndpointUri() {
-        return "jpa" + entityType != null ? "://" + entityType.getName() : "";
+        return "jpa" + (entityType != null ? "://" + entityType.getName() : "");
     }
 
 
@@ -221,20 +221,14 @@
         } else {
             return new ExpressionAdapter() {
                 public Object evaluate(Exchange exchange) {
-                    Object answer = null;
-                    try {
-                        answer = exchange.getIn().getBody(type);
-                    } catch (NoTypeConversionAvailableException e) {
-                        // ignore
-                    }
+                    Object answer = exchange.getIn().getBody(type);
                     if (answer == null) {
                         Object defaultValue = exchange.getIn().getBody();
                         if (defaultValue != null) {
                             throw new NoTypeConversionAvailableException(defaultValue, type);
                         }
 
-                        // if we don't have a body then
-                        // lets instantiate and inject a new instance
+                        // if we don't have a body then lets instantiate and inject a new instance
                         answer = exchange.getContext().getInjector().newInstance(type);
                     }
                     return answer;

Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaUdpProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaUdpProtocolCodecFactory.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaUdpProtocolCodecFactory.java (original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaUdpProtocolCodecFactory.java Thu Mar 19 10:05:14 2009
@@ -21,8 +21,6 @@
 import java.nio.charset.CharsetEncoder;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.NoTypeConversionAvailableException;
-import org.apache.camel.TypeConverter;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
@@ -83,36 +81,15 @@
     }
 
     private ByteBuffer toByteBuffer(Object message, CharsetEncoder encoder) throws CharacterCodingException {
-        // for fast convertions try this first instead of type converter registry
-        String value = null;
-        if (message instanceof String) {
-            value = (String) message;
-        } else {
-            // try to lookup if there is a string converter
-            TypeConverter tc = context.getTypeConverterRegistry().lookup(String.class, message.getClass());
-            if (tc != null) {
-                value = tc.convertTo(String.class, message);
-            }
-        }
-
-        TypeConverter tc = context.getTypeConverterRegistry().lookup(ByteBuffer.class, message.getClass());
-        if (tc == null && value == null) {
-            // use the slower converter that throws exception
-            try {
-                value = context.getTypeConverter().convertTo(String.class, message);
-            } catch (NoTypeConversionAvailableException e) {
-                // ignore
-            }
-        }
-
+        String value = context.getTypeConverter().convertTo(String.class, message);
         if (value != null) {
             ByteBuffer answer = ByteBuffer.allocate(value.length()).setAutoExpand(false);
             answer.putString(value, encoder);
             return answer;
         }
 
-        // failback if ther is a byte buffer type converter, in case there is a fallback converter as well
-        return context.getTypeConverter().convertTo(ByteBuffer.class, message);
+        // failback to use a byte buffer converter
+        return context.getTypeConverter().mandatoryConvertTo(ByteBuffer.class, message);
     }
 
 }

Modified: camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java (original)
+++ camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java Thu Mar 19 10:05:14 2009
@@ -51,7 +51,6 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Message;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeExpressionException;
@@ -412,17 +411,13 @@
         DynamicQueryContext dynamicQueryContext = new DynamicQueryContext(config);
 
         Message in = exchange.getIn();
-        Source source = null;
-        try {
-            Item item = in.getBody(Item.class);
+
+        Item item = in.getBody(Item.class);
+        if (item != null) {
             dynamicQueryContext.setContextItem(item);
-        } catch (NoTypeConversionAvailableException e) {
-            try {
-                source = in.getBody(Source.class);
-            } catch (NoTypeConversionAvailableException e2) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("No body available on exchange so using an empty document: " + exchange);
-                }
+        } else {
+            Source source = in.getBody(Source.class);
+            if (source == null) {
                 source = converter.toSource(converter.createDocument());
             }
             DocumentInfo doc = getStaticQueryContext().buildDocument(source);

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java Thu Mar 19 10:05:14 2009
@@ -17,7 +17,6 @@
 package org.apache.camel.component.event;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
@@ -114,13 +113,9 @@
     }
 
     protected ApplicationEvent toApplicationEvent(Exchange exchange) {
-        try {
-            ApplicationEvent event = exchange.getIn().getBody(ApplicationEvent.class);
-            if (event != null) {
-                return event;
-            }
-        } catch (NoTypeConversionAvailableException ex) {
-            // ignore, handled below
+        ApplicationEvent event = exchange.getIn().getBody(ApplicationEvent.class);
+        if (event != null) {
+            return event;
         }
         return new CamelEvent(this, exchange);
     }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java?rev=755890&r1=755889&r2=755890&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java Thu Mar 19 10:05:14 2009
@@ -17,7 +17,6 @@
 package org.apache.camel.spring;
 
 import org.apache.camel.Endpoint;
-import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.component.bean.BeanProcessor;
 import org.apache.camel.component.event.EventComponent;
 import org.apache.camel.component.event.EventEndpoint;
@@ -112,8 +111,6 @@
             // dependencies are initialized
             try {
                 maybeStart();
-            } catch (RuntimeException e) {
-                throw e;
             } catch (Exception e) {
                 throw wrapRuntimeCamelException(e);
             }
@@ -187,14 +184,10 @@
 
     protected Endpoint convertBeanToEndpoint(String uri, Object bean) {
         // We will use the type convert to build the endpoint first
-        try {
-            Endpoint endpoint = getTypeConverter().convertTo(Endpoint.class, bean);
-            if (endpoint != null) {
-                endpoint.setCamelContext(this);
-                return endpoint;
-            }
-        } catch (NoTypeConversionAvailableException ex) {
-            // ignore, handled below
+        Endpoint endpoint = getTypeConverter().convertTo(Endpoint.class, bean);
+        if (endpoint != null) {
+            endpoint.setCamelContext(this);
+            return endpoint;
         }
 
         return new ProcessorEndpoint(uri, this, new BeanProcessor(bean, this));