camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r771624 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/ main/java/org/apache/camel/impl/ main/java/org/apache/camel/util/ test/java/org/apache/camel/component/seda/
Date Tue, 05 May 2009 08:47:12 GMT
Author: davsclaus
Date: Tue May  5 08:47:12 2009
New Revision: 771624

URL: http://svn.apache.org/viewvc?rev=771624&view=rev
Log:
polished code a bit

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java?rev=771624&r1=771623&r2=771624&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java Tue May  5
08:47:12 2009
@@ -139,6 +139,7 @@
      * {@link Processor} to populate the exchange.
      * @param callback    the callback will be called when the exchange is completed.
      * @return the returned exchange
+     * @deprecated a new async API is planned for Camel 2.0
      */
     Exchange send(String endpointUri, Processor processor, AsyncCallback callback);
 
@@ -181,6 +182,7 @@
      * {@link Processor} to populate the exchange.
      * @param callback  the callback will be called when the exchange is completed.
      * @return the returned exchange
+     * @deprecated a new async API is planned for Camel 2.0
      */
     Exchange send(Endpoint endpoint, Processor processor, AsyncCallback callback);
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java?rev=771624&r1=771623&r2=771624&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
Tue May  5 08:47:12 2009
@@ -31,8 +31,7 @@
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.ObjectHelper;
-
-import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
+import org.apache.camel.util.ExchangeHelper;
 
 /**
  * A client helper object (named like Spring's TransactionTemplate & JmsTemplate
@@ -453,65 +452,12 @@
         endpointCache.clear();
     }
 
-    /**
-     * Extracts the body from the given result.
-     *
-     * @param result   the result
-     * @return  the result, can be <tt>null</tt>.
-     */
     protected Object extractResultBody(Exchange result) {
         return extractResultBody(result, null);
     }
 
-    /**
-     * Extracts the body from the given result.
-     * <p/>
-     * If the exchange pattern is provided it will try to honor it and retrive the body
-     * from either IN or OUT according to the pattern.
-     *
-     * @param result   the result
-     * @param pattern  exchange pattern if given, can be <tt>null</tt>
-     * @return  the result, can be <tt>null</tt>.
-     */
     protected Object extractResultBody(Exchange result, ExchangePattern pattern) {
-        Object answer = null;
-        if (result != null) {
-            // rethrow if there was an exception
-            if (result.getException() != null) {
-                throw wrapRuntimeCamelException(result.getException());
-            }
-
-            // result could have a fault message
-            if (hasFaultMessage(result)) {
-                return result.getFault().getBody();
-            }
-
-            // okay no fault then return the response according to the pattern
-            // try to honor pattern if provided
-            boolean notOut = pattern != null && !pattern.isOutCapable();
-            boolean hasOut = result.hasOut();
-            if (hasOut && !notOut) {
-                // we have a response in out and the pattern is out capable
-                answer = result.getOut().getBody();
-            } else if (!hasOut && result.getPattern() == ExchangePattern.InOptionalOut)
{
-                // special case where the result is InOptionalOut and with no OUT response
-                // so we should return null to indicate this fact
-                answer = null;
-            } else {
-                // use IN as the response
-                answer = result.getIn().getBody();
-            }
-        }
-        return answer;
+        return ExchangeHelper.extractResultBody(result, pattern);
     }
 
-    protected boolean hasFaultMessage(Exchange result) {
-        if (result.hasFault()) {
-            Object faultBody = result.getFault().getBody();
-            if (faultBody != null) {
-                return true;
-            }
-        }
-        return false;
-    }
 }
\ No newline at end of file

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=771624&r1=771623&r2=771624&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 Tue May
 5 08:47:12 2009
@@ -31,6 +31,7 @@
 import org.apache.camel.NoSuchPropertyException;
 import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.TypeConverter;
+import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
 
 /**
  * Some helper methods for working with {@link Exchange} objects
@@ -395,4 +396,63 @@
         exchange.setException(null);
     }
 
+    /**
+     * Extracts the body from the given result.
+     * <p/>
+     * If the exchange pattern is provided it will try to honor it and retrive the body
+     * from either IN or OUT according to the pattern.
+     *
+     * @param exchange   the result
+     * @param pattern  exchange pattern if given, can be <tt>null</tt>
+     * @return  the result, can be <tt>null</tt>.
+     */
+    public static Object extractResultBody(Exchange exchange, ExchangePattern pattern) {
+        Object answer = null;
+        if (exchange != null) {
+            // rethrow if there was an exception
+            if (exchange.getException() != null) {
+                throw wrapRuntimeCamelException(exchange.getException());
+            }
+
+            // result could have a fault message
+            if (hasFaultMessage(exchange)) {
+                return exchange.getFault().getBody();
+            }
+
+            // okay no fault then return the response according to the pattern
+            // try to honor pattern if provided
+            boolean notOut = pattern != null && !pattern.isOutCapable();
+            boolean hasOut = exchange.hasOut();
+            if (hasOut && !notOut) {
+                // we have a response in out and the pattern is out capable
+                answer = exchange.getOut().getBody();
+            } else if (!hasOut && exchange.getPattern() == ExchangePattern.InOptionalOut)
{
+                // special case where the result is InOptionalOut and with no OUT response
+                // so we should return null to indicate this fact
+                answer = null;
+            } else {
+                // use IN as the response
+                answer = exchange.getIn().getBody();
+            }
+        }
+        return answer;
+    }
+
+    /**
+     * Tests whether the exchange has a fault message set and that its not null.
+     *
+     * @param exchange  the exchange
+     * @return <tt>true</tt> if fault message exists
+     */
+    public static boolean hasFaultMessage(Exchange exchange) {
+        if (exchange.hasFault()) {
+            Object faultBody = exchange.getFault().getBody();
+            if (faultBody != null) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java?rev=771624&r1=771623&r2=771624&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaUnitOfWorkTest.java
Tue May  5 08:47:12 2009
@@ -60,7 +60,7 @@
 
                 from("seda:foo")
                         // use a little delay to allow the first route to complete
-                        .delay(100)
+                        .delay(200)
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 assertEquals("onCompleteA", sync);



Mime
View raw message