Unexpected error: java.security.InvalidAlgorithmParameterException

Unexpected error: java.security.InvalidAlgorithmParameterException

1. 异常信息

Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty executing POST https://xxxx/v1/corp/createcorp] with root cause fegin

2. 自定义 Feign 客户端以忽略 HTTPS 证书验证

这个错误提示说明在执行 HTTPS 请求时,Java 虚拟机无法找到任何可信任的根证书来验证服务器的 SSL 证书。这通常发生在 SSL 握手阶段,当客户端尝试建立与服务器的安全连接时。

错误发生在执行 POST 请求到 https://xxx/v1/corp/createcorp,这很可能是一个调用服务(如果这是正确的服务地址)的API。

import feign.Client;
import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

/**
 * feign 日志基本配置
 */
@Configuration
public class FeignConfig {



    @Bean
    public Client feignClient() throws NoSuchAlgorithmException, KeyManagementException {
        TrustManager[] trustAllCerts = new TrustManager[]{
                new X509TrustManager() {
                    @Override
                    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                    }

                    @Override
                    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                    }

                    @Override
                    public X509Certificate[] getAcceptedIssuers() {
                        return new X509Certificate[]{};
                    }
                }
        };

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, new java.security.SecureRandom());

        // 创建一个Client.Default实例,它接受一个SSLSocketFactory和一个HostnameVerifier
        return new Client.Default(sslContext.getSocketFactory(), (hostname, session) -> true);
    }
}


3. feign 配置
@FeignClient(name = "tt", url = "${cc.url}")
public interface TtClient {


    @PostMapping("/v1/corp/createcorp")
    JSONObject createcorp(@RequestBody JSONObject body);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潇凝子潇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值