@ParametersAreNonnullByDefault @ThreadSafe public final class BasicHttpClient extends Object implements Closeable
CloseableHttpClient
that aides in getting byte[] content at a URI.
Supports custom host and port routing. Usable as ResourceLoader
loader function.
NOTE: This class stores the HTTP response body in an in memory byte[] in BasicHttpResult
and as such should not be used for large or complex HTTP requests.Modifier and Type | Class and Description |
---|---|
static class |
BasicHttpClient.Builder
BasicHttpClient builder class.
|
Modifier and Type | Method and Description |
---|---|
protected static boolean |
acceptableStatusPredicateDefault(int statusCode)
Default HTTP status code predicate, if 2xx, success is true.
|
static BasicHttpClient.Builder |
builder() |
void |
close() |
BasicHttpResult |
get(URI uri)
Performs a GET request at URI and returns a BasicHttpResult accepting any 2xx status as a success.
|
BasicHttpResult |
get(URI uri,
IntPredicate acceptableStatus)
Performs a GET request at URI and returns a BasicHttpResult.
|
byte[] |
getAsBytes(URI uri)
Performs a GET request and returns the response body as a byte[].
|
BasicHttpResult |
post(URI endpoint,
byte[] data)
Performs a POST request to URI and returns a BasicHttpResult accepting any 2xx status as a success.
|
BasicHttpResult |
post(URI endpoint,
byte[] postBody,
org.apache.http.entity.ContentType contentType,
IntPredicate acceptableStatus)
Performs a POST request to URI and returns a BasicHttpResult.
|
BasicHttpResult |
post(URI endpoint,
org.apache.http.HttpEntity postBody,
IntPredicate acceptableStatus)
Performs a POST request to URI and returns a BasicHttpResult.
|
BasicHttpResult |
post(URI endpoint,
com.fasterxml.jackson.databind.ObjectMapper mapper,
com.fasterxml.jackson.databind.JsonNode node,
IntPredicate acceptableStatus)
Performs a POST request to URI and returns a BasicHttpResult.
|
@Nonnull public static BasicHttpClient.Builder builder()
@Nullable public byte[] getAsBytes(URI uri)
ResourceLoader
loader function.
Call resourceLoader.withHttpClient(basicHttpClient)
to have an instance
of ResourceLoader use a BasicHttpClient to load http and https URLs using this function.
Note that HTTP specifies that body can exist and be empty or not exist at all. In case
of an existing body that is empty, this method returns an empty byte[]
. In case
of a non-existing body, this method returns null
.@Nonnull public BasicHttpResult get(URI uri, IntPredicate acceptableStatus)
@Nonnull public BasicHttpResult get(URI uri)
@Nonnull public BasicHttpResult post(URI endpoint, byte[] data)
@Nonnull public BasicHttpResult post(URI endpoint, byte[] postBody, @Nullable org.apache.http.entity.ContentType contentType, IntPredicate acceptableStatus)
@Nonnull public BasicHttpResult post(URI endpoint, com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.JsonNode node, IntPredicate acceptableStatus)
@Nonnull public BasicHttpResult post(URI endpoint, org.apache.http.HttpEntity postBody, IntPredicate acceptableStatus)
protected static boolean acceptableStatusPredicateDefault(int statusCode)
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2025. All rights reserved.