Repository: camel
Updated Branches:
  refs/heads/master d82c76517 -> 3bf01d162


Rest DSL. camel-swagger work in progress.


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

Branch: refs/heads/master
Commit: 3bf01d1621aaa9a7b1ea45ad2c76b904a27eaca4
Parents: d82c765
Author: Claus Ibsen <davscl...@apache.org>
Authored: Mon Aug 11 10:30:52 2014 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Mon Aug 11 10:30:52 2014 +0200

----------------------------------------------------------------------
 .../processor/binding/RestBindingProcessor.java   | 18 ++++++++++++++----
 .../rest/RestServletPostJsonPojoListTest.java     |  1 +
 2 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3bf01d16/camel-core/src/main/java/org/apache/camel/processor/binding/RestBindingProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/binding/RestBindingProcessor.java
 
b/camel-core/src/main/java/org/apache/camel/processor/binding/RestBindingProcessor.java
index d2446f2..7537a82 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/binding/RestBindingProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/binding/RestBindingProcessor.java
@@ -41,6 +41,9 @@ import org.apache.camel.util.ObjectHelper;
  */
 public class RestBindingProcessor extends ServiceSupport implements 
AsyncProcessor {
 
+    // TODO: consumes/produces can be a list of media types, and prioritized 
1st to last. (eg the q=weight option)
+    // TODO: use content-type from produces/consumes if possible to set as 
Content-Type if missing
+
     private final AsyncProcessor jsonUnmarshal;
     private final AsyncProcessor xmlUnmarshal;
     private final AsyncProcessor jsonMarshal;
@@ -89,8 +92,6 @@ public class RestBindingProcessor extends ServiceSupport 
implements AsyncProcess
         AsyncProcessorHelper.process(this, exchange);
     }
 
-    // TODO: consumes/produces can be a list of media types, and prioritized 
1st to last.
-
     @Override
     public boolean process(Exchange exchange, final AsyncCallback callback) {
         if (bindingMode == null || "off".equals(bindingMode)) {
@@ -289,14 +290,23 @@ public class RestBindingProcessor extends ServiceSupport 
implements AsyncProcess
 
             try {
                 if (isXml && xmlMarshal != null) {
+                    // make sure there is a content-type with xml
+                    String type = ExchangeHelper.getContentType(exchange);
+                    if (type == null) {
+                        exchange.getIn().setHeader(Exchange.CONTENT_TYPE, 
"application/xml");
+                    }
                     xmlMarshal.process(exchange);
                 } else if (isJson && jsonMarshal != null) {
+                    // make sure there is a content-type with json
+                    String type = ExchangeHelper.getContentType(exchange);
+                    if (type == null) {
+                        exchange.getIn().setHeader(Exchange.CONTENT_TYPE, 
"application/json");
+                    }
                     jsonMarshal.process(exchange);
                 } else {
                     // we could not bind
                     if (bindingMode.equals("auto")) {
                         // okay for auto we do not mind if we could not bind
-                        return;
                     } else {
                         if (bindingMode.contains("xml")) {
                             exchange.setException(new BindingException("Cannot 
bind to xml as message body is not xml compatible", exchange));
@@ -304,11 +314,11 @@ public class RestBindingProcessor extends ServiceSupport 
implements AsyncProcess
                             exchange.setException(new BindingException("Cannot 
bind to json as message body is not json compatible", exchange));
                         }
                     }
-                    return;
                 }
             } catch (Throwable e) {
                 exchange.setException(e);
             }
         }
     }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/3bf01d16/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPostJsonPojoListTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPostJsonPojoListTest.java
 
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPostJsonPojoListTest.java
index 8bdc674..9f0f0c7 100644
--- 
a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPostJsonPojoListTest.java
+++ 
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPostJsonPojoListTest.java
@@ -43,6 +43,7 @@ public class RestServletPostJsonPojoListTest extends 
ServletCamelRouterTestSuppo
         WebResponse response = client.getResponse(req);
 
         assertEquals(200, response.getResponseCode());
+        assertEquals("application/json", response.getContentType());
 
         assertMockEndpointsSatisfied();
 

Reply via email to