Skip to content

Java system properties can not be applied to RestTemplate HttpClient connection in some cases #35815

@alex-kormukhin

Description

@alex-kormukhin

Spring boot 3.1.0 RestTemplateBuilder with apache HTTP client in classpath (org.apache.httpcomponents.client5:httpclient5) ignore java system HTTP proxy command line options like -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8888.

Spring boot before 3.1 respects such settings.

For simple RestTemplate restTemplate = restTemplateBuilder.build() spring boot 2.7 instantiate HttpComponentsClientHttpRequestFactory via default constructor, which create HTTP client as HttpClients.createSystem(), i.e. with system proxy support.

image

Spring boot 3.0 (if readTimeout duration is not set) also create HttpComponentsClientHttpRequestFactory via default constructor and HTTP client as HttpClients.createSystem().

image

But spring boot 3.1 create HTTP client as HttpClientBuilder.create().setConnectionManager(connectionManager).build(). Without useSystemProperties() as HttpClients.createSystem() makes.

image

Suggestion: add useSystemProperties() to createHttpClient method like this

return HttpClientBuilder.create()
    .useSystemProperties()
    .setConnectionManager(connectionManager)
    .build();

For compatibility with spring boot 2.x, 3.0, and core spring HttpComponentsClientHttpRequestFactory.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions