Package org.forgerock.http.spi
Interface HttpClient
-
- All Superinterfaces:
AutoCloseable
,Closeable
public interface HttpClient extends Closeable
An SPI interface for HTTPClient
implementations. AHttpClientProvider
is loaded during construction of a new HTTPClient
. The first available provider is selected and itsHttpClientProvider.newHttpClient(org.forgerock.util.Options)
method invoked in order to construct and configure a newHttpClient
.It is the responsibility of the caller to
close
the request and response messages.HttpClient client = ... try (Response response = client.sendAsync(...).getOrThrow()) { // consumes the response completely }
Note: Callers should not use try-with-resources pattern if they forward the response asynchronously (using a
Promise
for instance): the message would be emptied before the callbacks are applied.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Completes all pending requests and release resources associated with underlying implementation.Promise<Response,NeverThrowsException>
sendAsync(Request request)
-
-
-
Method Detail
-
sendAsync
Promise<Response,NeverThrowsException> sendAsync(Request request)
Returns aPromise
representing the asynchronousResponse
of the givenrequest
. If any (asynchronous) processing goes wrong, the promise still contains aResponse
(probably from the 4xx or 5xx status code family).The returned
Promise
contains the response returned from the server as-is. This is responsibility of the client to produce the appropriate error response (404, 500, ...) in case of processing or transport errors.- Parameters:
request
- The HTTP request to send.- Returns:
- A promise representing the pending HTTP response.
-
close
void close() throws IOException
Completes all pending requests and release resources associated with underlying implementation.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an I/O error occurs
-
-