Package org.forgerock.http.spi
Interface HttpClient
-
- All Superinterfaces:
AutoCloseable,Closeable
public interface HttpClient extends Closeable
An SPI interface for HTTPClientimplementations. AHttpClientProvideris 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
closethe 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
Promisefor instance): the message would be emptied before the callbacks are applied.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()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 aPromiserepresenting the asynchronousResponseof the givenrequest. If any (asynchronous) processing goes wrong, the promise still contains aResponse(probably from the 4xx or 5xx status code family).The returned
Promisecontains 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.This method should never throw any runtime exception. Exceptions must use the promise chain.
- Parameters:
request- The HTTP request to send.- Returns:
- A promise representing the pending HTTP response or any runtime exceptions that may occur.
-
close
void close() throws IOExceptionCompletes all pending requests and release resources associated with underlying implementation.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occurs
-
-