Author: davsclaus
Date: Fri Jul 11 04:20:21 2008
New Revision: 675919

URL: http://svn.apache.org/viewvc?rev=675919&view=rev
Log:
CAMEL-696: Try to honor the exchange pattern if provided

Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java?rev=675919&r1=675918&r2=675919&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
 Fri Jul 11 04:20:21 2008
@@ -94,7 +94,7 @@
 
     public Object sendBody(Endpoint<E> endpoint, ExchangePattern pattern, 
Object body) {
         E result = send(endpoint, pattern, createSetBodyProcessor(body));
-        return extractResultBody(result);
+        return extractResultBody(result, pattern);
     }
 
     public Object sendBody(Endpoint<E> endpoint, Object body) {
@@ -126,13 +126,13 @@
     public Object sendBodyAndHeader(Endpoint endpoint, ExchangePattern 
pattern, final Object body, final String header,
             final Object headerValue) {
         E result = send(endpoint, pattern, createBodyAndHeaderProcessor(body, 
header, headerValue));
-        return extractResultBody(result);
+        return extractResultBody(result, pattern);
     }
 
     public Object sendBodyAndHeader(String endpoint, ExchangePattern pattern, 
final Object body, final String header,
             final Object headerValue) {
         E result = send(endpoint, pattern, createBodyAndHeaderProcessor(body, 
header, headerValue));
-        return extractResultBody(result);
+        return extractResultBody(result, pattern);
     }
 
     public Object sendBodyAndHeaders(String endpointUri, final Object body, 
final Map<String, Object> headers) {
@@ -305,12 +305,34 @@
         endpointCache.clear();
     }
 
+    /**
+     * Extracts the body from the given result.
+     *
+     * @param result   the result
+     * @return  the result, can be <tt>null</tt>.
+     */
     protected Object extractResultBody(E 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(E result, ExchangePattern pattern) {
         Object answer = null;
         if (result != null) {
-            Message out = result.getOut(false);
-            if (out != null) {
-                answer = out.getBody();
+            // try to honor pattern if provided
+            boolean notOut = pattern != null && !pattern.isOutCapable();
+            boolean hasOut = result.getOut(false) != null;
+            if (hasOut && !notOut) {
+                answer = result.getOut().getBody();
             } else {
                 answer = result.getIn().getBody();
             }


Reply via email to