smartrics.rest.client
Class RestClientImpl

java.lang.Object
  extended by smartrics.rest.client.RestClientImpl
All Implemented Interfaces:
RestClient

public class RestClientImpl
extends Object
implements RestClient

A generic REST client based on HttpClient.


Constructor Summary
RestClientImpl(org.apache.commons.httpclient.HttpClient client)
          Constructor allowing the injection of an org.apache.commons.httpclient.HttpClient.
 
Method Summary
protected  void configureHttpMethod(org.apache.commons.httpclient.HttpMethod m, String hostAddr, RestRequest request)
          Configures the instance of HttpMethod with the data in the request and the host address.
protected  org.apache.commons.httpclient.HttpMethod createHttpClientMethod(RestRequest request)
          Utility method that creates an instance of org.apache.commons.httpclient.HttpMethod.
protected  org.apache.commons.httpclient.URI createUri(String uriString, boolean escaped)
           
 RestResponse execute(RestRequest request)
          See RestClient.execute(smartrics.rest.client.RestRequest)
 RestResponse execute(String hostAddr, RestRequest request)
          See RestClient.execute(java.lang.String, smartrics.rest.client.RestRequest)
 String getBaseUrl()
          See RestClient.getBaseUrl()
 org.apache.commons.httpclient.HttpClient getClient()
          Returns the Http client instance used by this implementation.
 String getContentType(RestRequest request)
           
protected  String getMethodClassnameFromMethodName(String mName)
          factory method that maps a string with a HTTP method name to an implementation class in Apache HttpClient.
 void setBaseUrl(String bUrl)
          See RestClient.setBaseUrl(java.lang.String)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RestClientImpl

public RestClientImpl(org.apache.commons.httpclient.HttpClient client)
Constructor allowing the injection of an org.apache.commons.httpclient.HttpClient.

Parameters:
client - the client See HttpClient
Method Detail

setBaseUrl

public void setBaseUrl(String bUrl)
See RestClient.setBaseUrl(java.lang.String)

Specified by:
setBaseUrl in interface RestClient
Parameters:
bUrl - a string with the base Url. See RestClient.execute(RestRequest)

getBaseUrl

public String getBaseUrl()
See RestClient.getBaseUrl()

Specified by:
getBaseUrl in interface RestClient
Returns:
the base Url See RestClient.setBaseUrl(String)

getClient

public org.apache.commons.httpclient.HttpClient getClient()
Returns the Http client instance used by this implementation.

Returns:
the instance of HttpClient See HttpClient See RestClientImpl(HttpClient)

execute

public RestResponse execute(RestRequest request)
See RestClient.execute(smartrics.rest.client.RestRequest)

Specified by:
execute in interface RestClient
Parameters:
request - the request to be executed
Returns:
the response of the rest request

execute

public RestResponse execute(String hostAddr,
                            RestRequest request)
See RestClient.execute(java.lang.String, smartrics.rest.client.RestRequest)

Specified by:
execute in interface RestClient
Parameters:
hostAddr - the base Url
request - the request to be executed
Returns:
the response of the rest request. See RestClient.setBaseUrl(java.lang.String)

configureHttpMethod

protected void configureHttpMethod(org.apache.commons.httpclient.HttpMethod m,
                                   String hostAddr,
                                   RestRequest request)
Configures the instance of HttpMethod with the data in the request and the host address.

Parameters:
m - the method class to configure
hostAddr - the host address
request - the rest request

getContentType

public String getContentType(RestRequest request)

createUri

protected org.apache.commons.httpclient.URI createUri(String uriString,
                                                      boolean escaped)
                                               throws org.apache.commons.httpclient.URIException
Throws:
org.apache.commons.httpclient.URIException

getMethodClassnameFromMethodName

protected String getMethodClassnameFromMethodName(String mName)
factory method that maps a string with a HTTP method name to an implementation class in Apache HttpClient. Currently the name is mapped to org.apache.commons.httpclient.methods.%sMethod where %s is the parameter mName.

Parameters:
mName - the method name
Returns:
the method class

createHttpClientMethod

protected org.apache.commons.httpclient.HttpMethod createHttpClientMethod(RestRequest request)
Utility method that creates an instance of org.apache.commons.httpclient.HttpMethod.

Parameters:
request - the rest request
Returns:
the instance of org.apache.commons.httpclient.HttpMethod matching the method in RestRequest.


Copyright © 2012 smartrics. All Rights Reserved.