Skip to content

Commit 167a866

Browse files
authored
Removes okhttp support (#1258)
Fixes gh-1205
1 parent 609fb4f commit 167a866

24 files changed

+14
-924
lines changed

docs/modules/ROOT/pages/spring-cloud-openfeign.adoc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,10 @@ If none of them is on the classpath, the default Feign client is used.
140140

141141
NOTE: `spring-cloud-starter-openfeign` supports `spring-cloud-starter-loadbalancer`. However, as is an optional dependency, you need to make sure it has been added to your project if you want to use it.
142142

143-
To use OkHttpClient-backed Feign clients and Http2Client Feign clients, make sure that the client you want to use is on the classpath and set `spring.cloud.openfeign.okhttp.enabled` or `spring.cloud.openfeign.http2client.enabled` to `true` respectively.
144-
145143
When it comes to the Apache HttpClient 5-backed Feign clients, it's enough to ensure HttpClient 5 is on the classpath, but you can still disable its use for Feign Clients by setting `spring.cloud.openfeign.httpclient.hc5.enabled` to `false`.
146144
You can customize the HTTP client used by providing a bean of either `org.apache.hc.client5.http.impl.classic.CloseableHttpClient` when using Apache HC5.
147145

148-
You can further customise http clients by setting values in the `spring.cloud.openfeign.httpclient.xxx` properties. The ones prefixed just with `httpclient` will work for all the clients, the ones prefixed with `httpclient.hc5` to Apache HttpClient 5, the ones prefixed with `httpclient.okhttp` to OkHttpClient and the ones prefixed with `httpclient.http2` to Http2Client. You can find a full list of properties you can customise in the appendix.
146+
You can further customise http clients by setting values in the `spring.cloud.openfeign.httpclient.xxx` properties. The ones prefixed just with `httpclient` will work for all the clients, the ones prefixed with `httpclient.hc5` to Apache HttpClient 5, and the ones prefixed with `httpclient.http2` to Http2Client. You can find a full list of properties you can customise in the appendix.
149147
If you can not configure Apache HttpClient 5 by using properties, there is an `HttpClient5FeignConfiguration.HttpClientBuilderCustomizer` interface for programmatic configuration.
150148

151149
TIP: Apache HTTP Components `5.4` have changed defaults in the HttpClient relating to HTTP/1.1 TLS upgrades. Most proxy servers handle upgrades without issue, however, you may encounter issues with Envoy or Istio. If you need to restore previous behaviour, you can use `HttpClient5FeignConfiguration.HttpClientBuilderCustomizer` to do it, as shown in the example below.
@@ -613,8 +611,6 @@ These properties allow you to be selective about the compressed media types and
613611
When the request matches the mime type set in `spring.cloud.openfeign.compression.request.mime-types` and the size set in `spring.cloud.openfeign.compression.request.min-request-size`, `spring.cloud.openfeign.compression.request.enabled=true` results in compression headers being added to the request.
614612
The functionality of the headers is to signal to the server that a compressed body is expected by the client. It is the responsibility of the server-side app to provide the compressed body based on the headers provided by the client.
615613

616-
TIP: Since the OkHttpClient uses "transparent" compression, that is disabled if the `content-encoding` or `accept-encoding` header is present, we do not enable compression when `feign.okhttp.OkHttpClient` is present on the classpath and `spring.cloud.openfeign.okhttp.enabled` is set to `true`.
617-
618614
[[feign-logging]]
619615
=== Feign logging
620616

docs/modules/ROOT/partials/_configprops.adoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,12 @@
9696
|spring.cloud.openfeign.httpclient.max-connections | `+++200+++` |
9797
|spring.cloud.openfeign.httpclient.max-connections-per-route | `+++50+++` |
9898
|spring.cloud.openfeign.httpclient.ok-http.protocols | | Configure the protocols used by this client to communicate with remote servers. Uses {@link String} values of {@link Protocol}.
99-
|spring.cloud.openfeign.httpclient.ok-http.read-timeout | `+++60s+++` | {@link OkHttpClient} read timeout; defaults to 60 seconds.
100-
|spring.cloud.openfeign.httpclient.time-to-live | `+++900+++` |
99+
|spring.cloud.openfeign.httpclient.time-to-live | `+++900+++` |
101100
|spring.cloud.openfeign.httpclient.time-to-live-unit | `+++seconds+++` |
102101
|spring.cloud.openfeign.lazy-attributes-resolution | `+++false+++` | Switches @FeignClient attributes resolution mode to lazy.
103102
|spring.cloud.openfeign.micrometer.enabled | `+++true+++` | Enables Micrometer capabilities for Feign.
104103
|spring.cloud.openfeign.oauth2.clientRegistrationId | | Provides a clientId to be used with OAuth2.
105104
|spring.cloud.openfeign.oauth2.enabled | `+++false+++` | Enables feign interceptor for managing oauth2 access token.
106-
|spring.cloud.openfeign.okhttp.enabled | `+++false+++` | Enables the use of the OK HTTP Client by Feign.
107105
|spring.cloud.refresh.additional-property-sources-to-retain | | Additional property sources to retain during a refresh. Typically only system property sources are retained. This property allows property sources, such as property sources created by EnvironmentPostProcessors to be retained as well.
108106
|spring.cloud.refresh.enabled | `+++true+++` | Enables autoconfiguration for the refresh scope and associated features.
109107
|spring.cloud.refresh.extra-refreshable | `+++true+++` | Additional bean names or class names for beans to post process into refresh scope.
@@ -114,4 +112,4 @@
114112
|spring.cloud.service-registry.auto-registration.register-management | `+++true+++` | Whether to register the management as a service. Defaults to true.
115113
|spring.cloud.util.enabled | `+++true+++` | Enables creation of Spring Cloud utility beans.
116114

117-
|===
115+
|===

spring-cloud-openfeign-core/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,11 @@
134134
<artifactId>feign-hc5</artifactId>
135135
<optional>true</optional>
136136
</dependency>
137-
<dependency>
138-
<groupId>io.github.openfeign</groupId>
139-
<artifactId>feign-okhttp</artifactId>
140-
<optional>true</optional>
141-
</dependency>
142137
<dependency>
143138
<groupId>io.github.openfeign</groupId>
144139
<artifactId>feign-java11</artifactId>
145140
<optional>true</optional>
146141
</dependency>
147-
<dependency>
148-
<groupId>com.squareup.okhttp3</groupId>
149-
<artifactId>okhttp</artifactId>
150-
<optional>true</optional>
151-
</dependency>
152142
<dependency>
153143
<groupId>org.springframework.boot</groupId>
154144
<artifactId>spring-boot-autoconfigure-processor</artifactId>

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,9 @@
1818

1919
import java.lang.reflect.Method;
2020
import java.net.http.HttpClient;
21-
import java.security.KeyManagementException;
22-
import java.security.NoSuchAlgorithmException;
23-
import java.security.cert.X509Certificate;
24-
import java.time.Duration;
2521
import java.util.ArrayList;
2622
import java.util.List;
2723
import java.util.Set;
28-
import java.util.concurrent.TimeUnit;
29-
import java.util.stream.Collectors;
30-
31-
import javax.net.ssl.HostnameVerifier;
32-
import javax.net.ssl.SSLContext;
33-
import javax.net.ssl.SSLSession;
34-
import javax.net.ssl.SSLSocketFactory;
35-
import javax.net.ssl.TrustManager;
36-
import javax.net.ssl.X509TrustManager;
3724

3825
import feign.Capability;
3926
import feign.Client;
@@ -42,10 +29,6 @@
4229
import feign.Target;
4330
import feign.hc5.ApacheHttp5Client;
4431
import feign.http2client.Http2Client;
45-
import feign.okhttp.OkHttpClient;
46-
import jakarta.annotation.PreDestroy;
47-
import okhttp3.ConnectionPool;
48-
import okhttp3.Protocol;
4932
import org.apache.commons.logging.Log;
5033
import org.apache.commons.logging.LogFactory;
5134

@@ -231,121 +214,6 @@ public String resolveCircuitBreakerName(String feignClientName, Target<?> target
231214

232215
}
233216

234-
// the following configuration is for alternate feign clients if
235-
// SC loadbalancer is not on the class path.
236-
// see corresponding configurations in FeignLoadBalancerAutoConfiguration
237-
// for load-balanced clients.
238-
@Configuration(proxyBeanMethods = false)
239-
@ConditionalOnClass(OkHttpClient.class)
240-
@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)
241-
@ConditionalOnProperty("spring.cloud.openfeign.okhttp.enabled")
242-
protected static class OkHttpFeignConfiguration {
243-
244-
private okhttp3.OkHttpClient okHttpClient;
245-
246-
@Bean
247-
@ConditionalOnMissingBean
248-
public okhttp3.OkHttpClient.Builder okHttpClientBuilder() {
249-
return new okhttp3.OkHttpClient.Builder();
250-
}
251-
252-
@Bean
253-
@ConditionalOnMissingBean(ConnectionPool.class)
254-
public ConnectionPool httpClientConnectionPool(FeignHttpClientProperties httpClientProperties) {
255-
int maxTotalConnections = httpClientProperties.getMaxConnections();
256-
long timeToLive = httpClientProperties.getTimeToLive();
257-
TimeUnit ttlUnit = httpClientProperties.getTimeToLiveUnit();
258-
return new ConnectionPool(maxTotalConnections, timeToLive, ttlUnit);
259-
}
260-
261-
@Bean
262-
public okhttp3.OkHttpClient okHttpClient(okhttp3.OkHttpClient.Builder builder, ConnectionPool connectionPool,
263-
FeignHttpClientProperties httpClientProperties) {
264-
boolean followRedirects = httpClientProperties.isFollowRedirects();
265-
int connectTimeout = httpClientProperties.getConnectionTimeout();
266-
boolean disableSslValidation = httpClientProperties.isDisableSslValidation();
267-
Duration readTimeout = httpClientProperties.getOkHttp().getReadTimeout();
268-
List<Protocol> protocols = httpClientProperties.getOkHttp()
269-
.getProtocols()
270-
.stream()
271-
.map(Protocol::valueOf)
272-
.collect(Collectors.toList());
273-
if (disableSslValidation) {
274-
disableSsl(builder);
275-
}
276-
this.okHttpClient = builder.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
277-
.followRedirects(followRedirects)
278-
.readTimeout(readTimeout)
279-
.connectionPool(connectionPool)
280-
.protocols(protocols)
281-
.build();
282-
return this.okHttpClient;
283-
}
284-
285-
private void disableSsl(okhttp3.OkHttpClient.Builder builder) {
286-
try {
287-
X509TrustManager disabledTrustManager = new DisableValidationTrustManager();
288-
TrustManager[] trustManagers = new TrustManager[1];
289-
trustManagers[0] = disabledTrustManager;
290-
SSLContext sslContext = SSLContext.getInstance("SSL");
291-
sslContext.init(null, trustManagers, new java.security.SecureRandom());
292-
SSLSocketFactory disabledSSLSocketFactory = sslContext.getSocketFactory();
293-
builder.sslSocketFactory(disabledSSLSocketFactory, disabledTrustManager);
294-
builder.hostnameVerifier(new TrustAllHostnames());
295-
}
296-
catch (NoSuchAlgorithmException | KeyManagementException e) {
297-
LOG.warn("Error setting SSLSocketFactory in OKHttpClient", e);
298-
}
299-
}
300-
301-
@PreDestroy
302-
public void destroy() {
303-
if (this.okHttpClient != null) {
304-
this.okHttpClient.dispatcher().executorService().shutdown();
305-
this.okHttpClient.connectionPool().evictAll();
306-
}
307-
}
308-
309-
@Bean
310-
@ConditionalOnMissingBean(Client.class)
311-
public Client feignClient(okhttp3.OkHttpClient client) {
312-
return new OkHttpClient(client);
313-
}
314-
315-
/**
316-
* A {@link X509TrustManager} that does not validate SSL certificates.
317-
*/
318-
class DisableValidationTrustManager implements X509TrustManager {
319-
320-
@Override
321-
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
322-
}
323-
324-
@Override
325-
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
326-
}
327-
328-
@Override
329-
public X509Certificate[] getAcceptedIssuers() {
330-
return new X509Certificate[0];
331-
}
332-
333-
}
334-
335-
/**
336-
* A {@link HostnameVerifier} that does not validate any hostnames.
337-
*/
338-
class TrustAllHostnames implements HostnameVerifier {
339-
340-
@Override
341-
public boolean verify(String s, SSLSession sslSession) {
342-
return true;
343-
}
344-
345-
}
346-
347-
}
348-
349217
// the following configuration is for alternate feign clients if
350218
// SC loadbalancer is not on the class path.
351219
// see corresponding configurations in FeignLoadBalancerAutoConfiguration

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/encoding/FeignAcceptGzipEncodingAutoConfiguration.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2727
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
2828
import org.springframework.context.annotation.Bean;
29-
import org.springframework.context.annotation.Conditional;
3029
import org.springframework.context.annotation.Configuration;
3130

3231
/**
@@ -41,9 +40,6 @@
4140
@ConditionalOnClass(Feign.class)
4241
@ConditionalOnBean(Client.class)
4342
@ConditionalOnProperty("spring.cloud.openfeign.compression.response.enabled")
44-
// The OK HTTP client uses "transparent" compression.
45-
// If the accept-encoding header is present, it disables transparent compression.
46-
@Conditional(OkHttpFeignClientBeanMissingCondition.class)
4743
@AutoConfigureAfter(FeignAutoConfiguration.class)
4844
public class FeignAcceptGzipEncodingAutoConfiguration {
4945

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/encoding/FeignContentGzipEncodingAutoConfiguration.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2525
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
2626
import org.springframework.context.annotation.Bean;
27-
import org.springframework.context.annotation.Conditional;
2827
import org.springframework.context.annotation.Configuration;
2928

3029
/**
@@ -37,9 +36,6 @@
3736
@Configuration(proxyBeanMethods = false)
3837
@EnableConfigurationProperties(FeignClientEncodingProperties.class)
3938
@ConditionalOnClass(Feign.class)
40-
// The OK HTTP client uses "transparent" compression.
41-
// If the content-encoding header is present, it disables transparent compression.
42-
@Conditional(OkHttpFeignClientBeanMissingCondition.class)
4339
@ConditionalOnProperty("spring.cloud.openfeign.compression.request.enabled")
4440
@AutoConfigureAfter(FeignAutoConfiguration.class)
4541
public class FeignContentGzipEncodingAutoConfiguration {

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/encoding/OkHttpFeignClientBeanMissingCondition.java

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

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/FeignLoadBalancerAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
// Order is important here, last should be the default, first should be optional
5454
// see
5555
// https://github.com/spring-cloud/spring-cloud-netflix/issues/2086#issuecomment-316281653
56-
@Import({ OkHttpFeignLoadBalancerConfiguration.class, HttpClient5FeignLoadBalancerConfiguration.class,
57-
Http2ClientFeignLoadBalancerConfiguration.class, DefaultFeignLoadBalancerConfiguration.class })
56+
@Import({ HttpClient5FeignLoadBalancerConfiguration.class, Http2ClientFeignLoadBalancerConfiguration.class,
57+
DefaultFeignLoadBalancerConfiguration.class })
5858
public class FeignLoadBalancerAutoConfiguration {
5959

6060
@Bean

0 commit comments

Comments
 (0)