【问题标题】:How to build the EndPoint correctly using jax-ws?如何使用 jax-ws 正确构建 EndPoint?
【发布时间】:2015-10-12 13:32:30
【问题描述】:

我正在使用引导方法通过使 WSDL 在本地可用来动态构建我的端点。对于 http 和 https,但我很确定在为 https 构建它们时我会出错。

Map<String, Object> context = ((BindingProvider)control).getRequestContext();
URL address = mInstance.getConnectionEndpoint();
    if (address != null && Settings.getSettings().isUsingHttpConnection()) {
        context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,address.toString());
        System.out.println(address);
    }
    else{
        //for https

HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
        {
            public boolean verify(String hostname, SSLSession session)
            {
                if (hostname.equals("myhostname"))
                    return true;
                return false;
            }
        });

        address = mInstance.getSecureConnectionEndpoint();
        context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,address.toString());
    }

getConnectionEndpoint 和 getSecureConnectionEndpoint 的样子:

   public URL getConnectionEndpoint() {
    URL url = null;
    try {
        int port = 50013;
        url = new URL("http", mHost.getHostAddress(), port, "");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return url;
}

public URL getSecureConnectionEndpoint() {
    URL url = null;
    try {
        int port = 50014;
        url = new URL("https", mHost.getHostAddress(), port, "");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return url;
}

当我使用 http 时,这很好用。但是对于 https,我总是会收到以下错误消息:

com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present

显然,通过谷歌搜索此错误,我找到了可能是由于在 Java TrustStore 中不正确地导入服务器和客户端 SSL 证书所致。

但我非常有信心,问题不在于这个。

上面提到的父错误的子错误看起来像这样:

at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)

如果您能帮我解决这个问题,我将不胜感激!提前喝彩。

【问题讨论】:

    标签: java security ssl https jax-ws


    【解决方案1】:

    问题可能是从mHost.getHostAddress() 返回的值与服务器提供的证书上的common name 不同的主机名。例如,如果 localhostmHost.getHostAddress() 的值,但 SSL 证书颁发给 127.0.0.1(反之亦然),您可能会遇到此问题。

    This post 标识了一种代码解决方法,以防使用不同的CN 重新生成和重新安装证书不可行或不可取。它涉及使用HttpsUrlConnectionHostnameVerifier机制。

    【讨论】:

    • 谢谢,但我仍然收到错误消息。检查我上面的编辑!
    • 发布mHost.getHostAddress() 返回的值和证书上的通用名称。两者必须匹配,否则您可能会遇到遇到的错误。
    • 成功了!我为CN使用了错误的域名,这就是问题所在。但是感谢您的帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-26
    • 2014-03-08
    • 2011-10-20
    • 1970-01-01
    相关资源
    最近更新 更多