From 21bfacef85b0b1124915508ead6baf7d03a86f15 Mon Sep 17 00:00:00 2001 From: Santiago Pericasgeertsen Date: Wed, 2 Aug 2023 13:06:30 -0400 Subject: [PATCH] Fixed ClientUri to extract query params when created from a URI. Signed-off-by: Santiago Pericasgeertsen --- .../io/helidon/nima/webclient/api/ClientUri.java | 7 +++++-- .../nima/webclient/api/ClientUriTest.java | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/nima/webclient/api/src/main/java/io/helidon/nima/webclient/api/ClientUri.java b/nima/webclient/api/src/main/java/io/helidon/nima/webclient/api/ClientUri.java index bfc948cc81a..3fe6d0e839d 100644 --- a/nima/webclient/api/src/main/java/io/helidon/nima/webclient/api/ClientUri.java +++ b/nima/webclient/api/src/main/java/io/helidon/nima/webclient/api/ClientUri.java @@ -191,8 +191,11 @@ public ClientUri resolve(URI uri) { uriBuilder.port(uri.getPort()); } - String uriPath = extractQuery(uri.getPath()); - uriBuilder.path(resolvePath(uriBuilder.path().path(), uriPath)); + uriBuilder.path(resolvePath(uriBuilder.path().path(), uri.getPath())); + + if (uri.getRawQuery() != null) { + query.fromQueryString(uri.getRawQuery()); + } if (uri.getRawFragment() != null) { uriBuilder.fragment(UriFragment.create(uri.getRawFragment())); diff --git a/nima/webclient/api/src/test/java/io/helidon/nima/webclient/api/ClientUriTest.java b/nima/webclient/api/src/test/java/io/helidon/nima/webclient/api/ClientUriTest.java index a3b1379d9fa..182c63672f1 100644 --- a/nima/webclient/api/src/test/java/io/helidon/nima/webclient/api/ClientUriTest.java +++ b/nima/webclient/api/src/test/java/io/helidon/nima/webclient/api/ClientUriTest.java @@ -19,7 +19,7 @@ import java.net.URI; import io.helidon.common.uri.UriPath; - +import io.helidon.common.uri.UriQueryWriteable; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; @@ -59,6 +59,20 @@ void testNonDefaults() { assertThat(helper.scheme(), is("http")); } + @Test + void testQueryParams() { + UriQueryWriteable query = UriQueryWriteable.create(); + query.fromQueryString("p1=v1&p2=v2&p3=%2F%2Fv3%2F%2F"); + ClientUri helper = ClientUri.create(URI.create("http://localhost:8080/loom/quick?" + query.value())); + + assertThat(helper.authority(), is("localhost:8080")); + assertThat(helper.host(), is("localhost")); + assertThat(helper.path(), is(UriPath.create("/loom/quick"))); + assertThat(helper.port(), is(8080)); + assertThat(helper.scheme(), is("http")); + assertThat(helper.query(), is(query)); + } + @Test void testResolvePath() { ClientUri helper = ClientUri.create(URI.create("http://localhost:8080/loom"));