This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 285cb46  CAMEL-12966: camel-netty-http: use relative pat...
285cb46 is described below

commit 285cb4670456650822ce86cde101075a704923b1
Author: Zoran Regvart <[email protected]>
AuthorDate: Tue May 14 12:14:33 2019 +0200

    CAMEL-12966: camel-netty-http: use relative pat...
    
    ...h by default
    
    Changes the default value of `useRelativePath` component/endpoint
    property from `false` to `true`. The previous default value of `false`
    would only make sense if the HTTP request was issued towards a HTTP
    proxy (`absolute-form`) otherwise it would not be a valid request to
    issue against a HTTP server (requires `origin-form`).
    
    See https://tools.ietf.org/html/rfc7230#section-5.3
---
 .../component/netty4/http/DefaultNettyHttpBinding.java  | 16 ++++++++++++----
 .../component/netty4/http/NettyHttpConfiguration.java   |  6 +++---
 .../camel/component/netty4/http/NettyHttpProducer.java  | 17 ++++++++++-------
 .../component/netty4/http/NettyDefaultProtocolTest.java |  2 +-
 ...tyHttpBindingPreservePostFormUrlEncodedBodyTest.java |  2 +-
 ...vePath.java => NettyHttpBindingUseAbsolutePath.java} | 12 ++++++------
 .../netty4/http/NettyHttpBindingUseRelativePath.java    |  6 +++---
 .../component/netty4/http/NettyHttpContentTypeTest.java |  2 +-
 .../component/netty4/http/NettyHttpHeadersTest.java     |  2 +-
 .../netty4/http/NettyHttpProducerSimpleTest.java        |  2 +-
 .../netty4/http/NettyHttpProtocolNoSlashTest.java       |  2 +-
 11 files changed, 40 insertions(+), 29 deletions(-)

diff --git 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
index 077fb6f..630eae1 100644
--- 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
+++ 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
@@ -456,7 +456,7 @@ public class DefaultNettyHttpBinding implements 
NettyHttpBinding, Cloneable {
     }
 
     @Override
-    public HttpRequest toNettyRequest(Message message, String uri, 
NettyHttpConfiguration configuration) throws Exception {
+    public HttpRequest toNettyRequest(Message message, String fullUri, 
NettyHttpConfiguration configuration) throws Exception {
         LOG.trace("toNettyRequest: {}", message);
 
         // the message body may already be a Netty HTTP response
@@ -464,9 +464,17 @@ public class DefaultNettyHttpBinding implements 
NettyHttpBinding, Cloneable {
             return (HttpRequest) message.getBody();
         }
 
-        String uriForRequest = uri;
+        String uriForRequest = fullUri;
         if (configuration.isUseRelativePath()) {
-            uriForRequest = URISupport.pathAndQueryOf(new URI(uriForRequest));
+            final URI uri = new URI(uriForRequest);
+            final String rawPath = uri.getRawPath();
+            if (rawPath != null) {
+                uriForRequest = rawPath;
+            }
+            final String rawQuery = uri.getRawQuery();
+            if (rawQuery != null) {
+                uriForRequest += "?" + rawQuery;
+            }
         }
 
         // just assume GET for now, we will later change that to the actual 
method to use
@@ -552,7 +560,7 @@ public class DefaultNettyHttpBinding implements 
NettyHttpBinding, Cloneable {
 
         // must include HOST header as required by HTTP 1.1
         // use URI as its faster than URL (no DNS lookup)
-        URI u = new URI(uri);
+        URI u = new URI(fullUri);
         String hostHeader = u.getHost() + (u.getPort() == 80 ? "" : ":" + 
u.getPort());
         request.headers().set(HttpHeaderNames.HOST.toString(), hostHeader);
         LOG.trace("Host: {}", hostHeader);
diff --git 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConfiguration.java
 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConfiguration.java
index 91fd100..11ec3f4 100644
--- 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConfiguration.java
+++ 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConfiguration.java
@@ -65,8 +65,8 @@ public class NettyHttpConfiguration extends 
NettyConfiguration {
     private int maxHeaderSize = 8192;
     @UriParam(label = "producer,advanced", defaultValue = "200-299")
     private String okStatusCodeRange = "200-299";
-    @UriParam(label = "producer,advanced")
-    private boolean useRelativePath;
+    @UriParam(label = "producer,advanced", defaultValue = "true")
+    private boolean useRelativePath = true;
     
     public NettyHttpConfiguration() {
         // we need sync=true as http is request/reply by nature
@@ -316,6 +316,6 @@ public class NettyHttpConfiguration extends 
NettyConfiguration {
     }
 
     public boolean isUseRelativePath() {
-        return this.useRelativePath;        
+        return this.useRelativePath;
     }
 }
diff --git 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
index 686621e..0d821f0 100644
--- 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
+++ 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
@@ -29,6 +29,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.component.netty4.NettyConfiguration;
 import org.apache.camel.component.netty4.NettyConstants;
 import org.apache.camel.component.netty4.NettyProducer;
+import org.apache.camel.http.common.cookie.CookieHandler;
 import org.apache.camel.support.SynchronizationAdapter;
 
 
@@ -59,12 +60,13 @@ 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());
-        URI u = NettyHttpHelper.createURI(exchange, uri, getEndpoint());
+        final NettyHttpEndpoint endpoint = getEndpoint();
+        final String uri = NettyHttpHelper.createURL(exchange, endpoint);
+        final URI u = NettyHttpHelper.createURI(exchange, uri, endpoint);
 
-        final HttpRequest request = 
getEndpoint().getNettyHttpBinding().toNettyRequest(exchange.getIn(), 
u.toString(), getConfiguration());
-        String actualUri = request.uri();
-        exchange.getIn().setHeader(Exchange.HTTP_URL, actualUri);
+        final NettyHttpBinding nettyHttpBinding = 
endpoint.getNettyHttpBinding();
+        final HttpRequest request = 
nettyHttpBinding.toNettyRequest(exchange.getIn(), u.toString(), 
getConfiguration());
+        exchange.getIn().setHeader(Exchange.HTTP_URL, uri);
         // Need to check if we need to close the connection or not
         if (!HttpUtil.isKeepAlive(request)) {
             // just want to make sure we close the channel if the keepAlive is 
not true
@@ -75,8 +77,9 @@ public class NettyHttpProducer extends NettyProducer {
             exchange.getIn().removeHeader("host");
         }
 
-        if (getEndpoint().getCookieHandler() != null) {
-            Map<String, List<String>> cookieHeaders = 
getEndpoint().getCookieHandler().loadCookies(exchange, new URI(actualUri));
+        final CookieHandler cookieHandler = endpoint.getCookieHandler();
+        if (cookieHandler != null) {
+            Map<String, List<String>> cookieHeaders = 
cookieHandler.loadCookies(exchange, u);
             for (Map.Entry<String, List<String>> entry : 
cookieHeaders.entrySet()) {
                 String key = entry.getKey();
                 if (entry.getValue().size() > 0) {
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyDefaultProtocolTest.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyDefaultProtocolTest.java
index 7055686..38d2934 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyDefaultProtocolTest.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyDefaultProtocolTest.java
@@ -44,7 +44,7 @@ public class NettyDefaultProtocolTest extends BaseNettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("netty4-http:http:0.0.0.0:{{port}}/foo")
+                from("netty4-http:http:localhost:{{port}}/foo")
                         .to("mock:input")
                         .transform().constant("Bye World");
             }
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingPreservePostFormUrlEncodedBodyTest.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingPreservePostFormUrlEncodedBodyTest.java
index 8a65294..97e8568 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingPreservePostFormUrlEncodedBodyTest.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingPreservePostFormUrlEncodedBodyTest.java
@@ -60,7 +60,7 @@ public class 
NettyHttpBindingPreservePostFormUrlEncodedBodyTest extends BaseNett
 
                         NettyHttpMessage in = (NettyHttpMessage) 
exchange.getIn();
                         FullHttpRequest request = in.getHttpRequest();
-                        assertNotEquals("Relative path should NOT be used in 
POST", "/myapp/myservice?query1=a&query2=b", request.uri());
+                        assertEquals("Relative path should be used", 
"/myapp/myservice?query1=a&query2=b", request.uri());
 
                         // send a response
                         exchange.getOut().getHeaders().clear();
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseRelativePath.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseAbsolutePath.java
similarity index 92%
copy from 
components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseRelativePath.java
copy to 
components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseAbsolutePath.java
index 249d92f..6a66c47 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseRelativePath.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseAbsolutePath.java
@@ -24,11 +24,11 @@ import org.apache.camel.component.http4.HttpMethods;
 import org.junit.Test;
 
 
-public class NettyHttpBindingUseRelativePath extends BaseNettyTest {
+public class NettyHttpBindingUseAbsolutePath extends BaseNettyTest {
 
     @Test
     public void testSendToNettyWithPath() throws Exception {
-        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}/mypath?useRelativePath=true";,
 new Processor() {
+        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}/mypath?useRelativePath=false";,
 new Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(Exchange.HTTP_METHOD, 
HttpMethods.POST);
             }
@@ -41,7 +41,7 @@ public class NettyHttpBindingUseRelativePath extends 
BaseNettyTest {
 
     @Test
     public void testSendToNettyWithoutPath() throws Exception {
-        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}?useRelativePath=true";, 
new Processor() {
+        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}?useRelativePath=false";, 
new Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(Exchange.HTTP_METHOD, 
HttpMethods.POST);
             }
@@ -54,7 +54,7 @@ public class NettyHttpBindingUseRelativePath extends 
BaseNettyTest {
 
     @Test
     public void testSendToNettyWithoutPath2() throws Exception {
-        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}/?useRelativePath=true";, 
new Processor() {
+        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}/?useRelativePath=false";,
 new Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(Exchange.HTTP_METHOD, 
HttpMethods.POST);
             }
@@ -75,7 +75,7 @@ public class NettyHttpBindingUseRelativePath extends 
BaseNettyTest {
 
                         NettyHttpMessage in = (NettyHttpMessage) 
exchange.getIn();
                         FullHttpRequest request = in.getHttpRequest();
-                        assertEquals("Relative path not used in POST", 
"/mypath", request.uri());
+                        assertEquals("Relative path not used in POST", 
"http://localhost:"; + getPort() + "/mypath", request.uri());
 
                         // send a response
                         exchange.getOut().getHeaders().clear();
@@ -90,7 +90,7 @@ public class NettyHttpBindingUseRelativePath extends 
BaseNettyTest {
 
                         NettyHttpMessage in = (NettyHttpMessage) 
exchange.getIn();
                         FullHttpRequest request = in.getHttpRequest();
-                        assertEquals("Relative path not used in POST", "/", 
request.uri());
+                        assertEquals("Relative path not used in POST", 
"http://localhost:"; + getPort() + "/", request.uri());
 
                         // send a response
                         exchange.getOut().getHeaders().clear();
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseRelativePath.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseRelativePath.java
index 249d92f..552b958 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseRelativePath.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBindingUseRelativePath.java
@@ -28,7 +28,7 @@ public class NettyHttpBindingUseRelativePath extends 
BaseNettyTest {
 
     @Test
     public void testSendToNettyWithPath() throws Exception {
-        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}/mypath?useRelativePath=true";,
 new Processor() {
+        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}/mypath";, new 
Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(Exchange.HTTP_METHOD, 
HttpMethods.POST);
             }
@@ -41,7 +41,7 @@ public class NettyHttpBindingUseRelativePath extends 
BaseNettyTest {
 
     @Test
     public void testSendToNettyWithoutPath() throws Exception {
-        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}?useRelativePath=true";, 
new Processor() {
+        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}";, new Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(Exchange.HTTP_METHOD, 
HttpMethods.POST);
             }
@@ -54,7 +54,7 @@ public class NettyHttpBindingUseRelativePath extends 
BaseNettyTest {
 
     @Test
     public void testSendToNettyWithoutPath2() throws Exception {
-        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}/?useRelativePath=true";, 
new Processor() {
+        Exchange exchange = 
template.request("netty4-http:http://localhost:{{port}}/";, new Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(Exchange.HTTP_METHOD, 
HttpMethods.POST);
             }
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpContentTypeTest.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpContentTypeTest.java
index f17d28a..d2dcae8 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpContentTypeTest.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpContentTypeTest.java
@@ -77,7 +77,7 @@ public class NettyHttpContentTypeTest extends BaseNettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("netty4-http:http://0.0.0.0:{{port}}/foo";)
+                from("netty4-http:http://localhost:{{port}}/foo";)
                     .to("mock:input")
                     .transform().constant("Bye World");
             }
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeadersTest.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeadersTest.java
index 7ee4593..5347fb5 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeadersTest.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeadersTest.java
@@ -44,7 +44,7 @@ public class NettyHttpHeadersTest extends BaseNettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("netty4-http:http://0.0.0.0:{{port}}/foo";)
+                from("netty4-http:http://localhost:{{port}}/foo";)
                     .to("mock:input")
                     .transform().constant("Bye World");
             }
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleTest.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleTest.java
index f14b7cb..e119641 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleTest.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleTest.java
@@ -64,7 +64,7 @@ public class NettyHttpProducerSimpleTest extends 
BaseNettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("netty4-http:http://0.0.0.0:{{port}}/foo";)
+                from("netty4-http:http://localhost:{{port}}/foo";)
                     .to("mock:input")
                     .transform().constant("Bye World");
             }
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProtocolNoSlashTest.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProtocolNoSlashTest.java
index b332b4f..7d14c11 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProtocolNoSlashTest.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProtocolNoSlashTest.java
@@ -44,7 +44,7 @@ public class NettyHttpProtocolNoSlashTest extends 
BaseNettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("netty4-http:http:0.0.0.0:{{port}}/foo")
+                from("netty4-http:http:localhost:{{port}}/foo")
                         .to("mock:input")
                         .transform().constant("Bye World");
             }

Reply via email to