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.
// 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;
}