Invalid proxy for apache httpclient5 with GET

629 Views Asked by At

I migrated to spring boot 3 and java 21. Since I have a patch rest call to make, i needed the dependency org.apache.httpcomponents.client5:httpclient5:5.2.2.

But with that dependency, I get a "java.lang.IllegalArgumentException: Invalid Proxy" if using org.springframework.web.client.RestTemplate with RequestEntity.get.

The patch call is working just fine with the same settings.

  • Spring 3.1.6
  • Java 21

Does have anyone an idea why this happens? I don't have a proxy. Do I have to define a default proxy?

Unfortunately, for this link: https://github.com/apache/httpcomponents-client/tree/5.1.x/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java I get 404. :-(

I tried using only apache dependencies without the resttemplate and get the same exception.

HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader(HttpHeaders.AUTHORIZATION, token);
httpGet.setHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
2

There are 2 best solutions below

0
On

I found the solution myself. There seems to be a bug in the httpclient5 version 5.2.2.

With version 5.2.1 also the GET request works just as expected.

1
On

The problem (https://issues.apache.org/jira/browse/HTTPCLIENT-2307) was inadvertently introduced in HttpClient 5.2.2 and it was fixed in 5.2.3 and 5.3.0.