Updated Branches:
  refs/heads/master 3cb60dd92 -> 96ce8d0f8

CAMEL-6349: camel-http/servlet should set response correctly on Exchange 
depending on has out or not


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

Branch: refs/heads/master
Commit: 96ce8d0f8a32afdd542ac55da7d5c33eee042a11
Parents: 3cb60dd
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sat May 11 10:18:22 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sat May 11 10:18:22 2013 +0200

----------------------------------------------------------------------
 .../camel/component/http/DefaultHttpBinding.java   |   12 ++--
 .../component/servlet/ServletSetBodyTest.java      |   47 +++++++++++++++
 2 files changed, 53 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/96ce8d0f/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
 
b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
index 8af47f3..e291480 100644
--- 
a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
+++ 
b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
@@ -212,20 +212,20 @@ public class DefaultHttpBinding implements HttpBinding {
     }
 
     public void writeResponse(Exchange exchange, HttpServletResponse response) 
throws IOException {
+        Message target = exchange.hasOut() ? exchange.getOut() : 
exchange.getIn();
         if (exchange.isFailed()) {
             if (exchange.getException() != null) {
                 doWriteExceptionResponse(exchange.getException(), response);
             } else {
                 // it must be a fault, no need to check for the fault flag on 
the message
-                doWriteFaultResponse(exchange.getOut(), response, exchange);
+                doWriteFaultResponse(target, response, exchange);
             }
         } else {
-            // just copy the protocol relates header
-            copyProtocolHeaders(exchange.getIn(), exchange.getOut());
-            Message out = exchange.getOut();            
-            if (out != null) {
-                doWriteResponse(out, response, exchange);
+            if (exchange.hasOut()) {
+                // just copy the protocol relates header if we do not have them
+                copyProtocolHeaders(exchange.getIn(), exchange.getOut());
             }
+            doWriteResponse(target, response, exchange);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/96ce8d0f/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletSetBodyTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletSetBodyTest.java
 
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletSetBodyTest.java
new file mode 100644
index 0000000..d0a7023
--- /dev/null
+++ 
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletSetBodyTest.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.servlet;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+import com.meterware.servletunit.ServletUnitClient;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class ServletSetBodyTest extends ServletCamelRouterTestSupport {
+
+    @Test
+    public void testSetBody() throws Exception {
+        WebRequest req = new GetMethodWebRequest(CONTEXT_URL + 
"/services/hello");
+        ServletUnitClient client = newClient();
+        WebResponse response = client.getResponse(req);
+
+        assertEquals("The response message is wrong ", "Bye World", 
response.getText());
+    }
+    
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("servlet:///hello")
+                    .setBody().constant("Bye World");
+            }
+        };
+    }
+
+}

Reply via email to