You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2023/12/06 20:21:28 UTC

(cxf) 06/07: [CXF-8965] Apache CXF Netty Integration, URI not encoded (#1552)

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

reta pushed a commit to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 0a6e064328ff25df422eb4daa99cd69b55786490
Author: wilhelmjochen <14...@users.noreply.github.com>
AuthorDate: Wed Dec 6 20:41:55 2023 +0100

    [CXF-8965] Apache CXF Netty Integration, URI not encoded (#1552)
    
    * [CXF-8965] Apache CXF Netty Integration, URI not encoded
    
    * [CXF-8965] Apache CXF Netty Integration, URI not encoded
    
    * Add integration test cases for encoded HTTP paths
    
    ---------
    
    Co-authored-by: Andriy Redko <dr...@gmail.com>
    (cherry picked from commit fce94b856c9d4060285bc0a6758b20ee0e957c62)
    (cherry picked from commit 835672d0650bda1031ebfcab8f8f5e63c5d294c0)
    
    # Conflicts:
    #       rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientRequest.java
---
 .../http/netty/client/NettyHttpClientRequest.java  |  3 +-
 .../netty/client/NettyHttpClientRequestTest.java   | 44 ++++++++++++++++++++++
 .../http2/AbstractApacheClientServerHttp2Test.java | 27 +++++++++++++
 .../apache/cxf/systest/hc5/http2/BookStore.java    |  9 ++++-
 .../netty/AbstractNettyClientServerHttp2Test.java  | 27 +++++++++++++
 .../apache/cxf/systest/http2/netty/BookStore.java  |  9 ++++-
 6 files changed, 116 insertions(+), 3 deletions(-)

diff --git a/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientRequest.java b/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientRequest.java
index 5e935623c9..8d1e1c32a4 100644
--- a/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientRequest.java
+++ b/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientRequest.java
@@ -55,7 +55,8 @@ public class NettyHttpClientRequest {
         this.request  =
             new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                                        HttpMethod.valueOf(method),
-                                       uri.getPath().toString(), content);
+                                       uri.getRawPath(), content);
+
         // setup the default headers
         request.headers().set("Connection", "keep-alive");
         request.headers().set("Host", uri.getHost() + ":"
diff --git a/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientRequestTest.java b/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientRequestTest.java
new file mode 100644
index 0000000000..78b286aa92
--- /dev/null
+++ b/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientRequestTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.cxf.transport.http.netty.client;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.buffer.EmptyByteBuf;
+import io.netty.handler.codec.http.HttpRequest;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NettyHttpClientRequestTest {
+
+    @Test
+    public void testCreateRequest() throws URISyntaxException {
+
+        URI uri = new URI("http://localhost:8080/my%20path");
+        NettyHttpClientRequest nettyHttpClientRequest = new NettyHttpClientRequest(uri, "GET", false);
+        nettyHttpClientRequest.createRequest(new EmptyByteBuf(ByteBufAllocator.DEFAULT));
+
+        HttpRequest httpRequest = nettyHttpClientRequest.getRequest();
+        Assert.assertEquals("/my%20path", httpRequest.uri());
+        Assert.assertEquals("/my path", uri.getPath());
+    }
+}
\ No newline at end of file
diff --git a/systests/transport-hc5/src/test/java/org/apache/cxf/systest/hc5/http2/AbstractApacheClientServerHttp2Test.java b/systests/transport-hc5/src/test/java/org/apache/cxf/systest/hc5/http2/AbstractApacheClientServerHttp2Test.java
index 9da63c85e2..2182a4ef79 100644
--- a/systests/transport-hc5/src/test/java/org/apache/cxf/systest/hc5/http2/AbstractApacheClientServerHttp2Test.java
+++ b/systests/transport-hc5/src/test/java/org/apache/cxf/systest/hc5/http2/AbstractApacheClientServerHttp2Test.java
@@ -79,6 +79,21 @@ abstract class AbstractApacheClientServerHttp2Test extends AbstractBusClientServ
         client.close();
     }
 
+    @Test
+    public void testBookEncodedWithHttp2() throws Exception {
+        final WebClient client = createWebClient("/web/bookstore/book%20names", true);
+        assertThat(WebClient.getConfig(client).getHttpConduit(), instanceOf(AsyncHTTPConduit.class));
+        
+        final Response response = client
+            .accept("text/plain")
+            .get();
+        
+        assertThat(response.getStatus(), equalTo(200));
+        assertEquals("CXF in Action", response.readEntity(String.class));
+
+        client.close();
+    }
+
     @Test
     public void testGetBookStreamHttp2() throws Exception {
         final WebClient client = createWebClient("/web/bookstore/bookstream", true);
@@ -107,6 +122,18 @@ abstract class AbstractApacheClientServerHttp2Test extends AbstractBusClientServ
         client.close();
     }
 
+    @Test
+    public void testBookEncodedWithHttp() throws Exception {
+        final WebClient client = createWebClient("/web/bookstore/book%20names", false);
+        
+        try (Response resp = client.get()) {
+            assertThat(resp.getStatus(), equalTo(200));
+            assertEquals("CXF in Action", resp.readEntity(String.class));
+        }
+        
+        client.close();
+    }
+
     @Test
     public void testBookTraceWithHttp() throws Exception {
         final WebClient client = createWebClient("/web/bookstore/trace", false);
diff --git a/systests/transport-hc5/src/test/java/org/apache/cxf/systest/hc5/http2/BookStore.java b/systests/transport-hc5/src/test/java/org/apache/cxf/systest/hc5/http2/BookStore.java
index e67dd40e97..b068a8da64 100644
--- a/systests/transport-hc5/src/test/java/org/apache/cxf/systest/hc5/http2/BookStore.java
+++ b/systests/transport-hc5/src/test/java/org/apache/cxf/systest/hc5/http2/BookStore.java
@@ -36,7 +36,14 @@ public class BookStore {
     @GET
     @Path("/booknames")
     @Produces("text/plain")
-    public byte[] getBookName() {
+    public byte[] getBookNames() {
+        return "CXF in Action".getBytes();
+    }
+
+    @GET
+    @Path("/book names")
+    @Produces("text/plain")
+    public byte[] getBookNamesEncoded() {
         return "CXF in Action".getBytes();
     }
 
diff --git a/systests/transport-netty/src/test/java/org/apache/cxf/systest/http2/netty/AbstractNettyClientServerHttp2Test.java b/systests/transport-netty/src/test/java/org/apache/cxf/systest/http2/netty/AbstractNettyClientServerHttp2Test.java
index c9917426cc..900b9e2078 100644
--- a/systests/transport-netty/src/test/java/org/apache/cxf/systest/http2/netty/AbstractNettyClientServerHttp2Test.java
+++ b/systests/transport-netty/src/test/java/org/apache/cxf/systest/http2/netty/AbstractNettyClientServerHttp2Test.java
@@ -78,6 +78,21 @@ abstract class AbstractNettyClientServerHttp2Test extends AbstractBusClientServe
         client.close();
     }
 
+    @Test
+    public void testBookEncodedWithHttp2() throws Exception {
+        final WebClient client = createWebClient("/web/bookstore/book%20names", true);
+        assertThat(WebClient.getConfig(client).getHttpConduit(), instanceOf(NettyHttpConduit.class));
+        
+        final Response response = client
+            .accept("text/plain")
+            .get();
+        
+        assertThat(response.getStatus(), equalTo(200));
+        assertEquals("CXF in Action", response.readEntity(String.class));
+
+        client.close();
+    }
+
     @Test
     public void testGetBookStreamHttp2() throws Exception {
         final WebClient client = createWebClient("/web/bookstore/bookstream", true);
@@ -106,6 +121,18 @@ abstract class AbstractNettyClientServerHttp2Test extends AbstractBusClientServe
         client.close();
     }
 
+    @Test
+    public void testBookEncodedWithHttp() throws Exception {
+        final WebClient client = createWebClient("/web/bookstore/book%20names", false);
+        
+        try (Response resp = client.get()) {
+            assertThat(resp.getStatus(), equalTo(200));
+            assertEquals("CXF in Action", resp.readEntity(String.class));
+        }
+        
+        client.close();
+    }
+
     @Test
     public void testBookTraceWithHttp() throws Exception {
         final WebClient client = createWebClient("/web/bookstore/trace", false);
diff --git a/systests/transport-netty/src/test/java/org/apache/cxf/systest/http2/netty/BookStore.java b/systests/transport-netty/src/test/java/org/apache/cxf/systest/http2/netty/BookStore.java
index 4715c02520..5c3204eced 100644
--- a/systests/transport-netty/src/test/java/org/apache/cxf/systest/http2/netty/BookStore.java
+++ b/systests/transport-netty/src/test/java/org/apache/cxf/systest/http2/netty/BookStore.java
@@ -40,7 +40,14 @@ public class BookStore {
     @GET
     @Path("/booknames")
     @Produces("text/plain")
-    public byte[] getBookName() {
+    public byte[] getBookNames() {
+        return "CXF in Action".getBytes();
+    }
+
+    @GET
+    @Path("/book names")
+    @Produces("text/plain")
+    public byte[] getBookNamesEncoded() {
         return "CXF in Action".getBytes();
     }