開発者ドキュメント

java.security.cert.CertificateException:localhostと一致する名前が見つかりません

問題

https/[SSLをサポートするTomcat]を展開し、このリンクをデプロイしました://webservices/jax-ws/jax-ws-hello-ワールド・サンプル/[シンプル・ハロー・ワールド・ウェブ・サービス]。また、次のクライアントを使用して、SSL接続を介してデプロイされたWebサービスに接続します。

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());

    }
}

それは ”

名前が一致するlocalhostが見つかりません

“例外:

Caused by: javax.net.ssl.SSLHandshakeException:
    java.security.cert.CertificateException: No name matching localhost found
    at 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 found
    at sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:210)
    at sun.security.util.HostnameChecker.match(HostnameChecker.java:77)
    ......

解決策

この問題とその解決方法については、このhttp://docs.sun.com/app/docs/doc/820-1072/6ncp48v40?a=view#hicy[article]に詳しく説明されています。トランスポートセキュリティ(SSL)の回避策を使用できますあなたの ”

localhost

“開発環境のために。

これを修正するには、 `javax.net.ssl.HostnameVerifier()`メソッドを追加して、既存のホスト名ベリファイアを次のようにオーバーライドします。

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 only
        javax.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());

    }
}


出力

Hello World JAX-WS

今はうまくいきます。

モバイルバージョンを終了