public class ApiCommand<T> extends Object
| Constructor and Description |
|---|
ApiCommand(HttpMethodBuilder.MethodBuilder<?> methodBuilder,
URI uri,
Status responseStatus,
com.fasterxml.jackson.core.type.TypeReference<T> responseType)
Creates a new instance of
ApiCommand. |
| Modifier and Type | Method and Description |
|---|---|
TypedResponseWithEntity<T> |
bundle()
Execute the current command and returns both
HttpResponse and
the entity typed. |
String |
content()
Executes the current command and returns the
HttpResponse entity
content as String. |
T |
execute()
|
T |
execute(boolean retryOnConnectTimeout)
|
Status |
getExpectedResponseStatus()
Gets the expected response status.
|
HttpMethodBuilder.Method |
getMethod()
Gets the HTTP method.
|
com.fasterxml.jackson.core.type.TypeReference<T> |
getResponseType()
Gets the response type.
|
org.apache.http.Header |
head(String headerName)
Executes the current command using the HTTP
HEAD method and
returns the value of the first HttpResponse Header
specified by headerName. |
void |
removeHeader(String name)
Removes the specified request header.
|
void |
removeQueryParam(String name)
Removes the specified query parameter.
|
org.apache.http.HttpResponse |
request()
Executes the current command and returns the native
HttpResponse. |
void |
setHeader(String name,
String value)
Sets (adds or overwrittes) the specified request header.
|
void |
setHttpParams(org.apache.http.params.HttpParams params)
Sets HTTP-specific params, {
|
void |
setQueryParam(QueryParamValue queryParam) |
void |
setQueryParam(String name,
List<String> value)
Sets (adds or overwrittes) the multi-value of specified query parameter.
|
void |
setQueryParam(String name,
String value)
Sets (adds or overwrittes) the specified query parameter.
|
protected void |
shutdown(org.apache.http.client.HttpClient client)
Shuts down the connection manager to ensure immediate deallocation of all
system resources.
|
InputStream |
stream()
Executes the current command and returns the
HttpResponse entity
body as InputStream. |
URI |
uri()
|
public ApiCommand(HttpMethodBuilder.MethodBuilder<?> methodBuilder, URI uri, Status responseStatus, com.fasterxml.jackson.core.type.TypeReference<T> responseType)
ApiCommand.methodBuilder - the HttpMethodBuilder.MethodBuilder used for creating the
requesturi - the URI holding the absolute URLresponseStatus - the expected HttpResponse statusresponseType - the native type to which the HttpResponse will be
mapped topublic Status getExpectedResponseStatus()
Status instancepublic com.fasterxml.jackson.core.type.TypeReference<T> getResponseType()
TypeReference instancepublic HttpMethodBuilder.Method getMethod()
HttpMethodBuilder.Method typepublic T execute() throws EvrythngException
HttpResponse entity mapped to TEvrythngExceptionpublic T execute(boolean retryOnConnectTimeout) throws EvrythngException
Executes the current command and maps the HttpResponse entity to
T specified by responseType.
If the retryOnConnectTimeout parameter is true the connection will be attempted up to
CONNECTION_RETRY_ATTEMPTS times.
retryOnConnectTimeout - if true the connection will be attempted up to
CONNECTION_RETRY_ATTEMPTS times when a connect timeout is encounteredHttpResponse entity mapped to TEvrythngException - in case an exception is encountered during the requestpublic String content() throws EvrythngException
HttpResponse entity
content as String.HttpResponse entity content as StringEvrythngExceptionpublic org.apache.http.HttpResponse request()
throws EvrythngException
HttpResponse.HttpResponse implied by the requestEvrythngExceptionpublic InputStream stream() throws EvrythngException
HttpResponse entity
body as InputStream.HttpResponse entity as InputStreamEvrythngExceptionpublic TypedResponseWithEntity<T> bundle() throws EvrythngException
HttpResponse and
the entity typed. Bundled in a TypedResponseWithEntity objectHttpResponse bundled with entityEvrythngExceptionpublic org.apache.http.Header head(String headerName) throws EvrythngException
HEAD method and
returns the value of the first HttpResponse Header
specified by headerName. This
method is usefull for obtaining
metainformation about the HttpResponse implied by the request
without transferring the entity-body.
FIXME: HEAD not supported for now, using GET instead
headerName - the HttpResponse header to be retrievedHttpResponse header or
null if no such header could be found.EvrythngExceptionHttpMessage.getFirstHeader(String)public void setHeader(String name, String value)
name - the request header namevalue - the request header valuepublic void removeHeader(String name)
name - the name of the request header to be removedpublic void setQueryParam(String name, String value)
name - the query parameter namevalue - the query parameter valuepublic void setQueryParam(QueryParamValue queryParam)
public void setQueryParam(String name, List<String> value)
name - the query parameter namevalue - the query parameter values listpublic void removeQueryParam(String name)
name - the name of the query parameter to be removedpublic void setHttpParams(org.apache.http.params.HttpParams params)
params - HttpParams instanceHttpClientpublic final URI uri() throws EvrythngClientException
EvrythngClientExceptionprotected void shutdown(org.apache.http.client.HttpClient client)
client - the HttpClient to shut downCopyright © 2016 EVRYTHNG Ltd London / Zurich. All rights reserved.