首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >openfeign: SSL握手异常与

openfeign: SSL握手异常与
EN

Stack Overflow用户
提问于 2018-12-06 05:56:30
回答 2查看 12K关注 0票数 1

当我尝试在中使用假想-httpclient时,我得到的是SSL握手异常,而如果我不使用假想-httpclient,则相同的代码可以工作。

我需要使用伪httpclient,因为我想使用连接工厂。

build.gradle

代码语言:javascript
复制
//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')

冒充客户

代码语言:javascript
复制
@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);
}

调用代码:

代码语言:javascript
复制
 testClient.get(new TestRequestDto("test"));

application.yml

代码语言:javascript
复制
feign:
   client:
     config:
       default:
         connectTimeout: 5000
         readTimeout: 5000
         loggerLevel: full
  httpclient:
     maxConnections: 200
     maxConnectionsPerRoute: 200
     enabled: true

例外:

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-07 04:19:21

所需的配置如下:

代码语言:javascript
复制
feign:
   httpclient:
      disableSslValidation: true
票数 3
EN

Stack Overflow用户

发布于 2018-12-10 16:25:19

如果需要自签名证书,请使用以下代码:

代码语言:javascript
复制
@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();
   }
  }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53645425

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档