camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject camel git commit: CAMEL-9442: Query string gets decoded when bridging netty-http to http4
Date Tue, 22 Dec 2015 14:02:40 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x ee9071a6b -> 1a20c1ce5


CAMEL-9442: Query string gets decoded when bridging netty-http to http4


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

Branch: refs/heads/camel-2.15.x
Commit: 1a20c1ce542e487943c90617d1af9fab0818106e
Parents: ee9071a
Author: Gert Vanthienen <gert.vanthienen@gmail.com>
Authored: Tue Dec 22 14:09:36 2015 +0100
Committer: Gert Vanthienen <gert.vanthienen@gmail.com>
Committed: Tue Dec 22 15:01:38 2015 +0100

----------------------------------------------------------------------
 .../component/http4/helper/HttpHelper.java      |  8 +++-
 .../component/http4/HttpBridgeEndpointTest.java | 27 ++++++++++++
 .../handler/BasicRawQueryValidationHandler.java | 45 ++++++++++++++++++++
 .../http4/handler/BasicValidationHandler.java   | 22 ++++++----
 4 files changed, 92 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1a20c1ce/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
index 81b7161..6ed1705 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
@@ -240,8 +240,12 @@ public final class HttpHelper {
      */
     public static URI createURI(Exchange exchange, String url, HttpEndpoint endpoint) throws
URISyntaxException {
         URI uri = new URI(url);
-        // is a query string provided in the endpoint URI or in a header (header overrules
endpoint)
-        String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+        // is a query string provided in the endpoint URI or in a header
+        // (header overrules endpoint, raw query header overrules query header)
+        String queryString = exchange.getIn().getHeader(Exchange.HTTP_RAW_QUERY, String.class);
+        if (queryString == null) {
+            queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+        }
         if (queryString == null) {
             queryString = endpoint.getHttpUri().getRawQuery();
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/1a20c1ce/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.java
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.java
index 3bbfd29..2755f18 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpBridgeEndpointTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.http4;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.component.http4.handler.BasicRawQueryValidationHandler;
 import org.apache.camel.component.http4.handler.BasicValidationHandler;
 import org.apache.http.localserver.LocalTestServer;
 import org.junit.Test;
@@ -50,8 +51,34 @@ public class HttpBridgeEndpointTest extends BaseHttpTest {
         assertExchange(exchange);
     }
 
+    @Test
+    public void bridgeEndpointWithQuery() throws Exception {
+        Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort()
+ "/query?bridgeEndpoint=true", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(Exchange.HTTP_URI, "http://host:8080/");
+                exchange.getIn().setHeader(Exchange.HTTP_QUERY, "x=%3B");
+            }
+        });
+
+        assertExchange(exchange);
+    }
+
+    @Test
+    public void bridgeEndpointWithRawQueryAndQuery() throws Exception {
+        Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort()
+ "/query?bridgeEndpoint=true", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(Exchange.HTTP_URI, "http://host:8080/");
+                exchange.getIn().setHeader(Exchange.HTTP_RAW_QUERY, "x=%3B");
+                exchange.getIn().setHeader(Exchange.HTTP_QUERY, "x=;");
+            }
+        });
+
+        assertExchange(exchange);
+    }
+
     @Override
     protected void registerHandler(LocalTestServer server) {
         server.register("/", new BasicValidationHandler("GET", null, null, getExpectedContent()));
+        server.register("/query", new BasicRawQueryValidationHandler("GET", "x=%3B", null,
getExpectedContent()));
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/1a20c1ce/components/camel-http4/src/test/java/org/apache/camel/component/http4/handler/BasicRawQueryValidationHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/handler/BasicRawQueryValidationHandler.java
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/handler/BasicRawQueryValidationHandler.java
new file mode 100644
index 0000000..2b2aae0
--- /dev/null
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/handler/BasicRawQueryValidationHandler.java
@@ -0,0 +1,45 @@
+/**
+ * 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.http4.handler;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.http.HttpRequest;
+
+/**
+ * Similar to {@link BasicValidationHandler} but validates the raw query instead.
+ */
+public class BasicRawQueryValidationHandler extends BasicValidationHandler {
+
+    public BasicRawQueryValidationHandler(String expectedMethod, String expectedQuery, Object
expectedContent, String responseContent) {
+        super(expectedMethod, expectedQuery, expectedContent, responseContent);
+    }
+
+    protected boolean validateQuery(HttpRequest request) throws IOException {
+        try {
+            String query = new URI(request.getRequestLine().getUri()).getRawQuery();
+            if (expectedQuery != null && !expectedQuery.equals(query)) {
+                return false;
+            }
+        } catch (URISyntaxException e) {
+            throw new IOException(e);
+        }
+        return true;
+    }
+    }

http://git-wip-us.apache.org/repos/asf/camel/blob/1a20c1ce/components/camel-http4/src/test/java/org/apache/camel/component/http4/handler/BasicValidationHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/handler/BasicValidationHandler.java
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/handler/BasicValidationHandler.java
index a89955f..70c1ce9 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/handler/BasicValidationHandler.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/handler/BasicValidationHandler.java
@@ -58,14 +58,9 @@ public class BasicValidationHandler implements HttpRequestHandler {
             return;
         }
 
-        try {
-            String query = new URI(request.getRequestLine().getUri()).getQuery();       
    
-            if (expectedQuery != null && !expectedQuery.equals(query)) {
-                response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
-                return;
-            }
-        } catch (URISyntaxException e) {
-            throw new IOException(e);
+        if (!validateQuery(request)) {
+            response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
+            return;
         }
 
         if (expectedContent != null) {
@@ -84,4 +79,15 @@ public class BasicValidationHandler implements HttpRequestHandler {
         }
     }
 
+    protected boolean validateQuery(HttpRequest request) throws IOException {
+        try {
+            String query = new URI(request.getRequestLine().getUri()).getQuery();
+            if (expectedQuery != null && !expectedQuery.equals(query)) {
+                return false;
+            }
+        } catch (URISyntaxException e) {
+            throw new IOException(e);
+        }
+        return true;
+    }
 }
\ No newline at end of file


Mime
View raw message