java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED

I’ve been dealing with this same exception in my application, and I finally found a helpful suggestion from this post – http://httpcomponents.10934.n7.nabble.com/I-O-reactor-status-STOPPED-td29059.html You can use #getAuditLog() method of the I/O reactor to find out exactly what exception caused it to terminate. If you keep a reference to your ConnectionManager’s IOReactor, you can call this method … Read more

How to send parallel GET requests and wait for result responses?

Just in general, you need to encapsulate your units of work in a Runnable or java.util.concurrent.Callable and execute them via java.util.concurrent.Executor (or org.springframework.core.task.TaskExecutor). This allows each unit of work to be executed separately, typically in an asynchronous fashion (depending on the implementation of the Executor). So for your specific problem, you could do something like … Read more

Connection and connection request timeout

HttpClient has a way to set connection and socket timeout (setConnectionTimeout() and setTimeout()) according to the HttpClient javadocs. Connection timeout is the timeout until a connection with the server is established. Socket timeout is the timeout to receive data (socket timeout). Example: Let’s say you point your browser to access a web page. If the … Read more

Using Spring REST template, either creating too many connections or slow

Actually Spring Boot is not leaking connections. What you’re seeing here is standard behavior of the Linux kernel (and every major OS). All sockets that are closed from the machine go to a TIME_WAIT state for some duration of time. This is to prevent the next socket that uses that ephemeral port from receiving packets … Read more

Apache HttpComponents HttpClient timeout

In version 4.3 of Apache Http Client the configuration was refactored (again). The new way looks like this: RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder.setConnectTimeout(timeout); requestBuilder.setConnectionRequestTimeout(timeout); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setDefaultRequestConfig(requestBuilder.build()); HttpClient client = builder.build();

Apache HttpClient Android (Gradle)

If you are using target SDK as 23 add the below code in your build.gradle android{ useLibrary ‘org.apache.http.legacy’ } Additional note here: don’t try using the gradle versions of those files. They are broken (28.08.15). I tried over 5 hours to get it to work. It just doesn’t. not working: compile ‘org.apache.httpcomponents:httpcore:4.4.1’ compile ‘org.apache.httpcomponents:httpclient:4.5’ Another … Read more

Ignoring SSL certificate in Apache HttpClient 4.3

The code below works for trusting self-signed certificates. You have to use the TrustSelfSignedStrategy when creating your client: SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( builder.build()); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory( sslsf).build(); HttpGet httpGet = new HttpGet(“https://some-server”); CloseableHttpResponse response = httpclient.execute(httpGet); try { System.out.println(response.getStatusLine()); HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); } … Read more

java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion

Update: This is no longer a bug or a workaround, it is required if your app targets API Level 28 (Android 9.0) or above and uses the Google Maps SDK for Android 16.0.0 or below (or if your app uses the Apache HTTP Legacy library). It is now included in the official docs. The public … Read more