Commit 966e03ba by Jakub Narloch Committed by Spencer Gibb

Feign OkHttp client configuration

parent 22f4b82e
......@@ -287,6 +287,11 @@
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>${hystrix.version}</version>
......@@ -364,6 +369,11 @@
<version>${spring-integration-dsl.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
......
......@@ -117,6 +117,11 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-okhttp</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<optional>true</optional>
......@@ -177,6 +182,11 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<!-- Only needed at compile time -->
......
......@@ -33,6 +33,7 @@ import com.netflix.loadbalancer.ILoadBalancer;
import feign.Client;
import feign.Feign;
import feign.httpclient.ApacheHttpClient;
import feign.okhttp.OkHttpClient;
/**
* Autoconfiguration to be activated if Feign is in use and needs to be use Ribbon as a
......@@ -81,4 +82,28 @@ public class FeignRibbonClientAutoConfiguration {
return new LoadBalancerFeignClient(delegate, this.cachingFactory);
}
}
@Configuration
@ConditionalOnClass(OkHttpClient.class)
@ConditionalOnProperty(value = "feign.okhttp.enabled", matchIfMissing = true)
protected static class OkHttpConfiguration {
@Autowired(required = false)
private com.squareup.okhttp.OkHttpClient okHttpClient;
@Autowired
CachingSpringLoadBalancerFactory cachingFactory;
@Bean
public Client feignClient() {
OkHttpClient delegate;
if (this.okHttpClient != null) {
delegate = new OkHttpClient(this.okHttpClient);
}
else {
delegate = new OkHttpClient();
}
return new LoadBalancerFeignClient(delegate, this.cachingFactory);
}
}
}
\ No newline at end of file
......@@ -74,7 +74,7 @@ import feign.RequestTemplate;
@WebIntegrationTest(randomPort = true, value = {
"spring.application.name=feignclienttest",
"logging.level.org.springframework.cloud.netflix.feign.valid=DEBUG",
"feign.httpclient.enabled=false"})
"feign.httpclient.enabled=false", "feign.okhttp.enabled=false"})
@DirtiesContext
public class FeignClientTests {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment