SMILA 1.0 API documentation

org.eclipse.smila.http.client.impl.base
Class RestClientBase

java.lang.Object
  extended by org.eclipse.smila.http.client.impl.base.RestClientBase
All Implemented Interfaces:
RestClient
Direct Known Subclasses:
DefaultRestClient, FailoverRestClient

public class RestClientBase
extends java.lang.Object
implements RestClient

Default implementation of RestClient.


Field Summary
protected static java.lang.String DEFAULT_HOSTANDPORT
          Connect to a SMILA on the same host on default port.
 
Constructor Summary
RestClientBase(ClientConnectionManager connectionManager, HttpRequestFactory requestFactory, HttpRequestExecutor requestExecutor, HttpResultHandler resultHandler)
          create instance with the given sub-objects.
 
Method Summary
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)
           
 AnyMap delete(java.lang.String resource)
          Do a DELETE request.
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.
 AnyMap get(java.lang.String resource)
          Do a GET request.
 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 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_HOSTANDPORT

protected static final java.lang.String DEFAULT_HOSTANDPORT
Connect to a SMILA on the same host on default port.

See Also:
Constant Field Values
Constructor Detail

RestClientBase

public RestClientBase(ClientConnectionManager connectionManager,
                      HttpRequestFactory requestFactory,
                      HttpRequestExecutor requestExecutor,
                      HttpResultHandler resultHandler)
create instance with the given sub-objects.

Method Detail

setRequestFactory

public void setRequestFactory(HttpRequestFactory requestFactory)
reset the HttpRequestFactory for this client. Not needed for standard use cases but useful for custom extensions of the client.


setRequestExecutor

public void setRequestExecutor(HttpRequestExecutor requestExecutor)
reset the HttpRequestExecutor for this client. Not needed for standard use cases but useful for custom extensions of the client.


setResultHandler

public void setResultHandler(HttpResultHandler resultHandler)
reset the HttpResultHandler for this client. Not needed for standard use cases but useful for custom extensions of the client.


setClientParameter

public void setClientParameter(java.lang.String name,
                               java.lang.Object value)
Description copied from interface: RestClient
Sets a parameter at the underlying Apache HttpClient client object. See org.apache.http.client.params.AllClientPNames for links to names of possible parameters and the expected value types.

Specified by:
setClientParameter in interface RestClient
Parameters:
name - the HttpClient parameter name.
value - the HttpClient parameter value.

shutdown

public void shutdown()
Description copied from interface: RestClient
shutdown this client. Currently running requests may be aborted.

Specified by:
shutdown in interface RestClient

getHostAndPort

public java.lang.String getHostAndPort()
Description copied from interface: RestClient
Get the base URL of the SMILA server this clients talks to, for example http://localhost:8080.

Specified by:
getHostAndPort in interface RestClient
Returns:
the base URL.

get

public AnyMap get(java.lang.String resource)
           throws RestException,
                  java.io.IOException
Description copied from interface: RestClient
Do a GET request. Query parameters can be added to the resource string after a '?' character.

Specified by:
get in interface RestClient
Parameters:
resource - the API resource to call, e.g. /smila. Can contain additional URL parameters, e.g. ...?returnDetails=true.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

getBulk

public BulkResponse getBulk(java.lang.String resource,
                            HttpParams methodParams)
                     throws java.io.IOException,
                            RestException
Description copied from interface: RestClient
Do a GET request on a resource that can produce a bulk response (i.e., single line JSON objects, separated by newlines). Query parameters can be added to the resource string after a '?' character.

Specified by:
getBulk in interface RestClient
Parameters:
resource - the API resource to call, e.g. /smila. Can contain additional URL parameters, e.g. ...?returnDetails=true.
Returns:
a 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.
Throws:
java.io.IOException - on all kinds of communication problems or data conversion errors.
RestException - on errors reported by the SMILA server.

post

public AnyMap post(java.lang.String resource)
            throws RestException,
                   java.io.IOException
Description copied from interface: RestClient
Do a POST request without parameters. To add parameters to POST requests, you should not use URL parameters ("...?parameter=value"), but create a parameter object and use the other methods.

Specified by:
post in interface RestClient
Parameters:
resource - the API resource to call, e.g. /smila/jobmanager/jobs/$name.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

post

public AnyMap post(java.lang.String resource,
                   AnyMap parameters)
            throws RestException,
                   java.io.IOException
Description copied from interface: RestClient
Do a POST request with parameters. The parameters may be definitions to be added to the server (e.g. workflow, job) or record metadata to be submitted to a workflow.

Specified by:
post in interface RestClient
Parameters:
resource - the API resource to call, e.g. /smila/jobmanager/jobs/$name.
parameters - a parameter object, definition object, or record metadata.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

post

public AnyMap post(java.lang.String resource,
                   AnyMap parameters,
                   Attachments attachments)
            throws RestException,
                   java.io.IOException
Description copied from interface: RestClient
Do a POST request with parameters and attachments. Usually, parameters are record metadata and attachments are the original binary documents.

Specified by:
post in interface RestClient
Parameters:
resource - the API resource to call, e.g. /smila/job/$name/record.
parameters - a parameter object, usually record metadata.
attachments - record attachments.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

post

public AnyMap post(java.lang.String resource,
                   Record record)
            throws RestException,
                   java.io.IOException
Description copied from interface: RestClient
Do a POST request with a record (may contain attachments) as input.

Specified by:
post in interface RestClient
Parameters:
resource - the API resource to call, e.g. /smila/job/$name/record.
record - record metadata and attachments
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

put

public AnyMap put(java.lang.String resource,
                  AnyMap parameters)
           throws RestException,
                  java.io.IOException
Description copied from interface: RestClient
Do a PUT request with parameters. For example, the parameters may describe an object to write the ObjectStore.

Specified by:
put in interface RestClient
Parameters:
resource - the API resource to call, e.g. /smila/store/$name/$id.
parameters - a parameter object, definition object, or record metadata.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

put

public AnyMap put(java.lang.String resource,
                  Record record)
           throws RestException,
                  java.io.IOException
Description copied from interface: RestClient
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.

Specified by:
put in interface RestClient
Parameters:
resource - the API resource to call, e.g. /smila/store/$name/$id.
record - record metadata. Attachments are ignored.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

delete

public AnyMap delete(java.lang.String resource)
              throws RestException,
                     java.io.IOException
Description copied from interface: RestClient
Do a DELETE request. Query parameters can be added to the resource string after a '?' character.

Specified by:
delete in interface RestClient
Parameters:
resource - the API resource to call, e.g. /smile/store/$name. Can contain additional URL parameters, e.g. ...?returnDetails=true.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

invoke

public Any invoke(HttpMethod method,
                  java.lang.String resource,
                  java.io.InputStream inputStream,
                  HttpParams params)
           throws RestException,
                  java.io.IOException
Description copied from interface: RestClient
Invoke an API resource using content from a input stream containing JSON and set special HttpClient parameters for this call only. See org.apache.http.client.params.AllClientPNames for links to names of possible parameters and the expected value types.

Specified by:
invoke in interface RestClient
Parameters:
method - the HTTP method to use
resource - 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.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

invoke

public Any invoke(HttpMethod method,
                  java.lang.String resource,
                  java.io.InputStream inputStream,
                  java.lang.String contentType,
                  HttpParams params)
           throws RestException,
                  java.io.IOException
Description copied from interface: RestClient
Invoke an API resource using content from a input stream containing the specified content type and set special HttpClient parameters for this call only. See org.apache.http.client.params.AllClientPNames for links to names of possible parameters and the expected value types.

Specified by:
invoke in interface RestClient
Parameters:
method - the HTTP method to use
resource - 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 type
contentType - content type of data.
params - HttpClient parameters for this call, may be null.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

invoke

public Any invoke(HttpMethod method,
                  java.lang.String resource,
                  AnyMap parameters,
                  Attachments attachments,
                  HttpParams httpParams)
           throws RestException,
                  java.io.IOException
Description copied from interface: RestClient
Generic method to invoke an API resource and set special HttpClient parameters for this call only. See org.apache.http.client.params.AllClientPNames for links to names of possible parameters and the expected value types.

Specified by:
invoke in interface RestClient
Parameters:
method - the HTTP method to use
resource - 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.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

invoke

public Any invoke(HttpMethod method,
                  java.lang.String resource,
                  AnySeq parameters,
                  Attachments attachments,
                  HttpParams httpParams)
           throws RestException,
                  java.io.IOException
Description copied from interface: RestClient
Generic method to invoke an API resource and set special HttpClient parameters for this call only. See org.apache.http.client.params.AllClientPNames for links to names of possible parameters and the expected value types.

Specified by:
invoke in interface RestClient
Parameters:
method - the HTTP method to use
resource - 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.
Returns:
the result object, if a JSON result was returned, else null.
Throws:
RestException - on errors reported by the SMILA server.
java.io.IOException - on all kinds of communication problems or data conversion errors.

invokeAsMap

protected AnyMap invokeAsMap(HttpMethod method,
                             java.lang.String resource,
                             AnyMap parameters,
                             Attachments attachments,
                             HttpParams httpParams)
                      throws RestException,
                             java.io.IOException
Invoke the named resource and ensure that the result is returned as a map object. If the original was not a map, wrap it in a new map under key "result".

Throws:
RestException
java.io.IOException

doRequest

protected Any doRequest(HttpMethod method,
                        java.lang.String resource,
                        HttpEntity requestEntity,
                        HttpParams params)
                 throws RestException,
                        java.io.IOException
Execute a request, try to parse a JSON result, create appropriate exceptions.

Throws:
RestException
java.io.IOException

createUrl

protected java.lang.String createUrl(java.lang.String resource)

createConnectErrorMessage

protected java.lang.String createConnectErrorMessage(java.lang.String url,
                                                     java.net.ConnectException e)
Create an error message for connection errors including the invoked URL.


SMILA 1.0 API documentation