Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass CxfClientInfo to VertxHttpClientConduit to allow implememting support for more configuration options #1672

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -71,15 +72,17 @@ 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);
}
},
@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);
}
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -198,7 +203,7 @@ protected void setupConnection(Message message, Address address, HTTPClientPolic
}

final RequestContext requestContext = new RequestContext(
configKey,
clientInfo,
uri,
requestOptions,
clientParameters != null
Expand Down Expand Up @@ -253,7 +258,7 @@ protected OutputStream createOutputStream(
incomingObserver);

final IOEHandler<RequestBodyEvent> requestBodyHandler = new RequestBodyHandler(
requestContext.configKey,
requestContext.clientInfo,
message,
requestContext.uri,
cookies,
Expand Down Expand Up @@ -343,7 +348,7 @@ public void setTlsClientParameters(TLSClientParameters params) {
}

static record RequestContext(
String configKey,
CXFClientInfo clientInfo,
URI uri,
RequestOptions requestOptions,
ClientSpec clientSpec,
Expand Down Expand Up @@ -451,7 +456,7 @@ static class RequestBodyHandler implements IOEHandler<RequestBodyEvent> {
private List<Buffer> bodyRecorder;
private List<URI> redirects;
private final int maxRetransmits;
private final String configKey;
private final CXFClientInfo clientInfo;

/* Locks and conditions */
private final ReentrantLock lock = new ReentrantLock();
Expand All @@ -464,7 +469,7 @@ static class RequestBodyHandler implements IOEHandler<RequestBodyEvent> {
private Mode mode;

public RequestBodyHandler(
String configKey,
CXFClientInfo clientInfo,
Message outMessage,
URI url,
Cookies cookies,
Expand All @@ -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;
Expand Down Expand Up @@ -621,14 +626,16 @@ 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."
+ qKey + ".redirect-relative-uri = true");
}
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);
Expand All @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading