public abstract class

AbstractServiceClient

extends Object
java.lang.Object
   ↳ org.mule.LiquidPlanner.client.services.impl.AbstractServiceClient
Known Direct Subclasses

Class Overview

Base class for all the service client in this project. The class handles: base URL creation, creation of the Jersey client, set up of basic authentication headers, read of files from input streams, string serialization of the responses

Summary

Constants
String DEFAULT_BASE_URL
Fields
private String baseUrl
protected Gson mapper
protected String password
protected String user
Public Constructors
AbstractServiceClient(String user, String password)
Public Methods
void setBaseUrl(String baseUrl)
Protected Methods
<T extends TreeItem> T createEntity(String entityType, T entity, String url)
<T extends TreeItem> T deleteEntity(String url, Class clazz)
<T> T deserializeResponse(ClientResponse clientResponse, Type type)
<T extends TreeItem> T deserializeResponse(ClientResponse clientResponse, Class<T> clazz)
abstract String extendGetBaseUrl(String baseUrl)
This method is called by getBaseURL for the user to extend the base URL of its ServiceClient implementation.
Map<String, String> filterListToMap(List<Filter> filters)
Wraps the filter into a map that can be use as a parameter map for the request.
String getBaseURL()
Builds the base URL for this service.
WebResource.Builder getBuilder(String user, String password, String url, Map<String, String> queryParameters)
Creates a Builder
String getFileContentInBase64(InputStream inputStream)
abstract ClientConfig getJerseyClientConfiguration()
This method is called by getBuilder before the creation of the Client.
abstract List<ClientFilter> getJerseyClientFilters()
This method is called by getBuilder before the creation of the Client.
MultivaluedMap<String, String> mapToMultivaluedMap(Map<String, String> map)
Transform a map in a MultivaluedMap which is needed by Jersey to send query parameters.
String readInputStreamToString(InputStream inputStream)
String readResponseFromClientResponse(ClientResponse clientResponse)
<T extends TreeItem> T updateEntity(String entityType, T entity, String url)
void validateHttpStatus(ClientResponse clientResponse)
Throws exception when the status is greater than 400.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

private static final String DEFAULT_BASE_URL

Constant Value: "https://app.liquidplanner.com/api"

Fields

private String baseUrl

protected Gson mapper

protected String password

protected String user

Public Constructors

public AbstractServiceClient (String user, String password)

Parameters
user
password

Public Methods

public void setBaseUrl (String baseUrl)

Parameters
baseUrl

Protected Methods

protected T createEntity (String entityType, T entity, String url)

Parameters
entityType
entity
url

protected T deleteEntity (String url, Class clazz)

Parameters
url
clazz

protected T deserializeResponse (ClientResponse clientResponse, Type type)

Parameters
clientResponse
type

protected T deserializeResponse (ClientResponse clientResponse, Class<T> clazz)

Parameters
clientResponse
clazz

protected abstract String extendGetBaseUrl (String baseUrl)

This method is called by getBaseURL for the user to extend the base URL of its ServiceClient implementation.

Parameters
baseUrl The URL created by getBaseURL
Returns
  • the enhanced base URL

protected Map<String, String> filterListToMap (List<Filter> filters)

Wraps the filter into a map that can be use as a parameter map for the request.

Parameters
filters
Returns
  • null if the filter is null

protected String getBaseURL ()

Builds the base URL for this service.

Returns
  • the base URL with no final "/".

protected WebResource.Builder getBuilder (String user, String password, String url, Map<String, String> queryParameters)

Creates a Builder

Parameters
user
password
url The URL to be hit by the client
queryParameters A map containing all the query parameters
Returns
  • the builder.

protected String getFileContentInBase64 (InputStream inputStream)

Parameters
inputStream

protected abstract ClientConfig getJerseyClientConfiguration ()

This method is called by getBuilder before the creation of the Client. The ClientConfig is used to create the Client.

Returns
  • null if there are ClientConfig to be added.

protected abstract List<ClientFilter> getJerseyClientFilters ()

This method is called by getBuilder before the creation of the Client. The ClientFilter is used to create the Client. If there are no ClientFilter to be added just return null.

Returns
  • null if there are no ClientFilter to be added.

protected MultivaluedMap<String, String> mapToMultivaluedMap (Map<String, String> map)

Transform a map in a MultivaluedMap which is needed by Jersey to send query parameters. It also validate that not empty parameters are being send.

Parameters
map The map of query parameters
Returns
  • the same map in an MultivaluedMap object.

protected String readInputStreamToString (InputStream inputStream)

Parameters
inputStream

protected String readResponseFromClientResponse (ClientResponse clientResponse)

Parameters
clientResponse

protected T updateEntity (String entityType, T entity, String url)

Parameters
entityType
entity
url

protected void validateHttpStatus (ClientResponse clientResponse)

Throws exception when the status is greater than 400. It knows how to build the error and deserialize the status response.

Parameters
clientResponse