I am having trouble sending an Apache HttpClient (4.3) request timeout using the following code:
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(4000).setConnectTimeout(4000) .setSocketTimeout(4000).build(); CloseableHttpClient client = HttpClients.custom().setSslcontext(sslContext) .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) .setDefaultRequestConfig(requestConfig).build(); HttpPost post = new HttpPost("https://localhost:" + connection.getLocalPort() + "/API/webservice.asmx"); StringEntity stringE = new StringEntity(REQUEST); post.setEntity(stringE); CloseableHttpResponse response = client.execute(post);
I get the connection and port through a proprietary API. When everything goes well, it works, although sometimes (due to poor communication, I believe) the code always stands on client.execute (post). Is there something that I am doing wrong here when implementing a timeout or some other method to make this call a timeout so that I don't get stuck indefinitely.
source share