Class AbstractHttpClientJUnit<T>

java.lang.Object
net.officefloor.server.http.AbstractHttpClientJUnit<T>
Direct Known Subclasses:
HttpClientExtension, HttpClientRule

public abstract class AbstractHttpClientJUnit<T> extends Object
Abstract HttpClient to HttpServer.
Author:
Daniel Sagenschneider
  • Constructor Details

    • AbstractHttpClientJUnit

      public AbstractHttpClientJUnit()
      Instantiate for non-secure (HTTP) connection to HttpServer.
    • AbstractHttpClientJUnit

      public AbstractHttpClientJUnit(boolean isSecure)
      Instantiate with flagging if secure (HTTPS) connection to HttpServer.
      Parameters:
      isSecure - Indicates if secure (HTTPS).
    • AbstractHttpClientJUnit

      public AbstractHttpClientJUnit(boolean isSecure, int port)
      Instantiate indicating the server port.
      Parameters:
      isSecure - Indicates if secure (HTTPS).
      port - Server port to connect.
  • Method Details

    • followRedirects

      public T followRedirects(boolean isFollowRedirects)
      Flags whether to follow redirects.
      Parameters:
      isFollowRedirects - Indicates if follow redirects.
      Returns:
      this.
    • timeout

      public T timeout(int timeout)
      Specifies the request timeout in milliseconds.
      Parameters:
      timeout - Time out.
      Returns:
      this.
    • getHttpClient

      public org.apache.http.client.HttpClient getHttpClient()
      Obtains the HttpClient.
      Returns:
      HttpClient.
    • url

      public String url(String path)
      Creates URL to the server.
      Parameters:
      path - Path on the server.
      Returns:
      URL to the server.
    • execute

      public org.apache.http.HttpResponse execute(org.apache.http.client.methods.HttpUriRequest request) throws IOException, org.apache.http.client.ClientProtocolException
      Convenience method to execute the HttpUriRequest.
      Parameters:
      request - HttpUriRequest.
      Returns:
      HttpResponse.
      Throws:
      IOException - If failure in communication with server.
      org.apache.http.client.ClientProtocolException - If client protocol issue.
    • openHttpClient

      protected void openHttpClient()
      Opens the CloseableHttpClient.
    • closeHttpClient

      protected void closeHttpClient() throws IOException
      Closes the HttpClient.
      Throws:
      IOException - If fails to close the HttpClient.