- Remove redundant parentheses
- No need to nest into else clause
- Add missing @Override
This commit is contained in:
Gary Gregory 2024-08-26 10:49:26 -04:00
parent 648690fdfd
commit a1eed8084d
33 changed files with 382 additions and 65 deletions

View File

@ -49,6 +49,8 @@ public interface AsyncExecCallback {
* @param entityDetails the response entity details or {@code null} if the response * @param entityDetails the response entity details or {@code null} if the response
* does not enclose an entity. * does not enclose an entity.
* @return the data consumer to be used for processing of incoming response message body. * @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( AsyncDataConsumer handleResponse(
HttpResponse response, HttpResponse response,
@ -58,6 +60,8 @@ AsyncDataConsumer handleResponse(
* Triggered to signal receipt of an intermediate response message. * Triggered to signal receipt of an intermediate response message.
* *
* @param response the 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; void handleInformationResponse(HttpResponse response) throws HttpException, IOException;

View File

@ -72,6 +72,8 @@ public interface AsyncExecChainHandler {
* @param scope the execution scope . * @param scope the execution scope .
* @param chain the next element in the request execution chain. * @param chain the next element in the request execution chain.
* @param asyncExecCallback the execution callback. * @param asyncExecCallback the execution callback.
* @throws HttpException If a protocol error occurs.
* @throws IOException If an I/O error occurs.
*/ */
void execute( void execute(
HttpRequest request, HttpRequest request,

View File

@ -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() { default EndpointInfo getEndpointInfo() {
return null; return null;

View File

@ -52,6 +52,8 @@ public abstract class AbstractBinPushConsumer extends AbstractBinDataConsumer im
* @param response the response message head * @param response the response message head
* @param contentType the content type of the response body, * @param contentType the content type of the response body,
* or {@code null} if the response does not enclose a response entity. * 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; protected abstract void start(HttpRequest promise, HttpResponse response, ContentType contentType) throws HttpException, IOException;

View File

@ -56,6 +56,8 @@ public abstract class AbstractBinResponseConsumer<T> extends AbstractBinDataCons
* @param response the response message head * @param response the response message head
* @param contentType the content type of the response body, * @param contentType the content type of the response body,
* or {@code null} if the response does not enclose a response entity. * 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; protected abstract void start(HttpResponse response, ContentType contentType) throws HttpException, IOException;

View File

@ -68,6 +68,8 @@ protected AbstractCharPushConsumer(final int bufSize,
* @param response the response message head * @param response the response message head
* @param contentType the content type of the response body, * @param contentType the content type of the response body,
* or {@code null} if the response does not enclose a response entity. * 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; protected abstract void start(HttpRequest promise, HttpResponse response, ContentType contentType) throws HttpException, IOException;

View File

@ -71,6 +71,8 @@ protected AbstractCharResponseConsumer(final int bufSize,
* @param response the response message head * @param response the response message head
* @param contentType the content type of the response body, * @param contentType the content type of the response body,
* or {@code null} if the response does not enclose a response entity. * 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; protected abstract void start(HttpResponse response, ContentType contentType) throws HttpException, IOException;

View File

@ -65,125 +65,280 @@ public static BasicHttpRequest create(final String method, final URI uri) {
return create(Method.normalizedValueOf(method), 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) { public static BasicHttpRequest delete(final String uri) {
return delete(URI.create(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) { public static BasicHttpRequest delete(final URI uri) {
return create(Method.DELETE, 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) { public static BasicHttpRequest delete(final HttpHost host, final String path) {
return create(Method.DELETE, host, 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) { public static BasicHttpRequest get(final String uri) {
return get(URI.create(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) { public static BasicHttpRequest get(final URI uri) {
return create(Method.GET, 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) { public static BasicHttpRequest get(final HttpHost host, final String path) {
return create(Method.GET, host, 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) { public static BasicHttpRequest head(final String uri) {
return head(URI.create(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) { public static BasicHttpRequest head(final URI uri) {
return create(Method.HEAD, 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) { public static BasicHttpRequest head(final HttpHost host, final String path) {
return create(Method.HEAD, host, 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) { public static BasicHttpRequest options(final String uri) {
return options(URI.create(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) { public static BasicHttpRequest options(final URI uri) {
return create(Method.OPTIONS, 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) { public static BasicHttpRequest options(final HttpHost host, final String path) {
return create(Method.OPTIONS, host, 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) { public static BasicHttpRequest patch(final String uri) {
return patch(URI.create(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) { public static BasicHttpRequest patch(final URI uri) {
return create(Method.PATCH, 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) { public static BasicHttpRequest patch(final HttpHost host, final String path) {
return create(Method.PATCH, host, 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) { public static BasicHttpRequest post(final String uri) {
return post(URI.create(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) { public static BasicHttpRequest post(final URI uri) {
return create(Method.POST, 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) { public static BasicHttpRequest post(final HttpHost host, final String path) {
return create(Method.POST, host, 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) { public static BasicHttpRequest put(final String uri) {
return put(URI.create(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) { public static BasicHttpRequest put(final URI uri) {
return create(Method.PUT, 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) { public static BasicHttpRequest put(final HttpHost host, final String path) {
return create(Method.PUT, host, 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) { public static BasicHttpRequest trace(final String uri) {
return trace(URI.create(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) { public static BasicHttpRequest trace(final URI uri) {
return create(Method.TRACE, 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) { public static BasicHttpRequest trace(final HttpHost host, final String path) {
return create(Method.TRACE, host, 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. * @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) { public static BasicHttpRequest create(final Method method, final String uri) {
return create(method, URI.create(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. * @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) { public static BasicHttpRequest create(final Method method, final URI uri) {
return new BasicHttpRequest(method, 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 host HTTP host.
* @param path request path. * @param path request path.
* @return a new subclass of BasicHttpRequest * @return a new subclass of BasicHttpRequest

View File

@ -45,21 +45,47 @@ public class ConfigurableHttpRequest extends BasicHttpRequest implements Configu
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private RequestConfig requestConfig; 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) { public ConfigurableHttpRequest(final String method, final String path) {
super(method, 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) { public ConfigurableHttpRequest(final String method, final HttpHost host, final String path) {
super(method, host, 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 * @since 5.1
*/ */
public ConfigurableHttpRequest(final String method, final String scheme, final URIAuthority authority, final String path) { public ConfigurableHttpRequest(final String method, final String scheme, final URIAuthority authority, final String path) {
super(method, scheme, authority, 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) { public ConfigurableHttpRequest(final String method, final URI requestUri) {
super(method, requestUri); super(method, requestUri);
} }
@ -69,6 +95,11 @@ public RequestConfig getConfig() {
return requestConfig; return requestConfig;
} }
/**
* Sets the request configuration.
*
* @param requestConfig the request configuration.
*/
public void setConfig(final RequestConfig requestConfig) { public void setConfig(final RequestConfig requestConfig) {
this.requestConfig = requestConfig; this.requestConfig = requestConfig;
} }

View File

@ -65,10 +65,20 @@ static SimpleBody create(final byte[] body, final ContentType contentType) {
return new SimpleBody(body, null, contentType); return new SimpleBody(body, null, contentType);
} }
/**
* Gets the content type.
*
* @return the content type.
*/
public ContentType getContentType() { public ContentType getContentType() {
return contentType; return contentType;
} }
/**
* Gets the body as a byte array.
*
* @return the body as a byte array.
*/
public byte[] getBodyBytes() { public byte[] getBodyBytes() {
if (bodyAsBytes != null) { if (bodyAsBytes != null) {
return bodyAsBytes; return bodyAsBytes;
@ -80,19 +90,33 @@ public byte[] getBodyBytes() {
} }
} }
/**
* Gets the body as a String.
*
* @return the body as a String.
*/
public String getBodyText() { public String getBodyText() {
if (bodyAsBytes != null) { if (bodyAsBytes != null) {
final Charset charset = (contentType != null ? contentType : ContentType.DEFAULT_TEXT).getCharset(); final Charset charset = (contentType != null ? contentType : ContentType.DEFAULT_TEXT).getCharset();
return new String(bodyAsBytes, charset != null ? charset : StandardCharsets.US_ASCII); 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() { public boolean isText() {
return bodyAsText != null; 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() { public boolean isBytes() {
return bodyAsBytes != null; return bodyAsBytes != null;
} }

View File

@ -58,6 +58,11 @@ public final class SimpleHttpRequest extends ConfigurableHttpRequest {
private SimpleBody body; 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 * @since 5.1
*/ */
public static SimpleHttpRequest create(final String method, final String uri) { 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 * @since 5.1
*/ */
public static SimpleHttpRequest create(final String method, final URI uri) { 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 * @since 5.1
*/ */
public static SimpleHttpRequest create(final Method method, final URI uri) { 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 * @since 5.1
*/ */
public static SimpleHttpRequest create(final Method method, final HttpHost host, final String path) { 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 * @since 5.1
*/ */
public static SimpleHttpRequest create(final String method, final String scheme, final URIAuthority authority, final String path) { 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 Use {@link SimpleRequestBuilder}
*/ */
@Deprecated @Deprecated
@ -108,19 +140,43 @@ public static SimpleHttpRequest copy(final HttpRequest original) {
return copy; 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) { public SimpleHttpRequest(final String method, final String path) {
super(method, 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) { public SimpleHttpRequest(final String method, final HttpHost host, final String path) {
super(method, host, 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) { public SimpleHttpRequest(final String method, final URI requestUri) {
super(method, 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 * @since 5.1
*/ */
public SimpleHttpRequest(final Method method, final URI requestUri) { 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 * @since 5.1
*/ */
public SimpleHttpRequest(final Method method, final HttpHost host, final String path) { 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 * @since 5.1
*/ */
public SimpleHttpRequest(final String method, final String scheme, final URIAuthority authority, final String path) { public SimpleHttpRequest(final String method, final String scheme, final URIAuthority authority, final String path) {
super(method, scheme, authority, path); super(method, scheme, authority, path);
} }
/**
* Sets the message body and content type.
*
* @param body request body.
*/
public void setBody(final SimpleBody body) { public void setBody(final SimpleBody body) {
this.body = 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) { public void setBody(final byte[] bodyBytes, final ContentType contentType) {
this.body = SimpleBody.create(bodyBytes, 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) { public void setBody(final String bodyText, final ContentType contentType) {
this.body = SimpleBody.create(bodyText, contentType); this.body = SimpleBody.create(bodyText, contentType);
} }
/**
* Gets the request body.
*
* @return the request body.
*/
public SimpleBody getBody() { public SimpleBody getBody() {
return body; return body;
} }
/**
* Gets the request content type.
*
* @return the request content type.
*/
public ContentType getContentType() { public ContentType getContentType() {
return body != null ? body.getContentType() : null; return body != null ? body.getContentType() : null;
} }
/**
* Gets the request body as a String.
*
* @return the request body.
*/
public String getBodyText() { public String getBodyText() {
return body != null ? body.getBodyText() : null; return body != null ? body.getBodyText() : null;
} }
/**
* Gets the request body as a byte array.
*
* @return the request body.
*/
public byte[] getBodyBytes() { public byte[] getBodyBytes() {
return body != null ? body.getBodyBytes() : null; return body != null ? body.getBodyBytes() : null;
} }

View File

@ -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}. * Creates a request object of the exact subclass of {@link SimpleHttpRequest}.
* *
* @param uri a non-null URI String. * @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) { public static SimpleHttpRequest create(final Method method, final String uri) {
return create(method, URI.create(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}. * Creates a request object of the exact subclass of {@link SimpleHttpRequest}.
* *
* @param method a non-null HTTP method.
* @param uri a non-null URI. * @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) { public static SimpleHttpRequest create(final Method method, final URI uri) {
return new SimpleHttpRequest(method, 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}. * Creates a request object of the exact subclass of {@link SimpleHttpRequest}.
* *
* @param method a non-null HTTP method.
* @param host HTTP host. * @param host HTTP host.
* @param path request path. * @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) { public static SimpleHttpRequest create(final Method method, final HttpHost host, final String path) {
return new SimpleHttpRequest(method, host, path); return new SimpleHttpRequest(method, host, path);

View File

@ -131,9 +131,8 @@ public AsyncDataConsumer handleResponse(
LOG.debug("{} retrying request in {}", exchangeId, state.delay); LOG.debug("{} retrying request in {}", exchangeId, state.delay);
} }
return new DiscardingEntityConsumer<>(); return new DiscardingEntityConsumer<>();
} else {
return asyncExecCallback.handleResponse(response, entityDetails);
} }
return asyncExecCallback.handleResponse(response, entityDetails);
} }
@Override @Override

View File

@ -619,7 +619,7 @@ public final H2AsyncClientBuilder setConnectionConfigResolver(final Resolver<Htt
* @since 5.2 * @since 5.2
*/ */
public final H2AsyncClientBuilder setDefaultConnectionConfig(final ConnectionConfig connectionConfig) { public final H2AsyncClientBuilder setDefaultConnectionConfig(final ConnectionConfig connectionConfig) {
this.connectionConfigResolver = (host) -> connectionConfig; this.connectionConfigResolver = host -> connectionConfig;
return this; return this;
} }

View File

@ -49,8 +49,7 @@ public IOSession decorate(final IOSession ioSession) {
final Logger sessionLog = LoggerFactory.getLogger(ioSession.getClass()); final Logger sessionLog = LoggerFactory.getLogger(ioSession.getClass());
if (sessionLog.isDebugEnabled() || WIRE_LOG.isDebugEnabled()) { if (sessionLog.isDebugEnabled() || WIRE_LOG.isDebugEnabled()) {
return new LoggingIOSession(ioSession, sessionLog, WIRE_LOG); return new LoggingIOSession(ioSession, sessionLog, WIRE_LOG);
} else {
return ioSession;
} }
return ioSession;
} }
} }

View File

@ -232,9 +232,8 @@ public String generateAuthResponse(
public State store() { public State store() {
if (complete) { if (complete) {
return new State(new HashMap<>(paramMap), credentials); return new State(new HashMap<>(paramMap), credentials);
} else {
return null;
} }
return null;
} }
@Override @Override

View File

@ -167,9 +167,8 @@ public String generateAuthResponse(
public State store() { public State store() {
if (complete) { if (complete) {
return new State(new HashMap<>(paramMap), bearerToken); return new State(new HashMap<>(paramMap), bearerToken);
} else {
return null;
} }
return null;
} }
@Override @Override

View File

@ -141,9 +141,8 @@ protected byte[] generateGSSToken(
final GSSContext gssContext = createGSSContext(manager, oid, serverName, gssCredential); final GSSContext gssContext = createGSSContext(manager, oid, serverName, gssCredential);
if (input != null) { if (input != null) {
return gssContext.initSecContext(input, 0, input.length); return gssContext.initSecContext(input, 0, input.length);
} else {
return gssContext.initSecContext(new byte[] {}, 0, 0);
} }
return gssContext.initSecContext(new byte[] {}, 0, 0);
} }
/** /**

View File

@ -76,6 +76,7 @@ public AIMDBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute) {
* @param curr the current pool size * @param curr the current pool size
* @return the backed-off pool size, with a minimum value of 1 * @return the backed-off pool size, with a minimum value of 1
*/ */
@Override
protected int getBackedOffPoolSize(final int curr) { protected int getBackedOffPoolSize(final int curr) {
if (curr <= 1) { if (curr <= 1) {
return 1; return 1;

View File

@ -71,6 +71,7 @@ public ExponentialBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute)
* @param curr the current pool size * @param curr the current pool size
* @return the new pool size after applying the backoff * @return the new pool size after applying the backoff
*/ */
@Override
protected int getBackedOffPoolSize(final int curr) { protected int getBackedOffPoolSize(final int curr) {
if (curr <= 1) { if (curr <= 1) {
return 1; return 1;
@ -84,6 +85,7 @@ protected int getBackedOffPoolSize(final int curr) {
return result; return result;
} }
@Override
public void setBackoffFactor(final double rate) { public void setBackoffFactor(final double rate) {
Args.check(rate > 0.0, "Growth rate must be greater than 0.0"); Args.check(rate > 0.0, "Growth rate must be greater than 0.0");
this.getBackoffFactor().set(rate); this.getBackoffFactor().set(rate);

View File

@ -73,9 +73,8 @@ public long startedTime() {
public long endedTime() { public long endedTime() {
if (isDone()) { if (isDone()) {
return callable.getEnded(); 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() { public long requestDuration() {
if (isDone()) { if (isDone()) {
return endedTime() - startedTime(); 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() { public long taskDuration() {
if (isDone()) { if (isDone()) {
return endedTime() - scheduledTime(); return endedTime() - scheduledTime();
} else {
throw new IllegalStateException("Task is not done yet");
} }
throw new IllegalStateException("Task is not done yet");
} }
@Override @Override

View File

@ -144,15 +144,14 @@ public ClassicHttpResponse execute(
} }
currentRequest = ClassicRequestBuilder.copy(scope.originalRequest).build(); currentRequest = ClassicRequestBuilder.copy(scope.originalRequest).build();
continue; 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 { try {

View File

@ -68,11 +68,7 @@ public boolean isConsumed() {
@Override @Override
public boolean isRepeatable() { public boolean isRepeatable() {
if (!consumed) { return consumed && original.isRepeatable();
return true;
} else {
return original.isRepeatable();
}
} }
@Override @Override

View File

@ -253,10 +253,9 @@ public void connect(
LOG.debug("{} connection to {} failed ({}); terminating operation", endpointHost, remoteAddress, ex.getClass()); LOG.debug("{} connection to {} failed ({}); terminating operation", endpointHost, remoteAddress, ex.getClass());
} }
throw ConnectExceptionSupport.enhance(ex, endpointHost, remoteAddresses); throw ConnectExceptionSupport.enhance(ex, endpointHost, remoteAddresses);
} else { }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("{} connection to {} failed ({}); retrying connection to the next address", endpointHost, remoteAddress, ex.getClass()); LOG.debug("{} connection to {} failed ({}); retrying connection to the next address", endpointHost, remoteAddress, ex.getClass());
}
} }
} }
} }

View File

@ -144,9 +144,8 @@ public SSLSession getSSLSession() {
final Socket socket = getSocket(); final Socket socket = getSocket();
if (socket instanceof SSLSocket) { if (socket instanceof SSLSocket) {
return ((SSLSocket) socket).getSession(); return ((SSLSocket) socket).getSession();
} else {
return null;
} }
return null;
} }
@Override @Override

View File

@ -591,7 +591,7 @@ public PoolStats getStats(final HttpRoute route) {
* Sets the same {@link SocketConfig} for all routes * Sets the same {@link SocketConfig} for all routes
*/ */
public void setDefaultSocketConfig(final SocketConfig config) { public void setDefaultSocketConfig(final SocketConfig config) {
this.socketConfigResolver = (route) -> config; this.socketConfigResolver = route -> config;
} }
/** /**
@ -609,7 +609,7 @@ public void setSocketConfigResolver(final Resolver<HttpRoute, SocketConfig> sock
* @since 5.2 * @since 5.2
*/ */
public void setDefaultConnectionConfig(final ConnectionConfig config) { public void setDefaultConnectionConfig(final ConnectionConfig config) {
this.connectionConfigResolver = (route) -> config; this.connectionConfigResolver = route -> config;
} }
/** /**
@ -627,7 +627,7 @@ public void setConnectionConfigResolver(final Resolver<HttpRoute, ConnectionConf
* @since 5.2 * @since 5.2
*/ */
public void setDefaultTlsConfig(final TlsConfig config) { public void setDefaultTlsConfig(final TlsConfig config) {
this.tlsConfigResolver = (host) -> config; this.tlsConfigResolver = host -> config;
} }
/** /**
@ -776,6 +776,7 @@ public ClassicHttpResponse execute(
/** /**
* @since 5.4 * @since 5.4
*/ */
@Override
public ClassicHttpResponse execute( public ClassicHttpResponse execute(
final String exchangeId, final String exchangeId,
final ClassicHttpRequest request, final ClassicHttpRequest request,

View File

@ -202,7 +202,7 @@ public final PoolingHttpClientConnectionManagerBuilder setMaxConnPerRoute(final
* @return this instance. * @return this instance.
*/ */
public final PoolingHttpClientConnectionManagerBuilder setDefaultSocketConfig(final SocketConfig config) { public final PoolingHttpClientConnectionManagerBuilder setDefaultSocketConfig(final SocketConfig config) {
this.socketConfigResolver = (route) -> config; this.socketConfigResolver = route -> config;
return this; return this;
} }
@ -225,7 +225,7 @@ public final PoolingHttpClientConnectionManagerBuilder setSocketConfigResolver(
* @since 5.2 * @since 5.2
*/ */
public final PoolingHttpClientConnectionManagerBuilder setDefaultConnectionConfig(final ConnectionConfig config) { public final PoolingHttpClientConnectionManagerBuilder setDefaultConnectionConfig(final ConnectionConfig config) {
this.connectionConfigResolver = (route) -> config; this.connectionConfigResolver = route -> config;
return this; return this;
} }
@ -248,7 +248,7 @@ public final PoolingHttpClientConnectionManagerBuilder setConnectionConfigResolv
* @since 5.2 * @since 5.2
*/ */
public final PoolingHttpClientConnectionManagerBuilder setDefaultTlsConfig(final TlsConfig config) { public final PoolingHttpClientConnectionManagerBuilder setDefaultTlsConfig(final TlsConfig config) {
this.tlsConfigResolver = (host) -> config; this.tlsConfigResolver = host -> config;
return this; return this;
} }

View File

@ -608,7 +608,7 @@ public PoolStats getStats(final HttpRoute route) {
* @since 5.2 * @since 5.2
*/ */
public void setDefaultConnectionConfig(final ConnectionConfig config) { public void setDefaultConnectionConfig(final ConnectionConfig config) {
this.connectionConfigResolver = (route) -> config; this.connectionConfigResolver = route -> config;
} }
/** /**
@ -626,7 +626,7 @@ public void setConnectionConfigResolver(final Resolver<HttpRoute, ConnectionConf
* @since 5.2 * @since 5.2
*/ */
public void setDefaultTlsConfig(final TlsConfig config) { public void setDefaultTlsConfig(final TlsConfig config) {
this.tlsConfigResolver = (host) -> config; this.tlsConfigResolver = host -> config;
} }
/** /**

View File

@ -175,7 +175,7 @@ public final PoolingAsyncClientConnectionManagerBuilder setMaxConnPerRoute(final
* @since 5.2 * @since 5.2
*/ */
public final PoolingAsyncClientConnectionManagerBuilder setDefaultConnectionConfig(final ConnectionConfig config) { public final PoolingAsyncClientConnectionManagerBuilder setDefaultConnectionConfig(final ConnectionConfig config) {
this.connectionConfigResolver = (route) -> config; this.connectionConfigResolver = route -> config;
return this; return this;
} }
@ -198,7 +198,7 @@ public final PoolingAsyncClientConnectionManagerBuilder setConnectionConfigResol
* @since 5.2 * @since 5.2
*/ */
public final PoolingAsyncClientConnectionManagerBuilder setDefaultTlsConfig(final TlsConfig config) { public final PoolingAsyncClientConnectionManagerBuilder setDefaultTlsConfig(final TlsConfig config) {
this.tlsConfigResolver = (host) -> config; this.tlsConfigResolver = host -> config;
return this; return this;
} }

View File

@ -169,9 +169,8 @@ public static HttpClientContext cast(final HttpContext context) {
} }
if (context instanceof HttpClientContext) { if (context instanceof HttpClientContext) {
return (HttpClientContext) context; return (HttpClientContext) context;
} else {
return new Delegate(context);
} }
return new Delegate(context);
} }
/** /**

View File

@ -215,9 +215,8 @@ static boolean matchDomainRoot(final String host, final String domainRoot) {
} }
} }
return true; return true;
} else {
return false;
} }
return false;
} }
private static boolean matchIdentity(final String host, final String identity, private static boolean matchIdentity(final String host, final String identity,

View File

@ -68,9 +68,8 @@ public static String normalize(final String s) {
remaining--; remaining--;
} }
return buf.toString(); return buf.toString();
} else {
return s;
} }
return s;
} }
} }

View File

@ -108,9 +108,8 @@ static ETag parse(final CharSequence buf, final Tokenizer.Cursor cursor) {
cursor.updatePos(cursor.getPos() + 1); cursor.updatePos(cursor.getPos() + 1);
if (ch == '"') { if (ch == '"') {
break; break;
} else {
sb.append(ch);
} }
sb.append(ch);
} }
value = sb.toString(); value = sb.toString();
} }