Programmatically and temporarily disable SNI check in JAX-RS client with sun.net.**.HttpsClient

Viewed 1887

I'm getting the old HTTP transport error: javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name error on service where I need to disable SNI handshake because reasons. I do NOT want to do it globally with System.setProperty("jsse.enableSNIExtension", "false"); as suggested elsewhere and the http binding uses sun.net.www.protocol.https.HttpsClient and I can't seem to change that. I have tried approaches like https://erikwramner.wordpress.com/2013/03/27/trust-self-signed-ssl-certificates-and-skip-host-name-verification-with-jax-ws/

where I have set custom SSLSocketFactories and HostnameVerifiers like so:

 BindingProvider bp = (BindingProvider) webServicePort;
            Map requestContext = bp.getRequestContext();
            requestContext.put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", getTrustingSSLSocketFactory());
            requestContext.put("com.sun.xml.ws.transport.https.client.SSLSocketFactory", getTrustingSSLSocketFactory());
            final NaiveHostnameVerifier naiveHostnameVerifier = new NaiveHostnameVerifier();
            requestContext.put("com.sun.xml.internal.ws.transport.https.client.hostname.verifier", naiveHostnameVerifier);
            requestContext.put("com.sun.xml.ws.transport.https.client.hostname.verifier", naiveHostnameVerifier);

This simply has no effect since the http client doesn't seem to honour these properties.

Any tips appreciated!

1 Answers
Related