camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] git commit: CAMEL-6903: Fixed netty-http endpoint being unique which could lead to netty http producer sending wrong data if uri parameters are part of endpoint uri.
Date Fri, 25 Oct 2013 10:46:53 GMT
CAMEL-6903: Fixed netty-http endpoint being unique which could lead to netty http producer
sending wrong data if uri parameters are part of endpoint uri.


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

Branch: refs/heads/camel-2.12.x
Commit: 7b9e13e2ae7fa6c439f38ced6d8fb1be6fb7f8fc
Parents: 7be01a0
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Oct 25 12:46:03 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Oct 25 12:47:27 2013 +0200

----------------------------------------------------------------------
 .../netty/http/NettyHttpComponent.java          | 14 +++---
 .../component/netty/http/NettyHttpEndpoint.java | 11 +----
 .../component/netty/http/NettyHttpHelper.java   |  5 +-
 .../component/netty/http/NettyHttpProducer.java |  7 +--
 ...ettyHttpSameHostDifferentParametersTest.java | 52 ++++++++++++++++++++
 5 files changed, 62 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7b9e13e2/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index f6f4a9a..d305d92 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -78,6 +78,7 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
         Map<String, Object> securityOptions = IntrospectionSupport.extractProperties(parameters,
"securityConfiguration.");
 
         config = parseConfiguration(config, remaining, parameters);
+        setProperties(config, parameters);
 
         // validate config
         config.validateConfiguration();
@@ -90,15 +91,12 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
             config.setPort(shared.getPort());
         }
 
-        NettyHttpEndpoint answer = new NettyHttpEndpoint(remaining, this, config);
-        answer.setTimer(getTimer());
-        setProperties(answer.getConfiguration(), parameters);
+        // create the address uri which includes the remainder parameters (which is not configuration
parameters for this component)
+        URI u = new URI(UnsafeUriCharactersEncoder.encode(remaining));
+        String addressUri = URISupport.createRemainingURI(u, parameters).toString();
 
-        // any leftover parameters is uri parameters
-        if (!parameters.isEmpty()) {
-            String query = URISupport.createQueryString(parameters);
-            answer.setUriParameters(query);
-        }
+        NettyHttpEndpoint answer = new NettyHttpEndpoint(addressUri, this, config);
+        answer.setTimer(getTimer());
 
         // set component options on endpoint as defaults
         if (answer.getNettyHttpBinding() == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/7b9e13e2/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
index 5e5de9d..27775c5 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
@@ -40,7 +40,6 @@ import org.slf4j.LoggerFactory;
 public class NettyHttpEndpoint extends NettyEndpoint implements HeaderFilterStrategyAware
{
 
     private static final Logger LOG = LoggerFactory.getLogger(NettyHttpEndpoint.class);
-    private String uriParameters;
     private NettyHttpBinding nettyHttpBinding;
     private HeaderFilterStrategy headerFilterStrategy;
     private boolean traceEnabled;
@@ -77,7 +76,7 @@ public class NettyHttpEndpoint extends NettyEndpoint implements HeaderFilterStra
 
     @Override
     public Producer createProducer() throws Exception {
-        Producer answer = new NettyHttpProducer(this, getConfiguration(), getUriParameters());
+        Producer answer = new NettyHttpProducer(this, getConfiguration());
         if (isSynchronous()) {
             return new SynchronousDelegateProducer(answer);
         } else {
@@ -156,14 +155,6 @@ public class NettyHttpEndpoint extends NettyEndpoint implements HeaderFilterStra
         this.httpMethodRestrict = httpMethodRestrict;
     }
 
-    public String getUriParameters() {
-        return uriParameters;
-    }
-
-    public void setUriParameters(String uriParameters) {
-        this.uriParameters = uriParameters;
-    }
-
     public NettySharedHttpServer getNettySharedHttpServer() {
         return nettySharedHttpServer;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7b9e13e2/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 0d4de7b..da4615b 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
@@ -183,11 +183,8 @@ public final class NettyHttpHelper {
      * @param endpoint the endpoint
      * @return the URL to invoke
      */
-    public static String createURL(Exchange exchange, NettyHttpEndpoint endpoint, String
uriParameters) throws URISyntaxException {
+    public static String createURL(Exchange exchange, NettyHttpEndpoint endpoint) throws
URISyntaxException {
         String uri = endpoint.getEndpointUri();
-        if (uriParameters != null) {
-            uri += "?" + uriParameters;
-        }
 
         // resolve placeholders in uri
         try {

http://git-wip-us.apache.org/repos/asf/camel/blob/7b9e13e2/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
index 261c6f9..8a5ae2e 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
@@ -30,11 +30,8 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
  */
 public class NettyHttpProducer extends NettyProducer {
 
-    private final String uriParameters;
-
-    public NettyHttpProducer(NettyHttpEndpoint nettyEndpoint, NettyConfiguration configuration,
String uriParameters) {
+    public NettyHttpProducer(NettyHttpEndpoint nettyEndpoint, NettyConfiguration configuration)
{
         super(nettyEndpoint, configuration);
-        this.uriParameters = uriParameters;
     }
 
     @Override
@@ -55,7 +52,7 @@ public class NettyHttpProducer extends NettyProducer {
     @Override
     protected Object getRequestBody(Exchange exchange) throws Exception {
         // creating the url to use takes 2-steps
-        String uri = NettyHttpHelper.createURL(exchange, getEndpoint(), uriParameters);
+        String uri = NettyHttpHelper.createURL(exchange, getEndpoint());
         URI u = NettyHttpHelper.createURI(exchange, uri, getEndpoint());
 
         HttpRequest request = getEndpoint().getNettyHttpBinding().toNettyRequest(exchange.getIn(),
u.toString(), getConfiguration());

http://git-wip-us.apache.org/repos/asf/camel/blob/7b9e13e2/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSameHostDifferentParametersTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSameHostDifferentParametersTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSameHostDifferentParametersTest.java
new file mode 100644
index 0000000..e4f1fdb
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSameHostDifferentParametersTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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 NettyHttpSameHostDifferentParametersTest extends BaseNettyTest {
+
+    @Test
+    public void testTwoRoutes() throws Exception {
+        getMockEndpoint("mock:foo").expectedMessageCount(2);
+        getMockEndpoint("mock:foo").message(0).header("param1").isEqualTo("value1");
+        getMockEndpoint("mock:foo").message(1).header("param2").isEqualTo("value2");
+
+        String out = template.requestBody("netty-http:http://localhost:{{port}}/foo?param1=value1",
"Hello World", String.class);
+        assertEquals("param1=value1", out);
+
+        out = template.requestBody("netty-http:http://localhost:{{port}}/foo?param2=value2",
"Hello Camel", String.class);
+        assertEquals("param2=value2", out);
+
+        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")
+                    .to("mock:foo")
+                    .transform().header(Exchange.HTTP_QUERY);
+            }
+        };
+    }
+
+}


Mime
View raw message