问题描述
我想在使用CXF客户端(3.1.2)进行休息呼叫时设置自定义SNI主机名(SNI配置)。我正在使用java 8.我能够使用HTTPClient做同样的事情(参见下面的强文本代码剪切以供参考),但我无法弄清楚如何使用CXF客户端做同样的事情。
I want to set custom SNI hostname(SNI configuration) while making rest call using CXF client(3.1.2). I'm using java 8.I'm able to do the same thing using HTTPClient(see below strong textcode snipped for reference), but I'm not able to figure out how to do the same using CXF client.
//对于HTTP客户端
// For HTTP client
private SSLConnectionSocketFactory createSSLConnectionSocketFactory(String sniHostanme,
SSLContext sslContext){
// Fix for host name verifier, need to implement----------------------
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1.2" }, null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier()) {
@Override
protected void prepareSocket(SSLSocket socket) throws IOException {
try {
// System.out.println("************ setting socket HOST property *************");
// If SNI is required
if (StringUtils.isNotBlank(sniHostanme)) {
log.debug("SNI HOSTNAME = "+sniHostanme);
List<SNIServerName> sniServerNames = new ArrayList<>();
sniServerNames.add(new SNIHostName(sniHostanme));
SSLParameters sslParam = new SSLParameters();
sslParam.setServerNames(sniServerNames);
socket.setSSLParameters(sslParam);
}
// PropertyUtils.setProperty(socket, "host", "ws.mastercard.com");
} catch (Exception ex) {
log.error(ex.getMessage());
}
// super.prepareSocket(socket);
}
};
return sslsf;
}
推荐答案
使用org.apache.cxf .configuration.jsse.TLSClientParameters类和public final void setCertAlias(String ctAlias)方法设置服务器端使用的证书别名这在密钥库有多个证书时很有用。希望这对你有所帮助。
Use org.apache.cxf.configuration.jsse.TLSClientParameters class and public final void setCertAlias(String ctAlias) method to set the cert alias used on server side this is useful when keystore has multiple certs.Hopefully this will help you.
这篇关于cxf客户端中的SNI配置(3.1.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!