Repository: camel
Updated Branches:
  refs/heads/master 7f7ce39d2 -> 8129b1a78


CAMEL-10164: Add support for binding in rest to


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

Branch: refs/heads/master
Commit: 8129b1a784b307d2a0b576c8f46c046c7739d762
Parents: 7f7ce39
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue Sep 6 10:07:53 2016 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Sep 6 10:07:53 2016 +0200

----------------------------------------------------------------------
 .../rest/RestProducerBindingProcessor.java      | 36 ++++++++++++--------
 1 file changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8129b1a7/camel-core/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java
 
b/camel-core/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java
index b1d879e..db838a1 100644
--- 
a/camel-core/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/component/rest/RestProducerBindingProcessor.java
@@ -62,28 +62,24 @@ public class RestProducerBindingProcessor extends 
DelegateAsyncProcessor {
 
         this.camelContext = camelContext;
 
-        if (jsonDataFormat != null) {
+        if (outJsonDataFormat != null) {
             this.jsonUnmarshal = new UnmarshalProcessor(outJsonDataFormat);
         } else {
             this.jsonUnmarshal = null;
         }
-        if (outJsonDataFormat != null) {
+        if (jsonDataFormat != null) {
             this.jsonMarshal = new MarshalProcessor(jsonDataFormat);
-        } else if (jsonDataFormat != null) {
-            this.jsonMarshal = new MarshalProcessor(outJsonDataFormat);
         } else {
             this.jsonMarshal = null;
         }
 
-        if (xmlDataFormat != null) {
+        if (outXmlDataFormat != null) {
             this.xmlUnmarshal = new UnmarshalProcessor(outXmlDataFormat);
         } else {
             this.xmlUnmarshal = null;
         }
-        if (outXmlDataFormat != null) {
+        if (xmlDataFormat != null) {
             this.xmlMarshal = new MarshalProcessor(xmlDataFormat);
-        } else if (xmlDataFormat != null) {
-            this.xmlMarshal = new MarshalProcessor(outXmlDataFormat);
         } else {
             this.xmlMarshal = null;
         }
@@ -139,18 +135,30 @@ public class RestProducerBindingProcessor extends 
DelegateAsyncProcessor {
         }
 
         // we only need to perform before binding if the message body is POJO 
based
-        // if its convertable to stream based then its not POJO based
-        InputStream is = 
camelContext.getTypeConverter().tryConvertTo(InputStream.class, exchange, body);
-        if (is != null) {
-            exchange.getIn().setBody(is);
+        if (body instanceof String || body instanceof byte[]) {
+            // the body is text based and thus not POJO so no binding needed
             if (outType != null) {
                 // wrap callback to add reverse operation if we know the 
output type from the REST service
                 callback = new RestProducerBindingUnmarshalCallback(exchange, 
callback, jsonMarshal, xmlMarshal, false);
             }
             // okay now we can continue routing to the producer
             return getProcessor().process(exchange, callback);
+        } else {
+            // if its convertable to stream based then its not POJO based
+            InputStream is = 
camelContext.getTypeConverter().tryConvertTo(InputStream.class, exchange, body);
+            if (is != null) {
+                exchange.getIn().setBody(is);
+                if (outType != null) {
+                    // wrap callback to add reverse operation if we know the 
output type from the REST service
+                    callback = new 
RestProducerBindingUnmarshalCallback(exchange, callback, jsonMarshal, 
xmlMarshal, false);
+                }
+                // okay now we can continue routing to the producer
+                return getProcessor().process(exchange, callback);
+            }
         }
 
+        // assume body is POJO based and binding needed
+
         String contentType = ExchangeHelper.getContentType(exchange);
         if (contentType != null) {
             isXml = contentType.toLowerCase(Locale.ENGLISH).contains("xml");
@@ -306,8 +314,8 @@ public class RestProducerBindingProcessor extends 
DelegateAsyncProcessor {
                 return;
             }
 
-            // is there any marshaller at all
-            if (jsonMarshal == null && xmlMarshal == null) {
+            // is there any unmarshaller at all
+            if (jsonUnmarshal == null && xmlUnmarshal == null) {
                 return;
             }
 

Reply via email to