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 2014/04/25 10:28:42 UTC
[2/2] git commit: CAMEL-7394: camel-netty-http - Add support for
HTTP_PATH for dynamic-to
CAMEL-7394: camel-netty-http - Add support for HTTP_PATH for dynamic-to
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/78f60f1b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/78f60f1b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/78f60f1b
Branch: refs/heads/camel-2.12.x
Commit: 78f60f1bf977b24b424641f132e14fb7bd975ccf
Parents: 022735f
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 25 10:27:46 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 25 10:28:21 2014 +0200
----------------------------------------------------------------------
.../component/netty/http/NettyHttpHelper.java | 17 +++++++
.../http/NettyRecipientListHttpBaseTest.java | 53 ++++++++++++++++++++
2 files changed, 70 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/78f60f1b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
index 7491c9b..07bd8b6 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
@@ -193,6 +193,23 @@ public final class NettyHttpHelper {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
}
+ // append HTTP_PATH to HTTP_URI if it is provided in the header
+ String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
+ // NOW the HTTP_PATH is just related path, we don't need to trim it
+ if (path != null) {
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+ if (path.length() > 0) {
+ // make sure that there is exactly one "/" between HTTP_URI and
+ // HTTP_PATH
+ if (!uri.endsWith("/")) {
+ uri = uri + "/";
+ }
+ uri = uri.concat(path);
+ }
+ }
+
// ensure uri is encoded to be valid
uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);
http://git-wip-us.apache.org/repos/asf/camel/blob/78f60f1b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyRecipientListHttpBaseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyRecipientListHttpBaseTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyRecipientListHttpBaseTest.java
new file mode 100644
index 0000000..be8bedb
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyRecipientListHttpBaseTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.netty.http;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyRecipientListHttpBaseTest extends BaseNettyTest {
+
+ @Test
+ public void testRecipientListHttpBase() throws Exception {
+ getMockEndpoint("mock:foo").expectedHeaderValuesReceivedInAnyOrder(Exchange.HTTP_PATH, "/bar", "/baz", "/bar/baz", "/baz/bar");
+ getMockEndpoint("mock:foo").expectedHeaderValuesReceivedInAnyOrder("num", "1", "2", "3", "4");
+
+ template.sendBodyAndHeader("direct:start", "A", Exchange.HTTP_PATH, "/foo/bar?num=1");
+ template.sendBodyAndHeader("direct:start", "B", Exchange.HTTP_PATH, "/foo/baz?num=2");
+ template.sendBodyAndHeader("direct:start", "C", Exchange.HTTP_PATH, "/foo/bar/baz?num=3");
+ template.sendBodyAndHeader("direct:start", "D", Exchange.HTTP_PATH, "/foo/baz/bar?num=4");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("netty-http:http://0.0.0.0:{{port}}/foo?matchOnUriPrefix=true")
+ .to("mock:foo")
+ .transform(body().prepend("Bye "));
+
+ from("direct:start")
+ .recipientList().constant("netty-http:http://0.0.0.0:{{port}}");
+ }
+ };
+ }
+
+}