public abstract class ResourceClient extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
LOGIN_TOKEN
Header field used to carry the authentication token.
|
| Constructor and Description |
|---|
ResourceClient() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
annotate(org.apache.http.client.methods.HttpRequestBase request,
LoginContext login)
Annotate the given request with the token of the supplied login
context.
|
protected org.apache.http.client.HttpClient |
client() |
ResponseData |
delete(LoginContext login,
URI uri)
Issues a delete request against the specified URI.
|
ResponseData |
delete(LoginContext login,
URI uri,
byte[] request)
Issues a delete request against the specified URI.
|
ResponseData |
get(LoginContext login,
URI uri)
Issues a get request against the specified URI.
|
InputStream |
getInputStream(LoginContext login,
URI uri,
String mediaType)
Issues a get request against the specified URI.
|
ResponseData |
post(LoginContext login,
URI uri)
Issues a post request against the specified URI
|
ResponseData |
post(LoginContext login,
URI uri,
byte[] request)
Issues a post request against the specified URI.
|
ResponseData |
post(LoginContext login,
URI uri,
org.apache.http.Header[] headers,
byte[] request)
Issues a post request against the specified URI.
|
ResponseData |
post(LoginContext login,
URI uri,
org.apache.http.Header[] headers,
InputStream request)
Issues a post request against the specified URI, with the expectation
that the response will not contain data.
|
ResponseData |
put(LoginContext login,
URI uri)
Issues a put request against the specified URI, with the expectation
that the response will not contain data
|
ResponseData |
put(LoginContext login,
URI uri,
byte[] request)
Issues a put request against the specified URI.
|
ResponseData |
put(LoginContext login,
URI uri,
org.apache.http.Header[] headers,
byte[] request)
Issues a put request against the specified URI.
|
protected byte[] |
request(WebUtils.Tag request)
Converts the specified tag to byte array in UTF-8.
|
protected com.fasterxml.jackson.databind.JsonNode |
response(com.fasterxml.jackson.databind.ObjectMapper mapper,
byte[] response,
String dataLabel)
Read and parse the specified JSON response.
|
protected org.apache.commons.configuration.XMLConfiguration |
response(String root,
byte[] response)
Get the XML configuration created from the specified request data and
rooted at the specified element.
|
protected URI |
uri(IpAddress address,
int port,
String path)
Creates a URI for accessing the specified resource path at the given
address and port.
|
protected URI |
uri(IpAddress address,
int port,
String path,
boolean isSSL,
QueryParameter... parameters)
Creates a URI for accessing the specified resource path at the given
address and port.
|
protected String |
webContext(String path)
Create a full web path.
|
public static final String LOGIN_TOKEN
protected String webContext(String path)
path - relative pathprotected URI uri(IpAddress address, int port, String path)
address - server addressport - server portpath - resource pathIllegalArgumentException - if address or path have invalid formatprotected URI uri(IpAddress address, int port, String path, boolean isSSL, QueryParameter... parameters)
address - server addressport - server portpath - resource pathisSSL - SSL enabled or notparameters - query parametersIllegalArgumentException - if address or path have invalid formatprotected byte[] request(WebUtils.Tag request)
request - tag structureRuntimeException - if UTF-8 encoding is not availableprotected org.apache.commons.configuration.XMLConfiguration response(String root, byte[] response)
root - root element nameresponse - XML-encoded request dataRuntimeException - if data could not be extractedprotected com.fasterxml.jackson.databind.JsonNode response(com.fasterxml.jackson.databind.ObjectMapper mapper,
byte[] response,
String dataLabel)
throws IOException
mapper - JSON object mapper to useresponse - response datadataLabel - request data label to be used in a log message, should
a parse or read error occurIOException - if issues arise when reading or parsing the request
dataprotected void annotate(org.apache.http.client.methods.HttpRequestBase request,
LoginContext login)
request - HTTP requestlogin - optional login contextpublic ResponseData get(LoginContext login, URI uri)
login - previously established login contexturi - resource URIRuntimeException - in case of an HTTP protocol error or
connection problemspublic InputStream getInputStream(LoginContext login, URI uri, String mediaType)
login - previously established login contexturi - resource URImediaType - optional expected media type specified in the Accept
headerRuntimeException - in case of an HTTP protocol error or
connection problemspublic ResponseData post(LoginContext login, URI uri, byte[] request)
login - previously established login contexturi - resource URIrequest - byte array of request dataRuntimeException - in case of an HTTP protocol error or
connection problemspublic ResponseData post(LoginContext login, URI uri, org.apache.http.Header[] headers, byte[] request)
login - previously established login contexturi - resource URIheaders - required headersrequest - byte array of request dataRuntimeException - in case of an HTTP protocol error or
connection problemspublic ResponseData post(LoginContext login, URI uri, org.apache.http.Header[] headers, InputStream request)
login - previously established login contexturi - resource URIheaders - required headersrequest - InputStream of request dataRuntimeException - in case of an HTTP protocol error or
connection problemspublic ResponseData post(LoginContext login, URI uri)
login - previously established login contexturi - resource URIRuntimeException - in case of an HTTP protocol error or
connection problemspublic ResponseData put(LoginContext login, URI uri, byte[] request)
login - previously established login contexturi - resource URIrequest - byte array of request dataRuntimeException - in case of an HTTP protocol error or
connection problemspublic ResponseData put(LoginContext login, URI uri, org.apache.http.Header[] headers, byte[] request)
login - previously established login contexturi - resource URIheaders - required headersrequest - byte array of request dataRuntimeException - in case of an HTTP protocol error or
connection problemspublic ResponseData put(LoginContext login, URI uri)
login - previously established login contexturi - resource URIRuntimeException - in case of an HTTP protocol error or
connection problemspublic ResponseData delete(LoginContext login, URI uri)
login - previously established login contexturi - resource URIRuntimeException - in case of an HTTP protocol error or
connection problemspublic ResponseData delete(LoginContext login, URI uri, byte[] request)
login - previously established login contexturi - resource URIrequest - byte array of request dataRuntimeException - in case of an HTTP protocol error or
connection problemsprotected org.apache.http.client.HttpClient client()
Copyright © 2014. All Rights Reserved.