I use a HTTPS Connection on my CLient in multiple Threads. Sometimes up to 20 times / second. I have made the following observation: somethimes the HTTPS Connection is reconnected with TLS Handshake and this debug message appears:
javax.net.ssl|DEBUG|42|Thread-15|2022-12-02 13:48:47.748 CET|Utilities.java:73|the previous server name in SNI (type=host_name (0), value=myServer.com) was replaced with (type=host_name (0), value=myServer.com)
After this message the TLS Handshake is made again.
How can I avoid the reconnection and the server replacment in the SNI?
In every thread this code is executed:
public SOAPConnecti2n soapConnection
soapConnection = SOAPConnectionFactory.newInstance().createConnection(); // done 1x in every thread in the constructor of the class
SOAPMessage response = soapConnection.call(myRequest, myURLEndpoint) // done x times in ervery thread in a for loop
The
HttpsClient#afterConnectcallsSSLSocketImpl#setHostwhich replaces the firstSNIHostName(more precisely theSNIServerNamewith type 0 - as the RFC6066 defines just type 0) with the hostname from the HTTPS Connection. So the trick is not to use the hostname for the connection, but to use the IP address instead for the connection. That way, theUtilitieswon't find the hostname to replace the SNIHostNames in the SSLParameters.