HttpsURLConnection.setDefaultHostnameVerifier:方法验证未调用 [英] HttpsURLConnection.setDefaultHostnameVerifier: method verify not invoked

查看:3525
本文介绍了HttpsURLConnection.setDefaultHostnameVerifier:方法验证未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样配置HttpsUrlConnection:

I configure HttpsUrlConnection like this:

HttpsURLConnection.setDefaultSSLSocketFactory(sslFactory);
HttpsURLConnection.setDefaultHostnameVerifier(new DummyHostnameVerifier());

DummyHostnameVerifier:

DummyHostnameVerifier:

public class DummyHostnameVerifier implements HostnameVerifier {
    @Override
    public boolean verify(String s, SSLSession sslSession) {
        return true;
    }
}

当然,这只是配置的一部分.但是问题是没有调用DummyHostnameVerifier中的verify方法. 当我在本地计算机上(glassfish 3服务器)上测试应用程序时,请验证已调用并且没有收到任何异常. 但是,当我在远程环境中对其进行测试时,不会调用验证,并且我会收到此消息:

Of course, it's only part of configuration. But the problem is that verify method in DummyHostnameVerifier isn't invoked. When I test my application on local machine, glassfish 3 server, verify invoked and I'm not recieving any exceptions. But when I test it on remote environment, verify isn't invoked, and I recieve this:

java.io.IOException: The https URL hostname does not match the Common Name (CN) on the server certificate.  To disable this check (NOT recommended for production) set the CXF client TLS configuration property "disableCNCheck" to true.

在远程环境中,应用程序在jboss 5上运行. 也许这取决于一些jboss配置?我无法理解,设置验证程序后默认主机名验证程序在哪里更改.

On remote env app runs on jboss 5. Maybe this depends on some jboss config? I can't understand, where default hostname verifier changed after setting my verifier.

推荐答案

问题出在以下方面:某种程度上,发送给服务器的消息中没有动作名称. 我这样配置连接:

The problem was in following: somehow there wasn't action name in message to server. I configured connection like this:

HttpsURLConnection.setDefaultSSLSocketFactory(sslFactory); HttpsURLConnection.setDefaultHostnameVerifier(new DummyHostnameVerifier());

HttpsURLConnection.setDefaultSSLSocketFactory(sslFactory); HttpsURLConnection.setDefaultHostnameVerifier(new DummyHostnameVerifier());

    URL url = null;
    try {
        url = new URL(endpoint + "/wsdl");
    } catch (MalformedURLException e) {
        LOG.error(e.getMessage());
    }

    javax.xml.ws.Service s = MyService.create(url, new QName(MyService.NAMESPACE, MyService.SERVICE));
    ServiceSoap port = s.getPort(ServiceSoap.class);

    Map<String, Object> reqCtx = ((BindingProvider)port).getRequestContext();
    reqCtx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    reqCtx.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    reqCtx.put(BindingProvider.SOAPACTION_URI_PROPERTY, actionName);

    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnection(ConnectionType.CLOSE);
    http.setClient(httpClientPolicy);
    TLSClientParameters tls = new TLSClientParameters();
    tls.setSSLSocketFactory(sslFactory);
    tls.setDisableCNCheck(true);
    http.setTlsClientParameters(tls);

因此,配置了端口,一切开始工作.

So, port configured and everything began to work.

这篇关于HttpsURLConnection.setDefaultHostnameVerifier:方法验证未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆