You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/05/11 10:19:27 UTC
[2/2] git commit: CAMEL-6349: camel-http/servlet should set response
correctly on Exchange depending on has out or not
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/6a56deb9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6a56deb9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6a56deb9
Branch: refs/heads/camel-2.10.x
Commit: 6a56deb972e7a62a417b128b686aab38ff6dc419
Parents: cdf1139
Author: Claus Ibsen <da...@apache.org>
Authored: Sat May 11 10:18:22 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat May 11 10:19:13 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/6a56deb9/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 3aadd37..0f6f814 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/6a56deb9/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");
+ }
+ };
+ }
+
+}