Feign Client SunCertPathBuilderException

问题描述

我已经实现了伪装客户端。但是在尝试调用 REST 端点时,我收到以下异常。 我在类路径中有信任库,我在那里没有发现任何问题。但在调用 REST 端点时,它因认证错误而失败。

但是,如果我使用 restTemplate,同样可以正常工作。

sun.security.validator.ValidatorException: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target executing POST
@Configuration
public class SSLFeignConfiguration {

    @Value("classpath:trustStore")
    private Resource trustStoreResource;

    @Value("${http.client.ssl.trust-store-password}")
    private String trustStorePassword;

    private SSLContext sslContext = null;

    @Bean
    Logger.Level vscanFeignLoggerLevel() {
        return Logger.Level.HEADERS;
    }

    @Bean
    public Client getFeignClient() {
        return new Client.Default(getClientSSLSocketFactory(),new NoopHostnameVerifier());
    }

    public SSLSocketFactory getClientSSLSocketFactory() {
        if (setupSslContext() != null) {
            return sslContext.getSocketFactory();
        }
        return null;
    }

    public SSLContext setupSslContext() {

        try {
            sslContext = new SSLContextBuilder().loadTrustMaterial(trustStoreResource.getURL(),trustStorePassword
                    .tochararray()).build();

            return sslContext;
        } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException
                | IOException e) {
            // Todo Auto-generated catch block
            e.printstacktrace();
        }
        return sslContext;

    }

}
@RefreshScope
@FeignClient(url = "${host.url}",name = "ssl",configuration = SSLFeignConfiguration.class)
@Component
public interface FeignClient {

    @GetMapping(value = "${test.digital.get.url}")
    ResponseEntity<JSONObject> getDigital(@PathVariable("entityName") String entityName,@RequestParam("entityId") String entityId,@RequestParam("entityModelName") String entityModelName);

    

}

属性文件

feign.okhttp.enabled=false
feign.httpclient.enabled=true
spring.sleuth.feign.enabled=true
feign.httpclient.disable-ssl-validation=true
feign.compression.request.mime-types=application/json
feign.hystrix.enabled=false

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)