2,341 questions
1
vote
2
answers
87
views
Does httpclient need to consume httpentity in finally?
1.The following code encapsulates the post method, is EntityUtils.consume(httpEntity); in finally segment code redundant? I asked claudai and he said it's not redundant, and asked chatgpt and he said ...
0
votes
2
answers
85
views
Cannot resolve method 'setDefaultSocketFactory' in 'PoolingHttpClientConnectionManager'
I have to migrate this httpclient 4 code to httpclient 5:
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
@...
0
votes
0
answers
69
views
Use keycloak-admin-client with httpclient5
I migrate legacy application on spring boot 3
Connect httpclient5, and removed the dependency httpclient4, as it conflicts with many modern libraries that use exactlyhttpclient5
And update dependency ...
0
votes
0
answers
77
views
How to debug apache http client thread pool performance bottlenecks
my backend Java Spring Boot application is calling a 3rd party web server via restTemplate. I have observed slowness when I switched from std JDK SimpleClientHttpRequestFactory to Apache http client ...
0
votes
0
answers
35
views
Java SSLMA implemenation (Apache httpClient 4.5 and BouncyCastle)
I need to connect to a service that request SSLMA (SSL Mutual Authentication using Apache HttpClient 4.5 and BouncyCastle.
I managed to prepare the SSLConnectionSocketFactory instance (see code) but ...
0
votes
1
answer
62
views
Jersey client connection reuse with chunked gzip response
I am trying to use a Jersey (3.x) client with ApacheConnector but I observed that in case a chunked gzip response is received. the connection gets closed as soon as the response is read. The ...
0
votes
1
answer
631
views
SSLContexts in HttpClient5
When migrating from httpclient 4.x to httpclient5. I was able to get all the packages sorted except for SSLContexts. There is a line of code that we were using:
return SSLContexts.custom().useTLS()....
1
vote
0
answers
173
views
Calling two consecutive POST requests from RestTemplate using apache httpclient in SpringBoot fails
My logic calls two consecutive POST requests from RestTemplate in SpringBoot.
The first call always succeeds but the second call always fails with:
I/O error on POST request for "https://httpbin....
0
votes
0
answers
79
views
Reason for wildcard certificate issue with Apache HTTP Client and Java 8
I get an SSLPeerUnverifiedException after switching from HTTP to HTTPS which I don't understand since the wildcard certificate should work for the URL.
javax.net.ssl.SSLPeerUnverifiedException: ...
0
votes
1
answer
38
views
EJB - Inject into @Schedule @Singleton with @Produces fails; no scheduler running
I want to call this method regularly to clean up Apache HTTP connection pool in an EJB context. For that I created this scheduler class:
@DependsOn("PoolingHttpClientConnectionManager")
...
0
votes
1
answer
64
views
Google Oauth2 exchange code for token returning 400
I am trying to follow https://developers.google.com/identity/protocols/oauth2/web-server#exchange-authorization-code to exchange a code for an access token. I am able to get my local endpoint to ...
-1
votes
1
answer
233
views
Apache HttpClient - SSL failures
I'm trying to connect to an endpoint using Apache's HttpClient 4.5, and am running into the below exception:
DEBUG [main] (RequestAddCookies) - CookieSpec selected: default
DEBUG [main] (...
1
vote
0
answers
849
views
Migrating from httpclient4 to httpclient5 - setSSLContext
We are trying to upgrade the httpclient from 4 to 5. As a part of the upgrade, we have changed the imports accordingly. But, the code uses Httpclientbuilder and sets the sslcontext. As per the ...
0
votes
1
answer
45
views
Stop callers from accidentally closing CloseableHttpClient
I am configuring a class to manage an Apache HttpClient that will be used application-wide for the lifetime of the application, like the following:
public class HttpManager {
private ...
-3
votes
1
answer
1k
views
Can the same HttpClient-using code compile against Spring-5.x and 6.x?
The following code compiles nicely against Spring-5.x:
import org.apache.http.client.HttpClient;
...
private static ClientHttpRequestFactory clientHttpRequestFactory(
int timeOut) throws ...
0
votes
1
answer
734
views
Difference between different timeouts for apache http client 5.1
With Apache Http client 5.1.x, I want to set timeout on every HTTP request(Get, Post, ..), as I don't want to wait for more than certain period for obvious reasons. But I'm confused mostly between ...
0
votes
0
answers
35
views
Apache EntityUtils.toString() timeouts for big response
We have deployed our code in AWS lambda. I am using EntityUtils to get string response body. But it gets timeout for big json response string. Total characters in json response is 6266832
String ...
0
votes
3
answers
541
views
Apache HttpClient PoolingHttpClientConnectionManager - allocated to maximum
I have set up PoolingHttpClientConnectionManager (with ssl):
private PoolingHttpClientConnectionManager getConnManager(
Registry<ConnectionSocketFactory> socketFactoryRegistry) {
...
0
votes
1
answer
1k
views
How can I set the Bearer Token just before making a request using Apache Http Client 4
I still use Apache Http Client 4.
But, I would like to set the Bearer Token just before making a request.
Then, I have tried the following
public class Test {
public static void main(final String[]...
1
vote
0
answers
468
views
Apache HTTP Client SSL via custom servername SNI
I have a Apache Async Http client which I use to connect to IP addresses (instead of domain name). I want to find a way to provide the SNI information, something like this so that the SSL handshake ...
0
votes
1
answer
385
views
WS02 APIM 4.1.0: High CPU Utilization over 100% and HTTP-Sender I/O dispatcher threads consuming %CPU
WSO2 APIM Server : 4.1.0
OpenJDK : 64-Bit Server VM (11.0.17+8-LTS mixed mode, sharing)
Linux : RHEL 8.x
CPU/Processor : 4
Memory : 8GB
WSO2 APIM 4.1.0 running on OpenJDK 11 continues to shows 100% ...
0
votes
1
answer
237
views
How can I migrate to apache httpclient5 about Zero Copy Get request
I am migrating to apache httpclient5 from apache httpclint 4.
I use the Zero Copy Get request process as follows.
https://svn.apache.org/viewvc/httpcomponents/httpasyncclient/branches/4.1.x/...
0
votes
0
answers
62
views
Buffered Reader hangs for ~8 seconds while checking br.readLine() for the last time
I'm working on some Java 8 code (using Apache httpclient 4.3) to process out the content from an HTTP response. I am able to print out the content but on the last iteration of the while loop after the ...
1
vote
1
answer
743
views
Is an IdleConnectionMonitorThread still recommended in Apache httpclient5?
I am updating an old project's dependencies. One of the transitive changes pulled in is a version bump of apache-httpclient from 4.5 to 5.2. This project implements the recommended ...
0
votes
0
answers
35
views
Does Apache HttpClient V4 HttpMessage use header case-insensitive matching?
RFC spec states Http headers are case-insensitive:
Are HTTP headers case-sensitive?
In our source code we set headers in [org.apache.hc.core5.http.HttpMessage](https://github.com/apache/httpcomponents-...
0
votes
1
answer
3k
views
required a bean of type 'org.apache.hc.client5.http.io.HttpClientConnectionManager' that could not be found
I want to migrate this apache http client code:
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client....
0
votes
1
answer
466
views
setRelativeRedirectsAllowed() in RequestConfig apache-httpclient 5.x
I was migrating the usage of apache httpclient 4.x to httpclient 5.x version and there a lot of changes in the classes and methods. This particular question is about setRelativeRedirectsAllowed() ...
0
votes
1
answer
353
views
Apache Http test cases using Junit
I want to write unit test for a method which uses Apache Http to fetch data.
public UserResponse getUserById(String id) {
UserResponse userResponse;
String jwtToken = SecurityUtil.getAuthToken(...
3
votes
1
answer
236
views
How do I safely resume with HTTP clients after Coordinated Restore at Checkpoint?
"Serverless" infrastructure like AWS lambda makes use of Coordinated Restore at Checkpoint to improve startup time of java programs.
AWS documentation states that
The state of connections ...
4
votes
2
answers
5k
views
Apache HttpClient 5 pool without timeout
We're upgrading from Apache HttpClient 4.5 to 5.2, and it seems there's been a significant change to how the pool timeout works. We want the pool configured so it has some fixed number of connections ...
-1
votes
1
answer
314
views
Java Apache HTTP client: initialize persistent file cache
I am trying to configure persistent HTTP caching using the org.apache.http.impl.client.cache.CachingHttpClients builder. However, when I configure a cache directory, the cache never seems to be read ...
2
votes
2
answers
8k
views
I received an error org.apache.hc.core5.http.NoHttpResponseException: server failed to respond when i call API via quotaguard proxy in SpringBoot 3
We are using QuotaGuard proxy to connect with external API.
Recently we did Spring Boot version update.
Technical configuration of our application.
Before Spring Boot version update.
Java 8
Spring ...
0
votes
1
answer
1k
views
Spring Cloud Open Feign: HttpURLConnection and Apache HttpClient
When using Feign, it defaults to using HttpURLConnection. I anticipated performance improvements by switching to Apache HttpClient for connection pooling. However, in my tests, the response time ...
0
votes
1
answer
275
views
Apache Http Client - Redirect URL gets URL decoded. Any way to work around?
I use the apache http client library (4.5.14). I'm doing a request which receives a 302 along with a Location response header.
The Location response header is URL encoded, but somehow the apache http ...
0
votes
1
answer
125
views
Apache HttpClients always takes 2x the configured ConnectTimeout to actually timeout?
Example code:
public static void main(String[] args) throws Exception {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(1_000)
.setSocketTimeout(...
0
votes
1
answer
841
views
How can I log data from HttpRequest and HttpResponse at the same time?
I have some custom logging logic that logs information from the request and response. Some log lines contain information from both the request and the response at the same time. Thus, I somehow need ...
0
votes
1
answer
184
views
Address family not supported by protocol using Apache HttpClient 4.5.x
I have a small application used to Test connectivity over https. I am using the Apache HttpClient 4.5 to create a HttpClient and invoking a HttpGet call. This works fine for IPv4 but when I try to ...
1
vote
1
answer
487
views
How to gather webflux client metrics when client is generated by OpenAPI
in our Spring Boot application we are using actuator and integrated prometheus. Now we would like to gather HTTP client metrics.
In our scenario we are using OpenAPI specification for defining the ...
0
votes
0
answers
288
views
Mocking a Post request with apache.http.client.HttpClient in Scala (2.11)
I'm trying to implement some unit tests for my HttpClient (in Scala 2.11); Here's my client:
import org.apache.http.client.methods.HttpPost
import org.apache.http.impl.client.HttpClientBuilder
import ...
1
vote
1
answer
240
views
Java-Apache BufferedHttpEntity loads whole file when sending the request
I want to make a Multipart request to my server from java using the apache CloseableHttpAsyncClient, this is what i currently have:
File file = new File("pathname");
MultipartEntityBuilder ...
0
votes
0
answers
77
views
Profiling java application
I have a problem with my spring boot application.
I have a rest controller that sends some http request by apache httpclient.
So when I load 1000 req/s to my controller I get answer after 1ms (in ...
0
votes
0
answers
669
views
After a read timeout, it takes time to shut down the connection in Apache HttpClient
I'm currently developing an application using Java 11 and Spring Boot. Within this application, I make calls to two external REST APIs using the RestTemplate library. Below, you'll find the ...
0
votes
1
answer
3k
views
How to build an older HTTP Client example in a Maven Project
I've been able to build and run the example code (from Alain O'Dea) in this older SO thread:
How do I pass the client certificate with HTTP client?
As described in that thread, I downloaded the 4 JAR ...
0
votes
0
answers
969
views
javax.net.ssl.SSLPeerUnverifiedException: Certificate for <g.i.t.n.c.com> doesn't match any of the subject alternative names: [*.t.n.c.com] [duplicate]
Why I'm getting this error, while the host I'd like to establish the ssl connection with matches the wildcard from the Alternative names field of the certificate?
We use
<dependency>
...
0
votes
1
answer
524
views
java.net.SocketException: Connection reset by peer (Write failed) after migrating to Http Client 4.x from 4.x
Recently I migrated from Apache Commons Http Client 3.x to the new Apache 4.x http client. Everything was replaced like Multithreaded Http Client Connection Manager to PoolingHttpClientManager. ...
0
votes
0
answers
689
views
How to dynamically change OpenSearch/ElasticSearch Apache HttpClient5 properties with new Java client?
I am using opensearch-java client to connect to my OpenSearch cluster hosted in AWS. The client uses Apache HttpClient5 Transport to connect to the cluster. This is how my client is setup:
protected ...
0
votes
2
answers
330
views
Apache HttpClient with limited waiters
I'm using Apache HttpClient 4.5 and I want to configure the connection pool to limit the number of waiting threads. So if the pool is exhausted, it should allow up to n threads to wait for a ...
0
votes
1
answer
381
views
Why 2 requests are sent from Java Apache HttpClient
I have created one HTTP Post request with Basic authentication using httpclient (org.apache.httpcomponents).
CredentialsProvider provider = new BasicCredentialsProvider();
provider....
1
vote
1
answer
12k
views
correct way to use PoolingHttpClientConnectionManager in HttpClient4 getting issue java.lang.IllegalStateException: Connection pool shut down
I am utilizing HTTPclient4 in Java to send HTTP requests and handle HTTP responses. I want to use connectionPooling for improved performance but I am not able to find a proper way to do it.
I am ...
0
votes
0
answers
515
views
PATCH HTTP Method : java.lang.NoClassDefFoundError: org/apache/http/conn/ssl/TrustAllStrategy in Java 8
I am posting JSON Payload to REST API by using PATCH method with the help of apache http client libraries
Java Version: 1.8.0_171
Following this link for PATCH method with apache http client
Code ...