Interface HttpClientProvider

All Superinterfaces:
Provider

public interface HttpClientProvider extends Provider
Author:
Stian Thorgersen
  • 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 the CloseableHttpClient that can be freely used.

      The returned HttpClient instance must never be close()d by the caller.

      Closing the HttpClient instance is responsibility of this provider. However, the objects created via the returned HttpClient need to be closed properly by the code that instantiated them.

      Returns:
    • postText

      int postText(String uri, String text) throws IOException
      Helper method
      Parameters:
      uri -
      text -
      Returns:
      http response status
      Throws:
      IOException
    • getString

      String getString(String uri) throws IOException
      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, use getInputStream(String) Implementations should limit the amount of data returned to avoid an OutOfMemoryError.
      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

      InputStream getInputStream(String uri) throws IOException
      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 default InputStream get(String uri) throws IOException
      Deprecated.
      For String content, use getString(String), for binary data use getInputStream(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