Class RequestAssembler
java.lang.Object
com.eqixiac.equinix.core.http.RequestAssembler
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidaddRequestParams(EquinixRequest<T> equinixRequest) Resolves the endpoint's URI template and HTTP method from the apiParams catalogue onto the request.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) 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 (viaderiveResponseType(RequestType, Class)) rather than a hand-declaredTypeReference.static com.fasterxml.jackson.databind.JavaTypederiveResponseType(RequestType requestType, Class<?> jsonClass) Derives the Jackson responseJavaTypefor an operation from itsRequestTypeand the resource's JSON class, so each JSON model no longer needs hand-declaredpaged/list/singleTypeReferencefields.static StringencodePathSegment(String value) Percent-encodes a value for use as one RFC 3986 path segment.
-
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 (viaderiveResponseType(RequestType, Class)) rather than a hand-declaredTypeReference.- 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 responseJavaTypefor an operation from itsRequestTypeand the resource's JSON class, so each JSON model no longer needs hand-declaredpaged/list/singleTypeReferencefields.- Parameters:
requestType- the operation's request typejsonClass- 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'srequestUrimust resolve to a non-null, non-blank request property or path parameter; otherwise anEquinixClientExceptionnaming the token and endpoint is thrown rather than dispatching a URI that addresses a different resource. Values are percent-encoded as single path segments (seeencodePathSegment(String)).- Throws:
EquinixClientException- if the endpoint is unknown or a URI token cannot be resolved
-
encodePathSegment
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'sproject:<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
-