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/03/18 19:40:02 UTC

[cxf] branch main updated: CXF-8822: AsyncHTTPConduit removes query-parameters when path is empty (#1158)

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

reta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/main by this push:
     new 3b0690f458 CXF-8822: AsyncHTTPConduit removes query-parameters when path is empty (#1158)
3b0690f458 is described below

commit 3b0690f4587789d9e33f403713bc57f8b2f836f1
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sat Mar 18 15:39:54 2023 -0400

    CXF-8822: AsyncHTTPConduit removes query-parameters when path is empty (#1158)
---
 .../http/asyncclient/AsyncHTTPConduit.java         | 12 +++++--
 .../http/asyncclient/AsyncHTTPConduitTest.java     | 39 +++++++++++++++++++++
 .../http/asyncclient/hc5/AsyncHTTPConduit.java     | 13 +++++--
 .../http/asyncclient/hc5/AsyncHTTPConduitTest.java | 40 ++++++++++++++++++++++
 4 files changed, 99 insertions(+), 5 deletions(-)

diff --git a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
index 7bb6978bbe..848e98b873 100755
--- a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
+++ b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
@@ -190,9 +190,17 @@ public class AsyncHTTPConduit extends HttpClientHTTPConduit {
             super.setupConnection(message, addressChanged ? new Address(uriString, uri) : address, csPolicy);
             return;
         }
+
         if (StringUtils.isEmpty(uri.getPath())) {
-            //hc needs to have the path be "/"
-            uri = uri.resolve("/");
+            try {
+                //hc needs to have the path be "/"
+                uri = new URI(uri.getScheme(),
+                    uri.getUserInfo(), uri.getHost(), uri.getPort(),
+                    uri.resolve("/").getPath(), uri.getQuery(),
+                    uri.getFragment());
+            } catch (final URISyntaxException ex) {
+                throw new IOException(ex);
+            }
         }
 
         message.put(USE_ASYNC, Boolean.TRUE);
diff --git a/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
index e92fce2f32..29bcca1ef1 100644
--- a/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
+++ b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.transport.http.asyncclient;
 
+import java.io.IOException;
 import java.net.URL;
 import java.util.Collections;
 import java.util.concurrent.CountDownLatch;
@@ -36,6 +37,9 @@ import org.apache.cxf.continuations.ContinuationProvider;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.cxf.transport.http.HTTPConduitFactory;
@@ -473,4 +477,39 @@ public class AsyncHTTPConduitTest extends AbstractBusClientServerTestBase {
         System.out.println("Total: " + (end - start) + " " + rlatch.getCount());
     }
 
+    @Test
+    public void testPathWithQueryParams() throws IOException {
+        final String address = "http://localhost:" + PORT + "/SoapContext/SoapPort?param1=value1&param2=value2";
+        final Greeter greeter = new SOAPService().getSoapPort();
+        setAddress(greeter, address);
+
+        final HTTPConduit c = (HTTPConduit)ClientProxy.getClient(greeter).getConduit();
+        final MessageImpl message = new MessageImpl();
+        message.put(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
+
+        final Exchange exchange = new ExchangeImpl();
+        message.setExchange(exchange);
+        c.prepare(message);
+
+        final CXFHttpRequest e = message.get(CXFHttpRequest.class);
+        assertEquals(address, e.getURI().toString());
+    }
+
+    @Test
+    public void testEmptyPathWithQueryParams() throws IOException {
+        final String address = "http://localhost:" + PORT + "?param1=value1&param2=value2";
+        final Greeter greeter = new SOAPService().getSoapPort();
+        setAddress(greeter, address);
+
+        final HTTPConduit c = (HTTPConduit)ClientProxy.getClient(greeter).getConduit();
+        final MessageImpl message = new MessageImpl();
+        message.put(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
+
+        final Exchange exchange = new ExchangeImpl();
+        message.setExchange(exchange);
+        c.prepare(message);
+
+        final CXFHttpRequest e = message.get(CXFHttpRequest.class);
+        assertEquals("http://localhost:" + PORT + "/?param1=value1&param2=value2", e.getURI().toString());
+    }
 }
diff --git a/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduit.java b/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduit.java
index 626c7058ae..1e05f6fa8c 100644
--- a/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduit.java
+++ b/rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduit.java
@@ -201,10 +201,17 @@ public class AsyncHTTPConduit extends HttpClientHTTPConduit {
             super.setupConnection(message, addressChanged ? new Address(uriString, uri) : address, csPolicy);
             return;
         }
-        
+
         if (StringUtils.isEmpty(uri.getPath())) {
-            //hc needs to have the path be "/"
-            uri = uri.resolve("/");
+            try {
+                //hc needs to have the path be "/"
+                uri = new URI(uri.getScheme(),
+                    uri.getUserInfo(), uri.getHost(), uri.getPort(),
+                    uri.resolve("/").getPath(), uri.getQuery(),
+                    uri.getFragment());
+            } catch (final URISyntaxException ex) {
+                throw new IOException(ex);
+            }
         }
 
         message.put(USE_ASYNC, Boolean.TRUE);
diff --git a/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduitTest.java b/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduitTest.java
index 4cb6fd6d01..091cbe41bf 100644
--- a/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduitTest.java
+++ b/rt/transports/http-hc5/src/test/java/org/apache/cxf/transport/http/asyncclient/hc5/AsyncHTTPConduitTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.transport.http.asyncclient.hc5;
 
+import java.io.IOException;
 import java.net.URL;
 import java.util.Collections;
 import java.util.concurrent.CountDownLatch;
@@ -37,6 +38,9 @@ import org.apache.cxf.continuations.ContinuationProvider;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.cxf.transport.http.HTTPConduitFactory;
@@ -334,4 +338,40 @@ public class AsyncHTTPConduitTest extends AbstractBusClientServerTestBase {
 
         assertEquals("All responses should be handled eventually", 0, doneLatch.getCount());
     }
+
+    @Test
+    public void testPathWithQueryParams() throws IOException {
+        final String address = "http://localhost:" + PORT + "/SoapContext/SoapPort?param1=value1&param2=value2";
+        final Greeter greeter = new SOAPService().getSoapPort();
+        setAddress(greeter, address);
+
+        final HTTPConduit c = (HTTPConduit)ClientProxy.getClient(greeter).getConduit();
+        final MessageImpl message = new MessageImpl();
+        message.put(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
+
+        final Exchange exchange = new ExchangeImpl();
+        message.setExchange(exchange);
+        c.prepare(message);
+
+        final CXFHttpRequest e = message.get(CXFHttpRequest.class);
+        assertEquals(address, e.getUri().toString());
+    }
+
+    @Test
+    public void testEmptyPathWithQueryParams() throws IOException {
+        final String address = "http://localhost:" + PORT + "?param1=value1&param2=value2";
+        final Greeter greeter = new SOAPService().getSoapPort();
+        setAddress(greeter, address);
+
+        final HTTPConduit c = (HTTPConduit)ClientProxy.getClient(greeter).getConduit();
+        final MessageImpl message = new MessageImpl();
+        message.put(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
+
+        final Exchange exchange = new ExchangeImpl();
+        message.setExchange(exchange);
+        c.prepare(message);
+
+        final CXFHttpRequest e = message.get(CXFHttpRequest.class);
+        assertEquals("http://localhost:" + PORT + "/?param1=value1&param2=value2", e.getUri().toString());
+    }
 }