java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

本文讲述了在使用HttpClient或RestTemplate时遇到SSL异常,经排查发现是由于使用了非官方OpenJDK,未正确安装安全证书。作者建议尝试下载并安装官方JDK,解决后成功调用第三方接口,适用于类似OpenJDK环境引发的安全问题。
摘要由CSDN通过智能技术生成
javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
	at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
	at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1964)
	at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1921)
	at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1904)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1420)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:436)
	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384)
	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
	at com.iauto.app.appstoreservice.util.HttpClientUtils.doPostJson(HttpClientUtils.java:92)
	at com.iauto.app.appstoreservice.util.HttpClientUtils.getServiceCertification(HttpClientUtils.java:55)
	at com.iauto.app.appstoreservice.controller.PaymentController.paymentCode(PaymentController.java:65)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)

之前在公司负责一个接口,需要调用第三方接口,用的是httpClient来发送请求,在调用过程中就是调用失败,之后也用了restTemplate,一直报上面这个错误,查了挺多的文章,看到好多人是去引两个jar包到jdk目录下,感觉麻烦,就没有去试,有兴趣的可以试试;

看这个错误是一个安全性的异常,又之前看到文章说有可能是jdk的问题,我就突然想起来,入职的时候下载软件是直接从老员工的电脑上拷贝下来的,我当时拷贝的是openjdk1.8,直接把目录拿过来,自己配置了下环境变量,就意识到可能是由于没有手动安装,导致一些安全证书文件没有安装成功,之后我就从官网上下载了一个新的jdk1.8,换了jdk之后,测试成功。是同种情况的可以试一试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值