Ning async http 客户端 1.9:设置 SSLParametersSNI 主机名的正确方法

问题描述

以下代码在 1.8 版中有效。 更新到 1.9 版后,删除了 setSSLEngineFactory 方法。 有没有优雅的方法来实现与 1.8 版本类似的方法

    Builder builder = new AsyncHttpClientConfig.Builder();
    try {
        builder.setSSLContext(sslContext);
        builder.setSSLEngineFactory(new SSLEngineFactory() {
            public SSLEngine newSSLEngine() throws GeneralSecurityException {
                if (sslContext != null) {
                    SSLEngine sslEngine = sslContext.createSSLEngine();
                    String sniHostname = null;
                    try {
                        URI uri = new URI(baseURI);
                        sniHostname = uri.getHost();
                    } catch (URISyntaxException e) {
                        LOGGER.warn("Failed to init URI",e);
                    }
                    if (sniHostname != null) {
                        List sniHostNames = new ArrayList(1);
                        sniHostNames.add(new SNIHostName(sniHostname));
                        SSLParameters sslParameters = new SSLParameters();
                        sslParameters.setServerNames(sniHostNames);
                        sslEngine.setSSLParameters(sslParameters);
                    }
                    sslEngine.setUseClientMode(true);
                    return sslEngine;
                } else {
                    return null;
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("Failed to init http builder",e);
    }
    AsyncHttpClientConfig config = builder.build();
    client = new AsyncHttpClient();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)