Use consistent variable names

This commit is contained in:
Michael Osipov 2019-12-15 10:47:57 +01:00
parent a1c63d46df
commit bca9a873a5
20 changed files with 115 additions and 117 deletions

View File

@ -53,9 +53,9 @@ class CacheValidityPolicy {
} }
public long getFreshnessLifetimeSecs(final HttpCacheEntry entry) { public long getFreshnessLifetimeSecs(final HttpCacheEntry entry) {
final long maxage = getMaxAge(entry); final long maxAge = getMaxAge(entry);
if (maxage > -1) { if (maxAge > -1) {
return maxage; return maxAge;
} }
final Date dateValue = entry.getDate(); final Date dateValue = entry.getDate();
@ -242,23 +242,23 @@ class CacheValidityPolicy {
} }
protected long getMaxAge(final HttpCacheEntry entry) { protected long getMaxAge(final HttpCacheEntry entry) {
long maxage = -1; long maxAge = -1;
final Iterator<HeaderElement> it = MessageSupport.iterate(entry, HeaderConstants.CACHE_CONTROL); final Iterator<HeaderElement> it = MessageSupport.iterate(entry, HeaderConstants.CACHE_CONTROL);
while (it.hasNext()) { while (it.hasNext()) {
final HeaderElement elt = it.next(); final HeaderElement elt = it.next();
if (HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName()) || "s-maxage".equals(elt.getName())) { if (HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName()) || "s-maxage".equals(elt.getName())) {
try { try {
final long currMaxAge = Long.parseLong(elt.getValue()); final long currMaxAge = Long.parseLong(elt.getValue());
if (maxage == -1 || currMaxAge < maxage) { if (maxAge == -1 || currMaxAge < maxAge) {
maxage = currMaxAge; maxAge = currMaxAge;
} }
} catch (final NumberFormatException nfe) { } catch (final NumberFormatException nfe) {
// be conservative if can't parse // be conservative if can't parse
maxage = 0; maxAge = 0;
} }
} }
} }
return maxage; return maxAge;
} }
public boolean hasCacheControlDirective(final HttpCacheEntry entry, final String directive) { public boolean hasCacheControlDirective(final HttpCacheEntry entry, final String directive) {

View File

@ -80,11 +80,11 @@ class CachedResponseSuitabilityChecker {
if (originInsistsOnFreshness(entry)) { if (originInsistsOnFreshness(entry)) {
return false; return false;
} }
final long maxstale = getMaxStale(request); final long maxStale = getMaxStale(request);
if (maxstale == -1) { if (maxStale == -1) {
return false; return false;
} }
return (maxstale > validityStrategy.getStalenessSecs(entry, now)); return (maxStale > validityStrategy.getStalenessSecs(entry, now));
} }
private boolean originInsistsOnFreshness(final HttpCacheEntry entry) { private boolean originInsistsOnFreshness(final HttpCacheEntry entry) {
@ -99,30 +99,30 @@ class CachedResponseSuitabilityChecker {
} }
private long getMaxStale(final HttpRequest request) { private long getMaxStale(final HttpRequest request) {
long maxstale = -1; long maxStale = -1;
final Iterator<HeaderElement> it = MessageSupport.iterate(request, HeaderConstants.CACHE_CONTROL); final Iterator<HeaderElement> it = MessageSupport.iterate(request, HeaderConstants.CACHE_CONTROL);
while (it.hasNext()) { while (it.hasNext()) {
final HeaderElement elt = it.next(); final HeaderElement elt = it.next();
if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) { if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) {
if ((elt.getValue() == null || "".equals(elt.getValue().trim())) && maxstale == -1) { if ((elt.getValue() == null || "".equals(elt.getValue().trim())) && maxStale == -1) {
maxstale = Long.MAX_VALUE; maxStale = Long.MAX_VALUE;
} else { } else {
try { try {
long val = Long.parseLong(elt.getValue()); long val = Long.parseLong(elt.getValue());
if (val < 0) { if (val < 0) {
val = 0; val = 0;
} }
if (maxstale == -1 || val < maxstale) { if (maxStale == -1 || val < maxStale) {
maxstale = val; maxStale = val;
} }
} catch (final NumberFormatException nfe) { } catch (final NumberFormatException nfe) {
// err on the side of preserving semantic transparency // err on the side of preserving semantic transparency
maxstale = 0; maxStale = 0;
} }
} }
} }
} }
return maxstale; return maxStale;
} }
/** /**
@ -185,9 +185,9 @@ class CachedResponseSuitabilityChecker {
if (HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName())) { if (HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName())) {
try { try {
final int maxage = Integer.parseInt(elt.getValue()); final int maxAge = Integer.parseInt(elt.getValue());
if (validityStrategy.getCurrentAgeSecs(entry, now) > maxage) { if (validityStrategy.getCurrentAgeSecs(entry, now) > maxAge) {
log.debug("Response from cache was NOT suitable due to max age"); log.debug("Response from cache was not suitable due to max age");
return false; return false;
} }
} catch (final NumberFormatException ex) { } catch (final NumberFormatException ex) {
@ -199,9 +199,9 @@ class CachedResponseSuitabilityChecker {
if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) { if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) {
try { try {
final int maxstale = Integer.parseInt(elt.getValue()); final int maxStale = Integer.parseInt(elt.getValue());
if (validityStrategy.getFreshnessLifetimeSecs(entry) > maxstale) { if (validityStrategy.getFreshnessLifetimeSecs(entry) > maxStale) {
log.debug("Response from cache was not suitable due to Max stale freshness"); log.debug("Response from cache was not suitable due to max stale freshness");
return false; return false;
} }
} catch (final NumberFormatException ex) { } catch (final NumberFormatException ex) {
@ -213,13 +213,13 @@ class CachedResponseSuitabilityChecker {
if (HeaderConstants.CACHE_CONTROL_MIN_FRESH.equals(elt.getName())) { if (HeaderConstants.CACHE_CONTROL_MIN_FRESH.equals(elt.getName())) {
try { try {
final long minfresh = Long.parseLong(elt.getValue()); final long minFresh = Long.parseLong(elt.getValue());
if (minfresh < 0L) { if (minFresh < 0L) {
return false; return false;
} }
final long age = validityStrategy.getCurrentAgeSecs(entry, now); final long age = validityStrategy.getCurrentAgeSecs(entry, now);
final long freshness = validityStrategy.getFreshnessLifetimeSecs(entry); final long freshness = validityStrategy.getFreshnessLifetimeSecs(entry);
if (freshness - age < minfresh) { if (freshness - age < minFresh) {
log.debug("Response from cache was not suitable due to min fresh " + log.debug("Response from cache was not suitable due to min fresh " +
"freshness requirement"); "freshness requirement");
return false; return false;

View File

@ -247,10 +247,10 @@ public class CachingExecBase {
final HeaderElement elt = it.next(); final HeaderElement elt = it.next();
if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) { if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) {
try { try {
final int maxstale = Integer.parseInt(elt.getValue()); final int maxStale = Integer.parseInt(elt.getValue());
final long age = validityPolicy.getCurrentAgeSecs(entry, now); final long age = validityPolicy.getCurrentAgeSecs(entry, now);
final long lifetime = validityPolicy.getFreshnessLifetimeSecs(entry); final long lifetime = validityPolicy.getFreshnessLifetimeSecs(entry);
if (age - lifetime > maxstale) { if (age - lifetime > maxStale) {
return true; return true;
} }
} catch (final NumberFormatException nfe) { } catch (final NumberFormatException nfe) {

View File

@ -99,29 +99,29 @@ public class Executor {
return this; return this;
} }
public Executor auth(final AuthScope authScope, final Credentials creds) { public Executor auth(final AuthScope authScope, final Credentials credentials) {
if (this.credentialsStore == null) { if (this.credentialsStore == null) {
this.credentialsStore = new BasicCredentialsProvider(); this.credentialsStore = new BasicCredentialsProvider();
} }
this.credentialsStore.setCredentials(authScope, creds); this.credentialsStore.setCredentials(authScope, credentials);
return this; return this;
} }
public Executor auth(final HttpHost host, final Credentials creds) { public Executor auth(final HttpHost host, final Credentials credentials) {
return auth(new AuthScope(host), creds); return auth(new AuthScope(host), credentials);
} }
/** /**
* @since 4.4 * @since 4.4
*/ */
public Executor auth(final String host, final Credentials creds) { public Executor auth(final String host, final Credentials credentials) {
final HttpHost httpHost; final HttpHost httpHost;
try { try {
httpHost = HttpHost.create(host); httpHost = HttpHost.create(host);
} catch (final URISyntaxException ex) { } catch (final URISyntaxException ex) {
throw new IllegalArgumentException("Invalid host: " + host); throw new IllegalArgumentException("Invalid host: " + host);
} }
return auth(httpHost, creds); return auth(httpHost, credentials);
} }
public Executor authPreemptive(final HttpHost host) { public Executor authPreemptive(final HttpHost host) {

View File

@ -127,14 +127,14 @@ public class AuthScope {
/** /**
* Creates a copy of the given credentials scope. * Creates a copy of the given credentials scope.
*/ */
public AuthScope(final AuthScope authscope) { public AuthScope(final AuthScope authScope) {
super(); super();
Args.notNull(authscope, "Scope"); Args.notNull(authScope, "Scope");
this.protocol = authscope.getProtocol(); this.protocol = authScope.getProtocol();
this.host = authscope.getHost(); this.host = authScope.getHost();
this.port = authscope.getPort(); this.port = authScope.getPort();
this.realm = authscope.getRealm(); this.realm = authScope.getRealm();
this.authScheme = authscope.getAuthScheme(); this.authScheme = authScope.getAuthScheme();
} }
public String getProtocol() { public String getProtocol() {

View File

@ -44,11 +44,11 @@ public interface CredentialsProvider {
* Returns {@link Credentials credentials} for the given authentication scope, * Returns {@link Credentials credentials} for the given authentication scope,
* if available. * if available.
* *
* @param authscope the {@link AuthScope authentication scope} * @param authScope the {@link AuthScope authentication scope}
* @param context the {@link HttpContext http context} * @param context the {@link HttpContext http context}
* @return the credentials * @return the credentials
* @since 5.0 * @since 5.0
*/ */
Credentials getCredentials(AuthScope authscope, HttpContext context); Credentials getCredentials(AuthScope authScope, HttpContext context);
} }

View File

@ -42,13 +42,13 @@ public interface CredentialsStore extends CredentialsProvider {
* Sets the {@link Credentials credentials} for the given authentication * Sets the {@link Credentials credentials} for the given authentication
* scope. Any previous credentials for the given scope will be overwritten. * scope. Any previous credentials for the given scope will be overwritten.
* *
* @param authscope the {@link AuthScope authentication scope} * @param authScope the {@link AuthScope authentication scope}
* @param credentials the authentication {@link Credentials credentials} * @param credentials the authentication {@link Credentials credentials}
* for the given scope. * for the given scope.
* *
* @see #getCredentials(AuthScope, org.apache.hc.core5.http.protocol.HttpContext) * @see #getCredentials(AuthScope, org.apache.hc.core5.http.protocol.HttpContext)
*/ */
void setCredentials(AuthScope authscope, Credentials credentials); void setCredentials(AuthScope authScope, Credentials credentials);
/** /**
* Clears all credentials. * Clears all credentials.

View File

@ -56,9 +56,9 @@ public interface ConnectionBackoffStrategy {
* signal. Implementations MUST restrict themselves to examining * signal. Implementations MUST restrict themselves to examining
* the response header and MUST NOT consume any of the response * the response header and MUST NOT consume any of the response
* body, if any. * body, if any.
* @param resp the {@code HttpResponse} that was received * @param response the {@code HttpResponse} that was received
* @return {@code true} if a backoff signal should be * @return {@code true} if a backoff signal should be
* given * given
*/ */
boolean shouldBackoff(HttpResponse resp); boolean shouldBackoff(HttpResponse response);
} }

View File

@ -91,7 +91,7 @@ abstract class AbstractMultipartFormat {
static final ByteArrayBuffer FIELD_SEP = encode(StandardCharsets.ISO_8859_1, ": "); static final ByteArrayBuffer FIELD_SEP = encode(StandardCharsets.ISO_8859_1, ": ");
static final ByteArrayBuffer CR_LF = encode(StandardCharsets.ISO_8859_1, "\r\n"); static final ByteArrayBuffer CR_LF = encode(StandardCharsets.ISO_8859_1, "\r\n");
static final ByteArrayBuffer TWO_DASHES = encode(StandardCharsets.ISO_8859_1, "--"); static final ByteArrayBuffer TWO_HYPHENS = encode(StandardCharsets.ISO_8859_1, "--");
final Charset charset; final Charset charset;
final String boundary; final String boundary;
@ -122,7 +122,7 @@ abstract class AbstractMultipartFormat {
final ByteArrayBuffer boundaryEncoded = encode(this.charset, this.boundary); final ByteArrayBuffer boundaryEncoded = encode(this.charset, this.boundary);
for (final MultipartPart part: getParts()) { for (final MultipartPart part: getParts()) {
writeBytes(TWO_DASHES, out); writeBytes(TWO_HYPHENS, out);
writeBytes(boundaryEncoded, out); writeBytes(boundaryEncoded, out);
writeBytes(CR_LF, out); writeBytes(CR_LF, out);
@ -135,9 +135,9 @@ abstract class AbstractMultipartFormat {
} }
writeBytes(CR_LF, out); writeBytes(CR_LF, out);
} }
writeBytes(TWO_DASHES, out); writeBytes(TWO_HYPHENS, out);
writeBytes(boundaryEncoded, out); writeBytes(boundaryEncoded, out);
writeBytes(TWO_DASHES, out); writeBytes(TWO_HYPHENS, out);
writeBytes(CR_LF, out); writeBytes(CR_LF, out);
} }

View File

@ -38,7 +38,7 @@ public class Wire {
private static final int MAX_STRING_BUILDER_SIZE = 2048; private static final int MAX_STRING_BUILDER_SIZE = 2048;
private static final ThreadLocal<StringBuilder> threadLocal = new ThreadLocal<>(); private static final ThreadLocal<StringBuilder> THREAD_LOCAL = new ThreadLocal<>();
/** /**
* Returns a {@code StringBuilder} that this Layout implementation can use to write the formatted log event to. * Returns a {@code StringBuilder} that this Layout implementation can use to write the formatted log event to.
@ -46,12 +46,11 @@ public class Wire {
* @return a {@code StringBuilder} * @return a {@code StringBuilder}
*/ */
private static StringBuilder getStringBuilder() { private static StringBuilder getStringBuilder() {
StringBuilder result = threadLocal.get(); StringBuilder result = THREAD_LOCAL.get();
if (result == null) { if (result == null) {
result = new StringBuilder(MAX_STRING_BUILDER_SIZE); result = new StringBuilder(MAX_STRING_BUILDER_SIZE);
threadLocal.set(result); THREAD_LOCAL.set(result);
} }
// TODO Delegate to Log4j's 2.9 StringBuilds.trimToMaxSize() when it is released.
trimToMaxSize(result, MAX_STRING_BUILDER_SIZE); trimToMaxSize(result, MAX_STRING_BUILDER_SIZE);
result.setLength(0); result.setLength(0);
return result; return result;
@ -64,7 +63,6 @@ public class Wire {
* @param stringBuilder the StringBuilder to check * @param stringBuilder the StringBuilder to check
* @param maxSize the maximum number of characters the StringBuilder is allowed to have * @param maxSize the maximum number of characters the StringBuilder is allowed to have
*/ */
// TODO Delete wheb Log4j's 2.9 (see #trimToMaxSize(StringBuild))
private static void trimToMaxSize(final StringBuilder stringBuilder, final int maxSize) { private static void trimToMaxSize(final StringBuilder stringBuilder, final int maxSize) {
if (stringBuilder != null && stringBuilder.capacity() > maxSize) { if (stringBuilder != null && stringBuilder.capacity() > maxSize) {
stringBuilder.setLength(maxSize); stringBuilder.setLength(maxSize);

View File

@ -54,7 +54,7 @@ abstract class AbstractMinimalHttpAsyncClientBase extends AbstractHttpAsyncClien
@Override @Override
protected <T> Future<T> doExecute( protected <T> Future<T> doExecute(
final HttpHost httphost, final HttpHost httpHost,
final AsyncRequestProducer requestProducer, final AsyncRequestProducer requestProducer,
final AsyncResponseConsumer<T> responseConsumer, final AsyncResponseConsumer<T> responseConsumer,
final HandlerFactory<AsyncPushConsumer> pushHandlerFactory, final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,

View File

@ -68,7 +68,7 @@ import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
@Internal @Internal
public final class InternalHttpAsyncClient extends InternalAbstractHttpAsyncClient { public final class InternalHttpAsyncClient extends InternalAbstractHttpAsyncClient {
private final AsyncClientConnectionManager connmgr; private final AsyncClientConnectionManager manager;
private final HttpRoutePlanner routePlanner; private final HttpRoutePlanner routePlanner;
private final HttpVersionPolicy versionPolicy; private final HttpVersionPolicy versionPolicy;
@ -77,7 +77,7 @@ public final class InternalHttpAsyncClient extends InternalAbstractHttpAsyncClie
final AsyncExecChainElement execChain, final AsyncExecChainElement execChain,
final AsyncPushConsumerRegistry pushConsumerRegistry, final AsyncPushConsumerRegistry pushConsumerRegistry,
final ThreadFactory threadFactory, final ThreadFactory threadFactory,
final AsyncClientConnectionManager connmgr, final AsyncClientConnectionManager manager,
final HttpRoutePlanner routePlanner, final HttpRoutePlanner routePlanner,
final HttpVersionPolicy versionPolicy, final HttpVersionPolicy versionPolicy,
final Lookup<CookieSpecProvider> cookieSpecRegistry, final Lookup<CookieSpecProvider> cookieSpecRegistry,
@ -88,14 +88,14 @@ public final class InternalHttpAsyncClient extends InternalAbstractHttpAsyncClie
final List<Closeable> closeables) { final List<Closeable> closeables) {
super(ioReactor, pushConsumerRegistry, threadFactory, execChain, super(ioReactor, pushConsumerRegistry, threadFactory, execChain,
cookieSpecRegistry, authSchemeRegistry, cookieStore, credentialsProvider, defaultConfig, closeables); cookieSpecRegistry, authSchemeRegistry, cookieStore, credentialsProvider, defaultConfig, closeables);
this.connmgr = connmgr; this.manager = manager;
this.routePlanner = routePlanner; this.routePlanner = routePlanner;
this.versionPolicy = versionPolicy; this.versionPolicy = versionPolicy;
} }
@Override @Override
AsyncExecRuntime createAsyncExecRuntime(final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) { AsyncExecRuntime createAsyncExecRuntime(final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) {
return new InternalHttpAsyncExecRuntime(log, connmgr, getConnectionInitiator(), pushHandlerFactory, versionPolicy); return new InternalHttpAsyncExecRuntime(log, manager, getConnectionInitiator(), pushHandlerFactory, versionPolicy);
} }
@Override @Override

View File

@ -98,7 +98,7 @@ import org.apache.hc.core5.util.Timeout;
@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL) @Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClientBase { public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClientBase {
private final AsyncClientConnectionManager connmgr; private final AsyncClientConnectionManager manager;
private final SchemePortResolver schemePortResolver; private final SchemePortResolver schemePortResolver;
private final HttpVersionPolicy versionPolicy; private final HttpVersionPolicy versionPolicy;
@ -109,7 +109,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
final IOReactorConfig reactorConfig, final IOReactorConfig reactorConfig,
final ThreadFactory threadFactory, final ThreadFactory threadFactory,
final ThreadFactory workerThreadFactory, final ThreadFactory workerThreadFactory,
final AsyncClientConnectionManager connmgr, final AsyncClientConnectionManager manager,
final SchemePortResolver schemePortResolver) { final SchemePortResolver schemePortResolver) {
super(new DefaultConnectingIOReactor( super(new DefaultConnectingIOReactor(
eventHandlerFactory, eventHandlerFactory,
@ -128,7 +128,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
}), }),
pushConsumerRegistry, pushConsumerRegistry,
threadFactory); threadFactory);
this.connmgr = connmgr; this.manager = manager;
this.schemePortResolver = schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE; this.schemePortResolver = schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE;
this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE; this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
} }
@ -142,7 +142,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
final HttpRoute route = new HttpRoute(RoutingSupport.normalize(host, schemePortResolver)); final HttpRoute route = new HttpRoute(RoutingSupport.normalize(host, schemePortResolver));
final ComplexFuture<AsyncConnectionEndpoint> resultFuture = new ComplexFuture<>(callback); final ComplexFuture<AsyncConnectionEndpoint> resultFuture = new ComplexFuture<>(callback);
final String exchangeId = ExecSupport.getNextExchangeId(); final String exchangeId = ExecSupport.getNextExchangeId();
final Future<AsyncConnectionEndpoint> leaseFuture = connmgr.lease( final Future<AsyncConnectionEndpoint> leaseFuture = manager.lease(
exchangeId, exchangeId,
route, route,
null, null,
@ -154,7 +154,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
if (connectionEndpoint.isConnected()) { if (connectionEndpoint.isConnected()) {
resultFuture.completed(connectionEndpoint); resultFuture.completed(connectionEndpoint);
} else { } else {
final Future<AsyncConnectionEndpoint> connectFuture = connmgr.connect( final Future<AsyncConnectionEndpoint> connectFuture = manager.connect(
connectionEndpoint, connectionEndpoint,
getConnectionInitiator(), getConnectionInitiator(),
connectTimeout, connectTimeout,
@ -478,7 +478,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
@Override @Override
public void releaseAndReuse() { public void releaseAndReuse() {
if (released.compareAndSet(false, true)) { if (released.compareAndSet(false, true)) {
connmgr.release(connectionEndpoint, null, TimeValue.NEG_ONE_MILLISECONDS); manager.release(connectionEndpoint, null, TimeValue.NEG_ONE_MILLISECONDS);
} }
} }
@ -486,7 +486,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
public void releaseAndDiscard() { public void releaseAndDiscard() {
if (released.compareAndSet(false, true)) { if (released.compareAndSet(false, true)) {
Closer.closeQuietly(connectionEndpoint); Closer.closeQuietly(connectionEndpoint);
connmgr.release(connectionEndpoint, null, TimeValue.ZERO_MILLISECONDS); manager.release(connectionEndpoint, null, TimeValue.ZERO_MILLISECONDS);
} }
} }

View File

@ -57,32 +57,32 @@ public class BasicCredentialsProvider implements CredentialsStore {
@Override @Override
public void setCredentials( public void setCredentials(
final AuthScope authscope, final AuthScope authScope,
final Credentials credentials) { final Credentials credentials) {
Args.notNull(authscope, "Authentication scope"); Args.notNull(authScope, "Authentication scope");
credMap.put(authscope, credentials); credMap.put(authScope, credentials);
} }
/** /**
* Find matching {@link Credentials credentials} for the given authentication scope. * Find matching {@link Credentials credentials} for the given authentication scope.
* *
* @param map the credentials hash map * @param map the credentials hash map
* @param authscope the {@link AuthScope authentication scope} * @param authScope the {@link AuthScope authentication scope}
* @return the credentials * @return the credentials
* *
*/ */
private static Credentials matchCredentials( private static Credentials matchCredentials(
final Map<AuthScope, Credentials> map, final Map<AuthScope, Credentials> map,
final AuthScope authscope) { final AuthScope authScope) {
// see if we get a direct hit // see if we get a direct hit
Credentials creds = map.get(authscope); Credentials creds = map.get(authScope);
if (creds == null) { if (creds == null) {
// Nope. // Nope.
// Do a full scan // Do a full scan
int bestMatchFactor = -1; int bestMatchFactor = -1;
AuthScope bestMatch = null; AuthScope bestMatch = null;
for (final AuthScope current: map.keySet()) { for (final AuthScope current: map.keySet()) {
final int factor = authscope.match(current); final int factor = authScope.match(current);
if (factor > bestMatchFactor) { if (factor > bestMatchFactor) {
bestMatchFactor = factor; bestMatchFactor = factor;
bestMatch = current; bestMatch = current;
@ -96,10 +96,10 @@ public class BasicCredentialsProvider implements CredentialsStore {
} }
@Override @Override
public Credentials getCredentials(final AuthScope authscope, public Credentials getCredentials(final AuthScope authScope,
final HttpContext httpContext) { final HttpContext httpContext) {
Args.notNull(authscope, "Authentication scope"); Args.notNull(authScope, "Authentication scope");
return matchCredentials(this.credMap, authscope); return matchCredentials(this.credMap, authScope);
} }
@Override @Override

View File

@ -88,13 +88,13 @@ public class SystemDefaultCredentialsProvider implements CredentialsStore {
} }
@Override @Override
public void setCredentials(final AuthScope authscope, final Credentials credentials) { public void setCredentials(final AuthScope authScope, final Credentials credentials) {
internal.setCredentials(authscope, credentials); internal.setCredentials(authScope, credentials);
} }
private static PasswordAuthentication getSystemCreds( private static PasswordAuthentication getSystemCreds(
final String protocol, final String protocol,
final AuthScope authscope, final AuthScope authScope,
final Authenticator.RequestorType requestorType, final Authenticator.RequestorType requestorType,
final HttpClientContext context) { final HttpClientContext context) {
final HttpRequest request = context != null ? context.getRequest() : null; final HttpRequest request = context != null ? context.getRequest() : null;
@ -107,41 +107,41 @@ public class SystemDefaultCredentialsProvider implements CredentialsStore {
} }
// use null addr, because the authentication fails if it does not exactly match the expected realm's host // use null addr, because the authentication fails if it does not exactly match the expected realm's host
return Authenticator.requestPasswordAuthentication( return Authenticator.requestPasswordAuthentication(
authscope.getHost(), authScope.getHost(),
null, null,
authscope.getPort(), authScope.getPort(),
protocol, protocol,
authscope.getRealm(), authScope.getRealm(),
translateAuthScheme(authscope.getAuthScheme()), translateAuthScheme(authScope.getAuthScheme()),
targetHostURL, targetHostURL,
requestorType); requestorType);
} }
@Override @Override
public Credentials getCredentials(final AuthScope authscope, final HttpContext context) { public Credentials getCredentials(final AuthScope authScope, final HttpContext context) {
Args.notNull(authscope, "Auth scope"); Args.notNull(authScope, "Auth scope");
final Credentials localcreds = internal.getCredentials(authscope, context); final Credentials localcreds = internal.getCredentials(authScope, context);
if (localcreds != null) { if (localcreds != null) {
return localcreds; return localcreds;
} }
final String host = authscope.getHost(); final String host = authScope.getHost();
if (host != null) { if (host != null) {
final HttpClientContext clientContext = context != null ? HttpClientContext.adapt(context) : null; final HttpClientContext clientContext = context != null ? HttpClientContext.adapt(context) : null;
final String protocol = authscope.getProtocol() != null ? authscope.getProtocol() : (authscope.getPort() == 443 ? URIScheme.HTTPS.id : URIScheme.HTTP.id); final String protocol = authScope.getProtocol() != null ? authScope.getProtocol() : (authScope.getPort() == 443 ? URIScheme.HTTPS.id : URIScheme.HTTP.id);
PasswordAuthentication systemcreds = getSystemCreds( PasswordAuthentication systemcreds = getSystemCreds(
protocol, authscope, Authenticator.RequestorType.SERVER, clientContext); protocol, authScope, Authenticator.RequestorType.SERVER, clientContext);
if (systemcreds == null) { if (systemcreds == null) {
systemcreds = getSystemCreds( systemcreds = getSystemCreds(
protocol, authscope, Authenticator.RequestorType.PROXY, clientContext); protocol, authScope, Authenticator.RequestorType.PROXY, clientContext);
} }
if (systemcreds == null) { if (systemcreds == null) {
// Look for values given using http.proxyUser/http.proxyPassword or // Look for values given using http.proxyUser/http.proxyPassword or
// https.proxyUser/https.proxyPassword. We cannot simply use the protocol from // https.proxyUser/https.proxyPassword. We cannot simply use the protocol from
// the origin since a proxy retrieved from https.proxyHost/https.proxyPort will // the origin since a proxy retrieved from https.proxyHost/https.proxyPort will
// still use http as protocol // still use http as protocol
systemcreds = getProxyCredentials("http", authscope); systemcreds = getProxyCredentials("http", authScope);
if (systemcreds == null) { if (systemcreds == null) {
systemcreds = getProxyCredentials("https", authscope); systemcreds = getProxyCredentials("https", authScope);
} }
} }
if (systemcreds != null) { if (systemcreds != null) {
@ -149,7 +149,7 @@ public class SystemDefaultCredentialsProvider implements CredentialsStore {
if (domain != null) { if (domain != null) {
return new NTCredentials(systemcreds.getUserName(), systemcreds.getPassword(), null, domain); return new NTCredentials(systemcreds.getUserName(), systemcreds.getPassword(), null, domain);
} }
if (AuthSchemes.NTLM.ident.equalsIgnoreCase(authscope.getAuthScheme())) { if (AuthSchemes.NTLM.ident.equalsIgnoreCase(authScope.getAuthScheme())) {
// Domain may be specified in a fully qualified user name // Domain may be specified in a fully qualified user name
return new NTCredentials( return new NTCredentials(
systemcreds.getUserName(), systemcreds.getPassword(), null, null); systemcreds.getUserName(), systemcreds.getPassword(), null, null);
@ -160,7 +160,7 @@ public class SystemDefaultCredentialsProvider implements CredentialsStore {
return null; return null;
} }
private static PasswordAuthentication getProxyCredentials(final String protocol, final AuthScope authscope) { private static PasswordAuthentication getProxyCredentials(final String protocol, final AuthScope authScope) {
final String proxyHost = System.getProperty(protocol + ".proxyHost"); final String proxyHost = System.getProperty(protocol + ".proxyHost");
if (proxyHost == null) { if (proxyHost == null) {
return null; return null;
@ -172,7 +172,7 @@ public class SystemDefaultCredentialsProvider implements CredentialsStore {
try { try {
final AuthScope systemScope = new AuthScope(proxyHost, Integer.parseInt(proxyPort)); final AuthScope systemScope = new AuthScope(proxyHost, Integer.parseInt(proxyPort));
if (authscope.match(systemScope) >= 0) { if (authScope.match(systemScope) >= 0) {
final String proxyUser = System.getProperty(protocol + ".proxyUser"); final String proxyUser = System.getProperty(protocol + ".proxyUser");
if (proxyUser == null) { if (proxyUser == null) {
return null; return null;

View File

@ -50,9 +50,9 @@ public class DefaultBackoffStrategy implements ConnectionBackoffStrategy {
} }
@Override @Override
public boolean shouldBackoff(final HttpResponse resp) { public boolean shouldBackoff(final HttpResponse response) {
return resp.getCode() == HttpStatus.SC_TOO_MANY_REQUESTS || return response.getCode() == HttpStatus.SC_TOO_MANY_REQUESTS ||
resp.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE; response.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE;
} }
} }

View File

@ -43,7 +43,7 @@ public class NullBackoffStrategy implements ConnectionBackoffStrategy {
} }
@Override @Override
public boolean shouldBackoff(final HttpResponse resp) { public boolean shouldBackoff(final HttpResponse response) {
return false; return false;
} }
} }

View File

@ -60,7 +60,7 @@ public interface ConnectionSocketFactory {
* Connects the socket to the target host with the given resolved remote address. * Connects the socket to the target host with the given resolved remote address.
* *
* @param connectTimeout connect timeout. * @param connectTimeout connect timeout.
* @param sock the socket to connect, as obtained from {@link #createSocket(HttpContext)}. * @param socket the socket to connect, as obtained from {@link #createSocket(HttpContext)}.
* {@code null} indicates that a new socket should be created and connected. * {@code null} indicates that a new socket should be created and connected.
* @param host target host as specified by the caller (end user). * @param host target host as specified by the caller (end user).
* @param remoteAddress the resolved remote address to connect to. * @param remoteAddress the resolved remote address to connect to.
@ -75,7 +75,7 @@ public interface ConnectionSocketFactory {
*/ */
Socket connectSocket( Socket connectSocket(
TimeValue connectTimeout, TimeValue connectTimeout,
Socket sock, Socket socket,
HttpHost host, HttpHost host,
InetSocketAddress remoteAddress, InetSocketAddress remoteAddress,
InetSocketAddress localAddress, InetSocketAddress localAddress,

View File

@ -121,7 +121,7 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor
return false; return false;
} }
private final javax.net.ssl.SSLSocketFactory socketfactory; private final javax.net.ssl.SSLSocketFactory socketFactory;
private final HostnameVerifier hostnameVerifier; private final HostnameVerifier hostnameVerifier;
private final String[] supportedProtocols; private final String[] supportedProtocols;
private final String[] supportedCipherSuites; private final String[] supportedCipherSuites;
@ -156,20 +156,20 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor
* @since 4.4 * @since 4.4
*/ */
public SSLConnectionSocketFactory( public SSLConnectionSocketFactory(
final javax.net.ssl.SSLSocketFactory socketfactory, final javax.net.ssl.SSLSocketFactory socketFactory,
final HostnameVerifier hostnameVerifier) { final HostnameVerifier hostnameVerifier) {
this(socketfactory, null, null, hostnameVerifier); this(socketFactory, null, null, hostnameVerifier);
} }
/** /**
* @since 4.4 * @since 4.4
*/ */
public SSLConnectionSocketFactory( public SSLConnectionSocketFactory(
final javax.net.ssl.SSLSocketFactory socketfactory, final javax.net.ssl.SSLSocketFactory socketFactory,
final String[] supportedProtocols, final String[] supportedProtocols,
final String[] supportedCipherSuites, final String[] supportedCipherSuites,
final HostnameVerifier hostnameVerifier) { final HostnameVerifier hostnameVerifier) {
this.socketfactory = Args.notNull(socketfactory, "SSL socket factory"); this.socketFactory = Args.notNull(socketFactory, "SSL socket factory");
this.supportedProtocols = supportedProtocols; this.supportedProtocols = supportedProtocols;
this.supportedCipherSuites = supportedCipherSuites; this.supportedCipherSuites = supportedCipherSuites;
this.hostnameVerifier = hostnameVerifier != null ? hostnameVerifier : HttpsSupport.getDefaultHostnameVerifier(); this.hostnameVerifier = hostnameVerifier != null ? hostnameVerifier : HttpsSupport.getDefaultHostnameVerifier();
@ -250,7 +250,7 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor
final String target, final String target,
final int port, final int port,
final HttpContext context) throws IOException { final HttpContext context) throws IOException {
final SSLSocket sslsock = (SSLSocket) this.socketfactory.createSocket( final SSLSocket sslsock = (SSLSocket) this.socketFactory.createSocket(
socket, socket,
target, target,
port, port,
@ -310,8 +310,8 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor
protected void verifySession( protected void verifySession(
final String hostname, final String hostname,
final SSLSession sslsession) throws SSLException { final SSLSession sslSession) throws SSLException {
tlsSessionValidator.verifySession(hostname, sslsession, hostnameVerifier); tlsSessionValidator.verifySession(hostname, sslSession, hostnameVerifier);
} }
} }

View File

@ -125,14 +125,14 @@ public class SSLConnectionSocketFactoryBuilder {
} }
public SSLConnectionSocketFactory build() { public SSLConnectionSocketFactory build() {
final javax.net.ssl.SSLSocketFactory socketfactory; final javax.net.ssl.SSLSocketFactory socketFactory;
if (sslContext != null) { if (sslContext != null) {
socketfactory = sslContext.getSocketFactory(); socketFactory = sslContext.getSocketFactory();
} else { } else {
if (systemProperties) { if (systemProperties) {
socketfactory = (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault(); socketFactory = (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault();
} else { } else {
socketfactory = SSLContexts.createDefault().getSocketFactory(); socketFactory = SSLContexts.createDefault().getSocketFactory();
} }
} }
final String[] tlsVersionsCopy; final String[] tlsVersionsCopy;
@ -148,7 +148,7 @@ public class SSLConnectionSocketFactoryBuilder {
ciphersCopy = systemProperties ? HttpsSupport.getSystemCipherSuits() : null; ciphersCopy = systemProperties ? HttpsSupport.getSystemCipherSuits() : null;
} }
return new SSLConnectionSocketFactory( return new SSLConnectionSocketFactory(
socketfactory, socketFactory,
tlsVersionsCopy, tlsVersionsCopy,
ciphersCopy, ciphersCopy,
hostnameVerifier != null ? hostnameVerifier : HttpsSupport.getDefaultHostnameVerifier()); hostnameVerifier != null ? hostnameVerifier : HttpsSupport.getDefaultHostnameVerifier());