I am trying to use a CloseableHttpClient to connect to a web server over HTTPS. Whenever I try to open a connection, though, the client throws a NoHttpResponseException.
When I try to cURL or Wget to the same webserver, I can only do it properly by using -k and --no-check-certificate (respectively), which makes me think that this is an issue related to SSL certificates. I have added a SSLContext to my HttpClient (code below), but it was not effective.
SSLContextBuilder sslContextBuilder = SSLContexts.custom();
sslContextBuilder.setSecureRandom(new java.security.SecureRandom());
sslContextBuilder.loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
return true;
}
});
SSLContext sslContext = sslContextBuilder.build();
The stacktrace looks like this:
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {s}->https://server.com:443: The target server failed to respond Jun 30, 2017 4:20:53 PM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {s}->https://server.com:443 Exception: org.apache.http.NoHttpResponseException: server.com:443 failed to respond at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163) at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
Has anyone had this sort of problem?
Thanks for the help,