背景:在开发一个项目中,要调用一个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. bzoj1651 / P2859 [USACO06FEB]摊位预订Stall Reservations

    P2859 [USACO06FEB]摊位预订Stall Reservations 维护一个按右端点从小到大的优先队列 蓝后把数据按左端点从小到大排序,顺序枚举. 每次把比右端点比枚举线段左端点小的数据 ...

  2. bzoj1639 / P2884 [USACO07MAR]每月的费用Monthly Expense

    P2884 [USACO07MAR]每月的费用Monthly Expense 二分经典题 二分每个段的限制花费,顺便统计下最大段 注意可以分空段 #include<iostream> #i ...

  3. 20145306 《网络攻防》 MSF基础应用

    20145306张文锦<网络对抗>MSF应用 Adobe阅读器渗透攻击 两台虚拟机,其中一台为kali,一台为windows xp sp3,并保证两台虚拟机可以ping通. 实验过程 进入 ...

  4. 删除string类型字符串中指定字符串段

    1.实现背景 在插入list行时用邮件的MessageID给对应行命名. 在回复全部邮件时,收件人变为之前收件人中出去“自己”同时加入之前发件人,抄送人还是之前的抄送人,密送人不用管,直接不用带. 在 ...

  5. Python3基础 os.path.basename 处理路径字符串,返回文件的名字

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. sqlserver数据库出错的解决方法

    1.SQLServer2008数据库sa账户登录127.0.0.1失败 http://blog.sina.com.cn/s/blog_546a30270102weh2.html 2.SqlServer ...

  7. Windows下搭建FTP服务器

    一.什么是ftp? FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议”.用于Internet上的控制文件的双向传输.同时,它也是一个应用程序(A ...

  8. HDU 3549 Flow Problem(最大流模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 刚接触网络流,感觉有点难啊,只好先拿几道基础的模板题来练练手. 最大流的模板题. #include< ...

  9. hdu 1370 || poj 1006 简单的中国剩余定理或者暴力

    Biorhythms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Probl ...

  10. TeamViewer 说明截图