diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java index 684f0f066..b6dad2324 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java @@ -92,7 +92,7 @@ public String generateKey(final HttpHost host, final HttpRequest req) { uri = URIUtils.rewriteURI(uri, host); } return normalize(uri).toASCIIString(); - } catch (URISyntaxException ex) { + } catch (final URISyntaxException ex) { return req.getRequestUri(); } } @@ -103,7 +103,7 @@ public String generateKey(final URL url) { } try { return normalize(url.toURI()).toASCIIString(); - } catch (URISyntaxException ex) { + } catch (final URISyntaxException ex) { return url.toString(); } } diff --git a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java index 2cf9393c7..e0515ef35 100644 --- a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java +++ b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java @@ -145,7 +145,7 @@ public Executor auth(final String host, final Credentials creds) { final HttpHost httpHost; try { httpHost = HttpHost.create(host); - } catch (URISyntaxException ex) { + } catch (final URISyntaxException ex) { throw new IllegalArgumentException("Invalid host: " + host); } return auth(httpHost, creds); @@ -170,7 +170,7 @@ public Executor authPreemptive(final String host) { final HttpHost httpHost; try { httpHost = HttpHost.create(host); - } catch (URISyntaxException ex) { + } catch (final URISyntaxException ex) { throw new IllegalArgumentException("Invalid host: " + host); } return authPreemptive(httpHost); @@ -195,7 +195,7 @@ public Executor authPreemptiveProxy(final String proxy) { final HttpHost httpHost; try { httpHost = HttpHost.create(proxy); - } catch (URISyntaxException ex) { + } catch (final URISyntaxException ex) { throw new IllegalArgumentException("Invalid host: " + proxy); } return authPreemptiveProxy(httpHost); diff --git a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java index 52ef46336..f98343af9 100644 --- a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java +++ b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java @@ -305,7 +305,7 @@ public Request viaProxy(final HttpHost proxy) { public Request viaProxy(final String proxy) { try { this.proxy = HttpHost.create(proxy); - } catch (URISyntaxException e) { + } catch (final URISyntaxException e) { throw new IllegalArgumentException("Invalid host"); } return this; diff --git a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Response.java b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Response.java index 62954ce8a..06a4f47b1 100644 --- a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Response.java +++ b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Response.java @@ -90,7 +90,7 @@ public T handleResponse( assertNotConsumed(); try { return handler.handleResponse(this.response); - } catch (HttpException ex) { + } catch (final HttpException ex) { throw new ClientProtocolException(ex); } finally { dispose(); diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/RelaxedLayeredConnectionSocketFactory.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/RelaxedLayeredConnectionSocketFactory.java index b760cf106..aadcce26d 100644 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/RelaxedLayeredConnectionSocketFactory.java +++ b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/RelaxedLayeredConnectionSocketFactory.java @@ -61,7 +61,7 @@ public Socket createLayeredSocket(final Socket socket, } // blindly verify the host if in the trust list - for (String trustedHost : trustedHostsConfiguration.getTrustedHosts()) { + for (final String trustedHost : trustedHostsConfiguration.getTrustedHosts()) { if (createMatcher(trustedHost).matches(target)) { return socket; } diff --git a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/WeakListTest.java b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/WeakListTest.java index 1c13d9463..a28e09ce8 100644 --- a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/WeakListTest.java +++ b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/WeakListTest.java @@ -53,7 +53,7 @@ public void testWeakList() { boolean thrown = false; try { it.next(); - } catch (NoSuchElementException e) { + } catch (final NoSuchElementException e) { thrown = true; } assertTrue(thrown); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java index 8383daabe..a937f4652 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java @@ -45,14 +45,14 @@ */ public class AsyncClientConnectionEviction { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { - IOReactorConfig ioReactorConfig = IOReactorConfig.custom() + final IOReactorConfig ioReactorConfig = IOReactorConfig.custom() .setConnectTimeout(5000) .setSoTimeout(5000) .build(); - CloseableHttpAsyncClient client = HttpAsyncClients.custom() + final CloseableHttpAsyncClient client = HttpAsyncClients.custom() .setIOReactorConfig(ioReactorConfig) .evictExpiredConnections() .evictIdleConnections(10, TimeUnit.SECONDS) @@ -60,7 +60,7 @@ public static void main(String[] args) throws Exception { client.start(); - HttpHost target = new HttpHost("httpbin.org"); + final HttpHost target = new HttpHost("httpbin.org"); final SimpleHttpRequest request = new SimpleHttpRequest("GET", target, "/", null, null); final Future future1 = client.execute( diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java index 860e1a578..39a91bc06 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java @@ -47,29 +47,29 @@ */ public class AsyncClientHttp1Pipelining { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { - IOReactorConfig ioReactorConfig = IOReactorConfig.custom() + final IOReactorConfig ioReactorConfig = IOReactorConfig.custom() .setConnectTimeout(5000) .setSoTimeout(5000) .build(); - CloseableHttpAsyncClient client = HttpAsyncClients.custom() + final CloseableHttpAsyncClient client = HttpAsyncClients.custom() .setProtocolVersion(HttpVersion.HTTP_1_1) .setIOReactorConfig(ioReactorConfig) .build(); client.start(); - HttpHost target = new HttpHost("httpbin.org"); - Future leaseFuture = client.lease(target, null); - AsyncClientEndpoint endpoint = leaseFuture.get(30, TimeUnit.SECONDS); + final HttpHost target = new HttpHost("httpbin.org"); + final Future leaseFuture = client.lease(target, null); + final AsyncClientEndpoint endpoint = leaseFuture.get(30, TimeUnit.SECONDS); try { - String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"}; + final String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"}; final CountDownLatch latch = new CountDownLatch(requestUris.length); for (final String requestUri: requestUris) { - SimpleHttpRequest request = new SimpleHttpRequest("GET", target, requestUri, null, null); + final SimpleHttpRequest request = new SimpleHttpRequest("GET", target, requestUri, null, null); endpoint.execute( new SimpleRequestProducer(request), new SimpleResponseConsumer(), diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2Multiplexing.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2Multiplexing.java index bed37877a..a8e1118a4 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2Multiplexing.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2Multiplexing.java @@ -49,18 +49,18 @@ */ public class AsyncClientHttp2Multiplexing { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { - IOReactorConfig ioReactorConfig = IOReactorConfig.custom() + final IOReactorConfig ioReactorConfig = IOReactorConfig.custom() .setConnectTimeout(5000) .setSoTimeout(5000) .build(); - H2Config h2Config = H2Config.custom() + final H2Config h2Config = H2Config.custom() .setPushEnabled(false) .build(); - CloseableHttpAsyncClient client = HttpAsyncClients.custom() + final CloseableHttpAsyncClient client = HttpAsyncClients.custom() .setIOReactorConfig(ioReactorConfig) .setProtocolVersion(HttpVersion.HTTP_2) .setH2Config(h2Config) @@ -68,15 +68,15 @@ public static void main(String[] args) throws Exception { client.start(); - HttpHost target = new HttpHost("http2bin.org"); - Future leaseFuture = client.lease(target, null); - AsyncClientEndpoint endpoint = leaseFuture.get(30, TimeUnit.SECONDS); + final HttpHost target = new HttpHost("http2bin.org"); + final Future leaseFuture = client.lease(target, null); + final AsyncClientEndpoint endpoint = leaseFuture.get(30, TimeUnit.SECONDS); try { - String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"}; + final String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"}; final CountDownLatch latch = new CountDownLatch(requestUris.length); for (final String requestUri: requestUris) { - SimpleHttpRequest request = new SimpleHttpRequest("GET", target, requestUri, null, null); + final SimpleHttpRequest request = new SimpleHttpRequest("GET", target, requestUri, null, null); endpoint.execute( new SimpleRequestProducer(request), new SimpleResponseConsumer(), diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2ServerPush.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2ServerPush.java index f75ccbcfa..6ece311b5 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2ServerPush.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2ServerPush.java @@ -54,18 +54,18 @@ */ public class AsyncClientHttp2ServerPush { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { - IOReactorConfig ioReactorConfig = IOReactorConfig.custom() + final IOReactorConfig ioReactorConfig = IOReactorConfig.custom() .setConnectTimeout(5000) .setSoTimeout(5000) .build(); - H2Config h2Config = H2Config.custom() + final H2Config h2Config = H2Config.custom() .setPushEnabled(true) .build(); - CloseableHttpAsyncClient client = HttpAsyncClients.custom() + final CloseableHttpAsyncClient client = HttpAsyncClients.custom() .setIOReactorConfig(ioReactorConfig) .setProtocolVersion(HttpVersion.HTTP_2) .setH2Config(h2Config) @@ -116,7 +116,7 @@ public void releaseResources() { final HttpHost target = new HttpHost("http2bin.org"); final String requestURI = "/"; - Future future = client.execute( + final Future future = client.execute( AsyncRequestBuilder.get(target, requestURI).build(), new AbstractCharResponseConsumer() { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchange.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchange.java index b7f862a79..f78acbe42 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchange.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchange.java @@ -44,25 +44,25 @@ */ public class AsyncClientHttpExchange { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { - IOReactorConfig ioReactorConfig = IOReactorConfig.custom() + final IOReactorConfig ioReactorConfig = IOReactorConfig.custom() .setConnectTimeout(5000) .setSoTimeout(5000) .build(); - CloseableHttpAsyncClient client = HttpAsyncClients.custom() + final CloseableHttpAsyncClient client = HttpAsyncClients.custom() .setIOReactorConfig(ioReactorConfig) .build(); client.start(); - HttpHost target = new HttpHost("httpbin.org"); - String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"}; + final HttpHost target = new HttpHost("httpbin.org"); + final String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"}; for (final String requestUri: requestUris) { - SimpleHttpRequest request = new SimpleHttpRequest("GET", target, requestUri, null, null); - Future future = client.execute( + final SimpleHttpRequest request = new SimpleHttpRequest("GET", target, requestUri, null, null); + final Future future = client.execute( new SimpleRequestProducer(request), new SimpleResponseConsumer(), new FutureCallback() { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchangeStreaming.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchangeStreaming.java index c46c8a5d2..088e2e6f9 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchangeStreaming.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchangeStreaming.java @@ -47,24 +47,24 @@ */ public class AsyncClientHttpExchangeStreaming { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { - IOReactorConfig ioReactorConfig = IOReactorConfig.custom() + final IOReactorConfig ioReactorConfig = IOReactorConfig.custom() .setConnectTimeout(5000) .setSoTimeout(5000) .build(); - CloseableHttpAsyncClient client = HttpAsyncClients.custom() + final CloseableHttpAsyncClient client = HttpAsyncClients.custom() .setIOReactorConfig(ioReactorConfig) .build(); client.start(); - HttpHost target = new HttpHost("httpbin.org"); - String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"}; + final HttpHost target = new HttpHost("httpbin.org"); + final String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"}; for (final String requestUri: requestUris) { - Future future = client.execute( + final Future future = client.execute( AsyncRequestBuilder.get(target, requestUri).build(), new AbstractCharResponseConsumer() { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAbortMethod.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAbortMethod.java index bd07c3f20..6dee77b4f 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAbortMethod.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAbortMethod.java @@ -37,9 +37,9 @@ */ public class ClientAbortMethod { - public final static void main(String[] args) throws Exception { + public final static void main(final String[] args) throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - HttpGet httpget = new HttpGet("http://httpbin.org/get"); + final HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); try (CloseableHttpResponse response = httpclient.execute(httpget)) { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAuthentication.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAuthentication.java index 0d81ced34..e9c53d31e 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAuthentication.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAuthentication.java @@ -41,15 +41,15 @@ */ public class ClientAuthentication { - public static void main(String[] args) throws Exception { - BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); + public static void main(final String[] args) throws Exception { + final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope("httpbin.org", 80), new UsernamePasswordCredentials("user", "passwd".toCharArray())); try (CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider) .build()) { - HttpGet httpget = new HttpGet("http://httpbin.org/basic-auth/user/passwd"); + final HttpGet httpget = new HttpGet("http://httpbin.org/basic-auth/user/passwd"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); try (CloseableHttpResponse response = httpclient.execute(httpget)) { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java index d8417c14d..77b085ef0 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java @@ -42,17 +42,17 @@ */ public class ClientChunkEncodedPost { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { if (args.length != 1) { System.out.println("File path not given"); System.exit(1); } try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - HttpPost httppost = new HttpPost("http://httpbin.org/post"); + final HttpPost httppost = new HttpPost("http://httpbin.org/post"); - File file = new File(args[0]); + final File file = new File(args[0]); - InputStreamEntity reqEntity = new InputStreamEntity( + final InputStreamEntity reqEntity = new InputStreamEntity( new FileInputStream(file), -1, ContentType.APPLICATION_OCTET_STREAM); reqEntity.setChunked(true); // It may be more appropriate to use FileEntity class in this particular diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java index e9445279e..46b837b3c 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java @@ -87,21 +87,21 @@ */ public class ClientConfiguration { - public final static void main(String[] args) throws Exception { + public final static void main(final String[] args) throws Exception { // Use custom message parser / writer to customize the way HTTP // messages are parsed from and written out to the data stream. - HttpMessageParserFactory responseParserFactory = new DefaultHttpResponseParserFactory() { + final HttpMessageParserFactory responseParserFactory = new DefaultHttpResponseParserFactory() { @Override - public HttpMessageParser create(H1Config h1Config) { - LineParser lineParser = new BasicLineParser() { + public HttpMessageParser create(final H1Config h1Config) { + final LineParser lineParser = new BasicLineParser() { @Override public Header parseHeader(final CharArrayBuffer buffer) { try { return super.parseHeader(buffer); - } catch (ParseException ex) { + } catch (final ParseException ex) { return new BasicHeader(buffer.toString(), null); } } @@ -111,15 +111,15 @@ public Header parseHeader(final CharArrayBuffer buffer) { } }; - HttpMessageWriterFactory requestWriterFactory = new DefaultHttpRequestWriterFactory(); + final HttpMessageWriterFactory requestWriterFactory = new DefaultHttpRequestWriterFactory(); // Create HTTP/1.1 protocol configuration - H1Config h1Config = H1Config.custom() + final H1Config h1Config = H1Config.custom() .setMaxHeaderCount(200) .setMaxLineLength(2000) .build(); // Create connection configuration - ConnectionConfig connectionConfig = ConnectionConfig.custom() + final ConnectionConfig connectionConfig = ConnectionConfig.custom() .setMalformedInputAction(CodingErrorAction.IGNORE) .setUnmappableInputAction(CodingErrorAction.IGNORE) .setCharset(StandardCharsets.UTF_8) @@ -129,7 +129,7 @@ public Header parseHeader(final CharArrayBuffer buffer) { // initialization of outgoing HTTP connections. Beside standard connection // configuration parameters HTTP connection factory can define message // parser / writer routines to be employed by individual connections. - HttpConnectionFactory connFactory = new ManagedHttpClientConnectionFactory( + final HttpConnectionFactory connFactory = new ManagedHttpClientConnectionFactory( h1Config, connectionConfig, requestWriterFactory, responseParserFactory); // Client HTTP connection objects when fully initialized can be bound to @@ -139,17 +139,17 @@ public Header parseHeader(final CharArrayBuffer buffer) { // SSL context for secure connections can be created either based on // system or application specific properties. - SSLContext sslcontext = SSLContexts.createSystemDefault(); + final SSLContext sslcontext = SSLContexts.createSystemDefault(); // Create a registry of custom connection socket factories for supported // protocol schemes. - Registry socketFactoryRegistry = RegistryBuilder.create() + final Registry socketFactoryRegistry = RegistryBuilder.create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLConnectionSocketFactory(sslcontext)) .build(); // Use custom DNS resolver to override the system DNS resolution. - DnsResolver dnsResolver = new SystemDefaultDnsResolver() { + final DnsResolver dnsResolver = new SystemDefaultDnsResolver() { @Override public InetAddress[] resolve(final String host) throws UnknownHostException { @@ -163,11 +163,11 @@ public InetAddress[] resolve(final String host) throws UnknownHostException { }; // Create a connection manager with custom configuration. - PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager( + final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry, connFactory, dnsResolver); // Create socket configuration - SocketConfig socketConfig = SocketConfig.custom() + final SocketConfig socketConfig = SocketConfig.custom() .setTcpNoDelay(true) .build(); // Configure the connection manager to use socket configuration either @@ -183,11 +183,11 @@ public InetAddress[] resolve(final String host) throws UnknownHostException { connManager.setMaxPerRoute(new HttpRoute(new HttpHost("somehost", 80)), 20); // Use custom cookie store if necessary. - CookieStore cookieStore = new BasicCookieStore(); + final CookieStore cookieStore = new BasicCookieStore(); // Use custom credentials provider if necessary. - CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); // Create global request configuration - RequestConfig defaultRequestConfig = RequestConfig.custom() + final RequestConfig defaultRequestConfig = RequestConfig.custom() .setCookieSpec(CookieSpecs.DEFAULT) .setExpectContinueEnabled(true) .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST)) @@ -203,10 +203,10 @@ public InetAddress[] resolve(final String host) throws UnknownHostException { .setProxy(new HttpHost("myproxy", 8080)) .setDefaultRequestConfig(defaultRequestConfig) .build()) { - HttpGet httpget = new HttpGet("http://httpbin.org/get"); + final HttpGet httpget = new HttpGet("http://httpbin.org/get"); // Request configuration can be overridden at the request level. // They will take precedence over the one set at the client level. - RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig) + final RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig) .setSocketTimeout(5000) .setConnectTimeout(5000) .setConnectionRequestTimeout(5000) @@ -215,7 +215,7 @@ public InetAddress[] resolve(final String host) throws UnknownHostException { httpget.setConfig(requestConfig); // Execution context can be customized locally. - HttpClientContext context = HttpClientContext.create(); + final HttpClientContext context = HttpClientContext.create(); // Contextual attributes set the local context level will take // precedence over those set at the client level. context.setCookieStore(cookieStore); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConnectionRelease.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConnectionRelease.java index 06d73a24e..51663b6a6 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConnectionRelease.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConnectionRelease.java @@ -42,9 +42,9 @@ */ public class ClientConnectionRelease { - public final static void main(String[] args) throws Exception { + public final static void main(final String[] args) throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - HttpGet httpget = new HttpGet("http://httpbin.org/get"); + final HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); try (CloseableHttpResponse response = httpclient.execute(httpget)) { @@ -52,7 +52,7 @@ public final static void main(String[] args) throws Exception { System.out.println(response.getCode() + " " + response.getReasonPhrase()); // Get hold of the response entity - HttpEntity entity = response.getEntity(); + final HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to bother about connection release @@ -60,7 +60,7 @@ public final static void main(String[] args) throws Exception { try (InputStream instream = entity.getContent()) { instream.read(); // do something useful with the response - } catch (IOException ex) { + } catch (final IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw ex; diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomContext.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomContext.java index 66b66bbd4..9ec06aac5 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomContext.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomContext.java @@ -45,24 +45,24 @@ */ public class ClientCustomContext { - public final static void main(String[] args) throws Exception { + public final static void main(final String[] args) throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { // Create a local instance of cookie store - CookieStore cookieStore = new BasicCookieStore(); + final CookieStore cookieStore = new BasicCookieStore(); // Create local HTTP context - HttpClientContext localContext = HttpClientContext.create(); + final HttpClientContext localContext = HttpClientContext.create(); // Bind custom cookie store to the local context localContext.setCookieStore(cookieStore); - HttpGet httpget = new HttpGet("http://httpbin.org/cookies"); + final HttpGet httpget = new HttpGet("http://httpbin.org/cookies"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); // Pass local context as a parameter try (CloseableHttpResponse response = httpclient.execute(httpget, localContext)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); - List cookies = cookieStore.getCookies(); + final List cookies = cookieStore.getCookies(); for (int i = 0; i < cookies.size(); i++) { System.out.println("Local cookie: " + cookies.get(i)); } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java index 7a9e5b403..b3321c1e1 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java @@ -51,26 +51,26 @@ */ public class ClientCustomPublicSuffixList { - public final static void main(String[] args) throws Exception { + public final static void main(final String[] args) throws Exception { // Use PublicSuffixMatcherLoader to load public suffix list from a file, // resource or from an arbitrary URL - PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load( + final PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load( new URL("https://publicsuffix.org/list/effective_tld_names.dat")); // Please use the publicsuffix.org URL to download the list no more than once per day !!! // Please consider making a local copy !!! - RFC6265CookieSpecProvider cookieSpecProvider = new RFC6265CookieSpecProvider(publicSuffixMatcher); - Lookup cookieSpecRegistry = RegistryBuilder.create() + final RFC6265CookieSpecProvider cookieSpecProvider = new RFC6265CookieSpecProvider(publicSuffixMatcher); + final Lookup cookieSpecRegistry = RegistryBuilder.create() .register(CookieSpecs.DEFAULT, cookieSpecProvider) .register(CookieSpecs.STANDARD, cookieSpecProvider) .register(CookieSpecs.STANDARD_STRICT, cookieSpecProvider) .build(); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( SSLContexts.createDefault(), new DefaultHostnameVerifier(publicSuffixMatcher)); - HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() + final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() .setSSLSocketFactory(sslsf) .build(); try (CloseableHttpClient httpclient = HttpClients.custom() @@ -78,7 +78,7 @@ public final static void main(String[] args) throws Exception { .setDefaultCookieSpecRegistry(cookieSpecRegistry) .build()) { - HttpGet httpget = new HttpGet("https://httpbin.org/get"); + final HttpGet httpget = new HttpGet("https://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java index adb0596ca..f2c282d9a 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java @@ -47,26 +47,26 @@ */ public class ClientCustomSSL { - public final static void main(String[] args) throws Exception { + public final static void main(final String[] args) throws Exception { // Trust own CA and all self-signed certs - SSLContext sslcontext = SSLContexts.custom() + final SSLContext sslcontext = SSLContexts.custom() .loadTrustMaterial(new File("my.keystore"), "nopassword".toCharArray(), new TrustSelfSignedStrategy()) .build(); // Allow TLSv1.2 protocol only - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( sslcontext, new String[] { "TLSv1.2" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); - HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() + final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() .setSSLSocketFactory(sslsf) .build(); try (CloseableHttpClient httpclient = HttpClients.custom() .setConnectionManager(cm) .build()) { - HttpGet httpget = new HttpGet("https://httpbin.org/"); + final HttpGet httpget = new HttpGet("https://httpbin.org/"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java index bf3ed6a93..32f0b476c 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java @@ -42,8 +42,8 @@ */ public class ClientEvictExpiredConnections { - public static void main(String[] args) throws Exception { - PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); + public static void main(final String[] args) throws Exception { + final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(100); try (CloseableHttpClient httpclient = HttpClients.custom() .setConnectionManager(cm) @@ -51,15 +51,15 @@ public static void main(String[] args) throws Exception { .evictIdleConnections(5L, TimeUnit.SECONDS) .build()) { // create an array of URIs to perform GETs on - String[] urisToGet = { + final String[] urisToGet = { "http://hc.apache.org/", "http://hc.apache.org/httpcomponents-core-ga/", "http://hc.apache.org/httpcomponents-client-ga/", }; for (int i = 0; i < urisToGet.length; i++) { - String requestURI = urisToGet[i]; - HttpGet request = new HttpGet(requestURI); + final String requestURI = urisToGet[i]; + final HttpGet request = new HttpGet(requestURI); System.out.println("Executing request " + request.getMethod() + " " + request.getRequestUri()); @@ -70,13 +70,13 @@ public static void main(String[] args) throws Exception { } } - PoolStats stats1 = cm.getTotalStats(); + final PoolStats stats1 = cm.getTotalStats(); System.out.println("Connections kept alive: " + stats1.getAvailable()); // Sleep 10 sec and let the connection evictor do its job Thread.sleep(10000); - PoolStats stats2 = cm.getTotalStats(); + final PoolStats stats2 = cm.getTotalStats(); System.out.println("Connections kept alive: " + stats2.getAvailable()); } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteProxy.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteProxy.java index 7e7f948a3..179b1c670 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteProxy.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteProxy.java @@ -42,15 +42,15 @@ */ public class ClientExecuteProxy { - public static void main(String[] args)throws Exception { + public static void main(final String[] args)throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - HttpHost target = new HttpHost("httpbin.org", 443, "https"); - HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http"); + final HttpHost target = new HttpHost("httpbin.org", 443, "https"); + final HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http"); - RequestConfig config = RequestConfig.custom() + final RequestConfig config = RequestConfig.custom() .setProxy(proxy) .build(); - HttpGet request = new HttpGet("/get"); + final HttpGet request = new HttpGet("/get"); request.setConfig(config); System.out.println("Executing request " + request.getMethod() + " " + request.getUri() + diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java index b7744c643..a50b44b2c 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java @@ -54,20 +54,20 @@ */ public class ClientExecuteSOCKS { - public static void main(String[] args)throws Exception { - Registry reg = RegistryBuilder.create() + public static void main(final String[] args)throws Exception { + final Registry reg = RegistryBuilder.create() .register("http", new MyConnectionSocketFactory()) .build(); - PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg); + final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg); try (CloseableHttpClient httpclient = HttpClients.custom() .setConnectionManager(cm) .build()) { - InetSocketAddress socksaddr = new InetSocketAddress("mysockshost", 1234); - HttpClientContext context = HttpClientContext.create(); + final InetSocketAddress socksaddr = new InetSocketAddress("mysockshost", 1234); + final HttpClientContext context = HttpClientContext.create(); context.setAttribute("socks.address", socksaddr); - HttpHost target = new HttpHost("httpbin.org", 80, "http"); - HttpGet request = new HttpGet("/get"); + final HttpHost target = new HttpHost("httpbin.org", 80, "http"); + final HttpGet request = new HttpGet("/get"); System.out.println("Executing request " + request.getMethod() + " " + request.getUri() + " via SOCKS proxy " + socksaddr); @@ -83,8 +83,8 @@ static class MyConnectionSocketFactory implements ConnectionSocketFactory { @Override public Socket createSocket(final HttpContext context) throws IOException { - InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("socks.address"); - Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr); + final InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("socks.address"); + final Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr); return new Socket(proxy); } @@ -107,7 +107,7 @@ public Socket connectSocket( } try { sock.connect(remoteAddress, connectTimeout); - } catch (SocketTimeoutException ex) { + } catch (final SocketTimeoutException ex) { throw new ConnectTimeoutException(ex, host, remoteAddress.getAddress()); } return sock; diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java index 2b08b19e3..28a40f66e 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java @@ -46,20 +46,20 @@ */ public class ClientFormLogin { - public static void main(String[] args) throws Exception { - BasicCookieStore cookieStore = new BasicCookieStore(); + public static void main(final String[] args) throws Exception { + final BasicCookieStore cookieStore = new BasicCookieStore(); try (CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCookieStore(cookieStore) .build()) { - HttpGet httpget = new HttpGet("https://someportal/"); + final HttpGet httpget = new HttpGet("https://someportal/"); try (CloseableHttpResponse response1 = httpclient.execute(httpget)) { - HttpEntity entity = response1.getEntity(); + final HttpEntity entity = response1.getEntity(); System.out.println("Login form get: " + response1.getCode() + " " + response1.getReasonPhrase()); EntityUtils.consume(entity); System.out.println("Initial set of cookies:"); - List cookies = cookieStore.getCookies(); + final List cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { @@ -69,19 +69,19 @@ public static void main(String[] args) throws Exception { } } - HttpUriRequest login = RequestBuilder.post() + final HttpUriRequest login = RequestBuilder.post() .setUri(new URI("https://someportal/")) .addParameter("IDToken1", "username") .addParameter("IDToken2", "password") .build(); try (CloseableHttpResponse response2 = httpclient.execute(login)) { - HttpEntity entity = response2.getEntity(); + final HttpEntity entity = response2.getEntity(); System.out.println("Login form get: " + response2.getCode() + " " + response2.getReasonPhrase()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); - List cookies = cookieStore.getCookies(); + final List cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java index 7c41a9ec2..694f920e7 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java @@ -42,27 +42,27 @@ */ public class ClientMultiThreadedExecution { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { // Create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. - PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); + final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(100); try (CloseableHttpClient httpclient = HttpClients.custom() .setConnectionManager(cm) .build()) { // create an array of URIs to perform GETs on - String[] urisToGet = { + final String[] urisToGet = { "http://hc.apache.org/", "http://hc.apache.org/httpcomponents-core-ga/", "http://hc.apache.org/httpcomponents-client-ga/", }; // create a thread for each URI - GetThread[] threads = new GetThread[urisToGet.length]; + final GetThread[] threads = new GetThread[urisToGet.length]; for (int i = 0; i < threads.length; i++) { - HttpGet httpget = new HttpGet(urisToGet[i]); + final HttpGet httpget = new HttpGet(urisToGet[i]); threads[i] = new GetThread(httpclient, httpget, i + 1); } @@ -89,7 +89,7 @@ static class GetThread extends Thread { private final HttpGet httpget; private final int id; - public GetThread(CloseableHttpClient httpClient, HttpGet httpget, int id) { + public GetThread(final CloseableHttpClient httpClient, final HttpGet httpget, final int id) { this.httpClient = httpClient; this.context = new BasicHttpContext(); this.httpget = httpget; @@ -106,13 +106,13 @@ public void run() { try (CloseableHttpResponse response = httpClient.execute(httpget, context)) { System.out.println(id + " - get executed"); // get the response body as an array of bytes - HttpEntity entity = response.getEntity(); + final HttpEntity entity = response.getEntity(); if (entity != null) { - byte[] bytes = EntityUtils.toByteArray(entity); + final byte[] bytes = EntityUtils.toByteArray(entity); System.out.println(id + " - " + bytes.length + " bytes read"); } } - } catch (Exception e) { + } catch (final Exception e) { System.out.println(id + " - error: " + e); } } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java index e30093b6b..f6ecaa269 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java @@ -44,19 +44,19 @@ */ public class ClientMultipartFormPost { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { if (args.length != 1) { System.out.println("File path not given"); System.exit(1); } try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - HttpPost httppost = new HttpPost("http://localhost:8080" + + final HttpPost httppost = new HttpPost("http://localhost:8080" + "/servlets-examples/servlet/RequestInfoExample"); - FileBody bin = new FileBody(new File(args[0])); - StringBody comment = new StringBody("A binary file of some kind", ContentType.TEXT_PLAIN); + final FileBody bin = new FileBody(new File(args[0])); + final StringBody comment = new StringBody("A binary file of some kind", ContentType.TEXT_PLAIN); - HttpEntity reqEntity = MultipartEntityBuilder.create() + final HttpEntity reqEntity = MultipartEntityBuilder.create() .addPart("bin", bin) .addPart("comment", comment) .build(); @@ -68,7 +68,7 @@ public static void main(String[] args) throws Exception { try (CloseableHttpResponse response = httpclient.execute(httppost)) { System.out.println("----------------------------------------"); System.out.println(response); - HttpEntity resEntity = response.getEntity(); + final HttpEntity resEntity = response.getEntity(); if (resEntity != null) { System.out.println("Response content length: " + resEntity.getContentLength()); } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java index 1e63ffedc..4b9fcffe6 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java @@ -46,20 +46,20 @@ */ public class ClientPreemptiveBasicAuthentication { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { // Generate BASIC scheme object and add it to the local auth cache - BasicScheme basicAuth = new BasicScheme(); + final BasicScheme basicAuth = new BasicScheme(); basicAuth.initPreemptive(new UsernamePasswordCredentials("user", "passwd".toCharArray())); - HttpHost target = new HttpHost("httpbin.org", 80, "http"); + final HttpHost target = new HttpHost("httpbin.org", 80, "http"); // Add AuthCache to the execution context - HttpClientContext localContext = HttpClientContext.create(); + final HttpClientContext localContext = HttpClientContext.create(); localContext.resetAuthExchange(target, basicAuth); - HttpGet httpget = new HttpGet("http://httpbin.org/hidden-basic-auth/user/passwd"); + final HttpGet httpget = new HttpGet("http://httpbin.org/hidden-basic-auth/user/passwd"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); for (int i = 0; i < 3; i++) { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java index 04a12d14a..8e968e220 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java @@ -49,24 +49,24 @@ */ public class ClientPreemptiveDigestAuthentication { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { // Create AuthCache instance - AuthCache authCache = new BasicAuthCache(); + final AuthCache authCache = new BasicAuthCache(); // Generate DIGEST scheme object, initialize it and add it to the local auth cache - DigestScheme digestAuth = new DigestScheme(); + final DigestScheme digestAuth = new DigestScheme(); // Suppose we already know the realm name and the expected nonce value digestAuth.initPreemptive(new UsernamePasswordCredentials("user", "passwd".toCharArray()), "whatever", "realm"); - HttpHost target = new HttpHost("httpbin.org", 80, "http"); + final HttpHost target = new HttpHost("httpbin.org", 80, "http"); authCache.put(target, digestAuth); // Add AuthCache to the execution context - HttpClientContext localContext = HttpClientContext.create(); + final HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); - HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd"); + final HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); for (int i = 0; i < 3; i++) { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java index ea0165ee4..caafd4461 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java @@ -43,8 +43,8 @@ */ public class ClientProxyAuthentication { - public static void main(String[] args) throws Exception { - BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); + public static void main(final String[] args) throws Exception { + final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope("localhost", 8888), new UsernamePasswordCredentials("squid", "squid".toCharArray())); @@ -53,13 +53,13 @@ public static void main(String[] args) throws Exception { new UsernamePasswordCredentials("user", "passwd".toCharArray())); try (CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider).build()) { - HttpHost target = new HttpHost("httpbin.org", 80, "http"); - HttpHost proxy = new HttpHost("localhost", 8888); + final HttpHost target = new HttpHost("httpbin.org", 80, "http"); + final HttpHost proxy = new HttpHost("localhost", 8888); - RequestConfig config = RequestConfig.custom() + final RequestConfig config = RequestConfig.custom() .setProxy(proxy) .build(); - HttpGet httpget = new HttpGet("/basic-auth/user/passwd"); + final HttpGet httpget = new HttpGet("/basic-auth/user/passwd"); httpget.setConfig(config); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri() + diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java index d2baed415..541c55ec3 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java @@ -47,61 +47,61 @@ public class ClientWithRequestFuture { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { // the simplest way to create a HttpAsyncClientWithFuture - HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() + final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() .setMaxConnPerRoute(5) .setMaxConnTotal(5) .build(); - CloseableHttpClient httpclient = HttpClientBuilder.create() + final CloseableHttpClient httpclient = HttpClientBuilder.create() .setConnectionManager(cm) .build(); - ExecutorService execService = Executors.newFixedThreadPool(5); + final ExecutorService execService = Executors.newFixedThreadPool(5); try (FutureRequestExecutionService requestExecService = new FutureRequestExecutionService( httpclient, execService)) { // Because things are asynchronous, you must provide a ResponseHandler - ResponseHandler handler = new ResponseHandler() { + final ResponseHandler handler = new ResponseHandler() { @Override - public Boolean handleResponse(ClassicHttpResponse response) throws IOException { + public Boolean handleResponse(final ClassicHttpResponse response) throws IOException { // simply return true if the status was OK return response.getCode() == HttpStatus.SC_OK; } }; // Simple request ... - HttpGet request1 = new HttpGet("http://httpbin.org/get"); - HttpRequestFutureTask futureTask1 = requestExecService.execute(request1, + final HttpGet request1 = new HttpGet("http://httpbin.org/get"); + final HttpRequestFutureTask futureTask1 = requestExecService.execute(request1, HttpClientContext.create(), handler); - Boolean wasItOk1 = futureTask1.get(); + final Boolean wasItOk1 = futureTask1.get(); System.out.println("It was ok? " + wasItOk1); // Cancel a request try { - HttpGet request2 = new HttpGet("http://httpbin.org/get"); - HttpRequestFutureTask futureTask2 = requestExecService.execute(request2, + final HttpGet request2 = new HttpGet("http://httpbin.org/get"); + final HttpRequestFutureTask futureTask2 = requestExecService.execute(request2, HttpClientContext.create(), handler); futureTask2.cancel(true); - Boolean wasItOk2 = futureTask2.get(); + final Boolean wasItOk2 = futureTask2.get(); System.out.println("It was cancelled so it should never print this: " + wasItOk2); - } catch (CancellationException e) { + } catch (final CancellationException e) { System.out.println("We cancelled it, so this is expected"); } // Request with a timeout - HttpGet request3 = new HttpGet("http://httpbin.org/get"); - HttpRequestFutureTask futureTask3 = requestExecService.execute(request3, + final HttpGet request3 = new HttpGet("http://httpbin.org/get"); + final HttpRequestFutureTask futureTask3 = requestExecService.execute(request3, HttpClientContext.create(), handler); - Boolean wasItOk3 = futureTask3.get(10, TimeUnit.SECONDS); + final Boolean wasItOk3 = futureTask3.get(10, TimeUnit.SECONDS); System.out.println("It was ok? " + wasItOk3); - FutureCallback callback = new FutureCallback() { + final FutureCallback callback = new FutureCallback() { @Override - public void completed(Boolean result) { + public void completed(final Boolean result) { System.out.println("completed with " + result); } @Override - public void failed(Exception ex) { + public void failed(final Exception ex) { System.out.println("failed with " + ex.getMessage()); } @@ -112,12 +112,12 @@ public void cancelled() { }; // Simple request with a callback - HttpGet request4 = new HttpGet("http://httpbin.org/get"); + final HttpGet request4 = new HttpGet("http://httpbin.org/get"); // using a null HttpContext here since it is optional // the callback will be called when the task completes, fails, or is cancelled - HttpRequestFutureTask futureTask4 = requestExecService.execute(request4, + final HttpRequestFutureTask futureTask4 = requestExecService.execute(request4, HttpClientContext.create(), handler, callback); - Boolean wasItOk4 = futureTask4.get(10, TimeUnit.SECONDS); + final Boolean wasItOk4 = futureTask4.get(10, TimeUnit.SECONDS); System.out.println("It was ok? " + wasItOk4); } } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java index e8c58c9ee..f9166d2b8 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java @@ -46,24 +46,24 @@ */ public class ClientWithResponseHandler { - public final static void main(String[] args) throws Exception { + public final static void main(final String[] args) throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - HttpGet httpget = new HttpGet("http://httpbin.org/get"); + final HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); // Create a custom response handler - ResponseHandler responseHandler = new ResponseHandler() { + final ResponseHandler responseHandler = new ResponseHandler() { @Override public String handleResponse( final ClassicHttpResponse response) throws IOException { - int status = response.getCode(); + final int status = response.getCode(); if (status >= HttpStatus.SC_SUCCESS && status < HttpStatus.SC_REDIRECTION) { - HttpEntity entity = response.getEntity(); + final HttpEntity entity = response.getEntity(); try { return entity != null ? EntityUtils.toString(entity) : null; - } catch (ParseException ex) { + } catch (final ParseException ex) { throw new ClientProtocolException(ex); } } else { @@ -72,7 +72,7 @@ public String handleResponse( } }; - String responseBody = httpclient.execute(httpget, responseHandler); + final String responseBody = httpclient.execute(httpget, responseHandler); System.out.println("----------------------------------------"); System.out.println(responseBody); } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java index 649b490b5..c82ff208e 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java @@ -43,21 +43,21 @@ */ public class ProxyTunnelDemo { - public final static void main(String[] args) throws Exception { + public final static void main(final String[] args) throws Exception { - ProxyClient proxyClient = new ProxyClient(); - HttpHost target = new HttpHost("www.yahoo.com", 80); - HttpHost proxy = new HttpHost("localhost", 8888); - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd".toCharArray()); + final ProxyClient proxyClient = new ProxyClient(); + final HttpHost target = new HttpHost("www.yahoo.com", 80); + final HttpHost proxy = new HttpHost("localhost", 8888); + final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd".toCharArray()); try (Socket socket = proxyClient.tunnel(proxy, target, credentials)) { - Writer out = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.ISO_8859_1); + final Writer out = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.ISO_8859_1); out.write("GET / HTTP/1.1\r\n"); out.write("Host: " + target.toHostString() + "\r\n"); out.write("Agent: whatever\r\n"); out.write("Connection: close\r\n"); out.write("\r\n"); out.flush(); - BufferedReader in = new BufferedReader( + final BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream(), StandardCharsets.ISO_8859_1)); String line = null; while ((line = in.readLine()) != null) { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/QuickStart.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/QuickStart.java index f4c9adee9..15e2a75a4 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/QuickStart.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/QuickStart.java @@ -42,9 +42,9 @@ public class QuickStart { - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - HttpGet httpGet = new HttpGet("http://httpbin.org/get"); + final HttpGet httpGet = new HttpGet("http://httpbin.org/get"); // The underlying HTTP connection is still held by the response object // to allow the response content to be streamed directly from the network socket. // In order to ensure correct deallocation of system resources @@ -54,21 +54,21 @@ public static void main(String[] args) throws Exception { // by the connection manager. try (CloseableHttpResponse response1 = httpclient.execute(httpGet)) { System.out.println(response1.getCode() + " " + response1.getReasonPhrase()); - HttpEntity entity1 = response1.getEntity(); + final HttpEntity entity1 = response1.getEntity(); // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity1); } - HttpPost httpPost = new HttpPost("http://httpbin.org/post"); - List nvps = new ArrayList<>(); + final HttpPost httpPost = new HttpPost("http://httpbin.org/post"); + final List nvps = new ArrayList<>(); nvps.add(new BasicNameValuePair("username", "vip")); nvps.add(new BasicNameValuePair("password", "secret")); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); try (CloseableHttpResponse response2 = httpclient.execute(httpPost)) { System.out.println(response2.getCode() + " " + response2.getReasonPhrase()); - HttpEntity entity2 = response2.getEntity(); + final HttpEntity entity2 = response2.getEntity(); // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity2); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractAsyncResponseConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractAsyncResponseConsumer.java index 9def0fe71..f75516e32 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractAsyncResponseConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractAsyncResponseConsumer.java @@ -67,7 +67,7 @@ public void completed(final E result) { try { contentType = ContentType.parse(entityDetails.getContentType()); resultCallback.completed(buildResult(response, result, contentType)); - } catch (UnsupportedCharsetException ex) { + } catch (final UnsupportedCharsetException ex) { resultCallback.failed(ex); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinPushConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinPushConsumer.java index 01a537139..9089e660d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinPushConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinPushConsumer.java @@ -50,7 +50,7 @@ public final void consumePromise( final ContentType contentType; try { contentType = ContentType.parse(entityDetails.getContentType()); - } catch (UnsupportedCharsetException ex) { + } catch (final UnsupportedCharsetException ex) { throw new UnsupportedEncodingException(ex.getMessage()); } start(promise, response, contentType); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinResponseConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinResponseConsumer.java index 99036e8ae..42ce04adf 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinResponseConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinResponseConsumer.java @@ -55,7 +55,7 @@ public final void consumeResponse( try { final ContentType contentType = ContentType.parse(entityDetails.getContentType()); start(response, contentType); - } catch (UnsupportedCharsetException ex) { + } catch (final UnsupportedCharsetException ex) { throw new UnsupportedEncodingException(ex.getMessage()); } } else { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java index 484d045af..21735152e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java @@ -52,7 +52,7 @@ public final void consumePromise( final ContentType contentType; try { contentType = ContentType.parse(entityDetails.getContentType()); - } catch (UnsupportedCharsetException ex) { + } catch (final UnsupportedCharsetException ex) { throw new UnsupportedEncodingException(ex.getMessage()); } Charset charset = contentType != null ? contentType.getCharset() : null; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java index 20ad8b4b9..f465fc986 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java @@ -57,7 +57,7 @@ public final void consumeResponse( final ContentType contentType; try { contentType = ContentType.parse(entityDetails.getContentType()); - } catch (UnsupportedCharsetException ex) { + } catch (final UnsupportedCharsetException ex) { throw new UnsupportedEncodingException(ex.getMessage()); } Charset charset = contentType != null ? contentType.getCharset() : null; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AbstractHttpAsyncClientBase.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AbstractHttpAsyncClientBase.java index c00c7babf..a3ce9fb66 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AbstractHttpAsyncClientBase.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AbstractHttpAsyncClientBase.java @@ -101,7 +101,7 @@ public final void start() { public void run() { try { ioReactor.execute(); - } catch (Exception ex) { + } catch (final Exception ex) { exceptionListener.onError(ex); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/DefaultAsyncHttp2ClientEventHandlerFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/DefaultAsyncHttp2ClientEventHandlerFactory.java index 33bfbf233..76245b38c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/DefaultAsyncHttp2ClientEventHandlerFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/DefaultAsyncHttp2ClientEventHandlerFactory.java @@ -133,7 +133,7 @@ private void logFrameInfo(final String prefix, final RawFrame frame) { final LogAppendable logAppendable = new LogAppendable(frameLog, prefix); framePrinter.printFrameInfo(frame, logAppendable); logAppendable.flush(); - } catch (IOException ignore) { + } catch (final IOException ignore) { } } @@ -142,7 +142,7 @@ private void logFramePayload(final String prefix, final RawFrame frame) { final LogAppendable logAppendable = new LogAppendable(framePayloadLog, prefix); framePrinter.printPayload(frame, logAppendable); logAppendable.flush(); - } catch (IOException ignore) { + } catch (final IOException ignore) { } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java index e4c581547..b5c5fce63 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java @@ -576,7 +576,7 @@ public boolean keepAlive( userTokenHandlerCopy, defaultRequestConfig, closeablesCopy); - } catch (IOReactorException ex) { + } catch (final IOReactorException ex) { throw new IllegalStateException(ex.getMessage(), ex); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java index 868d67221..134099552 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java @@ -131,7 +131,7 @@ private static MinimalHttpAsyncClient createMinimalImpl( new DefaultThreadFactory("httpclient-main", true), new DefaultThreadFactory("httpclient-dispatch", true), connmgr); - } catch (IOReactorException ex) { + } catch (final IOReactorException ex) { throw new IllegalStateException(ex.getMessage(), ex); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java index 2bace5cf9..e5c1b135c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java @@ -201,7 +201,7 @@ public void cancelled() { } }); - } catch (HttpException ex) { + } catch (final HttpException ex) { future.failed(ex); } return future; @@ -265,7 +265,7 @@ public void cancelled() { } }); - } catch (HttpException ex) { + } catch (final HttpException ex) { future.failed(ex); } return future; @@ -419,7 +419,7 @@ public void releaseResources() { private void closeEndpoint() { try { connectionEndpoint.close(); - } catch (IOException ex) { + } catch (final IOException ex) { log.debug("I/O error closing connection endpoint: " + ex.getMessage(), ex); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java index ecb6d0472..6a91b553e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java @@ -265,7 +265,7 @@ public void releaseAndDiscard() { if (released.compareAndSet(false, true)) { try { connectionEndpoint.close(); - } catch (IOException ignore) { + } catch (final IOException ignore) { } connmgr.release(connectionEndpoint, null, -1L, TimeUnit.MILLISECONDS); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java index ef5a8b8b9..1f95bc8a2 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java @@ -184,7 +184,7 @@ private void readObject(final ObjectInputStream in) throws IOException, ClassNot in.defaultReadObject(); try { this.charset = Charset.forName(in.readUTF()); - } catch (UnsupportedCharsetException ex) { + } catch (final UnsupportedCharsetException ex) { this.charset = StandardCharsets.US_ASCII; } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/CredSspScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/CredSspScheme.java index d2005849a..461f81855 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/CredSspScheme.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/CredSspScheme.java @@ -209,7 +209,7 @@ public X509Certificate[] getAcceptedIssuers() sslContext.init( null, new TrustManager[] { tm }, null ); } - catch ( KeyManagementException e ) + catch ( final KeyManagementException e ) { throw new RuntimeException( "SSL Context initialization error: " + e.getMessage(), e ); } @@ -409,11 +409,11 @@ private Certificate getPeerServerCertificate() throws AuthenticationException { peerCertificates = sslEngine.getSession().getPeerCertificates(); } - catch ( SSLPeerUnverifiedException e ) + catch ( final SSLPeerUnverifiedException e ) { throw new AuthenticationException( e.getMessage(), e ); } - for ( Certificate peerCertificate : peerCertificates ) + for ( final Certificate peerCertificate : peerCertificates ) { if ( !( peerCertificate instanceof X509Certificate ) ) { @@ -535,7 +535,7 @@ private byte[] createAuthInfo( final NTCredentials ntcredentials ) throws Authen { return ntlmOutgoingHandle.signAndEncryptMessage( authInfo ); } - catch ( NTLMEngineException e ) + catch ( final NTLMEngineException e ) { throw new AuthenticationException( e.getMessage(), e ); } @@ -607,7 +607,7 @@ private byte[] getSubjectPublicKeyDer( final PublicKey publicKey ) throws Authen buf.get( subjectPublicKey ); return subjectPublicKey; } - catch ( MalformedChallengeException e ) + catch ( final MalformedChallengeException e ) { throw new AuthenticationException( e.getMessage(), e ); } @@ -620,7 +620,7 @@ private void beginTlsHandshake() throws AuthenticationException { getSSLEngine().beginHandshake(); } - catch ( SSLException e ) + catch ( final SSLException e ) { throw new AuthenticationException( "SSL Engine error: " + e.getMessage(), e ); } @@ -675,7 +675,7 @@ private void wrap( final ByteBuffer src, final ByteBuffer dst ) throws Authentic throw new AuthenticationException( "SSL Engine error status: " + engineResult.getStatus() ); } } - catch ( SSLException e ) + catch ( final SSLException e ) { throw new AuthenticationException( "SSL Engine wrap error: " + e.getMessage(), e ); } @@ -725,7 +725,7 @@ private void unwrap( final ByteBuffer src, final ByteBuffer dst ) throws Malform } } - catch ( SSLException e ) + catch ( final SSLException e ) { throw new MalformedChallengeException( "SSL Engine unwrap error: " + e.getMessage(), e ); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DebugUtil.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DebugUtil.java index e7e8a53e5..d89404a3d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DebugUtil.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DebugUtil.java @@ -56,7 +56,7 @@ public static void dump( final StringBuilder sb, final byte[] bytes ) sb.append( "null" ); return; } - for ( byte b : bytes ) + for ( final byte b : bytes ) { sb.append( String.format( "%02X ", b ) ); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java index 1b7cb9d37..2c754f158 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java @@ -257,7 +257,7 @@ private String createDigestResponse(final HttpRequest request) throws Authentica Charset charset; try { charset = charsetName != null ? Charset.forName(charsetName) : StandardCharsets.ISO_8859_1; - } catch (UnsupportedCharsetException ex) { + } catch (final UnsupportedCharsetException ex) { charset = StandardCharsets.ISO_8859_1; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java index 4c1356c2d..271c304f6 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java @@ -874,7 +874,7 @@ private Cipher initCipher() throws NTLMEngineException cipher.init( Cipher.DECRYPT_MODE, new SecretKeySpec( sealingKey, "RC4" ) ); } } - catch ( Exception e ) + catch ( final Exception e ) { throw new NTLMEngineException( e.getMessage(), e ); } @@ -1854,7 +1854,7 @@ static int rotintlft(final int val, final int numbits) { static MessageDigest getMD5() { try { return MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException ex) { + } catch (final NoSuchAlgorithmException ex) { throw new RuntimeException("MD5 message digest doesn't seem to exist - fatal error: "+ex.getMessage(), ex); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/SystemDefaultCredentialsProvider.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/SystemDefaultCredentialsProvider.java index 57674b36d..eb43dbecc 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/SystemDefaultCredentialsProvider.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/SystemDefaultCredentialsProvider.java @@ -152,7 +152,7 @@ public Credentials getCredentials(final AuthScope authscope, final HttpContext c systemcreds = new PasswordAuthentication(proxyUser, proxyPassword != null ? proxyPassword.toCharArray() : new char[] {}); } } - } catch (NumberFormatException ex) { + } catch (final NumberFormatException ex) { } } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java index f7a27ff6d..5f25d481b 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java @@ -189,7 +189,7 @@ public ConnectionEndpoint get( final TimeUnit tunit) throws InterruptedException, ExecutionException, TimeoutException { try { return new InternalConnectionEndpoint(route, getConnection(route, state)); - } catch (IOException ex) { + } catch (final IOException ex) { throw new ExecutionException(ex.getMessage(), ex); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java index f374edf95..eef536fd1 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java @@ -268,7 +268,7 @@ public synchronized ConnectionEndpoint get( boolean stale; try { stale = conn.isStale(); - } catch (IOException ignore) { + } catch (final IOException ignore) { stale = true; } if (stale) { @@ -292,7 +292,7 @@ public synchronized ConnectionEndpoint get( this.endpoint = new InternalConnectionEndpoint(poolEntry); } return this.endpoint; - } catch (Exception ex) { + } catch (final Exception ex) { pool.release(poolEntry, false); throw new ExecutionException(ex.getMessage(), ex); } @@ -333,7 +333,7 @@ public void release( this.log.debug("Connection " + ConnPoolSupport.getId(conn) + " can be kept alive " + s); } } - } catch (RuntimeException ex) { + } catch (final RuntimeException ex) { reusable = false; throw ex; } finally { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java index c869d8850..d59ee77e9 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java @@ -82,14 +82,14 @@ public Future connect( final InetAddress[] remoteAddresses; try { remoteAddresses = dnsResolver.resolve(host.getHostName()); - } catch (UnknownHostException ex) { + } catch (final UnknownHostException ex) { future.failed(ex); return future; } final int port; try { port = schemePortResolver.resolve(host); - } catch (UnsupportedSchemeException ex) { + } catch (final UnsupportedSchemeException ex) { future.failed(ex); return future; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java index 4822f6a72..560f33d6f 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java @@ -229,7 +229,7 @@ public void release( log.debug("Connection " + ConnPoolSupport.getId(connection) + " can be kept alive " + s); } } - } catch (RuntimeException ex) { + } catch (final RuntimeException ex) { reusable = false; throw ex; } finally { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java index 99c2304c7..7b0325663 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java @@ -80,7 +80,7 @@ public class DefaultRedirectStrategy implements RedirectS public DefaultRedirectStrategy(final String... safeMethods) { super(); this.safeMethods = new ConcurrentHashMap<>(); - for (String safeMethod: safeMethods) { + for (final String safeMethod: safeMethods) { this.safeMethods.put(safeMethod.toUpperCase(Locale.ROOT), Boolean.TRUE); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java index c26187fbe..9a28701e6 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java @@ -90,7 +90,7 @@ private static HttpHost determineTarget(final ClassicHttpRequest request) throws URI requestURI = null; try { requestURI = request.getUri(); - } catch (URISyntaxException ignore) { + } catch (final URISyntaxException ignore) { } if (requestURI != null && requestURI.isAbsolute()) { target = URIUtils.extractHost(requestURI); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java index c06a964cb..bd176e057 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java @@ -876,7 +876,7 @@ public void close() throws IOException { connectionEvictor.shutdown(); try { connectionEvictor.awaitTermination(1L, TimeUnit.SECONDS); - } catch (InterruptedException interrupted) { + } catch (final InterruptedException interrupted) { Thread.currentThread().interrupt(); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java index c9849889a..41ecd1ba8 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java @@ -120,7 +120,7 @@ public ClassicHttpResponse execute( final URI redirectUri; try { redirectUri = redirect.getUri(); - } catch (URISyntaxException ex) { + } catch (final URISyntaxException ex) { // Should not happen throw new ProtocolException(ex.getMessage(), ex); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultHostnameVerifier.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultHostnameVerifier.java index a5d48ee58..64bc3240b 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultHostnameVerifier.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultHostnameVerifier.java @@ -301,7 +301,7 @@ static List getSubjectAltNames(final X509Certificate cert) { return Collections.emptyList(); } final List result = new ArrayList<>(); - for (List entry: entries) { + for (final List entry: entries) { final Integer type = entry.size() >= 2 ? (Integer) entry.get(0) : null; if (type != null) { final String s = (String) entry.get(1); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsSupport.java index aaf73b4d3..f30b7db87 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsSupport.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsSupport.java @@ -332,7 +332,7 @@ public static String[] excludeBlacklistedProtocols(final String[] protocols) { return null; } List enabledProtocols = null; - for (String protocol: protocols) { + for (final String protocol: protocols) { if (!protocol.startsWith("SSL") && !BLACKLISED_PROTOCOLS.contains(protocol)) { if (enabledProtocols == null) { enabledProtocols = new ArrayList<>(); @@ -348,7 +348,7 @@ public static String[] excludeBlacklistedCiphers(final String[] ciphers) { return null; } List enabledCiphers = null; - for (String cipher: ciphers) { + for (final String cipher: ciphers) { if (!BLACKLISED_CIPHERS.contains(cipher)) { if (enabledCiphers == null) { enabledCiphers = new ArrayList<>(); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/sync/methods/RequestBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/sync/methods/RequestBuilder.java index c57b960e2..93b5458ef 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/sync/methods/RequestBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/sync/methods/RequestBuilder.java @@ -289,7 +289,7 @@ private RequestBuilder doCopy(final ClassicHttpRequest request) { try { uri = request.getUri(); - } catch (URISyntaxException ignore) { + } catch (final URISyntaxException ignore) { } if (request instanceof Configurable) { config = ((Configurable) request).getConfig();