public class RestClientBase extends java.lang.Object implements RestClient
RestClient
.Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
DEFAULT_HOSTANDPORT
Connect to a SMILA on the same host on default port.
|
Constructor and Description |
---|
RestClientBase(ClientConnectionManager connectionManager,
HttpRequestFactory requestFactory,
HttpRequestExecutor requestExecutor,
HttpResultHandler resultHandler)
create instance with the given sub-objects.
|
Modifier and Type | Method and Description |
---|---|
protected AnyMap |
asMap(Any result)
Ensure that the result is returned as a map object.
|
protected java.lang.String |
buildPathAndQuery(java.lang.String resource,
AnyMap parameters) |
protected java.lang.String |
createConnectErrorMessage(java.lang.String url,
java.net.ConnectException e)
Create an error message for connection errors including the invoked URL.
|
protected java.lang.String |
createUrl(java.lang.String resource)
Create url with correct slashes.
|
AnyMap |
delete(java.lang.String resource)
Do a DELETE request.
|
AnyMap |
delete(java.lang.String resource,
AnyMap parameters)
Do a DELETE request with parameters.
|
protected Any |
doRequest(HttpMethod method,
java.lang.String resource,
HttpEntity requestEntity,
HttpParams params)
Execute a request, try to parse a JSON result, create appropriate exceptions.
|
protected Any |
doRequestWithHeaderReponse(HttpMethod method,
java.lang.String resource,
HttpEntity requestEntity,
HttpParams params,
AnyMap responseHeaders)
Execute a request, try to parse a JSON result, create appropriate exceptions.
|
AnyMap |
get(java.lang.String resource)
Do a GET request.
|
AnyMap |
get(java.lang.String resource,
AnyMap parameters)
Do a GET request with parameters.
|
BulkResponse |
getBulk(java.lang.String resource,
HttpParams methodParams)
Do a GET request on a resource that can produce a bulk response (i.e., single line JSON objects, separated by
newlines).
|
java.lang.String |
getHostAndPort()
Get the base URL of the SMILA server this clients talks to, for example http://localhost:8080.
|
Any |
invoke(HttpMethod method,
java.lang.String resource,
AnyMap parameters,
Attachments attachments,
HttpParams httpParams)
Generic method to invoke an API resource and set special HttpClient parameters for this call only.
|
Any |
invoke(HttpMethod method,
java.lang.String resource,
AnySeq parameters,
Attachments attachments,
HttpParams httpParams)
Generic method to invoke an API resource and set special HttpClient parameters for this call only.
|
Any |
invoke(HttpMethod method,
java.lang.String resource,
java.io.InputStream inputStream,
HttpParams params)
Invoke an API resource using content from a input stream containing JSON and set special HttpClient parameters for
this call only.
|
Any |
invoke(HttpMethod method,
java.lang.String resource,
java.io.InputStream inputStream,
java.lang.String contentType,
HttpParams params)
Invoke an API resource using content from a input stream containing the specified content type and set special
HttpClient parameters for this call only.
|
protected AnyMap |
invokeAsMap(HttpMethod method,
java.lang.String resource,
AnyMap parameters,
Attachments attachments,
HttpParams httpParams)
Invoke the named resource and ensure that the result is returned as a map object.
|
AnyMap |
post(java.lang.String resource)
Do a POST request without parameters.
|
AnyMap |
post(java.lang.String resource,
AnyMap parameters)
Do a POST request with parameters.
|
AnyMap |
post(java.lang.String resource,
AnyMap parameters,
Attachments attachments)
Do a POST request with parameters and attachments.
|
AnyMap |
post(java.lang.String resource,
Record record)
Do a POST request with a record (may contain attachments) as input.
|
AnyMap |
post(java.lang.String resource,
java.lang.String parameters,
java.lang.String encoding,
java.lang.String contentType)
Do a POST request with parameters.
|
AnyMap |
postWithResponseHeader(java.lang.String resource,
Record record,
AnyMap responseHeaderFields)
Do a POST request with a record as input.
|
AnyMap |
put(java.lang.String resource,
AnyMap parameters)
Do a PUT request with parameters.
|
AnyMap |
put(java.lang.String resource,
Record record)
Do a PUT request with a record as input, however, only the record metadata is used in the request, as PUT requests
cannot contain attachments.
|
void |
setAuthParameters(java.lang.String user,
java.lang.String password)
Sets authentication parameters at the underlying Apache HttpClient client object.
|
void |
setClientParameter(java.lang.String name,
java.lang.Object value)
Sets a parameter at the underlying Apache HttpClient client object.
|
void |
setRequestExecutor(HttpRequestExecutor requestExecutor)
reset the
HttpRequestExecutor for this client. |
void |
setRequestFactory(HttpRequestFactory requestFactory)
reset the
HttpRequestFactory for this client. |
void |
setResultHandler(HttpResultHandler resultHandler)
reset the
HttpResultHandler for this client. |
void |
shutdown()
shutdown this client.
|
protected static final java.lang.String DEFAULT_HOSTANDPORT
public RestClientBase(ClientConnectionManager connectionManager, HttpRequestFactory requestFactory, HttpRequestExecutor requestExecutor, HttpResultHandler resultHandler)
public void setRequestFactory(HttpRequestFactory requestFactory)
HttpRequestFactory
for this client. Not needed for standard use cases but useful for custom
extensions of the client.public void setRequestExecutor(HttpRequestExecutor requestExecutor)
HttpRequestExecutor
for this client. Not needed for standard use cases but useful for custom
extensions of the client.public void setResultHandler(HttpResultHandler resultHandler)
HttpResultHandler
for this client. Not needed for standard use cases but useful for custom
extensions of the client.public void setClientParameter(java.lang.String name, java.lang.Object value)
RestClient
setClientParameter
in interface RestClient
name
- the HttpClient parameter name.value
- the HttpClient parameter value.public void setAuthParameters(java.lang.String user, java.lang.String password)
RestClient
setAuthParameters
in interface RestClient
user
- the user name used for authentication.password
- the password used for authentication.public void shutdown()
RestClient
shutdown
in interface RestClient
public java.lang.String getHostAndPort()
RestClient
getHostAndPort
in interface RestClient
public AnyMap get(java.lang.String resource) throws RestException, java.io.IOException
RestClient
get
in interface RestClient
resource
- the API resource to call, e.g. /smila. Can contain additional URL parameters, e.g.
...?returnDetails=true.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public AnyMap get(java.lang.String resource, AnyMap parameters) throws RestException, java.io.IOException
RestClient
get
in interface RestClient
resource
- the API resource to call, e.g. /smila.parameters
- query parameters for the rest call.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public BulkResponse getBulk(java.lang.String resource, HttpParams methodParams) throws java.io.IOException, RestException
RestClient
getBulk
in interface RestClient
resource
- the API resource to call, e.g. /smila. Can contain additional URL parameters, e.g.
...?returnDetails=true.BulkResponse
objects that can be used to iterate over the objects contained in the response. If
no result content was returned, an empty iterator will be returned.java.io.IOException
- on all kinds of communication problems or data conversion errors.RestException
- on errors reported by the SMILA server.public AnyMap post(java.lang.String resource) throws RestException, java.io.IOException
RestClient
post
in interface RestClient
resource
- the API resource to call, e.g. /smila/jobmanager/jobs/$name.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public AnyMap post(java.lang.String resource, AnyMap parameters) throws RestException, java.io.IOException
RestClient
post
in interface RestClient
resource
- the API resource to call, e.g. /smila/jobmanager/jobs/$name.parameters
- a parameter object, definition object, or record metadata.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public AnyMap post(java.lang.String resource, AnyMap parameters, Attachments attachments) throws RestException, java.io.IOException
RestClient
post
in interface RestClient
resource
- the API resource to call, e.g. /smila/job/$name/record.parameters
- a parameter object, usually record metadata.attachments
- record attachments.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public AnyMap post(java.lang.String resource, Record record) throws RestException, java.io.IOException
RestClient
post
in interface RestClient
resource
- the API resource to call, e.g. /smila/job/$name/record.record
- record metadata and attachmentsRestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public AnyMap post(java.lang.String resource, java.lang.String parameters, java.lang.String encoding, java.lang.String contentType) throws RestException, java.io.IOException
RestClient
post
in interface RestClient
resource
- the API resource to call, e.g. /smila/jobmanager/jobs/$name.parameters
- a parameter object, definition object, or record metadata as a stringencoding
- the encosing of the parameters stringcontentType
- the contentType of the parametersRestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public AnyMap put(java.lang.String resource, AnyMap parameters) throws RestException, java.io.IOException
RestClient
put
in interface RestClient
resource
- the API resource to call, e.g. /smila/store/$name/$id.parameters
- a parameter object, definition object, or record metadata.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public AnyMap put(java.lang.String resource, Record record) throws RestException, java.io.IOException
RestClient
put
in interface RestClient
resource
- the API resource to call, e.g. /smila/store/$name/$id.record
- record metadata. Attachments are ignored.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public AnyMap delete(java.lang.String resource) throws RestException, java.io.IOException
RestClient
delete
in interface RestClient
resource
- the API resource to call, e.g. /smila/store/$name. Can contain additional URL parameters, e.g.
...?returnDetails=true.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public AnyMap delete(java.lang.String resource, AnyMap parameters) throws RestException, java.io.IOException
RestClient
delete
in interface RestClient
resource
- the API resource to call, e.g. /smila/job/$jobname/record.parameters
- a parameter object or record metadata to be attachedRestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public Any invoke(HttpMethod method, java.lang.String resource, java.io.InputStream inputStream, HttpParams params) throws RestException, java.io.IOException
RestClient
invoke
in interface RestClient
method
- the HTTP method to useresource
- the API resource to call, e.g. /smila/job/$name/record. Can contain URL parameters for GET and
DELETE calls.inputStream
- an input stream with valid JSON data.params
- HttpClient parameters for this call, may be null.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public Any invoke(HttpMethod method, java.lang.String resource, java.io.InputStream inputStream, java.lang.String contentType, HttpParams params) throws RestException, java.io.IOException
RestClient
invoke
in interface RestClient
method
- the HTTP method to useresource
- the API resource to call, e.g. /smila/job/$name/record. Can contain URL parameters for GET and
DELETE calls.inputStream
- an input stream with data of the specified content typecontentType
- content type of data.params
- HttpClient parameters for this call, may be null.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public Any invoke(HttpMethod method, java.lang.String resource, AnyMap parameters, Attachments attachments, HttpParams httpParams) throws RestException, java.io.IOException
RestClient
invoke
in interface RestClient
method
- the HTTP method to useresource
- the API resource to call, e.g. /smila/job/$name/record. Can contain URL parameters for GET and
DELETE calls.parameters
- a parameter object, usually record metadata, may be null.attachments
- record attachments, may be null.httpParams
- HttpClient parameters for this call, may be null.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.public Any invoke(HttpMethod method, java.lang.String resource, AnySeq parameters, Attachments attachments, HttpParams httpParams) throws RestException, java.io.IOException
RestClient
invoke
in interface RestClient
method
- the HTTP method to useresource
- the API resource to call, e.g. /smila/job/$name/record. Can contain URL parameters for GET and
DELETE calls.parameters
- a parameter object, usually record metadata, may be null.attachments
- record attachments, may be null.httpParams
- HttpClient parameters for this call, may be null.RestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.protected AnyMap invokeAsMap(HttpMethod method, java.lang.String resource, AnyMap parameters, Attachments attachments, HttpParams httpParams) throws RestException, java.io.IOException
RestException
java.io.IOException
protected AnyMap asMap(Any result) throws RestException, java.io.IOException
RestException
java.io.IOException
protected Any doRequest(HttpMethod method, java.lang.String resource, HttpEntity requestEntity, HttpParams params) throws RestException, java.io.IOException
RestException
java.io.IOException
protected java.lang.String createUrl(java.lang.String resource)
protected java.lang.String createConnectErrorMessage(java.lang.String url, java.net.ConnectException e)
protected java.lang.String buildPathAndQuery(java.lang.String resource, AnyMap parameters)
public AnyMap postWithResponseHeader(java.lang.String resource, Record record, AnyMap responseHeaderFields) throws RestException, java.io.IOException
RestClient
postWithResponseHeader
in interface RestClient
resource
- the API resource to call, e.g. /smila/job/$name/record.record
- record metadataresponseHeaderFields
- AnyMap which will be populated with the response header fieldsRestException
- on errors reported by the SMILA server.java.io.IOException
- on all kinds of communication problems or data conversion errors.protected Any doRequestWithHeaderReponse(HttpMethod method, java.lang.String resource, HttpEntity requestEntity, HttpParams params, AnyMap responseHeaders) throws RestException, java.io.IOException
RestException
java.io.IOException