diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecCallback.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecCallback.java index f87c295fe7..690b35aa8b 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecCallback.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecCallback.java @@ -49,6 +49,8 @@ public interface AsyncExecCallback { * @param entityDetails the response entity details or {@code null} if the response * does not enclose an entity. * @return the data consumer to be used for processing of incoming response message body. + * @throws HttpException If a protocol error occurs. + * @throws IOException If an I/O error occurs. */ AsyncDataConsumer handleResponse( HttpResponse response, @@ -58,6 +60,8 @@ AsyncDataConsumer handleResponse( * Triggered to signal receipt of an intermediate response message. * * @param response the intermediate response message. + * @throws HttpException If a protocol error occurs. + * @throws IOException If an I/O error occurs. */ void handleInformationResponse(HttpResponse response) throws HttpException, IOException; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecChainHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecChainHandler.java index 5ba3d42cc9..c82d280d3e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecChainHandler.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecChainHandler.java @@ -72,6 +72,8 @@ public interface AsyncExecChainHandler { * @param scope the execution scope . * @param chain the next element in the request execution chain. * @param asyncExecCallback the execution callback. + * @throws HttpException If a protocol error occurs. + * @throws IOException If an I/O error occurs. */ void execute( HttpRequest request, diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecRuntime.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecRuntime.java index 314860d932..4fd510b8c3 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecRuntime.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecRuntime.java @@ -135,7 +135,9 @@ default void upgradeTls(HttpClientContext context, } /** - * 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 the underlying endpoint or {@code null} */ default EndpointInfo getEndpointInfo() { return null; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinPushConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinPushConsumer.java index 04c0f7c412..e5187e0915 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinPushConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinPushConsumer.java @@ -52,6 +52,8 @@ public abstract class AbstractBinPushConsumer extends AbstractBinDataConsumer im * @param response the response message head * @param contentType the content type of the response body, * or {@code null} if the response does not enclose a response entity. + * @throws HttpException If a protocol error occurs. + * @throws IOException If an I/O error occurs. */ protected abstract void start(HttpRequest promise, HttpResponse response, ContentType contentType) throws HttpException, IOException; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinResponseConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinResponseConsumer.java index f35b55e768..b270297e54 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinResponseConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractBinResponseConsumer.java @@ -56,6 +56,8 @@ public abstract class AbstractBinResponseConsumer extends AbstractBinDataCons * @param response the response message head * @param contentType the content type of the response body, * or {@code null} if the response does not enclose a response entity. + * @throws HttpException If a protocol error occurs. + * @throws IOException If an I/O error occurs. */ protected abstract void start(HttpResponse response, ContentType contentType) throws HttpException, IOException; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java index 2d26172a80..21d23edc0f 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java @@ -68,6 +68,8 @@ protected AbstractCharPushConsumer(final int bufSize, * @param response the response message head * @param contentType the content type of the response body, * or {@code null} if the response does not enclose a response entity. + * @throws HttpException If a protocol error occurs. + * @throws IOException If an I/O error occurs. */ protected abstract void start(HttpRequest promise, HttpResponse response, ContentType contentType) throws HttpException, IOException; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java index eb39dbfaa2..3a0f66964c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java @@ -71,6 +71,8 @@ protected AbstractCharResponseConsumer(final int bufSize, * @param response the response message head * @param contentType the content type of the response body, * or {@code null} if the response does not enclose a response entity. + * @throws HttpException If a protocol error occurs. + * @throws IOException If an I/O error occurs. */ protected abstract void start(HttpResponse response, ContentType contentType) throws HttpException, IOException; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/BasicHttpRequests.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/BasicHttpRequests.java index c2fc683d09..caad0aa078 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/BasicHttpRequests.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/BasicHttpRequests.java @@ -65,125 +65,280 @@ public static BasicHttpRequest create(final String method, final URI uri) { return create(Method.normalizedValueOf(method), uri); } + /** + * Creates a new DELETE {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest delete(final String uri) { return delete(URI.create(uri)); } + /** + * Creates a new DELETE {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest delete(final URI uri) { return create(Method.DELETE, uri); } + /** + * Creates a new DELETE {@link BasicHttpRequest}. + * + * @param host HTTP host. + * @param path request path. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest delete(final HttpHost host, final String path) { return create(Method.DELETE, host, path); } + /** + * Creates a new GET {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest get(final String uri) { return get(URI.create(uri)); } + /** + * Creates a new GET {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest get(final URI uri) { return create(Method.GET, uri); } + /** + * Creates a new HEAD {@link BasicHttpRequest}. + * + * @param host HTTP host. + * @param path request path. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest get(final HttpHost host, final String path) { return create(Method.GET, host, path); } + /** + * Creates a new HEAD {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest head(final String uri) { return head(URI.create(uri)); } + /** + * Creates a new HEAD {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest head(final URI uri) { return create(Method.HEAD, uri); } + /** + * Creates a new HEAD {@link BasicHttpRequest}. + * + * @param host HTTP host. + * @param path request path. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest head(final HttpHost host, final String path) { return create(Method.HEAD, host, path); } + /** + * Creates a new OPTIONS {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest options(final String uri) { return options(URI.create(uri)); } + /** + * Creates a new OPTIONS {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest options(final URI uri) { return create(Method.OPTIONS, uri); } + /** + * Creates a new OPTIONS {@link BasicHttpRequest}. + * + * @param host HTTP host. + * @param path request path. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest options(final HttpHost host, final String path) { return create(Method.OPTIONS, host, path); } + /** + * Creates a new PATCH {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest patch(final String uri) { return patch(URI.create(uri)); } + /** + * Creates a new PATCH {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest patch(final URI uri) { return create(Method.PATCH, uri); } + /** + * Creates a new PATCH {@link BasicHttpRequest}. + * + * @param host HTTP host. + * @param path request path. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest patch(final HttpHost host, final String path) { return create(Method.PATCH, host, path); } + /** + * Creates a new POST {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest post(final String uri) { return post(URI.create(uri)); } + /** + * Creates a new POST {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest post(final URI uri) { return create(Method.POST, uri); } + /** + * Creates a new POST {@link BasicHttpRequest}. + * + * @param host HTTP host. + * @param path request path. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest post(final HttpHost host, final String path) { return create(Method.POST, host, path); } + /** + * Creates a new PUT {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest put(final String uri) { return put(URI.create(uri)); } + /** + * Creates a new PUT {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest put(final URI uri) { return create(Method.PUT, uri); } + /** + * Creates a new PUT {@link BasicHttpRequest}. + * + * @param host HTTP host. + * @param path request path. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest put(final HttpHost host, final String path) { return create(Method.PUT, host, path); } + /** + * Creates a new TRACE {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest trace(final String uri) { return trace(URI.create(uri)); } + /** + * Creates a new TRACE {@link BasicHttpRequest}. + * + * @param uri a non-null URI. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest trace(final URI uri) { return create(Method.TRACE, uri); } + /** + * Creates a new TRACE {@link BasicHttpRequest}. + * + * @param host HTTP host. + * @param path request path. + * @return a new BasicHttpRequest + */ public static BasicHttpRequest trace(final HttpHost host, final String path) { return create(Method.TRACE, host, path); } /** - * Creates a request object of the exact subclass of {@link BasicHttpRequest}. + * Creates a new {@link BasicHttpRequest}. * + * @param method a non-null HTTP method. * @param uri a non-null URI String. - * @return a new subclass of BasicHttpRequest + * @return a new BasicHttpRequest */ public static BasicHttpRequest create(final Method method, final String uri) { return create(method, URI.create(uri)); } /** - * Creates a request object of the exact subclass of {@link BasicHttpRequest}. + * Creates a new {@link BasicHttpRequest}. * + * @param method a non-null HTTP method. * @param uri a non-null URI. - * @return a new subclass of BasicHttpRequest + * @return a new BasicHttpRequest */ public static BasicHttpRequest create(final Method method, final URI uri) { return new BasicHttpRequest(method, uri); } /** - * Creates a request object of the exact subclass of {@link BasicHttpRequest}. + * Creates a new {@link BasicHttpRequest}. * + * @param method a non-null HTTP method. * @param host HTTP host. * @param path request path. * @return a new subclass of BasicHttpRequest diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/ConfigurableHttpRequest.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/ConfigurableHttpRequest.java index 5dba36b335..342e2cbb6d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/ConfigurableHttpRequest.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/ConfigurableHttpRequest.java @@ -45,21 +45,47 @@ public class ConfigurableHttpRequest extends BasicHttpRequest implements Configu private static final long serialVersionUID = 1L; private RequestConfig requestConfig; + /** + * Constructs a new request message with the given method and request path. + * + * @param method request method. + * @param path request path. + */ public ConfigurableHttpRequest(final String method, final String path) { super(method, path); } + /** + * Constructs a new request message with the given method, host, and request path. + * + * @param method request method. + * @param host request host. + * @param path request path. + */ public ConfigurableHttpRequest(final String method, final HttpHost host, final String path) { super(method, host, path); } /** + * Constructs a new request message with the given method, scheme, authority, and request path. + * + * @param method request method. + * @param scheme request host. + * @param authority request URI authority. + * @param path request path. * @since 5.1 */ public ConfigurableHttpRequest(final String method, final String scheme, final URIAuthority authority, final String path) { super(method, scheme, authority, path); } + /** + * Constructs a new request message with the given method, and request URI. + * + * @param method request method. + * @param requestUri request URI. + * @since 5.1 + */ public ConfigurableHttpRequest(final String method, final URI requestUri) { super(method, requestUri); } @@ -69,6 +95,11 @@ public RequestConfig getConfig() { return requestConfig; } + /** + * 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/async/methods/SimpleBody.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleBody.java index b1a0294508..d78abc89cd 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleBody.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleBody.java @@ -65,10 +65,20 @@ static SimpleBody create(final byte[] body, final ContentType contentType) { return new SimpleBody(body, null, contentType); } + /** + * Gets the content type. + * + * @return the content type. + */ public ContentType getContentType() { return contentType; } + /** + * Gets the body as a byte array. + * + * @return the body as a byte array. + */ public byte[] getBodyBytes() { if (bodyAsBytes != null) { return bodyAsBytes; @@ -80,19 +90,33 @@ public byte[] getBodyBytes() { } } + /** + * Gets the body as a String. + * + * @return the body as a String. + */ public String getBodyText() { if (bodyAsBytes != null) { final Charset charset = (contentType != null ? contentType : ContentType.DEFAULT_TEXT).getCharset(); return new String(bodyAsBytes, charset != null ? charset : StandardCharsets.US_ASCII); - } else { - return bodyAsText; } + return bodyAsText; } + /** + * Tests whether the body is currently cached as a String. + * + * @return whether the body is currently cached as a String. + */ public boolean isText() { return bodyAsText != null; } + /** + * Tests whether the body is currently cached as a byte array. + * + * @return whether the body is currently cached as a byte array. + */ public boolean isBytes() { return bodyAsBytes != null; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequest.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequest.java index 61d3a9f21e..43b4baf72d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequest.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequest.java @@ -58,6 +58,11 @@ public final class SimpleHttpRequest extends ConfigurableHttpRequest { private SimpleBody body; /** + * Creates a new request message with the given method and request path. + * + * @param method request method. + * @param uri request URI. + * @return a new SimpleHttpRequest. * @since 5.1 */ public static SimpleHttpRequest create(final String method, final String uri) { @@ -65,6 +70,11 @@ public static SimpleHttpRequest create(final String method, final String uri) { } /** + * Creates a new request message with the given method and request path. + * + * @param method request method. + * @param uri request URI. + * @return a new SimpleHttpRequest. * @since 5.1 */ public static SimpleHttpRequest create(final String method, final URI uri) { @@ -72,6 +82,11 @@ public static SimpleHttpRequest create(final String method, final URI uri) { } /** + * Creates a new request message with the given method and request path. + * + * @param method request method. + * @param uri request URI. + * @return a new SimpleHttpRequest. * @since 5.1 */ public static SimpleHttpRequest create(final Method method, final URI uri) { @@ -79,6 +94,12 @@ public static SimpleHttpRequest create(final Method method, final URI uri) { } /** + * Creates a new request message with the given method, host, and request path. + * + * @param method request method. + * @param host request host. + * @param path request path. + * @return a new SimpleHttpRequest. * @since 5.1 */ public static SimpleHttpRequest create(final Method method, final HttpHost host, final String path) { @@ -86,6 +107,13 @@ public static SimpleHttpRequest create(final Method method, final HttpHost host, } /** + * Creates a new request message with the given method, scheme, authority, and request path. + * + * @param method request method. + * @param scheme request host. + * @param authority request URI authority. + * @param path request path. + * @return a new SimpleHttpRequest. * @since 5.1 */ public static SimpleHttpRequest create(final String method, final String scheme, final URIAuthority authority, final String path) { @@ -93,6 +121,10 @@ public static SimpleHttpRequest create(final String method, final String scheme, } /** + * Copies the given HttpRequest. + * + * @param original the source to copy. + * @return a new SimpleHttpRequest. * @deprecated Use {@link SimpleRequestBuilder} */ @Deprecated @@ -108,19 +140,43 @@ public static SimpleHttpRequest copy(final HttpRequest original) { return copy; } + /** + * Constructs a new request message with the given method and request path. + * + * @param method request method. + * @param path request path. + */ public SimpleHttpRequest(final String method, final String path) { super(method, path); } + /** + * Constructs a new request message with the given method, host, and request path. + * + * @param method request method. + * @param host request host. + * @param path request path. + */ public SimpleHttpRequest(final String method, final HttpHost host, final String path) { super(method, host, path); } + /** + * Constructs a new request message with the given method, and request URI. + * + * @param method request method. + * @param requestUri request URI. + * @since 5.1 + */ public SimpleHttpRequest(final String method, final URI requestUri) { super(method, requestUri); } /** + * Constructs a new request message with the given method, and request URI. + * + * @param method request method. + * @param requestUri request URI. * @since 5.1 */ public SimpleHttpRequest(final Method method, final URI requestUri) { @@ -128,6 +184,11 @@ public SimpleHttpRequest(final Method method, final URI requestUri) { } /** + * Constructs a new request message with the given method, host, and request path. + * + * @param method request method. + * @param host request host. + * @param path request path. * @since 5.1 */ public SimpleHttpRequest(final Method method, final HttpHost host, final String path) { @@ -135,36 +196,79 @@ public SimpleHttpRequest(final Method method, final HttpHost host, final String } /** + * Constructs a new request message with the given method, scheme, authority, and request path. + * + * @param method request method. + * @param scheme request host. + * @param authority request URI authority. + * @param path request path. * @since 5.1 */ public SimpleHttpRequest(final String method, final String scheme, final URIAuthority authority, final String path) { super(method, scheme, authority, path); } + /** + * Sets the message body and content type. + * + * @param body request body. + */ public void setBody(final SimpleBody body) { this.body = body; } + /** + * Sets the message body and content type. + * + * @param bodyBytes request body. + * @param contentType request content type. + */ public void setBody(final byte[] bodyBytes, final ContentType contentType) { this.body = SimpleBody.create(bodyBytes, contentType); } + /** + * Sets the message body and content type. + * + * @param bodyText request body. + * @param contentType request content type. + */ public void setBody(final String bodyText, final ContentType contentType) { this.body = SimpleBody.create(bodyText, contentType); } + /** + * Gets the request body. + * + * @return the request body. + */ public SimpleBody getBody() { return body; } + /** + * Gets the request content type. + * + * @return the request content type. + */ public ContentType getContentType() { return body != null ? body.getContentType() : null; } + /** + * Gets the request body as a String. + * + * @return the request body. + */ public String getBodyText() { return body != null ? body.getBodyText() : null; } + /** + * Gets the request body as a byte array. + * + * @return the request body. + */ public byte[] getBodyBytes() { return body != null ? body.getBodyBytes() : null; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequests.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequests.java index 11a352498e..5f5a020693 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequests.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequests.java @@ -164,7 +164,7 @@ public static SimpleHttpRequest trace(final HttpHost host, final String path) { * Creates a request object of the exact subclass of {@link SimpleHttpRequest}. * * @param uri a non-null URI String. - * @return a new subclass of SimpleHttpRequest + * @return a new SimpleHttpRequest. */ public static SimpleHttpRequest create(final Method method, final String uri) { return create(method, URI.create(uri)); @@ -173,8 +173,9 @@ public static SimpleHttpRequest create(final Method method, final String uri) { /** * Creates a request object of the exact subclass of {@link SimpleHttpRequest}. * + * @param method a non-null HTTP method. * @param uri a non-null URI. - * @return a new subclass of SimpleHttpRequest + * @return a new SimpleHttpRequest. */ public static SimpleHttpRequest create(final Method method, final URI uri) { return new SimpleHttpRequest(method, uri); @@ -183,9 +184,10 @@ public static SimpleHttpRequest create(final Method method, final URI uri) { /** * Creates a request object of the exact subclass of {@link SimpleHttpRequest}. * + * @param method a non-null HTTP method. * @param host HTTP host. * @param path request path. - * @return a new subclass of SimpleHttpRequest + * @return a new SimpleHttpRequest. */ public static SimpleHttpRequest create(final Method method, final HttpHost host, final String path) { return new SimpleHttpRequest(method, host, path); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java index a1c3387778..465decb053 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java @@ -131,9 +131,8 @@ public AsyncDataConsumer handleResponse( LOG.debug("{} retrying request in {}", exchangeId, state.delay); } return new DiscardingEntityConsumer<>(); - } else { - return asyncExecCallback.handleResponse(response, entityDetails); } + return asyncExecCallback.handleResponse(response, entityDetails); } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java index 4fcfc5d8f9..15d5b395e0 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java @@ -619,7 +619,7 @@ public final H2AsyncClientBuilder setConnectionConfigResolver(final Resolver connectionConfig; + this.connectionConfigResolver = host -> connectionConfig; return this; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSessionDecorator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSessionDecorator.java index 0551aa982b..dcb09a7ad8 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSessionDecorator.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSessionDecorator.java @@ -49,8 +49,7 @@ public IOSession decorate(final IOSession ioSession) { final Logger sessionLog = LoggerFactory.getLogger(ioSession.getClass()); if (sessionLog.isDebugEnabled() || WIRE_LOG.isDebugEnabled()) { return new LoggingIOSession(ioSession, sessionLog, WIRE_LOG); - } else { - return ioSession; } + return ioSession; } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java index 34ceaf4745..15caa3ef71 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java @@ -232,9 +232,8 @@ public String generateAuthResponse( public State store() { if (complete) { return new State(new HashMap<>(paramMap), credentials); - } else { - return null; } + return null; } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BearerScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BearerScheme.java index dd1d17d271..9ee4c70858 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BearerScheme.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BearerScheme.java @@ -167,9 +167,8 @@ public String generateAuthResponse( public State store() { if (complete) { return new State(new HashMap<>(paramMap), bearerToken); - } else { - return null; } + return null; } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/GGSSchemeBase.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/GGSSchemeBase.java index e8fdc3b6c3..aa3bb94114 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/GGSSchemeBase.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/GGSSchemeBase.java @@ -141,9 +141,8 @@ protected byte[] generateGSSToken( final GSSContext gssContext = createGSSContext(manager, oid, serverName, gssCredential); if (input != null) { return gssContext.initSecContext(input, 0, input.length); - } else { - return gssContext.initSecContext(new byte[] {}, 0, 0); } + return gssContext.initSecContext(new byte[] {}, 0, 0); } /** diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/AIMDBackoffManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/AIMDBackoffManager.java index 5573278ae7..301d2eb323 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/AIMDBackoffManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/AIMDBackoffManager.java @@ -76,6 +76,7 @@ public AIMDBackoffManager(final ConnPoolControl connPerRoute) { * @param curr the current pool size * @return the backed-off pool size, with a minimum value of 1 */ + @Override protected int getBackedOffPoolSize(final int curr) { if (curr <= 1) { return 1; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ExponentialBackoffManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ExponentialBackoffManager.java index d33fdef7cf..3896f666d3 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ExponentialBackoffManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ExponentialBackoffManager.java @@ -71,6 +71,7 @@ public ExponentialBackoffManager(final ConnPoolControl connPerRoute) * @param curr the current pool size * @return the new pool size after applying the backoff */ + @Override protected int getBackedOffPoolSize(final int curr) { if (curr <= 1) { return 1; @@ -84,6 +85,7 @@ protected int getBackedOffPoolSize(final int curr) { return result; } + @Override public void setBackoffFactor(final double rate) { Args.check(rate > 0.0, "Growth rate must be greater than 0.0"); this.getBackoffFactor().set(rate); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestFutureTask.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestFutureTask.java index 85aabc063c..343a9b16fe 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestFutureTask.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestFutureTask.java @@ -73,9 +73,8 @@ public long startedTime() { public long endedTime() { if (isDone()) { return callable.getEnded(); - } else { - throw new IllegalStateException("Task is not done yet"); } + throw new IllegalStateException("Task is not done yet"); } /** @@ -85,9 +84,8 @@ public long endedTime() { public long requestDuration() { if (isDone()) { return endedTime() - startedTime(); - } else { - throw new IllegalStateException("Task is not done yet"); } + throw new IllegalStateException("Task is not done yet"); } /** @@ -96,9 +94,8 @@ public long requestDuration() { public long taskDuration() { if (isDone()) { return endedTime() - scheduledTime(); - } else { - throw new IllegalStateException("Task is not done yet"); } + throw new IllegalStateException("Task is not done yet"); } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java index 23c49d557e..2ab32b6644 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java @@ -144,15 +144,14 @@ public ClassicHttpResponse execute( } currentRequest = ClassicRequestBuilder.copy(scope.originalRequest).build(); continue; - } else { - if (ex instanceof NoHttpResponseException) { - final NoHttpResponseException updatedex = new NoHttpResponseException( - route.getTargetHost().toHostString() + " failed to respond"); - updatedex.setStackTrace(ex.getStackTrace()); - throw updatedex; - } - throw ex; } + if (ex instanceof NoHttpResponseException) { + final NoHttpResponseException updatedex = new NoHttpResponseException( + route.getTargetHost().toHostString() + " failed to respond"); + updatedex.setStackTrace(ex.getStackTrace()); + throw updatedex; + } + throw ex; } try { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RequestEntityProxy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RequestEntityProxy.java index c6d46b2056..29c861f6a7 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RequestEntityProxy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RequestEntityProxy.java @@ -68,11 +68,7 @@ public boolean isConsumed() { @Override public boolean isRepeatable() { - if (!consumed) { - return true; - } else { - return original.isRepeatable(); - } + return consumed && original.isRepeatable(); } @Override 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 a90847cb85..fa9fd3a7aa 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 @@ -253,10 +253,9 @@ public void connect( LOG.debug("{} connection to {} failed ({}); terminating operation", endpointHost, remoteAddress, ex.getClass()); } throw ConnectExceptionSupport.enhance(ex, endpointHost, remoteAddresses); - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("{} connection to {} failed ({}); retrying connection to the next address", endpointHost, remoteAddress, ex.getClass()); - } + } + if (LOG.isDebugEnabled()) { + LOG.debug("{} connection to {} failed ({}); retrying connection to the next address", endpointHost, remoteAddress, ex.getClass()); } } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java index 720d614e3b..13c9daaf79 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java @@ -144,9 +144,8 @@ public SSLSession getSSLSession() { final Socket socket = getSocket(); if (socket instanceof SSLSocket) { return ((SSLSocket) socket).getSession(); - } else { - return null; } + return null; } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java index 76ad4de4e8..d84167d050 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java @@ -591,7 +591,7 @@ public PoolStats getStats(final HttpRoute route) { * Sets the same {@link SocketConfig} for all routes */ public void setDefaultSocketConfig(final SocketConfig config) { - this.socketConfigResolver = (route) -> config; + this.socketConfigResolver = route -> config; } /** @@ -609,7 +609,7 @@ public void setSocketConfigResolver(final Resolver sock * @since 5.2 */ public void setDefaultConnectionConfig(final ConnectionConfig config) { - this.connectionConfigResolver = (route) -> config; + this.connectionConfigResolver = route -> config; } /** @@ -627,7 +627,7 @@ public void setConnectionConfigResolver(final Resolver config; + this.tlsConfigResolver = host -> config; } /** @@ -776,6 +776,7 @@ public ClassicHttpResponse execute( /** * @since 5.4 */ + @Override public ClassicHttpResponse execute( final String exchangeId, final ClassicHttpRequest request, diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java index 7f74e8ec89..d76c2720bc 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java @@ -202,7 +202,7 @@ public final PoolingHttpClientConnectionManagerBuilder setMaxConnPerRoute(final * @return this instance. */ public final PoolingHttpClientConnectionManagerBuilder setDefaultSocketConfig(final SocketConfig config) { - this.socketConfigResolver = (route) -> config; + this.socketConfigResolver = route -> config; return this; } @@ -225,7 +225,7 @@ public final PoolingHttpClientConnectionManagerBuilder setSocketConfigResolver( * @since 5.2 */ public final PoolingHttpClientConnectionManagerBuilder setDefaultConnectionConfig(final ConnectionConfig config) { - this.connectionConfigResolver = (route) -> config; + this.connectionConfigResolver = route -> config; return this; } @@ -248,7 +248,7 @@ public final PoolingHttpClientConnectionManagerBuilder setConnectionConfigResolv * @since 5.2 */ public final PoolingHttpClientConnectionManagerBuilder setDefaultTlsConfig(final TlsConfig config) { - this.tlsConfigResolver = (host) -> config; + this.tlsConfigResolver = host -> config; return this; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java index 07b5a2365c..c456dfa7ac 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java @@ -608,7 +608,7 @@ public PoolStats getStats(final HttpRoute route) { * @since 5.2 */ public void setDefaultConnectionConfig(final ConnectionConfig config) { - this.connectionConfigResolver = (route) -> config; + this.connectionConfigResolver = route -> config; } /** @@ -626,7 +626,7 @@ public void setConnectionConfigResolver(final Resolver config; + this.tlsConfigResolver = host -> config; } /** diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java index 28317dc662..36df24eb96 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java @@ -175,7 +175,7 @@ public final PoolingAsyncClientConnectionManagerBuilder setMaxConnPerRoute(final * @since 5.2 */ public final PoolingAsyncClientConnectionManagerBuilder setDefaultConnectionConfig(final ConnectionConfig config) { - this.connectionConfigResolver = (route) -> config; + this.connectionConfigResolver = route -> config; return this; } @@ -198,7 +198,7 @@ public final PoolingAsyncClientConnectionManagerBuilder setConnectionConfigResol * @since 5.2 */ public final PoolingAsyncClientConnectionManagerBuilder setDefaultTlsConfig(final TlsConfig config) { - this.tlsConfigResolver = (host) -> config; + this.tlsConfigResolver = host -> config; return this; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/HttpClientContext.java b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/HttpClientContext.java index 5e9519f1e0..6551d3dfdd 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/HttpClientContext.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/HttpClientContext.java @@ -169,9 +169,8 @@ public static HttpClientContext cast(final HttpContext context) { } if (context instanceof HttpClientContext) { return (HttpClientContext) context; - } else { - return new Delegate(context); } + return new Delegate(context); } /** 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 2d9fec92f2..4808c44bdb 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 @@ -215,9 +215,8 @@ static boolean matchDomainRoot(final String host, final String domainRoot) { } } return true; - } else { - return false; } + return false; } private static boolean matchIdentity(final String host, final String identity, diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/utils/DnsUtils.java b/httpclient5/src/main/java/org/apache/hc/client5/http/utils/DnsUtils.java index 4012b7f3a8..1e04cb118d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/utils/DnsUtils.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/utils/DnsUtils.java @@ -68,9 +68,8 @@ public static String normalize(final String s) { remaining--; } return buf.toString(); - } else { - return s; } + return s; } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/validator/ETag.java b/httpclient5/src/main/java/org/apache/hc/client5/http/validator/ETag.java index d4894b2656..100d3ba4c9 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/validator/ETag.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/validator/ETag.java @@ -108,9 +108,8 @@ static ETag parse(final CharSequence buf, final Tokenizer.Cursor cursor) { cursor.updatePos(cursor.getPos() + 1); if (ch == '"') { break; - } else { - sb.append(ch); } + sb.append(ch); } value = sb.toString(); }