背景:在开发一个项目中,要调用一个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. cojs 强连通图计数1-2 题解报告

    OwO 题目含义都是一样的,只是数据范围扩大了 对于n<=7的问题,我们直接暴力搜索就可以了 对于n<=1000的问题,我们不难联想到<主旋律>这一道题 没错,只需要把方程改一 ...

  2. Python Web学习笔记之GIL机制下的鸡肋多线程

    为什么有人会说 Python 多线程是鸡肋?知乎上有人提出这样一个问题,在我们常识中,多进程.多线程都是通过并发的方式充分利用硬件资源提高程序的运行效率,怎么在 Python 中反而成了鸡肋? 有同学 ...

  3. mysql引擎问题

    今天遇到需要修改数据库引擎问题 /*查看支持的引擎*/ show engines; /*默认引擎*/ show variables like '%storage_engine%'; /*看某个表用了什 ...

  4. Duilib Edit编辑框禁止输入中文的方法

    转载:http://www.myexception.cn/vc-mfc/300749.html 编辑框是供用户输入的,但有时候我们要限制用户输入的内容,比如我们不让用户输入中文,只能输入字符和数字,因 ...

  5. VC++ 进度条更新方案

    在实际开发中,如果有耗时操作,一般会在工作线程处理数据,然后处理完成后把时间传递到UI线程进行显示,切记不要在工作线程对UI进行操作. 场景: 1. 很多程序需要根据处理业务的进度来更新进度条,进度条 ...

  6. Android灯光系统--通知灯深入分析

    Android灯光系统--通知灯深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 getSystemService(获得通知服务) 构造notification 类别 其他参数(颜色, ...

  7. 筛选出sql 查询结果中 不包含某个字符

    select * from table1 where patindex('%关键字%' , aa) = 0 select * from table1 where charindex('关键字' , a ...

  8. json获取元素数量

    var keleyijson={"plug1":"myslider","plug2":"zonemenu"} funct ...

  9. [shiro] - 加入rememberMe功能

    shiro不加入rememberMe没事,一加入就出错. RememberMeAuthenticationToken : public interface RememberMeAuthenticati ...

  10. [shiro] - 怎样使用shiro?

    shiro是什么? Shiro是apache旗下的一个开源框架, 它将软件系统的安全认证相关的功能抽取出来, 实现用户身份认证, 权限授权, 加密, 会话管理等功能, 组成一个通用的安全认证框架. 为 ...