same problem here. I traced my code and got stuck in con.getInputStream () forever. To reproduce the problem, follow the code example below. (enter the correct URL)
A) Start any HTTPS server on another host
B) Run the client code
C) Shutting down the HTTPS server
D) Start the HTTPS server again
-> Stuck in con.getInputStream ()
During the restart of the HTTPS server, it seems that there is some kind of deadlock in the client. FYI I am using the org.apache.felix.http.jetty package as an HTTP (S) -Server with the Restlet servlet attached.
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; public class TestHTTPS{ public static void main(String[] args) throws InterruptedException { new TestHTTPS().activate(); } private void activate() throws InterruptedException{ TrustManager[] insecureTrustManager = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType) { } } }; try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, insecureTrustManager, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (KeyManagementException e1) {
Any recommendations are appreciated.
source share