Rename or inline local variables to avoid variable hiding
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1571416 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
036e717655
commit
7eb9097b1c
|
@ -105,18 +105,19 @@ public class CachingHttpClientBuilder extends HttpClientBuilder {
|
||||||
@Override
|
@Override
|
||||||
protected ClientExecChain decorateMainExec(final ClientExecChain mainExec) {
|
protected ClientExecChain decorateMainExec(final ClientExecChain mainExec) {
|
||||||
final CacheConfig config = this.cacheConfig != null ? this.cacheConfig : CacheConfig.DEFAULT;
|
final CacheConfig config = this.cacheConfig != null ? this.cacheConfig : CacheConfig.DEFAULT;
|
||||||
ResourceFactory resourceFactory = this.resourceFactory;
|
// We copy the instance fields to avoid changing them, and rename to avoid accidental use of the wrong version
|
||||||
if (resourceFactory == null) {
|
ResourceFactory resourceFactoryCopy = this.resourceFactory;
|
||||||
|
if (resourceFactoryCopy == null) {
|
||||||
if (this.cacheDir == null) {
|
if (this.cacheDir == null) {
|
||||||
resourceFactory = new HeapResourceFactory();
|
resourceFactoryCopy = new HeapResourceFactory();
|
||||||
} else {
|
} else {
|
||||||
resourceFactory = new FileResourceFactory(cacheDir);
|
resourceFactoryCopy = new FileResourceFactory(cacheDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HttpCacheStorage storage = this.storage;
|
HttpCacheStorage storageCopy = this.storage;
|
||||||
if (storage == null) {
|
if (storageCopy == null) {
|
||||||
if (this.cacheDir == null) {
|
if (this.cacheDir == null) {
|
||||||
storage = new BasicHttpCacheStorage(config);
|
storageCopy = new BasicHttpCacheStorage(config);
|
||||||
} else {
|
} else {
|
||||||
final ManagedHttpCacheStorage managedStorage = new ManagedHttpCacheStorage(config);
|
final ManagedHttpCacheStorage managedStorage = new ManagedHttpCacheStorage(config);
|
||||||
if (this.deleteCache) {
|
if (this.deleteCache) {
|
||||||
|
@ -131,7 +132,7 @@ public class CachingHttpClientBuilder extends HttpClientBuilder {
|
||||||
} else {
|
} else {
|
||||||
addCloseable(managedStorage);
|
addCloseable(managedStorage);
|
||||||
}
|
}
|
||||||
storage = managedStorage;
|
storageCopy = managedStorage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final AsynchronousValidator revalidator = createAsynchronousRevalidator(config);
|
final AsynchronousValidator revalidator = createAsynchronousRevalidator(config);
|
||||||
|
@ -139,13 +140,13 @@ public class CachingHttpClientBuilder extends HttpClientBuilder {
|
||||||
|
|
||||||
HttpCacheInvalidator cacheInvalidator = this.httpCacheInvalidator;
|
HttpCacheInvalidator cacheInvalidator = this.httpCacheInvalidator;
|
||||||
if (cacheInvalidator == null) {
|
if (cacheInvalidator == null) {
|
||||||
cacheInvalidator = new CacheInvalidator(uriExtractor, storage);
|
cacheInvalidator = new CacheInvalidator(uriExtractor, storageCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CachingExec(mainExec,
|
return new CachingExec(mainExec,
|
||||||
new BasicHttpCache(
|
new BasicHttpCache(
|
||||||
resourceFactory,
|
resourceFactoryCopy,
|
||||||
storage, config,
|
storageCopy, config,
|
||||||
uriExtractor,
|
uriExtractor,
|
||||||
cacheInvalidator), config, revalidator);
|
cacheInvalidator), config, revalidator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -691,34 +691,35 @@ public class HttpClientBuilder {
|
||||||
|
|
||||||
public CloseableHttpClient build() {
|
public CloseableHttpClient build() {
|
||||||
// Create main request executor
|
// Create main request executor
|
||||||
HttpRequestExecutor requestExec = this.requestExec;
|
// We copy the instance fields to avoid changing them, and rename to avoid accidental use of the wrong version
|
||||||
if (requestExec == null) {
|
HttpRequestExecutor requestExecCopy = this.requestExec;
|
||||||
requestExec = new HttpRequestExecutor();
|
if (requestExecCopy == null) {
|
||||||
|
requestExecCopy = new HttpRequestExecutor();
|
||||||
}
|
}
|
||||||
HttpClientConnectionManager connManager = this.connManager;
|
HttpClientConnectionManager connManagerCopy = this.connManager;
|
||||||
if (connManager == null) {
|
if (connManagerCopy == null) {
|
||||||
LayeredConnectionSocketFactory sslSocketFactory = this.sslSocketFactory;
|
LayeredConnectionSocketFactory sslSocketFactoryCopy = this.sslSocketFactory;
|
||||||
if (sslSocketFactory == null) {
|
if (sslSocketFactoryCopy == null) {
|
||||||
final String[] supportedProtocols = systemProperties ? split(
|
final String[] supportedProtocols = systemProperties ? split(
|
||||||
System.getProperty("https.protocols")) : null;
|
System.getProperty("https.protocols")) : null;
|
||||||
final String[] supportedCipherSuites = systemProperties ? split(
|
final String[] supportedCipherSuites = systemProperties ? split(
|
||||||
System.getProperty("https.cipherSuites")) : null;
|
System.getProperty("https.cipherSuites")) : null;
|
||||||
X509HostnameVerifier hostnameVerifier = this.hostnameVerifier;
|
X509HostnameVerifier hostnameVerifierCopy = this.hostnameVerifier;
|
||||||
if (hostnameVerifier == null) {
|
if (hostnameVerifierCopy == null) {
|
||||||
hostnameVerifier = SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
|
hostnameVerifierCopy = SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
|
||||||
}
|
}
|
||||||
if (sslcontext != null) {
|
if (sslcontext != null) {
|
||||||
sslSocketFactory = new SSLConnectionSocketFactory(
|
sslSocketFactoryCopy = new SSLConnectionSocketFactory(
|
||||||
sslcontext, supportedProtocols, supportedCipherSuites, hostnameVerifier);
|
sslcontext, supportedProtocols, supportedCipherSuites, hostnameVerifierCopy);
|
||||||
} else {
|
} else {
|
||||||
if (systemProperties) {
|
if (systemProperties) {
|
||||||
sslSocketFactory = new SSLConnectionSocketFactory(
|
sslSocketFactoryCopy = new SSLConnectionSocketFactory(
|
||||||
(SSLSocketFactory) SSLSocketFactory.getDefault(),
|
(SSLSocketFactory) SSLSocketFactory.getDefault(),
|
||||||
supportedProtocols, supportedCipherSuites, hostnameVerifier);
|
supportedProtocols, supportedCipherSuites, hostnameVerifierCopy);
|
||||||
} else {
|
} else {
|
||||||
sslSocketFactory = new SSLConnectionSocketFactory(
|
sslSocketFactoryCopy = new SSLConnectionSocketFactory(
|
||||||
SSLContexts.createDefault(),
|
SSLContexts.createDefault(),
|
||||||
hostnameVerifier);
|
hostnameVerifierCopy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -726,7 +727,7 @@ public class HttpClientBuilder {
|
||||||
final PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager(
|
final PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager(
|
||||||
RegistryBuilder.<ConnectionSocketFactory>create()
|
RegistryBuilder.<ConnectionSocketFactory>create()
|
||||||
.register("http", PlainConnectionSocketFactory.getSocketFactory())
|
.register("http", PlainConnectionSocketFactory.getSocketFactory())
|
||||||
.register("https", sslSocketFactory)
|
.register("https", sslSocketFactoryCopy)
|
||||||
.build());
|
.build());
|
||||||
if (defaultSocketConfig != null) {
|
if (defaultSocketConfig != null) {
|
||||||
poolingmgr.setDefaultSocketConfig(defaultSocketConfig);
|
poolingmgr.setDefaultSocketConfig(defaultSocketConfig);
|
||||||
|
@ -749,62 +750,62 @@ public class HttpClientBuilder {
|
||||||
if (maxConnPerRoute > 0) {
|
if (maxConnPerRoute > 0) {
|
||||||
poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
|
poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
|
||||||
}
|
}
|
||||||
connManager = poolingmgr;
|
connManagerCopy = poolingmgr;
|
||||||
}
|
}
|
||||||
ConnectionReuseStrategy reuseStrategy = this.reuseStrategy;
|
ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;
|
||||||
if (reuseStrategy == null) {
|
if (reuseStrategyCopy == null) {
|
||||||
if (systemProperties) {
|
if (systemProperties) {
|
||||||
final String s = System.getProperty("http.keepAlive", "true");
|
final String s = System.getProperty("http.keepAlive", "true");
|
||||||
if ("true".equalsIgnoreCase(s)) {
|
if ("true".equalsIgnoreCase(s)) {
|
||||||
reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE;
|
reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE;
|
||||||
} else {
|
} else {
|
||||||
reuseStrategy = NoConnectionReuseStrategy.INSTANCE;
|
reuseStrategyCopy = NoConnectionReuseStrategy.INSTANCE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE;
|
reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConnectionKeepAliveStrategy keepAliveStrategy = this.keepAliveStrategy;
|
ConnectionKeepAliveStrategy keepAliveStrategyCopy = this.keepAliveStrategy;
|
||||||
if (keepAliveStrategy == null) {
|
if (keepAliveStrategyCopy == null) {
|
||||||
keepAliveStrategy = DefaultConnectionKeepAliveStrategy.INSTANCE;
|
keepAliveStrategyCopy = DefaultConnectionKeepAliveStrategy.INSTANCE;
|
||||||
}
|
}
|
||||||
AuthenticationStrategy targetAuthStrategy = this.targetAuthStrategy;
|
AuthenticationStrategy targetAuthStrategyCopy = this.targetAuthStrategy;
|
||||||
if (targetAuthStrategy == null) {
|
if (targetAuthStrategyCopy == null) {
|
||||||
targetAuthStrategy = TargetAuthenticationStrategy.INSTANCE;
|
targetAuthStrategyCopy = TargetAuthenticationStrategy.INSTANCE;
|
||||||
}
|
}
|
||||||
AuthenticationStrategy proxyAuthStrategy = this.proxyAuthStrategy;
|
AuthenticationStrategy proxyAuthStrategyCopy = this.proxyAuthStrategy;
|
||||||
if (proxyAuthStrategy == null) {
|
if (proxyAuthStrategyCopy == null) {
|
||||||
proxyAuthStrategy = ProxyAuthenticationStrategy.INSTANCE;
|
proxyAuthStrategyCopy = ProxyAuthenticationStrategy.INSTANCE;
|
||||||
}
|
}
|
||||||
UserTokenHandler userTokenHandler = this.userTokenHandler;
|
UserTokenHandler userTokenHandlerCopy = this.userTokenHandler;
|
||||||
if (userTokenHandler == null) {
|
if (userTokenHandlerCopy == null) {
|
||||||
if (!connectionStateDisabled) {
|
if (!connectionStateDisabled) {
|
||||||
userTokenHandler = DefaultUserTokenHandler.INSTANCE;
|
userTokenHandlerCopy = DefaultUserTokenHandler.INSTANCE;
|
||||||
} else {
|
} else {
|
||||||
userTokenHandler = NoopUserTokenHandler.INSTANCE;
|
userTokenHandlerCopy = NoopUserTokenHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ClientExecChain execChain = new MainClientExec(
|
ClientExecChain execChain = new MainClientExec(
|
||||||
requestExec,
|
requestExecCopy,
|
||||||
connManager,
|
connManagerCopy,
|
||||||
reuseStrategy,
|
reuseStrategyCopy,
|
||||||
keepAliveStrategy,
|
keepAliveStrategyCopy,
|
||||||
targetAuthStrategy,
|
targetAuthStrategyCopy,
|
||||||
proxyAuthStrategy,
|
proxyAuthStrategyCopy,
|
||||||
userTokenHandler);
|
userTokenHandlerCopy);
|
||||||
|
|
||||||
execChain = decorateMainExec(execChain);
|
execChain = decorateMainExec(execChain);
|
||||||
|
|
||||||
HttpProcessor httpprocessor = this.httpprocessor;
|
HttpProcessor httpprocessorCopy = this.httpprocessor;
|
||||||
if (httpprocessor == null) {
|
if (httpprocessorCopy == null) {
|
||||||
|
|
||||||
String userAgent = this.userAgent;
|
String userAgentCopy = this.userAgent;
|
||||||
if (userAgent == null) {
|
if (userAgentCopy == null) {
|
||||||
if (systemProperties) {
|
if (systemProperties) {
|
||||||
userAgent = System.getProperty("http.agent");
|
userAgentCopy = System.getProperty("http.agent");
|
||||||
}
|
}
|
||||||
if (userAgent == null) {
|
if (userAgentCopy == null) {
|
||||||
userAgent = DEFAULT_USER_AGENT;
|
userAgentCopy = DEFAULT_USER_AGENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,7 +825,7 @@ public class HttpClientBuilder {
|
||||||
new RequestContent(),
|
new RequestContent(),
|
||||||
new RequestTargetHost(),
|
new RequestTargetHost(),
|
||||||
new RequestClientConnControl(),
|
new RequestClientConnControl(),
|
||||||
new RequestUserAgent(userAgent),
|
new RequestUserAgent(userAgentCopy),
|
||||||
new RequestExpectContinue());
|
new RequestExpectContinue());
|
||||||
if (!cookieManagementDisabled) {
|
if (!cookieManagementDisabled) {
|
||||||
b.add(new RequestAddCookies());
|
b.add(new RequestAddCookies());
|
||||||
|
@ -851,60 +852,58 @@ public class HttpClientBuilder {
|
||||||
b.addLast(i);
|
b.addLast(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
httpprocessor = b.build();
|
httpprocessorCopy = b.build();
|
||||||
}
|
}
|
||||||
execChain = new ProtocolExec(execChain, httpprocessor);
|
execChain = new ProtocolExec(execChain, httpprocessorCopy);
|
||||||
|
|
||||||
execChain = decorateProtocolExec(execChain);
|
execChain = decorateProtocolExec(execChain);
|
||||||
|
|
||||||
// Add request retry executor, if not disabled
|
// Add request retry executor, if not disabled
|
||||||
if (!automaticRetriesDisabled) {
|
if (!automaticRetriesDisabled) {
|
||||||
HttpRequestRetryHandler retryHandler = this.retryHandler;
|
HttpRequestRetryHandler retryHandlerCopy = this.retryHandler;
|
||||||
if (retryHandler == null) {
|
if (retryHandlerCopy == null) {
|
||||||
retryHandler = DefaultHttpRequestRetryHandler.INSTANCE;
|
retryHandlerCopy = DefaultHttpRequestRetryHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
execChain = new RetryExec(execChain, retryHandler);
|
execChain = new RetryExec(execChain, retryHandlerCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRoutePlanner routePlanner = this.routePlanner;
|
HttpRoutePlanner routePlannerCopy = this.routePlanner;
|
||||||
if (routePlanner == null) {
|
if (routePlannerCopy == null) {
|
||||||
SchemePortResolver schemePortResolver = this.schemePortResolver;
|
SchemePortResolver schemePortResolverCopy = this.schemePortResolver;
|
||||||
if (schemePortResolver == null) {
|
if (schemePortResolverCopy == null) {
|
||||||
schemePortResolver = DefaultSchemePortResolver.INSTANCE;
|
schemePortResolverCopy = DefaultSchemePortResolver.INSTANCE;
|
||||||
}
|
}
|
||||||
if (proxy != null) {
|
if (proxy != null) {
|
||||||
routePlanner = new DefaultProxyRoutePlanner(proxy, schemePortResolver);
|
routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy);
|
||||||
} else if (systemProperties) {
|
} else if (systemProperties) {
|
||||||
routePlanner = new SystemDefaultRoutePlanner(
|
routePlannerCopy = new SystemDefaultRoutePlanner(
|
||||||
schemePortResolver, ProxySelector.getDefault());
|
schemePortResolverCopy, ProxySelector.getDefault());
|
||||||
} else {
|
} else {
|
||||||
routePlanner = new DefaultRoutePlanner(schemePortResolver);
|
routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add redirect executor, if not disabled
|
// Add redirect executor, if not disabled
|
||||||
if (!redirectHandlingDisabled) {
|
if (!redirectHandlingDisabled) {
|
||||||
RedirectStrategy redirectStrategy = this.redirectStrategy;
|
RedirectStrategy redirectStrategyCopy = this.redirectStrategy;
|
||||||
if (redirectStrategy == null) {
|
if (redirectStrategyCopy == null) {
|
||||||
redirectStrategy = DefaultRedirectStrategy.INSTANCE;
|
redirectStrategyCopy = DefaultRedirectStrategy.INSTANCE;
|
||||||
}
|
}
|
||||||
execChain = new RedirectExec(execChain, routePlanner, redirectStrategy);
|
execChain = new RedirectExec(execChain, routePlannerCopy, redirectStrategyCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally, add service unavailable retry executor
|
// Optionally, add service unavailable retry executor
|
||||||
final ServiceUnavailableRetryStrategy serviceUnavailStrategy = this.serviceUnavailStrategy;
|
final ServiceUnavailableRetryStrategy serviceUnavailStrategyCopy = this.serviceUnavailStrategy;
|
||||||
if (serviceUnavailStrategy != null) {
|
if (serviceUnavailStrategyCopy != null) {
|
||||||
execChain = new ServiceUnavailableRetryExec(execChain, serviceUnavailStrategy);
|
execChain = new ServiceUnavailableRetryExec(execChain, serviceUnavailStrategyCopy);
|
||||||
}
|
}
|
||||||
// Optionally, add connection back-off executor
|
// Optionally, add connection back-off executor
|
||||||
final BackoffManager backoffManager = this.backoffManager;
|
if (this.backoffManager != null && this.connectionBackoffStrategy != null) {
|
||||||
final ConnectionBackoffStrategy connectionBackoffStrategy = this.connectionBackoffStrategy;
|
execChain = new BackoffStrategyExec(execChain, this.connectionBackoffStrategy, this.backoffManager);
|
||||||
if (backoffManager != null && connectionBackoffStrategy != null) {
|
|
||||||
execChain = new BackoffStrategyExec(execChain, connectionBackoffStrategy, backoffManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Lookup<AuthSchemeProvider> authSchemeRegistry = this.authSchemeRegistry;
|
Lookup<AuthSchemeProvider> authSchemeRegistryCopy = this.authSchemeRegistry;
|
||||||
if (authSchemeRegistry == null) {
|
if (authSchemeRegistryCopy == null) {
|
||||||
authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
|
authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeProvider>create()
|
||||||
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
|
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
|
||||||
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
|
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
|
||||||
.register(AuthSchemes.NTLM, new NTLMSchemeFactory())
|
.register(AuthSchemes.NTLM, new NTLMSchemeFactory())
|
||||||
|
@ -912,9 +911,9 @@ public class HttpClientBuilder {
|
||||||
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory())
|
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
Lookup<CookieSpecProvider> cookieSpecRegistry = this.cookieSpecRegistry;
|
Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;
|
||||||
if (cookieSpecRegistry == null) {
|
if (cookieSpecRegistryCopy == null) {
|
||||||
cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
|
cookieSpecRegistryCopy = RegistryBuilder.<CookieSpecProvider>create()
|
||||||
.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
|
.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
|
||||||
.register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
|
.register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
|
||||||
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
|
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
|
||||||
|
@ -941,10 +940,10 @@ public class HttpClientBuilder {
|
||||||
|
|
||||||
return new InternalHttpClient(
|
return new InternalHttpClient(
|
||||||
execChain,
|
execChain,
|
||||||
connManager,
|
connManagerCopy,
|
||||||
routePlanner,
|
routePlannerCopy,
|
||||||
cookieSpecRegistry,
|
cookieSpecRegistryCopy,
|
||||||
authSchemeRegistry,
|
authSchemeRegistryCopy,
|
||||||
defaultCookieStore,
|
defaultCookieStore,
|
||||||
defaultCredentialsProvider,
|
defaultCredentialsProvider,
|
||||||
defaultRequestConfig != null ? defaultRequestConfig : RequestConfig.DEFAULT,
|
defaultRequestConfig != null ? defaultRequestConfig : RequestConfig.DEFAULT,
|
||||||
|
|
Loading…
Reference in New Issue