Class HttpClientTestUtil

java.lang.Object
net.officefloor.server.http.HttpClientTestUtil

public class HttpClientTestUtil extends Object
Utility class aiding in testing HTTP functionality.
Author:
Daniel Sagenschneider
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    System property configured to true to not time out HttpClient instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.http.client.CredentialsProvider
    configureCredentials(org.apache.http.impl.client.HttpClientBuilder builder, String realm, String scheme, String username, String password)
    Configures CredentialsProvider for the HttpClientBuilder.
    static void
    configureHttps(org.apache.http.impl.client.HttpClientBuilder builder)
    Configures the HttpClientBuilder for HTTPS.
    static void
    configureNoRedirects(org.apache.http.impl.client.HttpClientBuilder builder)
    Configures no redirects for the HttpClientBuilder.
    static org.apache.http.impl.client.CloseableHttpClient
    Creates a CloseableHttpClient ready for use with default values.
    static org.apache.http.impl.client.CloseableHttpClient
    createHttpClient(boolean isSecure)
    Creates a CloseableHttpClient ready for use.
    static org.apache.http.impl.client.HttpClientBuilder
    Create the HttpClientBuilder.
    static org.apache.http.impl.client.HttpClientBuilder
    Create the HttpClientBuilder.
    static String
    entityToString(org.apache.http.HttpResponse response)
    Obtains the HttpEntity content.
    static String
    entityToString(org.apache.http.HttpResponse response, Charset charset)
    Obtains the HttpEntity content.
    static int
    Obtains the client time out.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PROPERTY_NO_TIMEOUT

      public static final String PROPERTY_NO_TIMEOUT
      System property configured to true to not time out HttpClient instances. This is useful for debugging server handling of requests.
      See Also:
  • Method Details

    • getClientTimeout

      public static int getClientTimeout()
      Obtains the client time out.
      Returns:
      Client time out.
    • entityToString

      public static String entityToString(org.apache.http.HttpResponse response) throws IOException
      Obtains the HttpEntity content.
      Parameters:
      response - HttpResponse.
      Returns:
      Content of HttpEntity.
      Throws:
      IOException - If fails to obtain content.
    • entityToString

      public static String entityToString(org.apache.http.HttpResponse response, Charset charset) throws IOException
      Obtains the HttpEntity content.
      Parameters:
      response - HttpResponse.
      charset - Charset.
      Returns:
      Content of HttpEntity.
      Throws:
      IOException - If fails to obtain content.
    • createHttpClientBuilder

      public static org.apache.http.impl.client.HttpClientBuilder createHttpClientBuilder()
      Create the HttpClientBuilder.
      Returns:
      HttpClientBuilder.
    • createHttpClientBuilder

      public static org.apache.http.impl.client.HttpClientBuilder createHttpClientBuilder(int timeout)
      Create the HttpClientBuilder.
      Parameters:
      timeout - Timeout in milliseconds.
      Returns:
      HttpClientBuilder.
    • createHttpClient

      public static org.apache.http.impl.client.CloseableHttpClient createHttpClient()
      Creates a CloseableHttpClient ready for use with default values.
      Returns:
      CloseableHttpClient.
    • createHttpClient

      public static org.apache.http.impl.client.CloseableHttpClient createHttpClient(boolean isSecure)
      Creates a CloseableHttpClient ready for use.
      Parameters:
      isSecure - Indicate if require secure connection.
      Returns:
      CloseableHttpClient.
    • configureHttps

      public static void configureHttps(org.apache.http.impl.client.HttpClientBuilder builder)
      Configures the HttpClientBuilder for HTTPS.
      Parameters:
      builder - HttpClientBuilder.
    • configureNoRedirects

      public static void configureNoRedirects(org.apache.http.impl.client.HttpClientBuilder builder)
      Configures no redirects for the HttpClientBuilder.
      Parameters:
      builder - HttpClientBuilder.
    • configureCredentials

      public static org.apache.http.client.CredentialsProvider configureCredentials(org.apache.http.impl.client.HttpClientBuilder builder, String realm, String scheme, String username, String password)
      Configures CredentialsProvider for the HttpClientBuilder.
      Parameters:
      builder - HttpClientBuilder.
      realm - Security realm.
      scheme - Security scheme.
      username - User name.
      password - Password.
      Returns:
      CredentialsProvider.