You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2024/09/12 13:16:54 UTC
(httpcomponents-client) 01/03: Javadoc and reduce boilerplate
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit d9a78ce076fc0fb379940b567dabf54d85f9cf5b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Sep 12 14:46:19 2024 +0200
Javadoc and reduce boilerplate
- Use final
- package-private methods can throw more precise exception
- Add missing Javadoc comments
- Use lambdas
- Better StringBuilder allocation
- Make private final class a static class
- Make private instance variable final in test
- Single lambda parameter does not need parentheses
- Package-private class constructor can be package-private
---
.../cache/HttpByteArrayCacheEntrySerializer.java | 4 +-
.../client5/http/impl/cache/ViaCacheGenerator.java | 2 +-
.../hc/client5/testing/async/TestHttp1Async.java | 16 +-
.../hc/client5/testing/fluent/TestFluent.java | 2 +-
.../testing/sync/AbstractIntegrationTestBase.java | 2 +-
.../client5/testing/sync/TestContentCodings.java | 168 ++++++++-------------
.../sync/TestFutureRequestExecutionService.java | 4 +-
.../hc/client5/testing/sync/TestRedirects.java | 31 ++--
.../async/methods/SimpleAsyncEntityConsumer.java | 2 +-
.../http/async/methods/SimpleResponseBuilder.java | 39 ++++-
.../http/async/methods/SimpleResponseConsumer.java | 5 +
.../hc/client5/http/classic/BackoffManager.java | 4 +
.../hc/client5/http/classic/ExecRuntime.java | 16 +-
.../http/classic/methods/ClassicHttpRequests.java | 116 +++++++++++++-
.../client5/http/classic/methods/HttpDelete.java | 12 +-
.../hc/client5/http/classic/methods/HttpGet.java | 7 +-
.../hc/client5/http/classic/methods/HttpHead.java | 7 +-
.../client5/http/classic/methods/HttpOptions.java | 13 +-
.../hc/client5/http/classic/methods/HttpPatch.java | 7 +-
.../hc/client5/http/classic/methods/HttpPost.java | 7 +-
.../hc/client5/http/classic/methods/HttpPut.java | 8 +-
.../hc/client5/http/classic/methods/HttpTrace.java | 7 +-
.../http/classic/methods/HttpUriRequestBase.java | 14 ++
.../hc/client5/http/config/Configurable.java | 4 +-
.../hc/client5/http/entity/mime/MimeField.java | 39 ++++-
.../io/DefaultHttpClientConnectionOperator.java | 9 +-
.../client5/http/ssl/DefaultHostnameVerifier.java | 23 +--
27 files changed, 380 insertions(+), 188 deletions(-)
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java
index 7c0dc7d5c..be0785e60 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java
@@ -181,7 +181,7 @@ public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializ
final RequestLine requestLine = new RequestLine(cacheEntry.getRequestMethod(), cacheEntry.getRequestURI(), HttpVersion.HTTP_1_1);
lineFormatter.formatRequestLine(line, requestLine);
outputBuffer.writeLine(line, out);
- for (Iterator<Header> it = cacheEntry.requestHeaderIterator(); it.hasNext(); ) {
+ for (final Iterator<Header> it = cacheEntry.requestHeaderIterator(); it.hasNext(); ) {
line.clear();
lineFormatter.formatHeader(line, it.next());
outputBuffer.writeLine(line, out);
@@ -193,7 +193,7 @@ public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializ
final StatusLine statusLine = new StatusLine(HttpVersion.HTTP_1_1, cacheEntry.getStatus(), "");
lineFormatter.formatStatusLine(line, statusLine);
outputBuffer.writeLine(line, out);
- for (Iterator<Header> it = cacheEntry.headerIterator(); it.hasNext(); ) {
+ for (final Iterator<Header> it = cacheEntry.headerIterator(); it.hasNext(); ) {
line.clear();
lineFormatter.formatHeader(line, it.next());
outputBuffer.writeLine(line, out);
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ViaCacheGenerator.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ViaCacheGenerator.java
index 22260b86d..3f333b156 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ViaCacheGenerator.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ViaCacheGenerator.java
@@ -53,7 +53,7 @@ final class ViaCacheGenerator {
}
String lookup(final ProtocolVersion pv) {
- return internalCache.computeIfAbsent(pv, (v) -> {
+ return internalCache.computeIfAbsent(pv, v -> {
final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.hc.client5", getClass().getClassLoader());
return generateViaHeader(vi, v);
});
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java
index 15f93b597..ac914deb8 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java
@@ -157,13 +157,7 @@ abstract class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest {
.setPath("/random/1000")
.build(), null);
- executorService.schedule(new Runnable() {
-
- @Override
- public void run() {
- future.cancel(true);
- }
- }, i % 5, TimeUnit.MILLISECONDS);
+ executorService.schedule(() -> future.cancel(true), i % 5, TimeUnit.MILLISECONDS);
try {
future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
@@ -181,13 +175,7 @@ abstract class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest {
.setPath("/random/1000")
.build(), null);
- executorService.schedule(new Runnable() {
-
- @Override
- public void run() {
- future.cancel(true);
- }
- }, rnd.nextInt(200), TimeUnit.MILLISECONDS);
+ executorService.schedule(() -> future.cancel(true), rnd.nextInt(200), TimeUnit.MILLISECONDS);
try {
future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
index 047178743..2c0f366f2 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
@@ -56,7 +56,7 @@ class TestFluent {
public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
@RegisterExtension
- private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, ClientProtocolLevel.STANDARD, TIMEOUT);
+ private final TestClientResources testResources = new TestClientResources(URIScheme.HTTP, ClientProtocolLevel.STANDARD, TIMEOUT);
@BeforeEach
void setUp() {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/AbstractIntegrationTestBase.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/AbstractIntegrationTestBase.java
index bf31dbf4c..daa5836ff 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/AbstractIntegrationTestBase.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/AbstractIntegrationTestBase.java
@@ -46,7 +46,7 @@ abstract class AbstractIntegrationTestBase {
public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
@RegisterExtension
- private TestClientResources testResources;
+ private final TestClientResources testResources;
protected AbstractIntegrationTestBase(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel) {
this.testResources = new TestClientResources(scheme, clientProtocolLevel, TIMEOUT);
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
index 5103c9756..0ec2f70c8 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
@@ -29,7 +29,6 @@ package org.apache.hc.client5.testing.sync;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -47,8 +46,6 @@ import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.client5.testing.extension.sync.ClientProtocolLevel;
import org.apache.hc.client5.testing.extension.sync.TestClient;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HeaderElement;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpStatus;
@@ -58,7 +55,6 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.message.MessageSupport;
-import org.apache.hc.core5.http.protocol.HttpContext;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -83,19 +79,7 @@ abstract class TestContentCodings extends AbstractIntegrationTestBase {
@Test
void testResponseWithNoContent() throws Exception {
configureServer(bootstrap -> bootstrap
- .register("*", new HttpRequestHandler() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void handle(
- final ClassicHttpRequest request,
- final ClassicHttpResponse response,
- final HttpContext context) {
- response.setCode(HttpStatus.SC_NO_CONTENT);
- }
- }));
+ .register("*", (request, response, context) -> response.setCode(HttpStatus.SC_NO_CONTENT)));
final HttpHost target = startServer();
@@ -326,43 +310,33 @@ abstract class TestContentCodings extends AbstractIntegrationTestBase {
*/
private HttpRequestHandler createDeflateEncodingRequestHandler(
final String entityText, final boolean rfc1951) {
- return new HttpRequestHandler() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void handle(
- final ClassicHttpRequest request,
- final ClassicHttpResponse response,
- final HttpContext context) {
- response.setEntity(new StringEntity(entityText));
- response.addHeader("Content-Type", "text/plain");
- final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
- while (it.hasNext()) {
- final HeaderElement element = it.next();
- if ("deflate".equalsIgnoreCase(element.getName())) {
- response.addHeader("Content-Encoding", "deflate");
-
- /* Gack. DeflaterInputStream is Java 6. */
- // response.setEntity(new InputStreamEntity(new DeflaterInputStream(new
- // ByteArrayInputStream(
- // entityText.getBytes("utf-8"))), -1));
- final byte[] uncompressed = entityText.getBytes(StandardCharsets.UTF_8);
- final Deflater compressor = new Deflater(Deflater.DEFAULT_COMPRESSION, rfc1951);
- compressor.setInput(uncompressed);
- compressor.finish();
- final byte[] output = new byte[100];
- final int compressedLength = compressor.deflate(output);
- final byte[] compressed = new byte[compressedLength];
- System.arraycopy(output, 0, compressed, 0, compressedLength);
- response.setEntity(new InputStreamEntity(
- new ByteArrayInputStream(compressed), compressedLength, null));
- return;
- }
- }
+ return (request, response, context) -> {
+ response.setEntity(new StringEntity(entityText));
+ response.addHeader("Content-Type", "text/plain");
+ final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
+ while (it.hasNext()) {
+ final HeaderElement element = it.next();
+ if ("deflate".equalsIgnoreCase(element.getName())) {
+ response.addHeader("Content-Encoding", "deflate");
+
+ /* Gack. DeflaterInputStream is Java 6. */
+ // response.setEntity(new InputStreamEntity(new DeflaterInputStream(new
+ // ByteArrayInputStream(
+ // entityText.getBytes("utf-8"))), -1));
+ final byte[] uncompressed = entityText.getBytes(StandardCharsets.UTF_8);
+ final Deflater compressor = new Deflater(Deflater.DEFAULT_COMPRESSION, rfc1951);
+ compressor.setInput(uncompressed);
+ compressor.finish();
+ final byte[] output = new byte[100];
+ final int compressedLength = compressor.deflate(output);
+ final byte[] compressed = new byte[compressedLength];
+ System.arraycopy(output, 0, compressed, 0, compressedLength);
+ response.setEntity(new InputStreamEntity(
+ new ByteArrayInputStream(compressed), compressedLength, null));
+ return;
+ }
}
- };
+ };
}
/**
@@ -374,57 +348,47 @@ abstract class TestContentCodings extends AbstractIntegrationTestBase {
* @return a non-null {@link HttpRequestHandler}
*/
private HttpRequestHandler createGzipEncodingRequestHandler(final String entityText) {
- return new HttpRequestHandler() {
-
- /**
- * {@inheritDoc}
+ return (request, response, context) -> {
+ response.setEntity(new StringEntity(entityText));
+ response.addHeader("Content-Type", "text/plain");
+ response.addHeader("Content-Type", "text/plain");
+ final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
+ while (it.hasNext()) {
+ final HeaderElement element = it.next();
+ if ("gzip".equalsIgnoreCase(element.getName())) {
+ response.addHeader("Content-Encoding", "gzip");
+
+ /*
+ * We have to do a bit more work with gzip versus deflate, since
+ * Gzip doesn't appear to have an equivalent to DeflaterInputStream in
+ * the JDK.
+ *
+ * UPDATE: DeflaterInputStream is Java 6 anyway, so we have to do a bit
+ * of work there too!
*/
- @Override
- public void handle(
- final ClassicHttpRequest request,
- final ClassicHttpResponse response,
- final HttpContext context) throws IOException {
- response.setEntity(new StringEntity(entityText));
- response.addHeader("Content-Type", "text/plain");
- response.addHeader("Content-Type", "text/plain");
- final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
- while (it.hasNext()) {
- final HeaderElement element = it.next();
- if ("gzip".equalsIgnoreCase(element.getName())) {
- response.addHeader("Content-Encoding", "gzip");
-
- /*
- * We have to do a bit more work with gzip versus deflate, since
- * Gzip doesn't appear to have an equivalent to DeflaterInputStream in
- * the JDK.
- *
- * UPDATE: DeflaterInputStream is Java 6 anyway, so we have to do a bit
- * of work there too!
- */
- final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- final OutputStream out = new GZIPOutputStream(bytes);
-
- final ByteArrayInputStream uncompressed = new ByteArrayInputStream(
- entityText.getBytes(StandardCharsets.UTF_8));
-
- final byte[] buf = new byte[60];
-
- int n;
- while ((n = uncompressed.read(buf)) != -1) {
- out.write(buf, 0, n);
- }
-
- out.close();
-
- final byte[] arr = bytes.toByteArray();
- response.setEntity(new InputStreamEntity(new ByteArrayInputStream(arr),
- arr.length, null));
-
- return;
- }
- }
+ final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ final OutputStream out = new GZIPOutputStream(bytes);
+
+ final ByteArrayInputStream uncompressed = new ByteArrayInputStream(
+ entityText.getBytes(StandardCharsets.UTF_8));
+
+ final byte[] buf = new byte[60];
+
+ int n;
+ while ((n = uncompressed.read(buf)) != -1) {
+ out.write(buf, 0, n);
+ }
+
+ out.close();
+
+ final byte[] arr = bytes.toByteArray();
+ response.setEntity(new InputStreamEntity(new ByteArrayInputStream(arr),
+ arr.length, null));
+
+ return;
+ }
}
- };
+ };
}
/**
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestFutureRequestExecutionService.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestFutureRequestExecutionService.java
index 1c40f580f..089c31f6f 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestFutureRequestExecutionService.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestFutureRequestExecutionService.java
@@ -164,7 +164,7 @@ class TestFutureRequestExecutionService {
}
}
- private final class CountingCallback implements FutureCallback<Boolean> {
+ private static final class CountingCallback implements FutureCallback<Boolean> {
private final CountDownLatch latch;
@@ -190,7 +190,7 @@ class TestFutureRequestExecutionService {
}
- private final class OkidokiHandler implements HttpClientResponseHandler<Boolean> {
+ private static final class OkidokiHandler implements HttpClientResponseHandler<Boolean> {
@Override
public Boolean handleResponse(
final ClassicHttpResponse response) {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
index 1a46d9972..7d27efb00 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
@@ -59,7 +59,6 @@ import org.apache.hc.client5.testing.classic.RedirectingDecorator;
import org.apache.hc.client5.testing.extension.sync.ClientProtocolLevel;
import org.apache.hc.client5.testing.extension.sync.TestClient;
import org.apache.hc.client5.testing.redirect.Redirect;
-import org.apache.hc.core5.function.Decorator;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ConnectionClosedException;
@@ -72,7 +71,6 @@ import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.io.HttpRequestHandler;
-import org.apache.hc.core5.http.io.HttpServerRequestHandler;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.message.BasicHeader;
@@ -607,26 +605,19 @@ abstract class TestRedirects extends AbstractIntegrationTestBase {
void testCompressionHeaderRedirect() throws Exception {
final Queue<String> values = new ConcurrentLinkedQueue<>();
configureServer(bootstrap -> bootstrap
- .setExchangeHandlerDecorator(new Decorator<HttpServerRequestHandler>() {
+ .setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
+ requestHandler,
+ new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_MOVED_TEMPORARILY)) {
@Override
- public HttpServerRequestHandler decorate(final HttpServerRequestHandler requestHandler) {
- return new RedirectingDecorator(
- requestHandler,
- new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_MOVED_TEMPORARILY)) {
-
- @Override
- public void handle(final ClassicHttpRequest request,
- final ResponseTrigger responseTrigger,
- final HttpContext context) throws HttpException, IOException {
- final Header header = request.getHeader(HttpHeaders.ACCEPT_ENCODING);
- if (header != null) {
- values.add(header.getValue());
- }
- super.handle(request, responseTrigger, context);
- }
-
- };
+ public void handle(final ClassicHttpRequest request,
+ final ResponseTrigger responseTrigger,
+ final HttpContext context) throws HttpException, IOException {
+ final Header header = request.getHeader(HttpHeaders.ACCEPT_ENCODING);
+ if (header != null) {
+ values.add(header.getValue());
+ }
+ super.handle(request, responseTrigger, context);
}
})
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleAsyncEntityConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleAsyncEntityConsumer.java
index 00a94a81f..b8a8ef613 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleAsyncEntityConsumer.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleAsyncEntityConsumer.java
@@ -39,7 +39,7 @@ final class SimpleAsyncEntityConsumer extends AbstractBinAsyncEntityConsumer<byt
private final ByteArrayBuffer buffer;
- public SimpleAsyncEntityConsumer() {
+ SimpleAsyncEntityConsumer() {
super();
this.buffer = new ByteArrayBuffer(1024);
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseBuilder.java
index 11e089904..0a2f941c0 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseBuilder.java
@@ -36,7 +36,7 @@ import org.apache.hc.core5.http.support.AbstractResponseBuilder;
import org.apache.hc.core5.util.Args;
/**
- * Builder for {@link SimpleHttpResponse} instances.
+ * Builds {@link SimpleHttpResponse} instances.
*
* @since 5.1
*/
@@ -48,11 +48,23 @@ public class SimpleResponseBuilder extends AbstractResponseBuilder<SimpleHttpRes
super(status);
}
+ /**
+ * Creates a new SimpleResponseBuilder with the given status.
+ *
+ * @param status response status.
+ * @return a new SimpleResponseBuilder.
+ */
public static SimpleResponseBuilder create(final int status) {
Args.checkRange(status, 100, 599, "HTTP status code");
return new SimpleResponseBuilder(status);
}
+ /**
+ * Copies a source instance into a new one.
+ *
+ * @param response the source instance to copy.
+ * @return a new SimpleResponseBuilder.
+ */
public static SimpleResponseBuilder copy(final SimpleHttpResponse response) {
Args.notNull(response, "HTTP response");
final SimpleResponseBuilder builder = new SimpleResponseBuilder(response.getCode());
@@ -113,20 +125,45 @@ public class SimpleResponseBuilder extends AbstractResponseBuilder<SimpleHttpRes
return this;
}
+ /**
+ * Gets the body.
+ *
+ * @return the body.
+ */
public SimpleBody getBody() {
return body;
}
+ /**
+ * Sets the body.
+ *
+ * @param body the body.
+ * @return this instance.
+ */
public SimpleResponseBuilder setBody(final SimpleBody body) {
this.body = body;
return this;
}
+ /**
+ * Sets the body.
+ *
+ * @param content the body content.
+ * @param contentType the body content-type.
+ * @return this instance.
+ */
public SimpleResponseBuilder setBody(final String content, final ContentType contentType) {
this.body = SimpleBody.create(content, contentType);
return this;
}
+ /**
+ * Sets the body.
+ *
+ * @param content the body content.
+ * @param contentType the body content-type.
+ * @return this instance.
+ */
public SimpleResponseBuilder setBody(final byte[] content, final ContentType contentType) {
this.body = SimpleBody.create(content, contentType);
return this;
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java
index 7f9dda6e9..8de7f87c7 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java
@@ -57,6 +57,11 @@ public final class SimpleResponseConsumer extends AbstractAsyncResponseConsumer<
super(entityConsumer);
}
+ /**
+ * Creates a new SimpleResponseConsumer instance initialized with a new {@code SimpleAsyncEntityConsumer}.
+ *
+ * @return a new SimpleResponseConsumer instance.
+ */
public static SimpleResponseConsumer create() {
return new SimpleResponseConsumer(new SimpleAsyncEntityConsumer());
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/BackoffManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/BackoffManager.java
index 48ca4f5c7..3685e6342 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/BackoffManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/BackoffManager.java
@@ -41,6 +41,8 @@ public interface BackoffManager {
* Called when we have decided that the result of
* using a connection should be interpreted as a
* backoff signal.
+ *
+ * @param route the affected route.
*/
void backOff(HttpRoute route);
@@ -48,6 +50,8 @@ public interface BackoffManager {
* Called when we have determined that the result of
* using a connection has succeeded and that we may
* probe for more connections.
+ *
+ * @param route the affected route.
*/
void probe(HttpRoute route);
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecRuntime.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecRuntime.java
index 3bb334dd0..e44bbcd2a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecRuntime.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecRuntime.java
@@ -76,6 +76,7 @@ public interface ExecRuntime {
* @param state the expected connection state. May be {@code null} if connection
* can be state-less or its state is irrelevant.
* @param context the execution context.
+ * @throws IOException if an I/O error occurs.
*/
void acquireEndpoint(
String id,
@@ -104,6 +105,8 @@ public interface ExecRuntime {
/**
* Disconnects the local endpoint from the initial hop in the connection route.
+ *
+ * @throws IOException if an I/O error occurs.
*/
void disconnectEndpoint() throws IOException;
@@ -113,6 +116,7 @@ public interface ExecRuntime {
* or multiple proxies).
*
* @param context the execution context.
+ * @throws IOException if an I/O error occurs.
*/
void connectEndpoint(HttpClientContext context) throws IOException;
@@ -120,11 +124,14 @@ public interface ExecRuntime {
* Upgrades transport security of the active connection by using the TLS security protocol.
*
* @param context the execution context.
+ * @throws IOException if an I/O error occurs.
*/
void upgradeTls(HttpClientContext context) throws IOException;
/**
- * Returns information about the underlying endpoint when connected or {@code null} otherwise.
+ * Gets information about the underlying endpoint when connected or {@code null} otherwise.
+ *
+ * @return an EndpointInfo, defaults to {@code null}.
*/
default EndpointInfo getEndpointInfo() {
return null;
@@ -136,6 +143,9 @@ public interface ExecRuntime {
* @param id unique operation ID or {@code null}.
* @param request the request message.
* @param context the execution context.
+ * @return a ClassicHttpResponse.
+ * @throws IOException if an I/O error occurs.
+ * @throws HttpException if a protocol error occurs.
*/
ClassicHttpResponse execute(
String id,
@@ -149,7 +159,9 @@ public interface ExecRuntime {
* @param request the request message.
* @param informationCallback information (1xx) response handler
* @param context the execution context.
- *
+ * @return a ClassicHttpResponse.
+ * @throws IOException if an I/O error occurs.
+ * @throws HttpException if a protocol error occurs.
* @since 5.4
*/
default ClassicHttpResponse execute(
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java
index 85125cfd3..1f09384a0 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java
@@ -92,7 +92,7 @@ public final class ClassicHttpRequests {
* @param method A method supported by this class.
* @param uri a non-null request string URI.
* @throws IllegalArgumentException if the method is not supported.
- * @throws IllegalArgumentException if the string uri is null.
+ * @throws IllegalArgumentException if the string URI is null.
* @return A new HttpUriRequest.
*/
public static HttpUriRequest create(final String method, final String uri) {
@@ -105,73 +105,185 @@ public final class ClassicHttpRequests {
* @param method A method supported by this class.
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the method is not supported.
- * @throws IllegalArgumentException if the uri is null.
+ * @throws IllegalArgumentException if the URI is null.
* @return A new HttpUriRequest.
*/
public static HttpUriRequest create(final String method, final URI uri) {
return create(Method.normalizedValueOf(method), uri);
}
+ /**
+ * Constructs a new {@code "DELETE"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "DELETE" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest delete(final String uri) {
return delete(URI.create(uri));
}
+ /**
+ * Constructs a new {@code "DELETE"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "DELETE" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest delete(final URI uri) {
return new HttpDelete(uri);
}
+ /**
+ * Constructs a new {@code "GET"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "GET" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest get(final String uri) {
return get(URI.create(uri));
}
+ /**
+ * Constructs a new {@code "GET"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "GET" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest get(final URI uri) {
return new HttpGet(uri);
}
+ /**
+ * Constructs a new {@code "HEAD"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "HEAD" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest head(final String uri) {
return head(URI.create(uri));
}
+ /**
+ * Constructs a new {@code "HEAD"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "HEAD" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest head(final URI uri) {
return new HttpHead(uri);
}
+ /**
+ * Constructs a new {@code "OPTIONS"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "OPTIONS" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest options(final String uri) {
return options(URI.create(uri));
}
+ /**
+ * Constructs a new {@code "OPTIONS"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "OPTIONS" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest options(final URI uri) {
return new HttpOptions(uri);
}
+ /**
+ * Constructs a new {@code "PATCH"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "PATCH" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest patch(final String uri) {
return patch(URI.create(uri));
}
+ /**
+ * Constructs a new {@code "PATCH"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "PATCH" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest patch(final URI uri) {
return new HttpPatch(uri);
}
+ /**
+ * Constructs a new {@code "POST"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "POST" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest post(final String uri) {
return post(URI.create(uri));
}
+ /**
+ * Constructs a new {@code "POST"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "POST" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest post(final URI uri) {
return new HttpPost(uri);
}
+ /**
+ * Constructs a new {@code "PUT"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "PUT" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest put(final String uri) {
return put(URI.create(uri));
}
+ /**
+ * Constructs a new {@code "PUT"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "PUT" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest put(final URI uri) {
return new HttpPut(uri);
}
+ /**
+ * Constructs a new {@code "TRACE"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "TRACE" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest trace(final String uri) {
return trace(URI.create(uri));
}
+ /**
+ * Constructs a new {@code "TRACE"} HttpUriRequest initialized with the given URI.
+ *
+ * @param uri a non-null request URI.
+ * @return a new "TRACE" HttpUriRequest.
+ * @throws IllegalArgumentException if the URI is null.
+ */
public static HttpUriRequest trace(final URI uri) {
return new HttpTrace(uri);
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpDelete.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpDelete.java
index 98a2e43b5..4b0b0bdfc 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpDelete.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpDelete.java
@@ -38,24 +38,26 @@ public class HttpDelete extends HttpUriRequestBase {
private static final long serialVersionUID = 1L;
+ /**
+ * The method name {@value}.
+ */
public final static String METHOD_NAME = "DELETE";
-
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
- * @throws IllegalArgumentException if the uri is null.
+ * @throws IllegalArgumentException if the URI is null.
*/
public HttpDelete(final URI uri) {
super(METHOD_NAME, uri);
}
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
- * @throws IllegalArgumentException if the uri is invalid.
+ * @throws IllegalArgumentException if the URI is invalid.
*/
public HttpDelete(final String uri) {
this(URI.create(uri));
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpGet.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpGet.java
index 8c30166c9..760ce0056 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpGet.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpGet.java
@@ -38,10 +38,13 @@ public class HttpGet extends HttpUriRequestBase {
private static final long serialVersionUID = 1L;
+ /**
+ * The method name {@value}.
+ */
public final static String METHOD_NAME = "GET";
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is null.
@@ -51,7 +54,7 @@ public class HttpGet extends HttpUriRequestBase {
}
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is invalid.
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpHead.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpHead.java
index c18835fd5..edd40c970 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpHead.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpHead.java
@@ -38,10 +38,13 @@ public class HttpHead extends HttpUriRequestBase {
private static final long serialVersionUID = 1L;
+ /**
+ * The method name {@value}.
+ */
public final static String METHOD_NAME = "HEAD";
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is null.
@@ -51,6 +54,8 @@ public class HttpHead extends HttpUriRequestBase {
}
/**
+ * Constructs a new instance initialized with the given URI.
+ *
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is invalid.
*/
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpOptions.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpOptions.java
index 7a1e41b6b..a25ed3e65 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpOptions.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpOptions.java
@@ -46,10 +46,13 @@ public class HttpOptions extends HttpUriRequestBase {
private static final long serialVersionUID = 1L;
+ /**
+ * The method name {@value}.
+ */
public final static String METHOD_NAME = "OPTIONS";
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is null.
@@ -59,7 +62,7 @@ public class HttpOptions extends HttpUriRequestBase {
}
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is invalid.
@@ -73,6 +76,12 @@ public class HttpOptions extends HttpUriRequestBase {
return METHOD_NAME;
}
+ /**
+ * Gets the allowed method names defined by {@code "Allow"} headers.
+ *
+ * @param response the response to query.
+ * @return The response to query.
+ */
public Set<String> getAllowedMethods(final HttpResponse response) {
Args.notNull(response, "HTTP response");
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPatch.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPatch.java
index c1ee0fc2a..47947b448 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPatch.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPatch.java
@@ -38,10 +38,13 @@ public class HttpPatch extends HttpUriRequestBase {
private static final long serialVersionUID = 1L;
+ /**
+ * The method name {@value}.
+ */
public final static String METHOD_NAME = "PATCH";
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is null.
@@ -51,7 +54,7 @@ public class HttpPatch extends HttpUriRequestBase {
}
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is invalid.
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPost.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPost.java
index 41c14531f..17b37f1f5 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPost.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPost.java
@@ -38,10 +38,13 @@ public class HttpPost extends HttpUriRequestBase {
private static final long serialVersionUID = 1L;
+ /**
+ * The method name {@value}.
+ */
public final static String METHOD_NAME = "POST";
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is null.
@@ -51,7 +54,7 @@ public class HttpPost extends HttpUriRequestBase {
}
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is invalid.
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPut.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPut.java
index 68e70b3ba..2de79864f 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPut.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPut.java
@@ -37,10 +37,14 @@ import java.net.URI;
public class HttpPut extends HttpUriRequestBase {
private static final long serialVersionUID = 1L;
+
+ /**
+ * The method name {@value}.
+ */
public final static String METHOD_NAME = "PUT";
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is null.
@@ -50,7 +54,7 @@ public class HttpPut extends HttpUriRequestBase {
}
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is invalid.
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpTrace.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpTrace.java
index a937ba21a..c40dcc538 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpTrace.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpTrace.java
@@ -40,10 +40,13 @@ public class HttpTrace extends HttpUriRequestBase {
private static final long serialVersionUID = 1L;
+ /**
+ * The method name {@value}.
+ */
public final static String METHOD_NAME = "TRACE";
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is null.
@@ -53,7 +56,7 @@ public class HttpTrace extends HttpUriRequestBase {
}
/**
- * Creates a new instance initialized with the given URI.
+ * Constructs a new instance initialized with the given URI.
*
* @param uri a non-null request URI.
* @throws IllegalArgumentException if the uri is invalid.
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java
index d6ea8b6f8..e410230a0 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java
@@ -34,6 +34,9 @@ import org.apache.hc.core5.concurrent.Cancellable;
import org.apache.hc.core5.concurrent.CancellableDependency;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+/**
+ * Base class for HTTP method subclasses.
+ */
public class HttpUriRequestBase extends BasicClassicHttpRequest implements HttpUriRequest, CancellableDependency {
private static final long serialVersionUID = 1L;
@@ -41,6 +44,12 @@ public class HttpUriRequestBase extends BasicClassicHttpRequest implements HttpU
private final AtomicMarkableReference<Cancellable> cancellableRef;
private RequestConfig requestConfig;
+ /**
+ * Constructs a new instance with the given method and request URI.
+ *
+ * @param method request method.
+ * @param requestUri request URI.
+ */
public HttpUriRequestBase(final String method, final URI requestUri) {
super(method, requestUri);
this.cancellableRef = new AtomicMarkableReference<>(null, false);
@@ -104,6 +113,11 @@ public class HttpUriRequestBase extends BasicClassicHttpRequest implements HttpU
return isCancelled();
}
+ /**
+ * Sets the request configuration.
+ *
+ * @param requestConfig the request configuration.
+ */
public void setConfig(final RequestConfig requestConfig) {
this.requestConfig = requestConfig;
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/config/Configurable.java b/httpclient5/src/main/java/org/apache/hc/client5/http/config/Configurable.java
index 6614a194e..f70006d58 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/config/Configurable.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/config/Configurable.java
@@ -35,7 +35,9 @@ package org.apache.hc.client5.http.config;
public interface Configurable {
/**
- * Returns actual request configuration.
+ * Gets the actual request configuration.
+ *
+ * @return the actual request configuration.
*/
RequestConfig getConfig();
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java
index 4fbbee4bc..6ad6359b2 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java
@@ -44,6 +44,12 @@ public class MimeField {
private final String value;
private final List<NameValuePair> parameters;
+ /**
+ * Constructs a new instance.
+ *
+ * @param name the field name.
+ * @param value the field value.
+ */
public MimeField(final String name, final String value) {
super();
this.name = name;
@@ -52,6 +58,11 @@ public class MimeField {
}
/**
+ * Constructs a new instance.
+ *
+ * @param name the field name.
+ * @param value the field value.
+ * @param parameters the field parameters.
* @since 4.6
*/
public MimeField(final String name, final String value, final List<NameValuePair> parameters) {
@@ -61,26 +72,43 @@ public class MimeField {
Collections.unmodifiableList(new ArrayList<>(parameters)) : Collections.emptyList();
}
+ /**
+ * Constructs a new instance by copying another's properties.
+ *
+ * @param from the source field.
+ */
public MimeField(final MimeField from) {
this(from.name, from.value, from.parameters);
}
+ /**
+ * Gets the field name.
+ *
+ * @return the field name.
+ */
public String getName() {
return this.name;
}
/**
+ * Gets the field value.
+ *
+ * @return the field value.
* @since 4.6
*/
public String getValue() {
return this.value;
}
+ /**
+ * Converts this instance to a body String.
+ *
+ * @return this instance as a body String.
+ */
public String getBody() {
final StringBuilder sb = new StringBuilder();
sb.append(this.value);
- for (int i = 0; i < this.parameters.size(); i++) {
- final NameValuePair parameter = this.parameters.get(i);
+ parameters.forEach(parameter -> {
sb.append("; ");
sb.append(parameter.getName());
sb.append("=\"");
@@ -93,10 +121,15 @@ public class MimeField {
sb.append(ch);
}
sb.append("\"");
- }
+ });
return sb.toString();
}
+ /**
+ * Gets the field parameters.
+ *
+ * @return the field parameters.
+ */
public List<NameValuePair> getParameters() {
return this.parameters;
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
index fa9fd3a7a..5d6b080c3 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
@@ -78,14 +78,7 @@ public class DefaultHttpClientConnectionOperator implements HttpClientConnection
private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpClientConnectionOperator.class);
- static final DetachedSocketFactory PLAIN_SOCKET_FACTORY = new DetachedSocketFactory() {
-
- @Override
- public Socket create(final Proxy socksProxy) throws IOException {
- return socksProxy == null ? new Socket() : new Socket(socksProxy);
- }
-
- };
+ static final DetachedSocketFactory PLAIN_SOCKET_FACTORY = socksProxy -> socksProxy == null ? new Socket() : new Socket(socksProxy);
private final DetachedSocketFactory detachedSocketFactory;
private final Lookup<TlsSocketStrategy> tlsSocketStrategyLookup;
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 4808c44bd..3d013865f 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
@@ -78,10 +78,18 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
private final PublicSuffixMatcher publicSuffixMatcher;
+ /**
+ * Constructs new instance with a PublicSuffixMatcher.
+ *
+ * @param publicSuffixMatcher a PublicSuffixMatcher.
+ */
public DefaultHostnameVerifier(final PublicSuffixMatcher publicSuffixMatcher) {
this.publicSuffixMatcher = publicSuffixMatcher;
}
+ /**
+ * Constructs new instance without a PublicSuffixMatcher.
+ */
public DefaultHostnameVerifier() {
this(null);
}
@@ -123,9 +131,8 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
}
}
- static void matchIPAddress(final String host, final List<SubjectName> subjectAlts) throws SSLException {
- for (int i = 0; i < subjectAlts.size(); i++) {
- final SubjectName subjectAlt = subjectAlts.get(i);
+ static void matchIPAddress(final String host, final List<SubjectName> subjectAlts) throws SSLPeerUnverifiedException {
+ for (final SubjectName subjectAlt : subjectAlts) {
if (subjectAlt.getType() == SubjectName.IP) {
if (host.equals(subjectAlt.getValue())) {
return;
@@ -136,10 +143,9 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
"of the subject alternative names: " + subjectAlts);
}
- static void matchIPv6Address(final String host, final List<SubjectName> subjectAlts) throws SSLException {
+ static void matchIPv6Address(final String host, final List<SubjectName> subjectAlts) throws SSLPeerUnverifiedException {
final String normalisedHost = normaliseAddress(host);
- for (int i = 0; i < subjectAlts.size(); i++) {
- final SubjectName subjectAlt = subjectAlts.get(i);
+ for (final SubjectName subjectAlt : subjectAlts) {
if (subjectAlt.getType() == SubjectName.IP) {
final String normalizedSubjectAlt = normaliseAddress(subjectAlt.getValue());
if (normalisedHost.equals(normalizedSubjectAlt)) {
@@ -152,10 +158,9 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
}
static void matchDNSName(final String host, final List<SubjectName> subjectAlts,
- final PublicSuffixMatcher publicSuffixMatcher) throws SSLException {
+ final PublicSuffixMatcher publicSuffixMatcher) throws SSLPeerUnverifiedException {
final String normalizedHost = DnsUtils.normalize(host);
- for (int i = 0; i < subjectAlts.size(); i++) {
- final SubjectName subjectAlt = subjectAlts.get(i);
+ for (final SubjectName subjectAlt : subjectAlts) {
if (subjectAlt.getType() == SubjectName.DNS) {
final String normalizedSubjectAlt = DnsUtils.normalize(subjectAlt.getValue());
if (matchIdentityStrict(normalizedHost, normalizedSubjectAlt, publicSuffixMatcher)) {