SSLSocket.getOutputStream()
initiates the SSL handshake if neceessary, which involves reads, which may block. You should set a read timeout on the socket before calling it, with Socket.setSoTimeout()
.
I'm intrigued by "SSLSocket.getOutputStream() initiates the SSL handshake if neceessary"
what defines "if necessary"?
If it hasn't already been done, or the current SSL Session has been invalidated.
Is this behavior (initiating the SSL handshake) something that's required by the JVM specification? IOW is it guaranteed across JVMs?
No, it's required by the TLS/SSL specification.
I've also read the only way to determine if a socket connex will work is to read/write data with it. This is not an option for me.
Yes it is. You're doing it. The SSL handshake consists of reads and writes.
and I'm wondering if I can rely on getOutputStream() not returning within a minute or so as an indication that there is a connectivity problem.
You can rely on SocketTimeoutException
being thrown during the handshake as an indication that the connection isn't working, provided you set a reasonable timeout with Socket.setSoTimeout()
as I mentioned in my answer. A minute is reasonable.