Interface HttpClientProvider
- All Superinterfaces:
Provider
- Author:
- Stian Thorgersen
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault InputStreamDeprecated.org.apache.http.impl.client.CloseableHttpClientReturns theCloseableHttpClientthat can be freely used.getInputStream(String uri) Helper method to retrieve the contents of a URL as an InputStream.default longGet the configured limit for the response size.Helper method to retrieve the contents of a URL as a String.intHelper method
-
Field Details
-
DEFAULT_MAX_CONSUMED_RESPONSE_SIZE
static final long DEFAULT_MAX_CONSUMED_RESPONSE_SIZE- See Also:
-
-
Method Details
-
getHttpClient
org.apache.http.impl.client.CloseableHttpClient getHttpClient()Returns theCloseableHttpClientthat can be freely used.The returned
HttpClientinstance must never beclose()d by the caller.Closing the
HttpClientinstance is responsibility of this provider. However, the objects created via the returnedHttpClientneed to be closed properly by the code that instantiated them.- Returns:
-
postText
Helper method- Parameters:
uri-text-- Returns:
- http response status
- Throws:
IOException
-
getString
Helper method to retrieve the contents of a URL as a String. Decoding response with the correct character set is performed according to the headers returned in the server's response. To retrieve binary data, usegetInputStream(String)Implementations should limit the amount of data returned to avoid anOutOfMemoryError.- Parameters:
uri- URI with data to receive.- Returns:
- Body of the response as a String.
- Throws:
IOException- On network errors, no content being returned or a non-2xx HTTP status code
-
getInputStream
Helper method to retrieve the contents of a URL as an InputStream. Use this to retrieve binary data where no additional HTTP headers need to be considered. The caller is required to close the returned InputStream to prevent a resource leak.To retrieve strings that depend on their encoding, use
getString(String)- Parameters:
uri- URI with data to receive.- Returns:
- Body of the response as an InputStream. The caller is required to close the returned InputStream to prevent a resource leak.
- Throws:
IOException- On network errors, no content being returned or a non-2xx HTTP status code.
-
get
Deprecated.For String content, usegetString(String), for binary data usegetInputStream(String). To be removed in Keycloak 27.Helper method. The caller is required to close the returned InputStream to prevent a resource leak.- Parameters:
uri- URI with data to receive.- Returns:
- Body of the response as an InputStream. The caller is required to close the returned InputStream to prevent a resource leak.
- Throws:
IOException- On network errors, no content being returned or a non-2xx HTTP status code.
-
getMaxConsumedResponseSize
default long getMaxConsumedResponseSize()Get the configured limit for the response size.- Returns:
- number of bytes
-
getString(String), for binary data usegetInputStream(String).