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/20 07:06:57 UTC

svn commit: r756335 - in /camel/trunk/camel-core/src/main/java/org/apache/camel: ./ builder/ impl/ util/

Author: davsclaus
Date: Fri Mar 20 06:06:56 2009
New Revision: 756335

URL: http://svn.apache.org/viewvc?rev=756335&view=rev
Log:
CAMEL-1459: Polished code a bit.

Removed:
    camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidTypeException.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadRuntimeException.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadRuntimeException.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadRuntimeException.java?rev=756335&r1=756334&r2=756335&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadRuntimeException.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/InvalidPayloadRuntimeException.java Fri Mar 20 06:06:56 2009
@@ -17,7 +17,7 @@
 package org.apache.camel;
 
 /**
- * Runtime version of the {@link org.apache.camel.InvalidTypeException}.
+ * Runtime version of the {@link InvalidPayloadException}.
  *
  * @version $Revision$
  */
@@ -25,8 +25,19 @@
     private final Class<?> type;
 
     public InvalidPayloadRuntimeException(Exchange exchange, Class<?> type) {
-        super("No in body available of type: " + type.getName()
-              + NoSuchPropertyException.valueDescription(exchange.getIn().getBody()), exchange);
+        this(exchange, type, exchange.getIn());
+    }
+
+    public InvalidPayloadRuntimeException(Exchange exchange, Class<?> type, Message message) {
+        super("No body available of type: " + type.getName()
+              + NoSuchPropertyException.valueDescription(message.getBody()) + " on: " + message, exchange);
+        this.type = type;
+    }
+
+    public InvalidPayloadRuntimeException(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;
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java?rev=756335&r1=756334&r2=756335&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java Fri Mar 20 06:06:56 2009
@@ -26,12 +26,12 @@
     private final Exchange exchange;
 
     public RuntimeExchangeException(String message, Exchange exchange) {
-        super(message + " on the exchange: " +  exchange);
+        super(createMessage(message, exchange));
         this.exchange = exchange;
     }
 
-    public RuntimeExchangeException(Exception e, Exchange exchange) {
-        super(e.getMessage(), e);
+    public RuntimeExchangeException(String message, Exchange exchange, Throwable cause) {
+        super(createMessage(message, exchange), cause);
         this.exchange = exchange;
     }
 
@@ -42,4 +42,8 @@
         return exchange;
     }
 
+    protected static String createMessage(String message, Exchange exchange) {
+        return message + " on the exchange: " + exchange;
+    }
+
 }
\ No newline at end of file

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?rev=756335&r1=756334&r2=756335&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java Fri Mar 20 06:06:56 2009
@@ -76,7 +76,6 @@
     /**
      * Returns an expression for the inbound message headers
      *
-     * @see Message#getHeaders()
      * @return an expression object which will return the inbound headers
      */
     public static Expression headersExpression() {
@@ -123,7 +122,6 @@
     /**
      * Returns an expression for the outbound message headers
      *
-     * @see Message#getHeaders()
      * @return an expression object which will return the headers
      */
     public static Expression outHeadersExpression() {
@@ -206,7 +204,6 @@
     /**
      * Returns an expression for the property value of exchange with the given name
      *
-     * @see Exchange#getProperty(String)
      * @param propertyName the name of the property the expression will return
      * @return an expression object which will return the property value
      */
@@ -224,9 +221,8 @@
     }
 
     /**
-     * Returns an expression for the properties of exchange with the given name
+     * Returns an expression for the properties of exchange
      *
-     * @see Exchange#getProperties()
      * @return an expression object which will return the properties
      */
     public static Expression propertiesExpression() {
@@ -243,9 +239,8 @@
     }
     
     /**
-     * Returns an expression for the properties of exchange with the given name
+     * Returns an expression for the properties of the camel context
      *
-     * @see Exchange#getProperties()
      * @return an expression object which will return the properties
      */
     public static Expression camelContextPropertiesExpression() {
@@ -264,7 +259,6 @@
     /**
      * Returns an expression for the property value of the camel context with the given name
      *
-     * @see Exchange#getProperty(String)
      * @param propertyName the name of the property the expression will return
      * @return an expression object which will return the property value
      */

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java?rev=756335&r1=756334&r2=756335&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java Fri Mar 20 06:06:56 2009
@@ -50,7 +50,7 @@
         try {
             processor.process(exchange);
         } catch (Exception e) {
-            throw new RuntimeExchangeException(e, exchange);
+            throw new RuntimeExchangeException("Error while processing exchange", exchange, e);
         }
         return 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=756335&r1=756334&r2=756335&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 Fri Mar 20 06:06:56 2009
@@ -24,12 +24,12 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.InvalidTypeException;
 import org.apache.camel.Message;
 import org.apache.camel.NoSuchBeanException;
 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;
 
 /**
@@ -111,11 +111,7 @@
      * an exception if it is not present
      */
     public static Object getMandatoryInBody(Exchange exchange) throws InvalidPayloadException {
-        Object answer = exchange.getIn().getBody();
-        if (answer == null) {
-            throw new InvalidPayloadException(exchange, Object.class);
-        }
-        return answer;
+        return exchange.getIn().getMandatoryBody();
     }
 
     /**
@@ -123,11 +119,7 @@
      * an exception if it is not present
      */
     public static <T> T getMandatoryInBody(Exchange exchange, Class<T> type) throws InvalidPayloadException {
-        T answer = exchange.getIn().getBody(type);
-        if (answer == null) {
-            throw new InvalidPayloadException(exchange, type);
-        }
-        return answer;
+        return exchange.getIn().getMandatoryBody(type);
     }
 
     /**
@@ -135,12 +127,7 @@
      * an exception if it is not present
      */
     public static Object getMandatoryOutBody(Exchange exchange) throws InvalidPayloadException {
-        Message out = exchange.getOut();
-        Object answer = out.getBody();
-        if (answer == null) {
-            throw new InvalidPayloadException(exchange, Object.class, out);
-        }
-        return answer;
+        return exchange.getOut().getMandatoryBody();
     }
 
     /**
@@ -148,24 +135,19 @@
      * an exception if it is not present
      */
     public static <T> T getMandatoryOutBody(Exchange exchange, Class<T> type) throws InvalidPayloadException {
-        Message out = exchange.getOut();
-        T answer = out.getBody(type);
-        if (answer == null) {
-            throw new InvalidPayloadException(exchange, type, out);
-        }
-        return answer;
+        return exchange.getOut().getMandatoryBody(type);
     }
 
     /**
      * Converts the value to the given expected type or throws an exception
      */
-    public static <T> T convertToMandatoryType(Exchange exchange, Class<T> type, Object value)
-        throws InvalidTypeException {
-        T answer = convertToType(exchange, type, value);
-        if (answer == null) {
-            throw new InvalidTypeException(exchange, value, type);
+    public static <T> T convertToMandatoryType(Exchange exchange, Class<T> type, Object value) throws NoTypeConversionAvailableException {
+        CamelContext camelContext = exchange.getContext();
+        TypeConverter converter = camelContext.getTypeConverter();
+        if (converter != null) {
+            return converter.mandatoryConvertTo(type, exchange, value);
         }
-        return answer;
+        throw new NoTypeConversionAvailableException(value, type);
     }
 
     /**