Repository: camel
Updated Branches:
  refs/heads/master 35527c18e -> 1b838547b


CAMEL-9944 : FluentProducerTemplate - Make extract as part of UoW


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1b838547
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1b838547
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1b838547

Branch: refs/heads/master
Commit: 1b838547b573670683baa6660cf63c664335ed54
Parents: 35527c1
Author: lburgazzoli <lburgazz...@gmail.com>
Authored: Mon May 9 17:38:57 2016 +0200
Committer: lburgazzoli <lburgazz...@gmail.com>
Committed: Mon May 9 17:38:57 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/ProducerTemplate.java   | 18 ++++++++++++++++++
 .../camel/builder/FluentProducerTemplate.java     | 16 +++++++++++++++-
 .../camel/impl/DefaultProducerTemplate.java       |  4 ++++
 3 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1b838547/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java 
b/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
index 2404d85..53e7936 100644
--- a/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
+++ b/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
@@ -309,6 +309,24 @@ public interface ProducerTemplate extends Service {
      */
     Exchange send(Endpoint endpoint, ExchangePattern pattern, Processor 
processor);
 
+
+    /**
+     * Sends an exchange to an endpoint using a supplied processor
+     * <br/><br/>
+     * <p/><b>Notice:</b> that if the processing of the exchange failed with 
an Exception
+     * it is <b>not</b> thrown from this method, but you can access it from 
the returned exchange using
+     * {@link org.apache.camel.Exchange#getException()}.
+     *
+     * @param endpoint  the endpoint to send the exchange to
+     * @param pattern   the message {@link ExchangePattern} such as
+     *                  {@link ExchangePattern#InOnly} or {@link 
ExchangePattern#InOut}
+     * @param processor the transformer used to populate the new exchange
+     * @param resultProcessor a processor to process the exchange when the 
send is complete.
+     * {@link Processor} to populate the exchange
+     * @return the returned exchange
+     */
+    Exchange send(Endpoint endpoint, ExchangePattern pattern, Processor 
processor, Processor resultProcessor);
+
     /**
      * Send the body to an endpoint
      * <br/><br/>

http://git-wip-us.apache.org/repos/asf/camel/blob/1b838547/camel-core/src/main/java/org/apache/camel/builder/FluentProducerTemplate.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/builder/FluentProducerTemplate.java 
b/camel-core/src/main/java/org/apache/camel/builder/FluentProducerTemplate.java
index 98bec58..54c34e5 100644
--- 
a/camel-core/src/main/java/org/apache/camel/builder/FluentProducerTemplate.java
+++ 
b/camel-core/src/main/java/org/apache/camel/builder/FluentProducerTemplate.java
@@ -30,11 +30,13 @@ import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.processor.ConvertBodyProcessor;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
 
 public class FluentProducerTemplate {
     private final CamelContext context;
+    private final ClassValue<ConvertBodyProcessor> resultProcessors;
     private Map<String, Object> headers;
     private Object body;
     private Endpoint endpoint;
@@ -52,6 +54,12 @@ public class FluentProducerTemplate {
         this.exchangeSupplier = null;
         this.processorSupplier = () -> this::populateExchange;
         this.template = null;
+        this.resultProcessors = new ClassValue<ConvertBodyProcessor>() {
+            @Override
+            protected ConvertBodyProcessor computeValue(Class<?> type) {
+                return new ConvertBodyProcessor(type);
+            }
+        };
     }
 
     /**
@@ -259,7 +267,13 @@ public class FluentProducerTemplate {
             Exchange exchange = template().request(endpoint, 
processorSupplier.get());
             result = exchange.hasOut() ? (T)exchange.getOut() : 
(T)exchange.getIn();
         } else {
-            Exchange exchange = template().send(endpoint, 
ExchangePattern.InOut, processorSupplier.get());
+            Exchange exchange = template().send(
+                endpoint,
+                ExchangePattern.InOut,
+                processorSupplier.get(),
+                resultProcessors.get(type)
+            );
+
             result = context.getTypeConverter().convertTo(
                 type,
                 ExchangeHelper.extractResultBody(exchange, 
exchange.getPattern())

http://git-wip-us.apache.org/repos/asf/camel/blob/1b838547/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
index a5c8867..6eff970 100644
--- 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
+++ 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
@@ -135,6 +135,10 @@ public class DefaultProducerTemplate extends 
ServiceSupport implements ProducerT
         return getProducerCache().send(endpoint, pattern, processor);
     }
 
+    public Exchange send(Endpoint endpoint, ExchangePattern pattern, Processor 
processor, Processor resultProcessor) {
+        return getProducerCache().send(endpoint, pattern, processor, 
resultProcessor);
+    }
+
     public Object sendBody(Endpoint endpoint, ExchangePattern pattern, Object 
body) {
         Exchange result = send(endpoint, pattern, 
createSetBodyProcessor(body));
         return extractResultBody(result, pattern);

Reply via email to