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, AbstractRemoteService.ProxyClassLoader
 
Field Summary
protected static java.lang.String DEFAULT_HTTP_CONTENT_CHARSET
           
protected static int DEFAULT_RESPONSE_BUFFER_SIZE
           
protected  org.apache.http.client.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.http.message.AbstractHttpMessage httpMethod, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.http.client.methods.HttpRequestBase createAndPrepareHttpMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  byte[] getResponseAsBytes(org.apache.http.HttpResponse response)
           
protected  org.apache.http.client.entity.UrlEncodedFormEntity getUrlEncodedFormEntity(java.util.List list, AbstractEntityRequestType postRequestType)
           
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, byte[] 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.http.client.methods.HttpRequestBase prepareDeleteMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.http.client.methods.HttpRequestBase prepareGetMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.http.client.methods.HttpRequestBase preparePostMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.http.client.methods.HttpRequestBase preparePutMethod(java.lang.String uri, IRemoteCall call, IRemoteCallable callable)
           
protected  boolean retrieveErrorResponseBody(org.apache.http.HttpResponse response)
           
protected  void setupAuthenticaton(org.apache.http.client.HttpClient httpClient, org.apache.http.client.methods.HttpRequestBase method)
           
protected  void setupTimeouts(org.apache.http.client.HttpClient httpClient, IRemoteCall call, IRemoteCallable callable)
           
protected  org.apache.http.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, getRemoteServiceProxyCreator, 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.http.client.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(org.apache.http.HttpResponse response)

getResponseAsBytes

protected byte[] getResponseAsBytes(org.apache.http.HttpResponse response)
                             throws java.io.IOException
Throws:
java.io.IOException

handleException

protected void handleException(java.lang.String message,
                               java.lang.Throwable e,
                               int responseCode,
                               byte[] 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.http.client.HttpClient httpClient,
                             IRemoteCall call,
                             IRemoteCallable callable)

addRequestHeaders

protected void addRequestHeaders(org.apache.http.message.AbstractHttpMessage httpMethod,
                                 IRemoteCall call,
                                 IRemoteCallable callable)

createAndPrepareHttpMethod

protected org.apache.http.client.methods.HttpRequestBase createAndPrepareHttpMethod(java.lang.String uri,
                                                                                    IRemoteCall call,
                                                                                    IRemoteCallable callable)
                                                                             throws RestException
Throws:
RestException

prepareDeleteMethod

protected org.apache.http.client.methods.HttpRequestBase prepareDeleteMethod(java.lang.String uri,
                                                                             IRemoteCall call,
                                                                             IRemoteCallable callable)
                                                                      throws RestException
Throws:
RestException

preparePutMethod

protected org.apache.http.client.methods.HttpRequestBase preparePutMethod(java.lang.String uri,
                                                                          IRemoteCall call,
                                                                          IRemoteCallable callable)
                                                                   throws java.io.NotSerializableException,
                                                                          java.io.UnsupportedEncodingException
Throws:
java.io.NotSerializableException
java.io.UnsupportedEncodingException

preparePostMethod

protected org.apache.http.client.methods.HttpRequestBase preparePostMethod(java.lang.String uri,
                                                                           IRemoteCall call,
                                                                           IRemoteCallable callable)
                                                                    throws java.io.NotSerializableException,
                                                                           java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException
ECFException
java.io.NotSerializableException

prepareGetMethod

protected org.apache.http.client.methods.HttpRequestBase prepareGetMethod(java.lang.String uri,
                                                                          IRemoteCall call,
                                                                          IRemoteCallable callable)
Throws:
ECFException

getUrlEncodedFormEntity

protected org.apache.http.client.entity.UrlEncodedFormEntity getUrlEncodedFormEntity(java.util.List list,
                                                                                     AbstractEntityRequestType postRequestType)
                                                                              throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

toNameValuePairs

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

setupAuthenticaton

protected void setupAuthenticaton(org.apache.http.client.HttpClient httpClient,
                                  org.apache.http.client.methods.HttpRequestBase 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