Skip to content

Commit a8cd98c

Browse files
committed
Remove the fallback to URLConnection when SSL is disabled for REST Client
The fallback was originally added to get around limitation in Apache HTTP Client when SSL is completely disabled in native binaries. However we can get around these limitations in a more elegant manner in Quarkus (see quarkusio/quarkus#9773). By defaulting to Apache HTTP Client, things like HTTP Patch can be supported OOTB (see quarkusio/quarkus#9342).
1 parent a57be66 commit a8cd98c

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

resteasy-client-microprofile/src/main/java/org/jboss/resteasy/microprofile/client/RestClientBuilderImpl.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,8 @@ public class RestClientBuilderImpl implements RestClientBuilder {
6767
public static final MethodInjectionFilter METHOD_INJECTION_FILTER = new MethodInjectionFilter();
6868
public static final ClientHeadersRequestFilter HEADERS_REQUEST_FILTER = new ClientHeadersRequestFilter();
6969

70-
static boolean SSL_ENABLED = true;
7170
static ResteasyProviderFactory PROVIDER_FACTORY;
7271

73-
public static void setSslEnabled(boolean enabled) {
74-
SSL_ENABLED = enabled;
75-
}
76-
7772
public static void setProviderFactory(ResteasyProviderFactory providerFactory) {
7873
PROVIDER_FACTORY = providerFactory;
7974
}
@@ -260,13 +255,12 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
260255
resteasyClientBuilder.connectTimeout(connectTimeout, connectTimeoutUnit);
261256
}
262257

263-
if (!SSL_ENABLED) {
258+
if (useURLConnection()) {
264259
resteasyClientBuilder.httpEngine(new URLConnectionClientEngineBuilder().resteasyClientBuilder(resteasyClientBuilder).build());
265260
resteasyClientBuilder.sslContext(null);
266261
resteasyClientBuilder.trustStore(null);
267262
resteasyClientBuilder.keyStore(null, "");
268263
}
269-
270264
client = resteasyClientBuilder
271265
.build();
272266
client.register(AsyncInterceptorRxInvokerProvider.class);
@@ -287,6 +281,19 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
287281
return proxy;
288282
}
289283

284+
/**
285+
* Determines whether or not to default to using the URLConnection instead of the Apache HTTP Client.
286+
* If the {@code org.jboss.resteasy.microprofile.defaultToURLConnectionHttpClient} system property is {@code true},
287+
* then this method returns {@code true}. In all other cases it returns {@code false}
288+
*/
289+
private boolean useURLConnection() {
290+
if (useURLConnection == null) {
291+
String defaultToURLConnection = System.getProperty("org.jboss.resteasy.microprofile.defaultToURLConnectionHttpClient", "false");
292+
useURLConnection = defaultToURLConnection.toLowerCase().equals("true");
293+
}
294+
return useURLConnection;
295+
}
296+
290297
private Optional<InetSocketAddress> selectHttpProxy() {
291298
return ProxySelector.getDefault().select(baseURI).stream()
292299
.filter(proxy -> proxy.type() == java.net.Proxy.Type.HTTP)
@@ -622,6 +629,7 @@ ResteasyClientBuilder getBuilderDelegate() {
622629
private KeyStore keyStore;
623630
private String keystorePassword;
624631
private HostnameVerifier hostnameVerifier;
632+
private Boolean useURLConnection;
625633

626634

627635
private Set<Object> localProviderInstances = new HashSet<>();

resteasy-client-microprofile/src/test/java/org/jboss/resteasy/microprofile/client/SslTest.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)