From 96983fe5b58fd9e782af4ca2b74447e1e84c1ca2 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Sat, 28 Dec 2024 16:09:00 +0100 Subject: [PATCH] Pass CxfClientInfo to VertxHttpClientConduit to allow implememting support for more configuration options --- .../io/quarkiverse/cxf/HTTPConduitImpl.java | 13 +++++--- .../io/quarkiverse/cxf/HTTPConduitSpec.java | 2 +- .../cxf/QuarkusHTTPConduitFactory.java | 2 +- .../client/VertxHttpClientHTTPConduit.java | 31 ++++++++++++------- .../cxf/transport/http/hc5/Hc5Recorder.java | 4 ++- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/HTTPConduitImpl.java b/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/HTTPConduitImpl.java index 68e2da542..c4cc1dd62 100644 --- a/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/HTTPConduitImpl.java +++ b/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/HTTPConduitImpl.java @@ -48,9 +48,10 @@ public HTTPConduitImpl resolveDefault() { @ConfigDocEnumValue("VertxHttpClientHTTPConduitFactory") VertxHttpClientHTTPConduitFactory { @Override - public HTTPConduit createConduit(String configKey, HttpClientPool httpClientPool, Bus b, EndpointInfo localInfo, + public HTTPConduit createConduit(CXFClientInfo cxfClientInfo, HttpClientPool httpClientPool, Bus b, + EndpointInfo localInfo, EndpointReferenceType target) throws IOException { - return new VertxHttpClientHTTPConduit(configKey, b, localInfo, target, httpClientPool); + return new VertxHttpClientHTTPConduit(cxfClientInfo, b, localInfo, target, httpClientPool); } @Override @@ -71,7 +72,8 @@ public TLSClientParameters createTLSClientParameters(CXFClientInfo cxfClientInfo @ConfigDocEnumValue("HttpClientHTTPConduitFactory") HttpClientHTTPConduitFactory { @Override - public HTTPConduit createConduit(String configKey, HttpClientPool httpClientPool, Bus b, EndpointInfo localInfo, + public HTTPConduit createConduit(CXFClientInfo cxfClientInfo, HttpClientPool httpClientPool, Bus b, + EndpointInfo localInfo, EndpointReferenceType target) throws IOException { return new HttpClientHTTPConduit(b, localInfo, target); } @@ -79,7 +81,8 @@ public HTTPConduit createConduit(String configKey, HttpClientPool httpClientPool @ConfigDocEnumValue("URLConnectionHTTPConduitFactory") URLConnectionHTTPConduitFactory { @Override - public HTTPConduit createConduit(String configKey, HttpClientPool httpClientPool, Bus b, EndpointInfo localInfo, + public HTTPConduit createConduit(CXFClientInfo cxfClientInfo, HttpClientPool httpClientPool, Bus b, + EndpointInfo localInfo, EndpointReferenceType target) throws IOException { return new URLConnectionHTTPConduit(b, localInfo, target); } @@ -96,7 +99,7 @@ public static HTTPConduitImpl findDefaultHTTPConduitImpl() { } @Override - public HTTPConduit createConduit(String configKey, HttpClientPool httpClientPool, Bus b, EndpointInfo localInfo, + public HTTPConduit createConduit(CXFClientInfo cxfClientInfo, HttpClientPool httpClientPool, Bus b, EndpointInfo localInfo, EndpointReferenceType target) throws IOException { throw new IllegalStateException( diff --git a/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/HTTPConduitSpec.java b/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/HTTPConduitSpec.java index c36f077a6..1ef1a9e12 100644 --- a/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/HTTPConduitSpec.java +++ b/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/HTTPConduitSpec.java @@ -27,7 +27,7 @@ default HTTPConduitSpec resolveDefault() { return this; } - HTTPConduit createConduit(String configKey, HttpClientPool httpClientPool, Bus b, EndpointInfo localInfo, + HTTPConduit createConduit(CXFClientInfo cxfClientInfo, HttpClientPool httpClientPool, Bus b, EndpointInfo localInfo, EndpointReferenceType target) throws IOException; diff --git a/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/QuarkusHTTPConduitFactory.java b/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/QuarkusHTTPConduitFactory.java index 4004b6994..5e8cadd68 100644 --- a/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/QuarkusHTTPConduitFactory.java +++ b/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/QuarkusHTTPConduitFactory.java @@ -78,7 +78,7 @@ private HTTPConduit configure(HTTPConduitSpec httpConduitImpl, CXFClientInfo cxf EndpointInfo localInfo, EndpointReferenceType target) throws IOException { final HTTPConduit httpConduit = httpConduitImpl.createConduit( - cxfClientInfo.getConfigKey(), + cxfClientInfo, httpClientPool, b, localInfo, diff --git a/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/vertx/http/client/VertxHttpClientHTTPConduit.java b/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/vertx/http/client/VertxHttpClientHTTPConduit.java index 8f2407b21..0be1e52d3 100644 --- a/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/vertx/http/client/VertxHttpClientHTTPConduit.java +++ b/extensions/core/runtime/src/main/java/io/quarkiverse/cxf/vertx/http/client/VertxHttpClientHTTPConduit.java @@ -72,6 +72,7 @@ import org.eclipse.microprofile.context.ManagedExecutor; import org.jboss.logging.Logger; +import io.quarkiverse.cxf.CXFClientInfo; import io.quarkiverse.cxf.QuarkusCxfUtils; import io.quarkiverse.cxf.QuarkusTLSClientParameters; import io.quarkiverse.cxf.vertx.http.client.HttpClientPool.ClientSpec; @@ -110,13 +111,17 @@ public class VertxHttpClientHTTPConduit extends HTTPConduit { private final HttpClientPool httpClientPool; private final String userAgent; - private final String configKey; + private final CXFClientInfo clientInfo; - public VertxHttpClientHTTPConduit(String configKey, Bus b, EndpointInfo ei, EndpointReferenceType t, + public VertxHttpClientHTTPConduit( + CXFClientInfo clientInfo, + Bus b, + EndpointInfo ei, + EndpointReferenceType t, HttpClientPool httpClientPool) throws IOException { super(b, ei, t); - this.configKey = configKey; + this.clientInfo = clientInfo; this.httpClientPool = httpClientPool; this.userAgent = Version.getCompleteVersionString(); } @@ -198,7 +203,7 @@ protected void setupConnection(Message message, Address address, HTTPClientPolic } final RequestContext requestContext = new RequestContext( - configKey, + clientInfo, uri, requestOptions, clientParameters != null @@ -253,7 +258,7 @@ protected OutputStream createOutputStream( incomingObserver); final IOEHandler requestBodyHandler = new RequestBodyHandler( - requestContext.configKey, + requestContext.clientInfo, message, requestContext.uri, cookies, @@ -343,7 +348,7 @@ public void setTlsClientParameters(TLSClientParameters params) { } static record RequestContext( - String configKey, + CXFClientInfo clientInfo, URI uri, RequestOptions requestOptions, ClientSpec clientSpec, @@ -451,7 +456,7 @@ static class RequestBodyHandler implements IOEHandler { private List bodyRecorder; private List redirects; private final int maxRetransmits; - private final String configKey; + private final CXFClientInfo clientInfo; /* Locks and conditions */ private final ReentrantLock lock = new ReentrantLock(); @@ -464,7 +469,7 @@ static class RequestBodyHandler implements IOEHandler { private Mode mode; public RequestBodyHandler( - String configKey, + CXFClientInfo clientInfo, Message outMessage, URI url, Cookies cookies, @@ -478,7 +483,7 @@ public RequestBodyHandler( boolean possibleRetransmit, int maxRetransmits) { super(); - this.configKey = configKey; + this.clientInfo = clientInfo; this.outMessage = outMessage; this.url = url; this.cookies = cookies; @@ -621,7 +626,8 @@ void finishRequest(HttpClientRequest req, Buffer buffer) { if (loc != null && !loc.startsWith("http") && !MessageUtils.getContextualBoolean(outMessage, AUTO_REDIRECT_ALLOW_REL_URI)) { - final String qKey = QuarkusCxfUtils.quoteCongurationKeyIfNeeded(configKey); + final String qKey = QuarkusCxfUtils + .quoteCongurationKeyIfNeeded(clientInfo.getConfigKey()); throw new IOException( "Illegal relative redirect " + loc + " detected by client " + qKey + "; you may want to set quarkus.cxf.client." @@ -629,6 +635,7 @@ void finishRequest(HttpClientRequest req, Buffer buffer) { } final URI previousUri = redirects.get(redirects.size() - 1); final URI newUri = HttpUtils.resolveURIReference(previousUri, loc); + final String configKey = clientInfo.getConfigKey(); detectRedirectLoop(configKey, redirects, newUri, outMessage); redirects.add(newUri); checkAllowedRedirectUri(configKey, previousUri, newUri, outMessage); @@ -649,7 +656,7 @@ void finishRequest(HttpClientRequest req, Buffer buffer) { return; } else { if (!possibleRetransmit && isRedirect) { - final String qKey = QuarkusCxfUtils.quoteCongurationKeyIfNeeded(configKey); + final String qKey = QuarkusCxfUtils.quoteCongurationKeyIfNeeded(clientInfo.getConfigKey()); final IOException ioe = new IOException( "Received redirection status " + response.statusCode() + " from " + url + " by client " + qKey @@ -662,7 +669,7 @@ void finishRequest(HttpClientRequest req, Buffer buffer) { } if (possibleRetransmit && isRedirect && maxRetransmits >= 0 && maxRetransmits <= performedRetransmits(redirects)) { - final String qKey = QuarkusCxfUtils.quoteCongurationKeyIfNeeded(configKey); + final String qKey = QuarkusCxfUtils.quoteCongurationKeyIfNeeded(clientInfo.getConfigKey()); final IOException ioe = new IOException("Received redirection status " + response.statusCode() + " from " + redirects.get(redirects.size() - 1) + " by client " + qKey + ", but already performed maximum" diff --git a/extensions/transports-http-hc5/runtime/src/main/java/io/quarkiverse/cxf/transport/http/hc5/Hc5Recorder.java b/extensions/transports-http-hc5/runtime/src/main/java/io/quarkiverse/cxf/transport/http/hc5/Hc5Recorder.java index 9b116e6e1..073dce240 100644 --- a/extensions/transports-http-hc5/runtime/src/main/java/io/quarkiverse/cxf/transport/http/hc5/Hc5Recorder.java +++ b/extensions/transports-http-hc5/runtime/src/main/java/io/quarkiverse/cxf/transport/http/hc5/Hc5Recorder.java @@ -13,6 +13,7 @@ import org.apache.cxf.ws.addressing.EndpointReferenceType; import org.eclipse.microprofile.context.ManagedExecutor; +import io.quarkiverse.cxf.CXFClientInfo; import io.quarkiverse.cxf.HTTPConduitSpec; import io.quarkiverse.cxf.vertx.http.client.HttpClientPool; import io.quarkus.arc.Arc; @@ -48,7 +49,8 @@ public static class Hc5HTTPConduitImpl implements HTTPConduitSpec { private AsyncHTTPConduitFactory asyncHTTPConduitFactory; @Override - public HTTPConduit createConduit(String configKey, HttpClientPool httpClientPool, Bus b, EndpointInfo localInfo, + public HTTPConduit createConduit(CXFClientInfo cxfClientInfo, HttpClientPool httpClientPool, Bus b, + EndpointInfo localInfo, EndpointReferenceType target) throws IOException { AsyncHTTPConduitFactory factory;