org.eclipse.ecf.remoteservice.rest.client
Class RestClientService

java.lang.Object
  extended by org.eclipse.ecf.remoteservice.AbstractRemoteService
      extended by org.eclipse.ecf.remoteservice.client.AbstractClientService
          extended by org.eclipse.ecf.remoteservice.rest.client.RestClientService
All Implemented Interfaces:
java.lang.reflect.InvocationHandler, IRemoteService

public class RestClientService
extends AbstractClientService

This class represents a REST service from the client side of view. So a RESTful web service can be accessed via the methods provided by this class. Mostly the methods are inherited from IRemoteService.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.ecf.remoteservice.client.AbstractClientService
AbstractClientService.AsyncResult
 
Nested classes/interfaces inherited from class org.eclipse.ecf.remoteservice.AbstractRemoteService
AbstractRemoteService.AsyncArgs
 
Field Summary
protected static java.lang.String DEFAULT_HTTP_CONTENT_CHARSET
           
protected static int DEFAULT_RESPONSE_BUFFER_SIZE
           
protected  org.apache.commons.httpclient.HttpClient httpClient
           
protected  int responseBufferSize
           
 
Fields inherited from class org.eclipse.ecf.remoteservice.client.AbstractClientService
container, registration
 
Fields inherited from class org.eclipse.ecf.remoteservice.AbstractRemoteService
EMPTY_ARGS
 
Constructor Summary
RestClientService(RestClientContainer container, RemoteServiceClientRegistration registration)
           
 
Method Summary
protected  void addRequestHeaders(org.apache.commons.httpclient.HttpMethod httpMethod, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.commons.httpclient.HttpMethod createAndPrepareHttpMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  java.lang.String getResponseAsString(byte[] bytes, java.lang.String responseCharSet)
           
protected  java.lang.String getResponseAsString(org.apache.commons.httpclient.HttpMethod httpMethod)
           
protected  void handleException(java.lang.String message, java.lang.Throwable e, int responseCode)
           
protected  void handleException(java.lang.String message, java.lang.Throwable e, int responseCode, java.lang.String responseBody)
           
protected  java.lang.Object invokeRemoteCall(IRemoteCall call, IRemoteCallable callable)
          Calls the Rest service with given URL of IRestCall.
protected  void logException(java.lang.String string, java.lang.Throwable e)
           
protected  void logWarning(java.lang.String string, java.lang.Throwable e)
           
protected  org.apache.commons.httpclient.HttpMethod prepareDeleteMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.commons.httpclient.HttpMethod prepareGetMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.commons.httpclient.HttpMethod preparePostMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.commons.httpclient.HttpMethod preparePutMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  boolean retrieveErrorResponseBody(int responseCode)
           
protected  void setupAuthenticaton(org.apache.commons.httpclient.HttpClient httpClient, org.apache.commons.httpclient.HttpMethod method)
           
protected  void setupTimeouts(org.apache.commons.httpclient.HttpClient httpClient, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.commons.httpclient.NameValuePair[] toNameValuePairs(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
 
Methods inherited from class org.eclipse.ecf.remoteservice.client.AbstractClientService
callAsync, callAsync, callAsync, callAsync, callSync, fireAsync, getCallMethodNameForProxyInvoke, getCallParametersForProxyInvoke, getClientContainer, getInterfaceClassNames, getNextRequestID, getRegistration, getRemoteServiceID, getRemoteServiceReference, handleInvokeException, invokeSync, prepareEndpointAddress, prepareParameters, processResponse
 
Methods inherited from class org.eclipse.ecf.remoteservice.AbstractRemoteService
addRemoteServiceProxyToProxy, convertInterfaceNameToAsyncInterfaceName, createProxy, createProxy, findAsyncRemoteServiceProxyClass, findAsyncRemoteServiceProxyClass, getAsyncArgs, getAsyncInvokeMethodName, getCallTimeoutForProxyInvoke, getDefaultTimeout, getProxy, getProxy, getRemoteService, invoke, invokeAsync, invokeObject, loadInterfaceClass, loadInterfaceClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RESPONSE_BUFFER_SIZE

protected static final int DEFAULT_RESPONSE_BUFFER_SIZE
See Also:
Constant Field Values

DEFAULT_HTTP_CONTENT_CHARSET

protected static final java.lang.String DEFAULT_HTTP_CONTENT_CHARSET
See Also:
Constant Field Values

httpClient

protected org.apache.commons.httpclient.HttpClient httpClient

responseBufferSize

protected int responseBufferSize
Constructor Detail

RestClientService

public RestClientService(RestClientContainer container,
                         RemoteServiceClientRegistration registration)
Method Detail

invokeRemoteCall

protected java.lang.Object invokeRemoteCall(IRemoteCall call,
                                            IRemoteCallable callable)
                                     throws ECFException
Calls the Rest service with given URL of IRestCall. The returned value is the response body as an InputStream.

Specified by:
invokeRemoteCall in class AbstractClientService
Parameters:
call - The remote call to make. Must not be null.
callable - The callable with default parameters to use to make the call.
Returns:
The InputStream of the response body or null if an error occurs.
Throws:
ECFException - thrown if the call fails.

retrieveErrorResponseBody

protected boolean retrieveErrorResponseBody(int responseCode)

getResponseAsString

protected java.lang.String getResponseAsString(org.apache.commons.httpclient.HttpMethod httpMethod)
                                        throws java.io.IOException
Throws:
java.io.IOException

getResponseAsString

protected java.lang.String getResponseAsString(byte[] bytes,
                                               java.lang.String responseCharSet)

handleException

protected void handleException(java.lang.String message,
                               java.lang.Throwable e,
                               int responseCode,
                               java.lang.String responseBody)
                        throws RestException
Throws:
RestException

handleException

protected void handleException(java.lang.String message,
                               java.lang.Throwable e,
                               int responseCode)
                        throws RestException
Throws:
RestException

setupTimeouts

protected void setupTimeouts(org.apache.commons.httpclient.HttpClient httpClient,
                             IRemoteCall call,
                             IRemoteCallable callable)

addRequestHeaders

protected void addRequestHeaders(org.apache.commons.httpclient.HttpMethod httpMethod,
                                 IRemoteCall call,
                                 IRemoteCallable callable)

createAndPrepareHttpMethod

protected org.apache.commons.httpclient.HttpMethod createAndPrepareHttpMethod(java.lang.String uri,
                                                                              IRemoteCall call,
                                                                              IRemoteCallable callable)
                                                                       throws RestException
Throws:
RestException

prepareDeleteMethod

protected org.apache.commons.httpclient.HttpMethod prepareDeleteMethod(java.lang.String uri,
                                                                       IRemoteCall call,
                                                                       IRemoteCallable callable)
                                                                throws RestException
Throws:
RestException

preparePutMethod

protected org.apache.commons.httpclient.HttpMethod preparePutMethod(java.lang.String uri,
                                                                    IRemoteCall call,
                                                                    IRemoteCallable callable)
                                                             throws java.io.NotSerializableException
Throws:
java.io.NotSerializableException

preparePostMethod

protected org.apache.commons.httpclient.HttpMethod preparePostMethod(java.lang.String uri,
                                                                     IRemoteCall call,
                                                                     IRemoteCallable callable)
                                                              throws java.io.NotSerializableException
Throws:
ECFException
java.io.NotSerializableException

prepareGetMethod

protected org.apache.commons.httpclient.HttpMethod prepareGetMethod(java.lang.String uri,
                                                                    IRemoteCall call,
                                                                    IRemoteCallable callable)
                                                             throws java.io.NotSerializableException
Throws:
ECFException
java.io.NotSerializableException

toNameValuePairs

protected org.apache.commons.httpclient.NameValuePair[] toNameValuePairs(java.lang.String uri,
                                                                         IRemoteCall call,
                                                                         IRemoteCallable callable)
                                                                  throws java.io.NotSerializableException
Throws:
java.io.NotSerializableException

setupAuthenticaton

protected void setupAuthenticaton(org.apache.commons.httpclient.HttpClient httpClient,
                                  org.apache.commons.httpclient.HttpMethod method)

logException

protected void logException(java.lang.String string,
                            java.lang.Throwable e)

logWarning

protected void logWarning(java.lang.String string,
                          java.lang.Throwable e)
Overrides:
logWarning in class AbstractRemoteService