Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two missing configuration for Apache - DefaultAuthSchemeRegistry … #4686

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -156,6 +156,19 @@ public final class ApacheClientProperties {
*/
public static final String KEEPALIVE_STRATEGY = "jersey.config.apache.client.keepAliveStrategy";

/**
* RedirectStrategy which can customize how redirects are handled.
* <p/>
* The value MUST be a subclass of {@link RedirectStrategy}.
*/
public static final String REDIRECT_STRATEGY = "jersey.config.apache.client.redirectStrategy";

/**
* DefaultAuthSchemeRegistry which can customize the auth scheme used.
* <p/>
* The value MUST be a subclass of {@link org.apache.http.config.Registry}.
*/
public static final String DEFAULT_AUTH_SCHEME_REGISTRY = "jersey.config.apache.client.defaultAuthSchemeRegistry";
nddipiazza marked this conversation as resolved.
Show resolved Hide resolved

/**
* Strategy that closes the Apache Connection. Accepts an instance of {@link ApacheConnectionClosingStrategy}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
Expand Down Expand Up @@ -249,6 +251,34 @@ class ApacheConnector implements Connector {
}
}

Object redirectStrategy = config.getProperties().get(ApacheClientProperties.REDIRECT_STRATEGY);
if (redirectStrategy != null) {
if (!(redirectStrategy instanceof RedirectStrategy)) {
nddipiazza marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.log(
Level.WARNING,
LocalizationMessages.IGNORING_VALUE_OF_PROPERTY(
ApacheClientProperties.REDIRECT_STRATEGY,
redirectStrategy.getClass().getName(),
RedirectStrategy.class.getName())
);
redirectStrategy = null;
}
}

Object defaultAuthSchemeRegistry = config.getProperties().get(ApacheClientProperties.DEFAULT_AUTH_SCHEME_REGISTRY);
nddipiazza marked this conversation as resolved.
Show resolved Hide resolved
if (defaultAuthSchemeRegistry != null) {
if (!(defaultAuthSchemeRegistry instanceof Registry)) {
nddipiazza marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.log(
Level.WARNING,
LocalizationMessages.IGNORING_VALUE_OF_PROPERTY(
ApacheClientProperties.DEFAULT_AUTH_SCHEME_REGISTRY,
defaultAuthSchemeRegistry.getClass().getName(),
Registry.class.getName())
);
defaultAuthSchemeRegistry = null;
}
}

final SSLContext sslContext = client.getSslContext();
final HttpClientBuilder clientBuilder = HttpClientBuilder.create();

Expand Down Expand Up @@ -317,6 +347,14 @@ class ApacheConnector implements Connector {
requestConfig = requestConfigBuilder.build();
}

if (redirectStrategy != null) {
clientBuilder.setRedirectStrategy((RedirectStrategy) redirectStrategy);
}

if (defaultAuthSchemeRegistry != null) {
clientBuilder.setDefaultAuthSchemeRegistry((Registry<AuthSchemeProvider>) defaultAuthSchemeRegistry);
nddipiazza marked this conversation as resolved.
Show resolved Hide resolved
}

if (requestConfig.getCookieSpec() == null || !requestConfig.getCookieSpec().equals(CookieSpecs.IGNORE_COOKIES)) {
this.cookieStore = new BasicCookieStore();
clientBuilder.setDefaultCookieStore(cookieStore);
Expand Down