Class HttpAsyncClientImpl
java.lang.Object
com.suse.salt.netapi.client.impl.HttpAsyncClientImpl
- All Implemented Interfaces:
AsyncHttpClient
AsyncHttpClient implemented with Apache's HttpAsyncClient.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.apache.http.nio.client.HttpAsyncClientHTTP client instance -
Constructor Summary
ConstructorsConstructorDescriptionHttpAsyncClientImpl(org.apache.http.nio.client.HttpAsyncClient httpClientIn) Init a connection to a given Salt API endpoint. -
Method Summary
Modifier and TypeMethodDescriptionprivate SaltExceptioncreateSaltException(org.apache.http.HttpResponse response) Create the appropriate exception for the given HTTP response.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.<T> CompletionStage<T> Send a GET request and parse the result into object of given type.<T> CompletionStage<T> Send a POST request and parse the result into object of given type.private <T> org.apache.http.client.methods.HttpUriRequestPrepares the HTTP request object creating a POST or GET request depending on if data is supplied or not.private <T> CompletionStage<T> Perform HTTP request and parse the result into a given result type.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AsyncHttpClient
get, post
-
Field Details
-
httpClient
private final org.apache.http.nio.client.HttpAsyncClient httpClientHTTP 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:
postin interfaceAsyncHttpClient- Type Parameters:
T- return type the response json will be parsed into- Parameters:
uri- uri to make the http request toheaders- headers to pass to the requestdata- 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
Send a GET request and parse the result into object of given type.- Specified by:
getin interfaceAsyncHttpClient- Type Parameters:
T- return type the response json will be parsed into- Parameters:
uri- uri to make the http request toheaders- headers to pass to the requestparser- 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 requesthttpRequest- the prepared request to perform- Returns:
- CompletionStage holding object of type T
-
createSaltException
Create the appropriate exception for the given HTTP response.- Parameters:
response- HTTP response- Returns:
SaltExceptioninstance
-