From c44a10df752dfce7071fa912a183e2454076a1ed Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Tue, 2 Apr 2019 11:21:37 +0200 Subject: [PATCH 1/2] [HTTPCORE-572] Move examples to the src/test folders for each module --- .../http/examples/fluent/FluentAsync.java | 16 ++++++++-------- .../http/examples/fluent/FluentExecutor.java | 4 ++-- .../http/examples/fluent/FluentQuickStart.java | 2 +- .../http/examples/fluent/FluentRequests.java | 2 +- .../fluent/FluentResponseHandling.java | 18 +++++++++--------- .../examples/AsyncClientAuthentication.java | 8 ++++---- .../AsyncClientConnectionEviction.java | 0 .../http/examples/AsyncClientCustomSSL.java | 4 ++-- .../AsyncClientFullDuplexExchange.java | 0 .../examples/AsyncClientHttp1Pipelining.java | 0 .../AsyncClientHttp2FullDuplexExchange.java | 0 .../examples/AsyncClientHttp2Multiplexing.java | 0 .../examples/AsyncClientHttp2ServerPush.java | 0 .../http/examples/AsyncClientHttpExchange.java | 0 .../AsyncClientHttpExchangeStreaming.java | 0 .../http/examples/AsyncClientInterceptors.java | 10 +++++----- .../examples/AsyncClientMessageTrailers.java | 0 .../http/examples/AsyncClientTlsAlpn.java | 2 +- .../client5/http/examples/AsyncQuickStart.java | 10 +++++----- .../http/examples/ClientAbortMethod.java | 6 +++--- .../http/examples/ClientAuthentication.java | 4 ++-- .../http/examples/ClientChunkEncodedPost.java | 4 ++-- .../http/examples/ClientConfiguration.java | 4 ++-- .../http/examples/ClientConnectionRelease.java | 6 +++--- .../http/examples/ClientCustomContext.java | 6 +++--- .../examples/ClientCustomPublicSuffixList.java | 6 +++--- .../client5/http/examples/ClientCustomSSL.java | 0 .../ClientEvictExpiredConnections.java | 7 +++---- .../http/examples/ClientExecuteProxy.java | 4 ++-- .../http/examples/ClientExecuteSOCKS.java | 6 +++--- .../client5/http/examples/ClientFormLogin.java | 6 +++--- .../http/examples/ClientInterceptors.java | 10 +++++----- .../examples/ClientMultiThreadedExecution.java | 10 +++++----- .../http/examples/ClientMultipartFormPost.java | 4 ++-- .../ClientPreemptiveBasicAuthentication.java | 4 ++-- .../ClientPreemptiveDigestAuthentication.java | 6 +++--- .../examples/ClientProxyAuthentication.java | 4 ++-- .../http/examples/ClientWithRequestFuture.java | 2 +- .../examples/ClientWithResponseHandler.java | 4 ++-- .../client5/http/examples/ProxyTunnelDemo.java | 2 +- .../hc/client5/http/examples/QuickStart.java | 6 +++--- .../ReactiveClientFullDuplexExchange.java | 4 ++-- 42 files changed, 95 insertions(+), 96 deletions(-) rename httpclient5-fluent/src/{examples => test/java}/org/apache/hc/client5/http/examples/fluent/FluentAsync.java (84%) rename httpclient5-fluent/src/{examples => test/java}/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java (96%) rename httpclient5-fluent/src/{examples => test/java}/org/apache/hc/client5/http/examples/fluent/FluentQuickStart.java (96%) rename httpclient5-fluent/src/{examples => test/java}/org/apache/hc/client5/http/examples/fluent/FluentRequests.java (97%) rename httpclient5-fluent/src/{examples => test/java}/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java (84%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientAuthentication.java (91%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientCustomSSL.java (97%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientFullDuplexExchange.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientHttp2FullDuplexExchange.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientHttp2Multiplexing.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientHttp2ServerPush.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientHttpExchange.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientHttpExchangeStreaming.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientInterceptors.java (92%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientMessageTrailers.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncClientTlsAlpn.java (98%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/AsyncQuickStart.java (92%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientAbortMethod.java (90%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientAuthentication.java (94%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java (94%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientConfiguration.java (98%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientConnectionRelease.java (92%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientCustomContext.java (92%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java (94%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientCustomSSL.java (100%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java (92%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientExecuteProxy.java (93%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java (95%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientFormLogin.java (94%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientInterceptors.java (91%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java (94%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java (94%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java (94%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java (93%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java (95%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java (98%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java (95%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java (97%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/QuickStart.java (93%) rename httpclient5/src/{examples => test/java}/org/apache/hc/client5/http/examples/ReactiveClientFullDuplexExchange.java (96%) diff --git a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentAsync.java b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentAsync.java similarity index 84% rename from httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentAsync.java rename to httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentAsync.java index 476709e52..29d87d132 100644 --- a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentAsync.java +++ b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentAsync.java @@ -44,12 +44,12 @@ import org.apache.hc.core5.concurrent.FutureCallback; */ public class FluentAsync { - public static void main(String[] args)throws Exception { + public static void main(final String... args)throws Exception { // Use pool of two threads - ExecutorService threadpool = Executors.newFixedThreadPool(2); - Async async = Async.newInstance().use(threadpool); + final ExecutorService threadpool = Executors.newFixedThreadPool(2); + final Async async = Async.newInstance().use(threadpool); - Request[] requests = new Request[] { + final Request[] requests = new Request[] { Request.Get("http://www.google.com/"), Request.Get("http://www.yahoo.com/"), Request.Get("http://www.apache.com/"), @@ -57,10 +57,10 @@ public class FluentAsync { }; - Queue> queue = new LinkedList<>(); + final Queue> queue = new LinkedList<>(); // Execute requests asynchronously for (final Request request: requests) { - Future future = async.execute(request, new FutureCallback() { + final Future future = async.execute(request, new FutureCallback() { @Override public void failed(final Exception ex) { @@ -81,10 +81,10 @@ public class FluentAsync { } while(!queue.isEmpty()) { - Future future = queue.remove(); + final Future future = queue.remove(); try { future.get(); - } catch (ExecutionException ex) { + } catch (final ExecutionException ex) { } } System.out.println("Done"); diff --git a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java similarity index 96% rename from httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java rename to httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java index 2c763d153..6333c9923 100644 --- a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java +++ b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java @@ -44,8 +44,8 @@ import org.apache.hc.core5.util.Timeout; */ public class FluentExecutor { - public static void main(String[] args)throws Exception { - Executor executor = Executor.newInstance() + public static void main(final String... args)throws Exception { + final Executor executor = Executor.newInstance() .auth(new HttpHost("somehost"), "username", "password".toCharArray()) .auth(new HttpHost("myproxy", 8080), "username", "password".toCharArray()) .authPreemptive(new HttpHost("myproxy", 8080)); diff --git a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentQuickStart.java b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentQuickStart.java similarity index 96% rename from httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentQuickStart.java rename to httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentQuickStart.java index ac38048c6..67d600822 100644 --- a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentQuickStart.java +++ b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentQuickStart.java @@ -31,7 +31,7 @@ import org.apache.hc.client5.http.fluent.Request; public class FluentQuickStart { - public static void main(String[] args) throws Exception { + public static void main(final String... args) throws Exception { // The fluent API relieves the user from having to deal with manual // deallocation of system resources at the cost of having to buffer // response content in memory in some cases. diff --git a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentRequests.java b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentRequests.java similarity index 97% rename from httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentRequests.java rename to httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentRequests.java index a8d22bf06..a2559f70d 100644 --- a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentRequests.java +++ b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentRequests.java @@ -40,7 +40,7 @@ import org.apache.hc.core5.util.Timeout; */ public class FluentRequests { - public static void main(String[] args)throws Exception { + public static void main(final String... args)throws Exception { // Execute a GET with timeout settings and return response content as String. Request.Get("http://somehost/") .connectTimeout(Timeout.ofSeconds(1)) diff --git a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java similarity index 84% rename from httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java rename to httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java index 18f9ab6bc..9fa5aa174 100644 --- a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java +++ b/httpclient5-fluent/src/test/java/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java @@ -51,24 +51,24 @@ import org.xml.sax.SAXException; */ public class FluentResponseHandling { - public static void main(String[] args)throws Exception { - Document result = Request.Get("http://somehost/content") + public static void main(final String... args)throws Exception { + final Document result = Request.Get("http://somehost/content") .execute().handleResponse(new HttpClientResponseHandler() { @Override public Document handleResponse(final ClassicHttpResponse response) throws IOException { - int status = response.getCode(); - HttpEntity entity = response.getEntity(); + final int status = response.getCode(); + final HttpEntity entity = response.getEntity(); if (status >= HttpStatus.SC_REDIRECTION) { throw new HttpResponseException(status, response.getReasonPhrase()); } if (entity == null) { throw new ClientProtocolException("Response contains no content"); } - DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); + final DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); try { - DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); - ContentType contentType = ContentType.parseLenient(entity.getContentType()); + final DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); + final ContentType contentType = ContentType.parseLenient(entity.getContentType()); if (!contentType.equals(ContentType.APPLICATION_XML)) { throw new ClientProtocolException("Unexpected content type:" + contentType); } @@ -77,9 +77,9 @@ public class FluentResponseHandling { charset = StandardCharsets.ISO_8859_1; } return docBuilder.parse(entity.getContent(), charset.name()); - } catch (ParserConfigurationException ex) { + } catch (final ParserConfigurationException ex) { throw new IllegalStateException(ex); - } catch (SAXException ex) { + } catch (final SAXException ex) { throw new ClientProtocolException("Malformed XML document", ex); } } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientAuthentication.java similarity index 91% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientAuthentication.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientAuthentication.java index c3287d092..08278f34c 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientAuthentication.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientAuthentication.java @@ -45,18 +45,18 @@ import org.apache.hc.core5.io.CloseMode; */ public class AsyncClientAuthentication { - 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())); - CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom() + final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom() .setDefaultCredentialsProvider(credsProvider) .build(); httpclient.start(); final String requestUri = "http://httpbin.org/basic-auth/user/passwd"; - SimpleHttpRequest httpget = SimpleHttpRequests.GET.create(requestUri); + final SimpleHttpRequest httpget = SimpleHttpRequests.GET.create(requestUri); System.out.println("Executing request " + requestUri); final Future future = httpclient.execute( diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientConnectionEviction.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientCustomSSL.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientCustomSSL.java similarity index 97% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientCustomSSL.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientCustomSSL.java index 2a2f9de57..2f1bb9237 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientCustomSSL.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientCustomSSL.java @@ -57,7 +57,7 @@ import org.apache.hc.core5.ssl.TrustStrategy; */ public class AsyncClientCustomSSL { - public final static void main(final String[] args) throws Exception { + public static void main(final String[] args) throws Exception { // Trust standard CA and those trusted by our custom strategy final SSLContext sslcontext = SSLContexts.custom() .loadTrustMaterial(new TrustStrategy() { @@ -91,7 +91,7 @@ public class AsyncClientCustomSSL { final PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder.create() .setTlsStrategy(tlsStrategy) .build(); - try (CloseableHttpAsyncClient client = HttpAsyncClients.custom() + try (final CloseableHttpAsyncClient client = HttpAsyncClients.custom() .setConnectionManager(cm) .build()) { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientFullDuplexExchange.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientFullDuplexExchange.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientFullDuplexExchange.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientFullDuplexExchange.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2FullDuplexExchange.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttp2FullDuplexExchange.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2FullDuplexExchange.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttp2FullDuplexExchange.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2Multiplexing.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttp2Multiplexing.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2Multiplexing.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttp2Multiplexing.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2ServerPush.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttp2ServerPush.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttp2ServerPush.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttp2ServerPush.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchange.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttpExchange.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchange.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttpExchange.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchangeStreaming.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttpExchangeStreaming.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientHttpExchangeStreaming.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttpExchangeStreaming.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientInterceptors.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInterceptors.java similarity index 92% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientInterceptors.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInterceptors.java index 50a19ab77..e1a6d97a2 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientInterceptors.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInterceptors.java @@ -66,7 +66,7 @@ import org.apache.hc.core5.util.Timeout; */ public class AsyncClientInterceptors { - public final static void main(final String[] args) throws Exception { + public static void main(final String[] args) throws Exception { final IOReactorConfig ioReactorConfig = IOReactorConfig.custom() .setSoTimeout(Timeout.ofSeconds(5)) @@ -101,11 +101,11 @@ public class AsyncClientInterceptors { final AsyncExecChain.Scope scope, final AsyncExecChain chain, final AsyncExecCallback asyncExecCallback) throws HttpException, IOException { - Header idHeader = request.getFirstHeader("request-id"); + final Header idHeader = request.getFirstHeader("request-id"); if (idHeader != null && "13".equalsIgnoreCase(idHeader.getValue())) { - HttpResponse response = new BasicHttpResponse(HttpStatus.SC_NOT_FOUND, "Oppsie"); - ByteBuffer content = ByteBuffer.wrap("bad luck".getBytes(StandardCharsets.US_ASCII)); - AsyncDataConsumer asyncDataConsumer = asyncExecCallback.handleResponse( + final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_NOT_FOUND, "Oppsie"); + final ByteBuffer content = ByteBuffer.wrap("bad luck".getBytes(StandardCharsets.US_ASCII)); + final AsyncDataConsumer asyncDataConsumer = asyncExecCallback.handleResponse( response, new BasicEntityDetails(content.remaining(), ContentType.TEXT_PLAIN)); asyncDataConsumer.consume(content); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientMessageTrailers.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientMessageTrailers.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientMessageTrailers.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientMessageTrailers.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientTlsAlpn.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientTlsAlpn.java similarity index 98% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientTlsAlpn.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientTlsAlpn.java index 151615c83..412307a21 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncClientTlsAlpn.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientTlsAlpn.java @@ -72,7 +72,7 @@ public class AsyncClientTlsAlpn { final PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder.create() .setTlsStrategy(tlsStrategy) .build(); - try (CloseableHttpAsyncClient client = HttpAsyncClients.custom() + try (final CloseableHttpAsyncClient client = HttpAsyncClients.custom() .setVersionPolicy(HttpVersionPolicy.NEGOTIATE) .setConnectionManager(cm) .build()) { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncQuickStart.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncQuickStart.java similarity index 92% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncQuickStart.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncQuickStart.java index 121398c2f..22c28a238 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/AsyncQuickStart.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncQuickStart.java @@ -48,15 +48,15 @@ import org.apache.hc.core5.http.nio.AsyncRequestProducer; public class AsyncQuickStart { - public static void main(String[] args) throws Exception { - CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault(); + public static void mainfinal (final String[] args) throws Exception { + final CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault(); try { // Start the client httpclient.start(); // Execute request final SimpleHttpRequest request1 = SimpleHttpRequests.GET.create("http://httpbin.org/get"); - Future future = httpclient.execute(request1, null); + final Future future = httpclient.execute(request1, null); // and wait until response is received final SimpleHttpResponse response1 = future.get(); System.out.println(request1.getRequestUri() + "->" + response1.getCode()); @@ -90,8 +90,8 @@ public class AsyncQuickStart { // In real world one most likely would want also want to stream // request and response body content final CountDownLatch latch2 = new CountDownLatch(1); - AsyncRequestProducer producer3 = AsyncRequestBuilder.get("http://httpbin.org/get").build(); - AbstractCharResponseConsumer consumer3 = new AbstractCharResponseConsumer() { + final AsyncRequestProducer producer3 = AsyncRequestBuilder.get("http://httpbin.org/get").build(); + final AbstractCharResponseConsumer consumer3 = new AbstractCharResponseConsumer() { HttpResponse response; diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAbortMethod.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java similarity index 90% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAbortMethod.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java index 9c07b16c3..55ab2fd69 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAbortMethod.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java @@ -37,12 +37,12 @@ import org.apache.hc.client5.http.impl.classic.HttpClients; */ public class ClientAbortMethod { - public final static void main(final String[] args) throws Exception { - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + public static void main(final String[] args) throws Exception { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { final HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); - try (CloseableHttpResponse response = httpclient.execute(httpget)) { + try (final CloseableHttpResponse response = httpclient.execute(httpget)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); // Do not feel like reading the response body diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAuthentication.java similarity index 94% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAuthentication.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAuthentication.java index 3e2b89ab0..aa75fefe2 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientAuthentication.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAuthentication.java @@ -46,13 +46,13 @@ public class ClientAuthentication { credsProvider.setCredentials( new AuthScope("httpbin.org", 80), new UsernamePasswordCredentials("user", "passwd".toCharArray())); - try (CloseableHttpClient httpclient = HttpClients.custom() + try (final CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider) .build()) { 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)) { + try (final CloseableHttpResponse response = httpclient.execute(httpget)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); System.out.println(EntityUtils.toString(response.getEntity())); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java similarity index 94% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java index d94064c36..9117d3362 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java @@ -47,7 +47,7 @@ public class ClientChunkEncodedPost { System.out.println("File path not given"); System.exit(1); } - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { final HttpPost httppost = new HttpPost("http://httpbin.org/post"); final File file = new File(args[0]); @@ -63,7 +63,7 @@ public class ClientChunkEncodedPost { httppost.setEntity(reqEntity); System.out.println("Executing request " + httppost.getMethod() + " " + httppost.getUri()); - try (CloseableHttpResponse response = httpclient.execute(httppost)) { + try (final CloseableHttpResponse response = httpclient.execute(httppost)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); System.out.println(EntityUtils.toString(response.getEntity())); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java similarity index 98% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java index 726281665..54db78e83 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java @@ -201,7 +201,7 @@ public class ClientConfiguration { // Create an HttpClient with the given custom dependencies and configuration. - try (CloseableHttpClient httpclient = HttpClients.custom() + try (final CloseableHttpClient httpclient = HttpClients.custom() .setConnectionManager(connManager) .setDefaultCookieStore(cookieStore) .setDefaultCredentialsProvider(credentialsProvider) @@ -226,7 +226,7 @@ public class ClientConfiguration { context.setCredentialsProvider(credentialsProvider); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); - try (CloseableHttpResponse response = httpclient.execute(httpget, context)) { + try (final CloseableHttpResponse response = httpclient.execute(httpget, context)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); System.out.println(EntityUtils.toString(response.getEntity())); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConnectionRelease.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java similarity index 92% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConnectionRelease.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java index cab177855..648160be6 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConnectionRelease.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java @@ -43,11 +43,11 @@ import org.apache.hc.core5.http.HttpEntity; public class ClientConnectionRelease { public final static void main(final String[] args) throws Exception { - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { final HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); - try (CloseableHttpResponse response = httpclient.execute(httpget)) { + try (final CloseableHttpResponse response = httpclient.execute(httpget)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); @@ -57,7 +57,7 @@ public class ClientConnectionRelease { // If the response does not enclose an entity, there is no need // to bother about connection release if (entity != null) { - try (InputStream inStream = entity.getContent()) { + try (final InputStream inStream = entity.getContent()) { inStream.read(); // do something useful with the response } catch (final IOException ex) { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomContext.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java similarity index 92% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomContext.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java index 189ee2351..8ef79dfe4 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomContext.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java @@ -45,8 +45,8 @@ import org.apache.hc.core5.http.io.entity.EntityUtils; */ public class ClientCustomContext { - public final static void main(final String[] args) throws Exception { - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + public static void main(final String[] args) throws Exception { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { // Create a local instance of cookie store final CookieStore cookieStore = new BasicCookieStore(); @@ -59,7 +59,7 @@ public class ClientCustomContext { System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); // Pass local context as a parameter - try (CloseableHttpResponse response = httpclient.execute(httpget, localContext)) { + try (final CloseableHttpResponse response = httpclient.execute(httpget, localContext)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); final List cookies = cookieStore.getCookies(); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java similarity index 94% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java index eed530d43..2e93774da 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java @@ -51,7 +51,7 @@ import org.apache.hc.core5.ssl.SSLContexts; */ public class ClientCustomPublicSuffixList { - public final static void main(final String[] args) throws Exception { + public static void main(final String[] args) throws Exception { // Use PublicSuffixMatcherLoader to load public suffix list from a file, // resource or from an arbitrary URL @@ -72,7 +72,7 @@ public class ClientCustomPublicSuffixList { final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() .setSSLSocketFactory(sslsf) .build(); - try (CloseableHttpClient httpclient = HttpClients.custom() + try (final CloseableHttpClient httpclient = HttpClients.custom() .setConnectionManager(cm) .setDefaultCookieSpecRegistry(cookieSpecRegistry) .build()) { @@ -81,7 +81,7 @@ public class ClientCustomPublicSuffixList { System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); - try (CloseableHttpResponse response = httpclient.execute(httpget)) { + try (final CloseableHttpResponse response = httpclient.execute(httpget)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); System.out.println(EntityUtils.toString(response.getEntity())); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomSSL.java similarity index 100% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomSSL.java diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java similarity index 92% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java index b2a062768..338a52a16 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientEvictExpiredConnections.java @@ -44,7 +44,7 @@ public class ClientEvictExpiredConnections { public static void main(final String[] args) throws Exception { final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(100); - try (CloseableHttpClient httpclient = HttpClients.custom() + try (final CloseableHttpClient httpclient = HttpClients.custom() .setConnectionManager(cm) .evictExpiredConnections() .evictIdleConnections(TimeValue.ofSeconds(5)) @@ -56,13 +56,12 @@ public class ClientEvictExpiredConnections { "http://hc.apache.org/httpcomponents-client-ga/", }; - for (int i = 0; i < urisToGet.length; i++) { - final String requestURI = urisToGet[i]; + for (final String requestURI : urisToGet) { final HttpGet request = new HttpGet(requestURI); System.out.println("Executing request " + request.getMethod() + " " + request.getRequestUri()); - try (CloseableHttpResponse response = httpclient.execute(request)) { + try (final CloseableHttpResponse response = httpclient.execute(request)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); EntityUtils.consume(response.getEntity()); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteProxy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteProxy.java similarity index 93% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteProxy.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteProxy.java index 30d47511f..65536bbac 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteProxy.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteProxy.java @@ -43,7 +43,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils; public class ClientExecuteProxy { public static void main(final String[] args)throws Exception { - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { final HttpHost target = new HttpHost("https", "httpbin.org", 443); final HttpHost proxy = new HttpHost("http", "127.0.0.1", 8080); @@ -56,7 +56,7 @@ public class ClientExecuteProxy { System.out.println("Executing request " + request.getMethod() + " " + request.getUri() + " via " + proxy); - try (CloseableHttpResponse response = httpclient.execute(target, request)) { + try (final CloseableHttpResponse response = httpclient.execute(target, request)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); System.out.println(EntityUtils.toString(response.getEntity())); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java similarity index 95% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java index 9cda6a33a..9c1abf835 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientExecuteSOCKS.java @@ -60,7 +60,7 @@ public class ClientExecuteSOCKS { .register("http", new MyConnectionSocketFactory()) .build(); final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg); - try (CloseableHttpClient httpclient = HttpClients.custom() + try (final CloseableHttpClient httpclient = HttpClients.custom() .setConnectionManager(cm) .build()) { final InetSocketAddress socksaddr = new InetSocketAddress("mysockshost", 1234); @@ -72,7 +72,7 @@ public class ClientExecuteSOCKS { System.out.println("Executing request " + request.getMethod() + " " + request.getUri() + " via SOCKS proxy " + socksaddr); - try (CloseableHttpResponse response = httpclient.execute(target, request, context)) { + try (final CloseableHttpResponse response = httpclient.execute(target, request, context)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); System.out.println(EntityUtils.toString(response.getEntity())); @@ -97,7 +97,7 @@ public class ClientExecuteSOCKS { final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpContext context) throws IOException { - Socket sock; + final Socket sock; if (socket != null) { sock = socket; } else { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientFormLogin.java similarity index 94% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientFormLogin.java index b427104ef..4d0989d14 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientFormLogin.java @@ -48,11 +48,11 @@ public class ClientFormLogin { public static void main(final String[] args) throws Exception { final BasicCookieStore cookieStore = new BasicCookieStore(); - try (CloseableHttpClient httpclient = HttpClients.custom() + try (final CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCookieStore(cookieStore) .build()) { final HttpGet httpget = new HttpGet("https://someportal/"); - try (CloseableHttpResponse response1 = httpclient.execute(httpget)) { + try (final CloseableHttpResponse response1 = httpclient.execute(httpget)) { final HttpEntity entity = response1.getEntity(); System.out.println("Login form get: " + response1.getCode() + " " + response1.getReasonPhrase()); @@ -74,7 +74,7 @@ public class ClientFormLogin { .addParameter("IDToken1", "username") .addParameter("IDToken2", "password") .build(); - try (CloseableHttpResponse response2 = httpclient.execute(login)) { + try (final CloseableHttpResponse response2 = httpclient.execute(login)) { final HttpEntity entity = response2.getEntity(); System.out.println("Login form get: " + response2.getCode() + " " + response2.getReasonPhrase()); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientInterceptors.java similarity index 91% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientInterceptors.java index 4eb606319..72dce943f 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientInterceptors.java @@ -57,8 +57,8 @@ import org.apache.hc.core5.http.protocol.HttpContext; */ public class ClientInterceptors { - public final static void main(final String[] args) throws Exception { - try (CloseableHttpClient httpclient = HttpClients.custom() + public static void main(final String[] args) throws Exception { + try (final CloseableHttpClient httpclient = HttpClients.custom() // Add a simple request ID to each outgoing request @@ -85,9 +85,9 @@ public class ClientInterceptors { final ExecChain.Scope scope, final ExecChain chain) throws IOException, HttpException { - Header idHeader = request.getFirstHeader("request-id"); + final Header idHeader = request.getFirstHeader("request-id"); if (idHeader != null && "13".equalsIgnoreCase(idHeader.getValue())) { - ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_NOT_FOUND, "Oppsie"); + final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_NOT_FOUND, "Oppsie"); response.setEntity(new StringEntity("bad luck", ContentType.TEXT_PLAIN)); return response; } else { @@ -103,7 +103,7 @@ public class ClientInterceptors { System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); - try (CloseableHttpResponse response = httpclient.execute(httpget)) { + try (final CloseableHttpResponse response = httpclient.execute(httpget)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); System.out.println(EntityUtils.toString(response.getEntity())); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java similarity index 94% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java index cf8dd70c6..ba26684eb 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultiThreadedExecution.java @@ -49,7 +49,7 @@ public class ClientMultiThreadedExecution { final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(100); - try (CloseableHttpClient httpclient = HttpClients.custom() + try (final CloseableHttpClient httpclient = HttpClients.custom() .setConnectionManager(cm) .build()) { // create an array of URIs to perform GETs on @@ -67,13 +67,13 @@ public class ClientMultiThreadedExecution { } // start the threads - for (int j = 0; j < threads.length; j++) { - threads[j].start(); + for (final GetThread thread : threads) { + thread.start(); } // join the threads - for (int j = 0; j < threads.length; j++) { - threads[j].join(); + for (final GetThread thread : threads) { + thread.join(); } } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java similarity index 94% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java index c449b1968..4d5a8f3ff 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java @@ -49,7 +49,7 @@ public class ClientMultipartFormPost { System.out.println("File path not given"); System.exit(1); } - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { final HttpPost httppost = new HttpPost("http://localhost:8080" + "/servlets-examples/servlet/RequestInfoExample"); @@ -65,7 +65,7 @@ public class ClientMultipartFormPost { httppost.setEntity(reqEntity); System.out.println("executing request " + httppost); - try (CloseableHttpResponse response = httpclient.execute(httppost)) { + try (final CloseableHttpResponse response = httpclient.execute(httppost)) { System.out.println("----------------------------------------"); System.out.println(response); final HttpEntity resEntity = response.getEntity(); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java similarity index 94% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java index de13335f2..e34493a8f 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java @@ -47,7 +47,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils; public class ClientPreemptiveBasicAuthentication { public static void main(final String[] args) throws Exception { - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { // Generate BASIC scheme object and add it to the local auth cache final BasicScheme basicAuth = new BasicScheme(); @@ -63,7 +63,7 @@ public class ClientPreemptiveBasicAuthentication { System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); for (int i = 0; i < 3; i++) { - try (CloseableHttpResponse response = httpclient.execute(httpget, localContext)) { + try (final CloseableHttpResponse response = httpclient.execute(httpget, localContext)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); System.out.println(EntityUtils.toString(response.getEntity())); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java similarity index 93% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java index 2f407018c..e18c23556 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java @@ -49,7 +49,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils; public class ClientPreemptiveDigestAuthentication { public static void main(final String[] args) throws Exception { - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { final HttpHost target = new HttpHost("http", "httpbin.org", 80); @@ -64,7 +64,7 @@ public class ClientPreemptiveDigestAuthentication { System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); for (int i = 0; i < 3; i++) { - try (CloseableHttpResponse response = httpclient.execute(target, httpget, localContext)) { + try (final CloseableHttpResponse response = httpclient.execute(target, httpget, localContext)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); EntityUtils.consume(response.getEntity()); @@ -73,7 +73,7 @@ public class ClientPreemptiveDigestAuthentication { if (authExchange != null) { final AuthScheme authScheme = authExchange.getAuthScheme(); if (authScheme instanceof DigestScheme) { - DigestScheme digestScheme = (DigestScheme) authScheme; + final DigestScheme digestScheme = (DigestScheme) authScheme; System.out.println("Nonce: " + digestScheme.getNonce() + "; count: " + digestScheme.getNounceCount()); } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java similarity index 95% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java index 18e136ad9..54dc420da 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientProxyAuthentication.java @@ -51,7 +51,7 @@ public class ClientProxyAuthentication { credsProvider.setCredentials( new AuthScope("httpbin.org", 80), new UsernamePasswordCredentials("user", "passwd".toCharArray())); - try (CloseableHttpClient httpclient = HttpClients.custom() + try (final CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider).build()) { final HttpHost target = new HttpHost("http", "httpbin.org", 80); final HttpHost proxy = new HttpHost("localhost", 8888); @@ -65,7 +65,7 @@ public class ClientProxyAuthentication { System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri() + " via " + proxy); - try (CloseableHttpResponse response = httpclient.execute(target, httpget)) { + try (final CloseableHttpResponse response = httpclient.execute(target, httpget)) { System.out.println("----------------------------------------"); System.out.println(response.getCode() + " " + response.getReasonPhrase()); System.out.println(EntityUtils.toString(response.getEntity())); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java similarity index 98% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java index daff64642..0601c7711 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java @@ -57,7 +57,7 @@ public class ClientWithRequestFuture { .setConnectionManager(cm) .build(); final ExecutorService execService = Executors.newFixedThreadPool(5); - try (FutureRequestExecutionService requestExecService = new FutureRequestExecutionService( + try (final FutureRequestExecutionService requestExecService = new FutureRequestExecutionService( httpclient, execService)) { // Because things are asynchronous, you must provide a HttpClientResponseHandler final HttpClientResponseHandler handler = new HttpClientResponseHandler() { diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java similarity index 95% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java index 8dca3829d..1ea4d6faa 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientWithResponseHandler.java @@ -46,8 +46,8 @@ import org.apache.hc.core5.http.io.entity.EntityUtils; */ public class ClientWithResponseHandler { - public final static void main(final String[] args) throws Exception { - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + public static void main(final String[] args) throws Exception { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { final HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java similarity index 97% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java index b0dc51a44..d71ad79ce 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java @@ -49,7 +49,7 @@ public class ProxyTunnelDemo { 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)) { + try (final Socket socket = proxyClient.tunnel(proxy, target, credentials)) { 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"); diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/QuickStart.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/QuickStart.java similarity index 93% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/QuickStart.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/QuickStart.java index d0522fccf..e8e2e238f 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/QuickStart.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/QuickStart.java @@ -43,7 +43,7 @@ import org.apache.hc.core5.http.message.BasicNameValuePair; public class QuickStart { public static void main(final String[] args) throws Exception { - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { 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. @@ -52,7 +52,7 @@ public class QuickStart { // Please note that if response content is not fully consumed the underlying // connection cannot be safely re-used and will be shut down and discarded // by the connection manager. - try (CloseableHttpResponse response1 = httpclient.execute(httpGet)) { + try (final CloseableHttpResponse response1 = httpclient.execute(httpGet)) { System.out.println(response1.getCode() + " " + response1.getReasonPhrase()); final HttpEntity entity1 = response1.getEntity(); // do something useful with the response body @@ -66,7 +66,7 @@ public class QuickStart { nvps.add(new BasicNameValuePair("password", "secret")); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); - try (CloseableHttpResponse response2 = httpclient.execute(httpPost)) { + try (final CloseableHttpResponse response2 = httpclient.execute(httpPost)) { System.out.println(response2.getCode() + " " + response2.getReasonPhrase()); final HttpEntity entity2 = response2.getEntity(); // do something useful with the response body diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ReactiveClientFullDuplexExchange.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ReactiveClientFullDuplexExchange.java similarity index 96% rename from httpclient5/src/examples/org/apache/hc/client5/http/examples/ReactiveClientFullDuplexExchange.java rename to httpclient5/src/test/java/org/apache/hc/client5/http/examples/ReactiveClientFullDuplexExchange.java index 12e427da4..2f2abdebf 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ReactiveClientFullDuplexExchange.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ReactiveClientFullDuplexExchange.java @@ -75,7 +75,7 @@ public class ReactiveClientFullDuplexExchange { client.start(); final URI requestUri = new URI("http://httpbin.org/post"); - byte[] bs = "stuff".getBytes(StandardCharsets.UTF_8); + final byte[] bs = "stuff".getBytes(StandardCharsets.UTF_8); final ReactiveEntityProducer reactiveEntityProducer = new ReactiveEntityProducer( Flowable.just(ByteBuffer.wrap(bs)), bs.length, ContentType.TEXT_PLAIN, null); final BasicRequestProducer requestProducer = new BasicRequestProducer( @@ -86,7 +86,7 @@ public class ReactiveClientFullDuplexExchange { final Message> streamingResponse = consumer.getResponseFuture().get(); System.out.println(streamingResponse.getHead()); - for (Header header : streamingResponse.getHead().getHeaders()) { + for (final Header header : streamingResponse.getHead().getHeaders()) { System.out.println(header.toString()); } System.out.println(); From 9710652c633b15906c7eff6df6ec4e7bb204a91e Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Tue, 2 Apr 2019 15:32:01 +0200 Subject: [PATCH 2/2] Updated release notes for HttpClient 5.0-beta4 release --- RELEASE_NOTES.txt | 91 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 17 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 8cdc6bccf..fcec1bea4 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,26 +1,14 @@ Release 5.0-BETA4 ------------------- -* Update Apache Commons Codec from 1.11 to 1.12 - Contributed by Gary Gregory - -* Update RxJava from 2.2.2 to 2.2.7 - Contributed by Gary Gregory - -* Update JNA from 5.0.0 to 5.2.0 - Contributed by Gary Gregory - - -Release 5.0-BETA3 -------------------- - -This BETA release adds support for advanced TLS functions (such as ALPN protocol negotiation) -on Java 1.7 and Java 1.8 through Conscrypt TLS library and picks up the latest fixes -and performance improvements from HttpCore. +This BETA release picks up the latest fixes and performance improvements from HttpCore +and addresses a number of issues found since the previous BETA release. Notable features in this release: -* TLS ALPN protocol negotiation support on older JREs through Conscrypt TLS library. +* Security improvements. + +* URI handling improvements. Notable changes and features included in the 5.0 series are: @@ -60,6 +48,75 @@ and documentation improvements. +Changelog: +------------------- + +* HTTPCLIENT-1976: Unsafe deserialization in DefaultHttpCacheEntrySerializer. + Contributed by Artem Smotrakov + +* HTTPCLIENT-1969: Filter out weak cipher suites. + Contributed by Artem Smotrakov + +* HttpClient should not retry requests in case of ConnectionClosedException + Contributed by Oleg Kalnichevski + +* Bug fix: Simple response consumer to discard stored content when releasing resources. + Contributed by Oleg Kalnichevski + +* Bug fix: main async request execution handlers to release the associated response consumer + upon exception. + Contributed by Oleg Kalnichevski + +* Update Apache Commons Codec from 1.11 to 1.12. + Contributed by Gary Gregory + +* Update RxJava from 2.2.2 to 2.2.7. + Contributed by Gary Gregory + +* Update JNA from 5.0.0 to 5.2.0. + Contributed by Gary Gregory + +* Some well known proxies respond with Content-Length=0, when returning 304. For robustness, + always use the cached entity's content length, as modern browsers do. + Contributed by Jayson Raymond + +* HTTPCLIENT-1960: URIBuilder incorrect handling of multiple leading slashes in path component. + Contributed by Oleg Kalnichevski + +* HTTPCLIENT-1958: PoolingHttpClientConnectionManager to throw ExecutionException + in case of a lease operation cancellation instead of InterruptedException. + Contributed by Oleg Kalnichevski + +* Shutdown executorService on AbstractHttpAsyncClientBase shutdown. + Contributed by 吴雪山 + +* [HTTPCLIENT-1952: Allow default User Agent to be disabled + Contributed by Michael Osipov + +* Improve HttpResponseException#getMessage. + Contributed by Michael Osipov + +* Better handling of http(s).proxyUser and http(s).proxyPassword + Contributed by Jens Borgland + +* Wrong argument name in PoolingAsyncClientConnectionManagerBuilder#setConnPoolPolicy results + with self assignment of variable. + Contributed by Eryk Szymanski + + + +Release 5.0-BETA3 +------------------- + +This BETA release adds support for advanced TLS functions (such as ALPN protocol negotiation) +on Java 1.7 and Java 1.8 through Conscrypt TLS library and picks up the latest fixes +and performance improvements from HttpCore. + +Notable features in this release: + +* TLS ALPN protocol negotiation support on older JREs through Conscrypt TLS library. + + Changelog: -------------------