public class HttpAsyncClientImpl extends java.lang.Object implements AsyncHttpClient
Modifier and Type | Field and Description |
---|---|
private org.apache.http.nio.client.HttpAsyncClient |
httpClient
HTTP client instance
|
Constructor and Description |
---|
HttpAsyncClientImpl(org.apache.http.nio.client.HttpAsyncClient httpClientIn)
Init a connection to a given Salt API endpoint.
|
Modifier and Type | Method and Description |
---|---|
private SaltException |
createSaltException(int statusCode)
Create the appropriate exception for the given HTTP status code.
|
private <T> java.util.concurrent.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> java.util.concurrent.CompletionStage<T> |
get(java.net.URI uri,
java.util.Map<java.lang.String,java.lang.String> headers,
JsonParser<T> parser)
Send a GET request and parse the result into object of given type.
|
<T> java.util.concurrent.CompletionStage<T> |
post(java.net.URI uri,
java.util.Map<java.lang.String,java.lang.String> headers,
java.lang.String data,
JsonParser<T> parser)
Send a POST request and parse the result into object of given type.
|
private <T> org.apache.http.client.methods.HttpUriRequest |
prepareRequest(java.net.URI uri,
java.util.Map<java.lang.String,java.lang.String> headers,
java.lang.String jsonData)
Prepares the HTTP request object creating a POST or GET request depending on if data
is supplied or not.
|
private <T> java.util.concurrent.CompletionStage<T> |
request(java.net.URI uri,
java.util.Map<java.lang.String,java.lang.String> headers,
java.lang.String data,
JsonParser<T> parser)
Perform HTTP request and parse the result into a given result type.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
get, post
private final org.apache.http.nio.client.HttpAsyncClient httpClient
public HttpAsyncClientImpl(org.apache.http.nio.client.HttpAsyncClient httpClientIn)
httpClientIn
- the HTTP clientpublic <T> java.util.concurrent.CompletionStage<T> post(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.String data, JsonParser<T> parser)
post
in interface AsyncHttpClient
T
- return type the response json will be parsed intouri
- 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 jsonpublic <T> java.util.concurrent.CompletionStage<T> get(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, JsonParser<T> parser)
get
in interface AsyncHttpClient
T
- return type the response json will be parsed intouri
- uri to make the http request toheaders
- headers to pass to the requestparser
- parser to use for the response jsonprivate <T> java.util.concurrent.CompletionStage<T> request(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.String data, JsonParser<T> parser)
data
- the data to send with the requestprivate <T> org.apache.http.client.methods.HttpUriRequest prepareRequest(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.String jsonData)
jsonData
- json POST data, will use GET if nullprivate <T> java.util.concurrent.CompletionStage<T> executeRequest(org.apache.http.nio.client.HttpAsyncClient httpClient, org.apache.http.client.methods.HttpUriRequest httpRequest, JsonParser<T> parser)
httpClient
- the client to use for the requesthttpRequest
- the prepared request to performprivate SaltException createSaltException(int statusCode)
statusCode
- HTTP status codeSaltException
instance