public interface RestClient
DefaultRestClient for
the standard implementation.
A RestClient always contains an Apache HttpClient to handle the actual HTTP communication. For documentation on classes and interfaces coming directly from these libraries see the following JavaDocs:
Note that all resource strings given to the methods must be correctly URL-encoded. For incorrectly encoded resources
a IllegalArgumentException is thrown.
Currently, all SMILA APIs return a JSON object as their result (if any), i.e. the result string starts with "{" and
ends with "}". Consequently, most RestClient methods return an AnyMap object. If the actual result
is not a JSON object but a JSON array ("[...]") or a simple value, when one of these methods is used, the
result will be wrapped in an AnyMap object with a single key result. The more generic
invoke(...) methods return the original result as is.
Use ResourceHelper to get the correct resource locations. See TaskManagerClientHelper for resources
needed by workers that want to communicate with the TaskManager using the HTTP interface.
See How to
access the REST API with the RestClient for more information.
| Modifier and Type | Method and Description |
|---|---|
AnyMap |
delete(java.lang.String resource)
Do a DELETE request.
|
AnyMap |
delete(java.lang.String resource,
AnyMap parameters)
Do a DELETE request with parameters.
|
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 httpParams)
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 httpParams)
Invoke an API resource using content from a input stream containing the specified content type and set special
HttpClient parameters for this call only.
|
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 |
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 |
setClientParameter(java.lang.String name,
java.lang.Object value)
Sets a parameter at the underlying Apache HttpClient client object.
|
void |
shutdown()
shutdown this client.
|
java.lang.String getHostAndPort()
void setClientParameter(java.lang.String name,
java.lang.Object value)
name - the HttpClient parameter name.value - the HttpClient parameter value.void shutdown()
AnyMap get(java.lang.String resource) throws RestException, java.io.IOException
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.AnyMap get(java.lang.String resource, AnyMap parameters) throws RestException, java.io.IOException
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.BulkResponse getBulk(java.lang.String resource, HttpParams methodParams) throws java.io.IOException, RestException
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.RestException - on errors reported by the SMILA server.java.io.IOException - on all kinds of communication problems or data conversion errors.AnyMap post(java.lang.String resource) throws RestException, java.io.IOException
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.AnyMap post(java.lang.String resource, AnyMap parameters) throws RestException, java.io.IOException
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.AnyMap post(java.lang.String resource, java.lang.String parameters, java.lang.String encoding, java.lang.String contentType) throws RestException, java.io.IOException
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.AnyMap post(java.lang.String resource, AnyMap parameters, Attachments attachments) throws RestException, java.io.IOException
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.AnyMap post(java.lang.String resource, Record record) throws RestException, java.io.IOException
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.AnyMap put(java.lang.String resource, AnyMap parameters) throws RestException, java.io.IOException
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.AnyMap put(java.lang.String resource, Record record) throws RestException, java.io.IOException
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.AnyMap delete(java.lang.String resource) throws RestException, java.io.IOException
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.AnyMap delete(java.lang.String resource, AnyMap parameters) throws RestException, java.io.IOException
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.Any invoke(HttpMethod method, java.lang.String resource, AnyMap parameters, Attachments attachments, HttpParams httpParams) throws RestException, java.io.IOException
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.Any invoke(HttpMethod method, java.lang.String resource, AnySeq parameters, Attachments attachments, HttpParams httpParams) throws RestException, java.io.IOException
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.Any invoke(HttpMethod method, java.lang.String resource, java.io.InputStream inputStream, HttpParams httpParams) throws RestException, java.io.IOException
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.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.Any invoke(HttpMethod method, java.lang.String resource, java.io.InputStream inputStream, java.lang.String contentType, HttpParams httpParams) throws RestException, java.io.IOException
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.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.