diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsConfiguration.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsConfiguration.java index 0f065be0..883ba736 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsConfiguration.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsConfiguration.java @@ -59,19 +59,19 @@ public class FeignClientsConfiguration { @Bean @ConditionalOnMissingBean public Decoder feignDecoder() { - return new ResponseEntityDecoder(new SpringDecoder(messageConverters)); + return new ResponseEntityDecoder(new SpringDecoder(this.messageConverters)); } @Bean @ConditionalOnMissingBean public Encoder feignEncoder() { - return new SpringEncoder(messageConverters); + return new SpringEncoder(this.messageConverters); } @Bean @ConditionalOnMissingBean public Contract feignContract() { - return new SpringMvcContract(parameterProcessors); + return new SpringMvcContract(this.parameterProcessors); } @Configuration @@ -101,9 +101,10 @@ public class FeignClientsConfiguration { private HttpClient httpClient; @ConditionalOnMissingBean + @Bean public Client feignClient() { - if (httpClient != null) { - return new ApacheHttpClient(httpClient); + if (this.httpClient != null) { + return new ApacheHttpClient(this.httpClient); } return new ApacheHttpClient(); } diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignLoadBalancer.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignLoadBalancer.java index 24b7fb23..2547180a 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignLoadBalancer.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignLoadBalancer.java @@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.feign.ribbon; import java.io.IOException; import java.net.URI; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.Map; import org.springframework.cloud.netflix.ribbon.ServerIntrospector; @@ -39,6 +40,7 @@ import feign.Client; import feign.Request; import feign.RequestTemplate; import feign.Response; +import feign.Util; public class FeignLoadBalancer extends AbstractLoadBalancerAwareClient { @@ -112,14 +114,22 @@ public class FeignLoadBalancer extends RibbonRequest(Client client, Request request, URI uri) { this.client = client; - this.request = request; setUri(uri); + this.request = toRequest(request); + } + + private Request toRequest(Request request) { + Map> headers = new LinkedHashMap<>( + request.headers()); + // Apache client barfs if you set the content length + headers.remove(Util.CONTENT_LENGTH); + return new RequestTemplate().method(request.method()) + .append(getUri().toASCIIString()) + .body(request.body(), request.charset()).headers(headers).request(); } Request toRequest() { - return new RequestTemplate().method(this.request.method()) - .append(getUri().toASCIIString()).headers(this.request.headers()) - .body(this.request.body(), this.request.charset()).request(); + return toRequest(this.request); } Client client() { diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignRibbonClientAutoConfiguration.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignRibbonClientAutoConfiguration.java index 8c1d22a8..420bd2cd 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignRibbonClientAutoConfiguration.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignRibbonClientAutoConfiguration.java @@ -63,7 +63,6 @@ public class FeignRibbonClientAutoConfiguration { @Configuration @ConditionalOnClass(ApacheHttpClient.class) @ConditionalOnProperty(value = "feign.httpclient.enabled", matchIfMissing = true) - @ConditionalOnMissingBean(Client.class) protected static class HttpClientConfiguration { @Autowired(required = false) @@ -73,6 +72,7 @@ public class FeignRibbonClientAutoConfiguration { CachingSpringLoadBalancerFactory cachingFactory; @Bean + @ConditionalOnMissingBean(Client.class) public Client feignClient() { ApacheHttpClient delegate; if (this.httpClient != null) { @@ -88,7 +88,6 @@ public class FeignRibbonClientAutoConfiguration { @Configuration @ConditionalOnClass(OkHttpClient.class) @ConditionalOnProperty(value = "feign.okhttp.enabled", matchIfMissing = true) - @ConditionalOnMissingBean(Client.class) protected static class OkHttpConfiguration { @Autowired(required = false) @@ -98,6 +97,7 @@ public class FeignRibbonClientAutoConfiguration { CachingSpringLoadBalancerFactory cachingFactory; @Bean + @ConditionalOnMissingBean(Client.class) public Client feignClient() { OkHttpClient delegate; if (this.okHttpClient != null) { diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/LoadBalancerFeignClient.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/LoadBalancerFeignClient.java index 7d233bff..a86646d7 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/LoadBalancerFeignClient.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/LoadBalancerFeignClient.java @@ -36,7 +36,8 @@ public class LoadBalancerFeignClient implements Client { private final Client delegate; private CachingSpringLoadBalancerFactory lbClientFactory; - public LoadBalancerFeignClient(Client delegate, CachingSpringLoadBalancerFactory lbClientFactory) { + public LoadBalancerFeignClient(Client delegate, + CachingSpringLoadBalancerFactory lbClientFactory) { this.delegate = delegate; this.lbClientFactory = lbClientFactory; } @@ -47,8 +48,8 @@ public class LoadBalancerFeignClient implements Client { URI asUri = URI.create(request.url()); String clientName = asUri.getHost(); URI uriWithoutHost = cleanUrl(request.url(), clientName); - FeignLoadBalancer.RibbonRequest ribbonRequest = new FeignLoadBalancer.RibbonRequest(this.delegate, - request, uriWithoutHost); + FeignLoadBalancer.RibbonRequest ribbonRequest = new FeignLoadBalancer.RibbonRequest( + this.delegate, request, uriWithoutHost); return lbClient(clientName).executeWithLoadBalancer(ribbonRequest, new FeignOptionsClientConfig(options)).toResponse(); }