Updated Branches: refs/heads/master 60d482b15 -> c620d73cb
[CAMEL-7138] Storing the value of raw HTTP query in the header. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c620d73c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c620d73c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c620d73c Branch: refs/heads/master Commit: c620d73cb01ed85e3e929432d4a021bb924f898d Parents: 60d482b Author: Henryk Konsek <hekon...@gmail.com> Authored: Fri Jan 17 14:49:09 2014 +0100 Committer: Henryk Konsek <hekon...@gmail.com> Committed: Fri Jan 17 14:49:09 2014 +0100 ---------------------------------------------------------------------- .../main/java/org/apache/camel/Exchange.java | 1 + .../netty/http/DefaultNettyHttpBinding.java | 1 + .../netty/http/NettyHttpRawQueryTest.java | 57 ++++++++++++++++++++ 3 files changed, 59 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c620d73c/camel-core/src/main/java/org/apache/camel/Exchange.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java b/camel-core/src/main/java/org/apache/camel/Exchange.java index 9f7a22d..506ba29 100644 --- a/camel-core/src/main/java/org/apache/camel/Exchange.java +++ b/camel-core/src/main/java/org/apache/camel/Exchange.java @@ -136,6 +136,7 @@ public interface Exchange { String HTTP_PATH = "CamelHttpPath"; String HTTP_PROTOCOL_VERSION = "CamelHttpProtocolVersion"; String HTTP_QUERY = "CamelHttpQuery"; + String HTTP_RAW_QUERY = "CamelHttpRawQuery"; String HTTP_RESPONSE_CODE = "CamelHttpResponseCode"; String HTTP_URI = "CamelHttpUri"; String HTTP_URL = "CamelHttpUrl"; http://git-wip-us.apache.org/repos/asf/camel/blob/c620d73c/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java index f6c6c45..40bb99e 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java @@ -119,6 +119,7 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding { // uri is path and query parameters headers.put(Exchange.HTTP_URI, uri.getPath()); headers.put(Exchange.HTTP_QUERY, uri.getQuery()); + headers.put(Exchange.HTTP_RAW_QUERY, uri.getRawQuery()); // strip the starting endpoint path so the path is relative to the endpoint uri String path = uri.getPath(); http://git-wip-us.apache.org/repos/asf/camel/blob/c620d73c/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRawQueryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRawQueryTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRawQueryTest.java new file mode 100644 index 0000000..e257d18 --- /dev/null +++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRawQueryTest.java @@ -0,0 +1,57 @@ +/** + * 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 java.net.URL; + +import org.apache.camel.EndpointInject; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +import static org.apache.camel.Exchange.HTTP_QUERY; +import static org.apache.camel.Exchange.HTTP_RAW_QUERY; + +public class NettyHttpRawQueryTest extends BaseNettyTest { + + @EndpointInject(uri = "mock:test") + MockEndpoint mockEndpoint; + + @Test + public void shouldAccessRawQuery() throws Exception { + String query = "param=x1%26y%3D2"; + mockEndpoint.expectedMessageCount(1); + mockEndpoint.message(0).header(HTTP_QUERY).isEqualTo("param=x1&y=2"); + mockEndpoint.message(0).header(HTTP_RAW_QUERY).isEqualTo(query); + + new URL("http://localhost:" + getPort() + "/?" + query).openConnection().getInputStream().close(); + + 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}}/") + .to(mockEndpoint); + } + }; + } + +}