Skip to content

Commit

Permalink
fix: list found httpclient implementations and output selected one
Browse files Browse the repository at this point in the history
Fixes #4935
  • Loading branch information
metacosm committed Mar 1, 2023
1 parent e1a316f commit 0cc5ae2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* Fix #4863: default HttpClient retry logic to 100ms interval
* Fix #4863: default HttpClient retry logic to 10 attempts
* Fix #4865: (java-generator) performance improvements
* Fix #4935: improve HTTP client implementation selection messages

#### Dependency Upgrade
* Fix #4655: Upgrade Fabric8 Kubernetes Model to Kubernetes v1.26.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import io.fabric8.kubernetes.client.http.HttpRequest;
import io.fabric8.kubernetes.client.http.Interceptor;
import io.fabric8.kubernetes.client.internal.SSLUtils;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -73,7 +75,6 @@ public void before(BasicBuilder builder, HttpRequest request, RequestTags tags)
private static final Pattern IPV4_PATTERN = Pattern.compile(
"(http://|https://)?(?<ipAddressOrSubnet>(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])(\\/([1-2]\\d|3[0-2]|\\d))?)(\\D+|$)");
private static final Pattern INVALID_HOST_PATTERN = Pattern.compile("[^\\da-zA-Z.\\-/:]+");
private static final AtomicBoolean MULTIPLE_HTTP_CLIENT_WARNING_LOGGED = new AtomicBoolean();

private HttpClientUtils() {
}
Expand Down Expand Up @@ -145,22 +146,27 @@ public static HttpClient.Factory getHttpClientFactory() {
"No httpclient implementations found on the context classloader, please ensure your classpath includes an implementation jar");
}
}
LOGGER.info("Using httpclient {} factory", factory.getClass().getName());
return factory;
}

private static HttpClient.Factory getFactory(ServiceLoader<HttpClient.Factory> loader) {
HttpClient.Factory factory = null;
List<String> detectedFactories = new ArrayList<>(7);
for (HttpClient.Factory possible : loader) {
if (factory != null && MULTIPLE_HTTP_CLIENT_WARNING_LOGGED.compareAndSet(false, true)) {
LOGGER.warn("There are multiple httpclient implementation in the classpath, "
+ "choosing the first non-default implementation. "
+ "You should exclude dependencies that aren't needed or use an explicit association of the HttpClient.Factory.");
}
detectedFactories.add(possible.getClass().getName());
if (factory == null || (factory.isDefault() && !possible.isDefault())
|| (!factory.isDefault()) && factory.priority() < possible.priority()) {
factory = possible;
}
}

if(detectedFactories.size() > 1) {
LOGGER.warn("The following httpclient factories were detected on your classpath: {}, "
+ "choosing the first non-default implementation. "
+ "You should exclude dependencies that aren't needed or use an explicit association of the HttpClient.Factory.",
detectedFactories);
}
return factory;
}

Expand Down

0 comments on commit 0cc5ae2

Please sign in to comment.