背景:在开发一个项目中,要调用一个webservice服务,之前设置的是http协议,项目中采用jdk自带的wsimport工具生成的客户端代码;

后来,需求变更要求兼容https协议的webservice,开始以为只需要简单的将服务地址的连接改为https就可以了;但不行,总是报错

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present

    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
at com.vrv.paw.client.area.VRVRange.<init>(VRVRange.java:48)
at com.vrv.paw.client.area.mainTest.main(mainTest.java:12)

然后就是这种百度查资料,查到以下解释

http://www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/

在开发设计中当我们在java中打开一个SSL连接(比如:java.net.URL.openConnection(“https://….”)),
JSSE实现的SSL协议执行一些验证以确保这个请求的主机不是假的。
这包括用PKIX算法验证服务器的X.509证书和检查主机名称与证书中的subject是否一致。
如果SSL证书不可信或与目标主机不匹配,HTTPS和SSL加密连接就不能建立并且抛出SSLHandshakeException 或 IOException By design when we open an SSL connection in Java (e.g. through java.net.URL.openConnection(“https://….”))
the JSSE implementation of the SSL protocol performs few validations to ensure the requested host is not fake.
This involves validation of the server’s  X.509 certificate with the PKIX algorithm and checking the host name agains the certificate subject.
If the SSL certificate is not validates as trusted or does not match the target host,
an HTTPS and other SSL encrypted connection cannot be established and all attempts will result in SSLHandshakeException or IOException.

总得来说就是要将SLL数据证书加入到ketstore中

也按照http://www.cnblogs.com/liaojie970/p/4919485.html总提到的方法生成了证书,并且在代码中

System.setProperty("javax.net.ssl.trustStore", "E:\\vrvcacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
package com.vrv.paw.client.area;public class mainTest {
public static void main(String[] args) {
System.setProperty("javax.net.ssl.trustStore", "E:\\vrvcacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
Gson gson = new Gson();
// 同步数据
VRVRange vrvRange = new VRVRange();
VRVRangeSoap vrvRangeSoap = vrvRange.getVRVRangeSoap();
String cString = vrvRangeSoap.login("admin", "123456");
System.out.println(cString);
}
}

问题依旧存在,最后没有办法,就尝试了在项目中新建wsdl文件,在Eclipse中右键该wsdl文件,web service-->Generate Client生成客户端,具体生成方式见这里

然后再次

package org.tempuri;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;public class TestClient {
public static void main(String[] args) {
try {
System.setProperty("javax.net.ssl.trustStore", "E:\\jssecacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
Gson gson = new Gson();
VRVRange vrvRange = new VRVRangeLocator();
VRVRangeSoap vrvRangeSoap = vrvRange.getVRVRangeSoap();
String login = vrvRangeSoap.login("admin", "123456");
System.out.println(login);
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}

结果成了。。。。

具体为什么wsimport生成的客户端代码不行,我也不知道,如果有哪位大神知道,请指教。

java.security.cert.CertificateException: No subject alternative names present的更多相关文章

  1. java.security.cert.CertificateException: No subject alternative names matching IP address xxx.xxx.xxx.xxx found

    https与http不同的是,https加密,需要验证证书,而http不需要. 在连接的代码中加上: static { disableSslVerification(); } private stat ...

  2. SpringBoot 连接kafka ssl 报 CertificateException: No subject alternative names present 异常解决

    当使用较新版本SpringBoot时,对应的 kafka-client 版本也比较新,如果使用了 2.x 以上的 kafka-client ,并且配置了 kafka ssl 连接方式时,可能会报如下异 ...

  3. JDK安全证书的一个错误消息 No subject alternative names present的解决办法

    我使用Java消费某网站一个Restful API时,遇到这个错误: 21:31:16.383 [main] DEBUG org.springframework.web.client.RestTemp ...

  4. 终极解决方案:java.security.cert.CertificateException: Certificates does not conform to algorithm constraints

    报错信息 javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Certificates does ...

  5. JAVA 调用https接口, java.security.cert.CertificateException

    package com.easycare.store.util; import java.security.cert.CertificateException; import java.securit ...

  6. 在ssm框架测试中解决javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException

    在单元测试发现causeBy:javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException 经发现是db.p ...

  7. 解決 java.security.cert.CertificateException: Certificates does not conform to algorithm constraints

    找到 jre/lib/security/java.security 将 jdk.certpath.disabledAlgorithms=MD2, DSA, RSA keySize < 2048 ...

  8. Java_解决java.security.cert.CertificateException: Certificates does not conform to algorithm constraints

    找到 jre/lib/security/java.security 将 jdk.certpath.disabledAlgorithms=MD2, DSA, RSA keySize < 2048 ...

  9. 【java细节】Java代码忽略https证书:No subject alternative names present

    https://blog.csdn.net/audioo1/article/details/51746333

随机推荐

  1. (二) MySQL常用命令及语法规范

  2. 20145304 Exp6 信息搜集与漏洞扫描

    20145304 Exp6 信息搜集与漏洞扫描 实验后回答问题 (1)哪些组织负责DNS,IP的管理. NSI负责Internet顶级域名系统的注册.协调与维护,IAIA负责Internet的地址资源 ...

  3. 20145204《网络对抗》逆向及bof基础实践

    20145204<网络对抗>逆向及bof基础实践 实践目的说明 实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何 ...

  4. luogu1049装箱问题

    装箱问题 传送门 一个箱子容量为V//容量 同时有n个物品//n个 体积&&价值 要求n个物品中任取若干个装入箱内,使箱子的剩余空间为最小// v减去价值最大 */ #include& ...

  5. RedHat6使用CentOS yum源 换yum

    yum 简单介绍一下 yum 主要功能是更方便的添加/删除/更新RPM 包,自动解决包的倚赖性问题,便于管理大量系统的更新问题. yum 可以同时配置多个资源库(Repository),简洁的配置文件 ...

  6. VS中sln和suo的区别

    1.调试程序出现这个错误an error occurred while validating 解决方案:http://stackoverflow.com/questions/8648428/an-er ...

  7. thymeleaf和easyui配合可能出现的错误

    thymeleaf和easyui 在easyui的内页,不再使用th:href引入静态资源文件. 在easyui页面中,script执行easyui自己的方法要加入: <script th:in ...

  8. LCA离线算法Tarjan详解

    离线算法也就是需要先把所有查询给保存下来,最后一次输出结果. 离线算法是基于并查集实现的,首先就是初始化P[i] = i. 接下来对于每个点进行dfs: ①首先判断是否有与该点有关的查询,如果当前该点 ...

  9. go 通道

    1. package main import "fmt" func sum(s []int, c chan int) { sum := for _, v := range s { ...

  10. StringBuffer中的sBuffer.delete(0,4);

    只删除第0-3位的字符,第4位是不删的