eclipse-ee4j / eclipse-ee4j/jersey

Supplying custom HttpClientBuilder to ApacheConnector

Open
#4,210 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

I am writing a java AWS lambda and using Jersey as my REST client. AWS X-Ray is automatically connected to the lambda and I would to use the AWS X-Ray instrumented version of HttpClientBuilder but the current implementation of ApacheConnector does not permit that. This issue is similar to #4089 but for Apache HttpComponents HttpClient.

I propose adding a new property to ApacheClientProperties such as CLIENT_BUILDER which could be set to an HttpClientBuilder implementation which must be a subclass of org.apache.http.impl.client.HttpClientBuilder.

Then, the code in ApacheConnector could be enhanced to replace the line reading
```java
final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
```
with something like
```java
final HttpClientBuilder clientBuilder = getHttpClientBuilder();
```
where `getHttpClientBuilder()` looks like
```java
private HttpClientBuilder getHttpClientBuilder() {
final Object cbObject = config.getProperties().get(ApacheClientProperties.CLIENT_BUILDER);

if (cbObject != null) {
if (cbObject instanceof HttpClientBuilder ) {
return (HttpClientBuilder ) cbObject;
} else {
LOGGER.log(
Level.WARNING,
LocalizationMessages.IGNORING_VALUE_OF_PROPERTY(
ApacheClientProperties.CLIENT_BUILDER,
cbObject.getClass().getName(),
HttpClientBuilder.class.getName())
);
}
}

// Create standard HttpClientBuilder.
return HttpClientBuilder.create();
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.