Class RequestAssembler

java.lang.Object
com.eqixiac.equinix.core.http.RequestAssembler

public final class RequestAssembler extends Object
Assembles EquinixRequest instances: instantiates the right request subtype for the operation's RequestType, derives the response JavaType from the resource's JSON class, and resolves the endpoint's URI template ({$token} placeholders) against the request's properties and path parameters.

Split out of the former monolithic Utils class; see ResponseHandler, ParameterMapper and SerializationHelper for the other request/response helpers.

Author:
ianjones
  • Constructor Details

    • RequestAssembler

      public RequestAssembler()
  • Method Details

    • buildRequest

      public static <T> EquinixRequest<T> buildRequest(String functionalArea, String requestParent, String serviceEndpoint, RequestType requestType, EquinixClient equinixClient, Map<String,String> pathParams, Map<String, List<String>> queryParams, com.fasterxml.jackson.core.type.TypeReference<?> typeReference)
    • buildRequest

      public static <T> EquinixRequest<T> buildRequest(String functionalArea, String requestParent, String serviceEndpoint, RequestType requestType, EquinixClient equinixClient, Map<String,String> pathParams, Map<String, List<String>> queryParams, Class<?> jsonClass)
      Builds a request whose response type is derived from the resource's JSON class (via deriveResponseType(RequestType, Class)) rather than a hand-declared TypeReference.
      Parameters:
      jsonClass - the resource's JSON model class (e.g. ServiceProfileJson.class)
    • deriveResponseType

      public static com.fasterxml.jackson.databind.JavaType deriveResponseType(RequestType requestType, Class<?> jsonClass)
      Derives the Jackson response JavaType for an operation from its RequestType and the resource's JSON class, so each JSON model no longer needs hand-declared paged/list/single TypeReference fields.
      Parameters:
      requestType - the operation's request type
      jsonClass - the resource's JSON model class
      Returns:
      the JavaType to deserialize the response into
    • addRequestParams

      public static <T> void addRequestParams(EquinixRequest<T> equinixRequest) throws EquinixClientException
      Resolves the endpoint's URI template and HTTP method from the apiParams catalogue onto the request. Every {$token} placeholder in the endpoint's requestUri must resolve to a non-null, non-blank request property or path parameter; otherwise an EquinixClientException naming the token and endpoint is thrown rather than dispatching a URI that addresses a different resource. Values are percent-encoded as single path segments (see encodePathSegment(String)).
      Throws:
      EquinixClientException - if the endpoint is unknown or a URI token cannot be resolved
    • encodePathSegment

      public static String encodePathSegment(String value)
      Percent-encodes a value for use as one RFC 3986 path segment. The unreserved characters (A-Z a-z 0-9 - . _ ~) and : and @ (both legal in a segment) are kept literally, so IAM's project:<uuid> and ERN values pass through unchanged; every other character, including /, space, #, ?, %, & and +, is UTF-8 percent-encoded.
      Parameters:
      value - the raw path-parameter value
      Returns:
      the encoded segment