При попытке использовать feign-httpclient с Spring-cloud-starter-openfeign я получаю исключение SSL Handshake, в то время как тот же код работает, если я не использую притворяться-httpclient.
Мне нужно использовать feign-httpclient, поскольку я хочу использовать фабрику соединений.
build.gradle
//on commenting the below dependency the code works fine.
compile('io.github.openfeign:feign-httpclient:9.4.0')
compile('org.springframework.cloud:spring-cloud-starter-openfeign')
Имитировать клиента
@FeignClient(name = "testClient", url = "https://test:9820")
public interface TestClient {
@RequestMapping(method = RequestMethod.POST, value = "/test", consumes = "application/json", produces = "application/json")
TesteDto get(TestRequestDto testRequestDto);
}
Код вызова:
testClient.get(new TestRequestDto("test"));
application.yml
feign:
client:
config:
default:
connectTimeout: 5000
readTimeout: 5000
loggerLevel: full
httpclient:
maxConnections: 200
maxConnectionsPerRoute: 200
enabled: true
Исключение:
javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target




Требовалась следующая конфигурация:
feign:
httpclient:
disableSslValidation: true
Если вам нужен самоподписанный сертификат, используйте следующий код:
@FeignClient(name = "testClient", url = "https://test:9820", configuration = CustomFeignConfiguration.class)
public interface TestClient {
@RequestMapping(method = RequestMethod.POST, value = "/test", consumes =
"application/json", produces = "application/json")
TesteDto get(TestRequestDto testRequestDto);
}
public class CustomFeignConfiguration {
@Bean
public Client feignClient() {
return new ApacheHttpClient(getHttpClient());
}
private CloseableHttpClient getHttpClient() {
int timeout = 10000;
try {
SSLContext sslContext = SSLContextBuilder.create()
.loadTrustMaterial(new TrustSelfSignedStrategy()).build();
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout)
.setConnectionRequestTimeout(timeout)
.setSocketTimeout(timeout)
.build();
return HttpClientBuilder
.create()
.useSystemProperties()
.setDefaultRequestConfig(config)
.setSSLContext(sslContext)
.setSSLHostnameVerifier(new NoopHostnameVerifier())
.build();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
Наряду с приведенной выше конфигурацией мне также пришлось добавить ниже:
feign.httpclient.enabled=false feign.okhttp.enabled=true