Class HttpAsyncClientImpl

java.lang.Object
com.suse.salt.netapi.client.impl.HttpAsyncClientImpl
All Implemented Interfaces:
AsyncHttpClient

public class HttpAsyncClientImpl extends Object implements AsyncHttpClient
AsyncHttpClient implemented with Apache's HttpAsyncClient.
  • Field Details

    • httpClient

      private final org.apache.http.nio.client.HttpAsyncClient httpClient
      HTTP client instance
  • Constructor Details

    • HttpAsyncClientImpl

      public HttpAsyncClientImpl(org.apache.http.nio.client.HttpAsyncClient httpClientIn)
      Init a connection to a given Salt API endpoint.
      Parameters:
      httpClientIn - the HTTP client
  • Method Details

    • post

      public <T> CompletionStage<T> post(URI uri, Map<String,String> headers, String data, JsonParser<T> parser)
      Send a POST request and parse the result into object of given type.
      Specified by:
      post in interface AsyncHttpClient
      Type Parameters:
      T - return type the response json will be parsed into
      Parameters:
      uri - uri to make the http request to
      headers - headers to pass to the request
      data - the data to send (in JSON format)
      parser - parser to use for the response json
      Returns:
      CompletionStage holding object of the given return type T
    • get

      public <T> CompletionStage<T> get(URI uri, Map<String,String> headers, JsonParser<T> parser)
      Send a GET request and parse the result into object of given type.
      Specified by:
      get in interface AsyncHttpClient
      Type Parameters:
      T - return type the response json will be parsed into
      Parameters:
      uri - uri to make the http request to
      headers - headers to pass to the request
      parser - parser to use for the response json
      Returns:
      CompletionStage holding object of the given return type T
    • request

      private <T> CompletionStage<T> request(URI uri, Map<String,String> headers, String data, JsonParser<T> parser)
      Perform HTTP request and parse the result into a given result type.
      Parameters:
      data - the data to send with the request
      Returns:
      CompletionStage holding object of type T
    • prepareRequest

      private <T> org.apache.http.client.methods.HttpUriRequest prepareRequest(URI uri, Map<String,String> headers, String jsonData)
      Prepares the HTTP request object creating a POST or GET request depending on if data is supplied or not.
      Parameters:
      jsonData - json POST data, will use GET if null
      Returns:
      HttpUriRequest object the prepared request
    • executeRequest

      private <T> CompletionStage<T> executeRequest(org.apache.http.nio.client.HttpAsyncClient httpClient, org.apache.http.client.methods.HttpUriRequest httpRequest, JsonParser<T> parser)
      Executes a prepared HTTP request using the given client.
      Parameters:
      httpClient - the client to use for the request
      httpRequest - the prepared request to perform
      Returns:
      CompletionStage holding object of type T
    • createSaltException

      private SaltException createSaltException(org.apache.http.HttpResponse response)
      Create the appropriate exception for the given HTTP response.
      Parameters:
      response - HTTP response
      Returns:
      SaltException instance