Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Allow external modifier while building HttpClient #3777

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
* @see ApacheClientProperties#CONNECTION_MANAGER
*/
@SuppressWarnings("deprecation")
class ApacheConnector implements Connector {
public class ApacheConnector implements Connector {

private static final Logger LOGGER = Logger.getLogger(ApacheConnector.class.getName());

Expand All @@ -201,13 +201,33 @@ class ApacheConnector implements Connector {
private final boolean preemptiveBasicAuth;
private final RequestConfig requestConfig;

public interface ClientBuilderModifier {

/** This external interface wants to modify the default builder */
HttpClientBuilder custom(final HttpClientBuilder builder);

/** This external interface also has its own build function (rather than the builder.build()) */
CloseableHttpClient build();
}

/**
* Create the new Apache HTTP Client connector.
*
* @param client JAX-RS client instance for which the connector is being created.
* @param config client configuration.
*/
ApacheConnector(final Client client, final Configuration config) {
this(client, config, null);
}

/**
* Create the new Apache HTTP Client connector.
*
* @param client JAX-RS client instance for which the connector is being created.
* @param config client configuration.
* @param builderModifier modifier for the default client builder
*/
public ApacheConnector(final Client client, final Configuration config, final ClientBuilderModifier builderModifier) {
final Object connectionManager = config.getProperties().get(ApacheClientProperties.CONNECTION_MANAGER);
if (connectionManager != null) {
if (!(connectionManager instanceof HttpClientConnectionManager)) {
Expand Down Expand Up @@ -304,7 +324,14 @@ class ApacheConnector implements Connector {
this.cookieStore = null;
}
clientBuilder.setDefaultRequestConfig(requestConfig);
this.client = clientBuilder.build();

//Support external modifier
if (null != builderModifier) {
builderModifier.custom(clientBuilder);
this.client = builderModifier.build();
} else {
this.client = clientBuilder.build();
}
}

private HttpClientConnectionManager getConnectionManager(final Client client,
Expand Down