com.orbitz.consul.util
Class ClientUtil

java.lang.Object
  extended by com.orbitz.consul.util.ClientUtil

public class ClientUtil
extends java.lang.Object

A collection of stateless utility methods for use in constructing requests and responses to the Consul HTTP API.


Constructor Summary
ClientUtil()
           
 
Method Summary
static java.lang.String decodeBase64(java.lang.String value)
          Decodes a Base 64 encoded string.
static javax.ws.rs.client.WebTarget eventConfig(javax.ws.rs.client.WebTarget webTarget, EventOptions eventOptions)
          Given a EventOptions object, adds the appropriate query string parameters to the request being built.
static void handleErrors(javax.ws.rs.core.Response response)
          Since Consul returns plain text when an error occurs, check for unsuccessful HTTP status code, and throw an exception with the text from Consul as the message.
static javax.ws.rs.client.WebTarget queryConfig(javax.ws.rs.client.WebTarget webTarget, QueryOptions queryOptions)
          Given a QueryOptions object, adds the appropriate query string parameters to the request being built.
static javax.ws.rs.client.WebTarget queryParams(javax.ws.rs.client.WebTarget webTarget, java.util.Map<java.lang.String,java.lang.String> params)
          Applies all key/values from the params map to query string parameters.
static
<T> ConsulResponse<T>
response(javax.ws.rs.client.WebTarget target, CatalogOptions catalogOptions, QueryOptions queryOptions, javax.ws.rs.core.GenericType<T> type)
          Generates a ConsulResponse for a specific datacenter, set of QueryOptions, and a result type.
static
<T> void
response(javax.ws.rs.client.WebTarget target, CatalogOptions catalogOptions, QueryOptions queryOptions, javax.ws.rs.core.GenericType<T> type, ConsulResponseCallback<T> callback)
          Generates a ConsulResponse for a specific datacenter, set of QueryOptions, and a result type.
static
<T> ConsulResponse<T>
response(javax.ws.rs.client.WebTarget webTarget, javax.ws.rs.core.GenericType<T> responseType)
          Given a WebTarget object and a type to marshall the result JSON into, complete the HTTP GET request.
static
<T> void
response(javax.ws.rs.client.WebTarget webTarget, javax.ws.rs.core.GenericType<T> responseType, ConsulResponseCallback<T> callback)
          Given a WebTarget object and a type to marshall the result JSON into, complete the HTTP GET request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientUtil

public ClientUtil()
Method Detail

queryParams

public static javax.ws.rs.client.WebTarget queryParams(javax.ws.rs.client.WebTarget webTarget,
                                                       java.util.Map<java.lang.String,java.lang.String> params)
Applies all key/values from the params map to query string parameters.

Parameters:
webTarget - The JAX-RS target to apply the query parameters.
params - Map of parameters.
Returns:
The new target with the parameters applied.

queryConfig

public static javax.ws.rs.client.WebTarget queryConfig(javax.ws.rs.client.WebTarget webTarget,
                                                       QueryOptions queryOptions)
Given a QueryOptions object, adds the appropriate query string parameters to the request being built.

Parameters:
webTarget - The base WebTarget.
queryOptions - Query specific options to use.
Returns:
A WebTarget with all appropriate query string parameters.

eventConfig

public static javax.ws.rs.client.WebTarget eventConfig(javax.ws.rs.client.WebTarget webTarget,
                                                       EventOptions eventOptions)
Given a EventOptions object, adds the appropriate query string parameters to the request being built.

Parameters:
webTarget - The base WebTarget.
eventOptions - Event specific options to use.
Returns:
A WebTarget with all appropriate query string parameters.

response

public static <T> ConsulResponse<T> response(javax.ws.rs.client.WebTarget target,
                                             CatalogOptions catalogOptions,
                                             QueryOptions queryOptions,
                                             javax.ws.rs.core.GenericType<T> type)
Generates a ConsulResponse for a specific datacenter, set of QueryOptions, and a result type.

Type Parameters:
T - The result type.
Parameters:
target - The base WebTarget.
catalogOptions - Catalog specific options to use.
queryOptions - The Query Options to use.
type - The generic type to marshall the resulting data to.
Returns:
A ConsulResponse.

response

public static <T> void response(javax.ws.rs.client.WebTarget target,
                                CatalogOptions catalogOptions,
                                QueryOptions queryOptions,
                                javax.ws.rs.core.GenericType<T> type,
                                ConsulResponseCallback<T> callback)
Generates a ConsulResponse for a specific datacenter, set of QueryOptions, and a result type.

Type Parameters:
T - The result type.
Parameters:
target - The base WebTarget.
catalogOptions - Catalog specific options to use.
queryOptions - The Query Options to use.
type - The generic type to marshall the resulting data to.

response

public static <T> ConsulResponse<T> response(javax.ws.rs.client.WebTarget webTarget,
                                             javax.ws.rs.core.GenericType<T> responseType)
Given a WebTarget object and a type to marshall the result JSON into, complete the HTTP GET request.

Type Parameters:
T - The class to marshall the JSON into.
Parameters:
webTarget - The JAX-RS target.
responseType - The class to marshall the JSON into.
Returns:
A ConsulResponse containing the result.

response

public static <T> void response(javax.ws.rs.client.WebTarget webTarget,
                                javax.ws.rs.core.GenericType<T> responseType,
                                ConsulResponseCallback<T> callback)
Given a WebTarget object and a type to marshall the result JSON into, complete the HTTP GET request.

Type Parameters:
T - The class to marshall the JSON into.
Parameters:
webTarget - The JAX-RS target.
responseType - The class to marshall the JSON into.
callback - The callback object to handle the result on a different thread.

decodeBase64

public static java.lang.String decodeBase64(java.lang.String value)
Decodes a Base 64 encoded string.

Parameters:
value - The encoded string.
Returns:
The decoded string.

handleErrors

public static void handleErrors(javax.ws.rs.core.Response response)
Since Consul returns plain text when an error occurs, check for unsuccessful HTTP status code, and throw an exception with the text from Consul as the message.

Parameters:
response - The HTTP response.