java.security.cert.CertificateException: No name matching localhost found

解释;安全证书异常,IP地址找不到

解决方案如下:程序加入static里面的代码块就OK了

代码的意思就是程序默认这个IP地址是安全可访问的

Problem

Configured Tomcat to support SSL and deployed this simple hello world web service. And use following client connect to the deployed web service over SSL connection :

package com.mkyong.client;import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;import com.mkyong.ws.HelloWorld;public class HelloWorldClient{public static void main(String[] args) throws Exception {URL url = new URL("https://localhost:8443/HelloWorld/hello?wsdl");QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");Service service = Service.create(url, qname);HelloWorld hello = service.getPort(HelloWorld.class);System.out.println(hello.getHelloWorldAsString());}
}

Copy

It hits “No name matching localhost found” exception :

Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching localhost foundat com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1611)at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181)......
Caused by: java.security.cert.CertificateException: No name matching localhost foundat sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:210)at sun.security.util.HostnameChecker.match(HostnameChecker.java:77)......

Copy

Solution

This problem and solution is well explained in this article, you can use a Transport Security (SSL) Workaround for your “localhost” development environment.

To fix it, add a javax.net.ssl.HostnameVerifier() method to override the existing hostname verifier like this :

package com.mkyong.client;import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;import com.mkyong.ws.HelloWorld;public class HelloWorldClient{static {//for localhost testing onlyjavax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier(){public boolean verify(String hostname,javax.net.ssl.SSLSession sslSession) {if (hostname.equals("localhost")) {return true;}return false;}});}public static void main(String[] args) throws Exception {URL url = new URL("https://localhost:8443/HelloWorld/hello?wsdl");QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");Service service = Service.create(url, qname);HelloWorld hello = service.getPort(HelloWorld.class);System.out.println(hello.getHelloWorldAsString());}
}

Copy

Output

Hello World JAX-WS

Copy

It’s working fine now.

java.security.cert.CertificateException: No name matching IP found相关推荐

  1. java.security.cert.CertificateException: No name matching https证书验证不通过

    1.报错信息 1 java.security.cert.CertificateException: No name matching api.weibo.com found; nested excep ...

  2. CAS部署错误3:java.security.cert.CertificateException: No name match

    javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching casse ...

  3. sqlserver 项目中连接失败,驱动程序无法通过使用安全套接字层(SSL) 与 java.security.cert.CertificateException

    问题一:驱动程序无法通过使用安全套接字层(SSL) 注意: 有两个 jre 文件夹,一个是 jdk内包含的,一个是 单独的 jre 解决办法:把jdk下面的\jre\lib\security下面的ja ...

  4. java.security.cert.CertificateException: X.509 not found,X.509证书找不到

    对接支付宝转账接口,本地测试没有问题,部署到服务器就报错. 报错代码: org.apache.catalina.loader.WebappClassLoaderBase.checkStateForRe ...

  5. Caused by: java.security.cert.CertPathValidatorException: timestamp check failed

    客户端在连接Server端https的时候出现了 以下错误, 12-27 17:52:45.976: W/System.err(10361): Caused by: java.security.cer ...

  6. java.security.cert.Certificate:No subject alternative DNS name matching api.exmail.qq.com found.解决方法

    工作中使用https请求,本地调用正常,放到服务器端运行失败,报错为java.security.cert.Certificate:No subject alternative DNS name mat ...

  7. imageloader 的 java.security.cert.CertPathValidatorException

    最近使用imageloader 发现ssl问题 (java.security.cert.CertPathValidatorException) 网上找了个方法,亲测通过,如下: universalim ...

  8. java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

    Android 忽略Https请求认证 新建一个工具类 package com.gbom.vms_mcu.util;import java.security.SecureRandom; import ...

  9. Java SSL - CertificateException: No name matching

    用java去连接SSL网站时,有时候出现: Caused by: java.security.cert.CertificateException: No name matching ... 这是因为虽 ...

最新文章

  1. ubuntu18.04搭建SLAM环境 转 高翔 十四讲匹配环境
  2. tensorflow与keras关系
  3. 不存在完美的入门书,但是有些书在某些方面很惊艳
  4. char* 长度_leetcode之最后一个单词的长度
  5. 支付宝支付 第五集:二维码生成工具
  6. java数组拼字符串_java数组、字符串拼接
  7. java oracle 字符_Oracle转义字符
  8. java emoji编码转换_编码:unicode、utf-8以及emoji
  9. 【 Gym - 101138K 】 The World of Trains (DP)
  10. java ognl 值栈_ognl-值栈基本操作
  11. 《Java语言程序设计》(基础篇原书第10版)第十一章复习题答案
  12. 如何成为Java高级工程师?
  13. 净推荐值(NPS)完整行动指南
  14. 中国本地化汽车“软件战争”打响
  15. C语言循环结构作业总结
  16. 《深入理解java虚拟机》学习-第三章-内存分配策略
  17. 15亿参数的NLP模型究竟有多强大?有人用它生成了一部《哈利·波特》
  18. 内涵外延发生巨变的嵌入式技术,未来如何发展?
  19. 谈产品的差异化思路:进可攻退可守
  20. 群晖搭建照片文件服务器,使用群晖Moments管理家庭照片的解决方案

热门文章

  1. JMX超详细解读(转)
  2. 无锡设计类——CAD设计在机械制图中的优势
  3. 使用Redis缓存Shiro授权认证信息,搭建集群权限系统
  4. Traefik监控系统搭建
  5. excel另存为csv格式时修改默认分隔符
  6. 计算机网络工程期刊,信息工程学院李挥教授课题组在计算机网络顶级期刊JSAC上发表学术论文...
  7. 团体程序设计天梯赛-练习集L1-005 考试座位号 (15 分)c语言
  8. 实验5 支持向量机分类实验
  9. 近期准备秋招的一些体会(二)
  10. 【node】nodemailer 实现邮件发送