Class RequestBody

java.lang.Object
com.eqixiac.equinix.core.http.request.RequestBody

public final class RequestBody extends Object
The single request-body representation carried by an EquinixRequest. An immutable carrier in one of three shapes:
  • json(Object) - a Java payload object serialized to JSON;
  • form(Map) - application/x-www-form-urlencoded form fields;
  • bytes(byte[], String) - a pre-encoded raw body (e.g. a hand-built multipart/form-data payload).

The wire entity is built from this carrier by RequestFactory at dispatch time - once per attempt - so a JSON payload that is mutated between dispatches (the POST-search paging pipeline advances the body's pagination offset) is re-serialized automatically. No transport (Apache HttpClient) type appears in this class's API.

Author:
ianjones
  • Method Details

    • json

      public static RequestBody json(Object payload)
      A body whose payload object is serialized to JSON at dispatch time, honoring the request's content type and any Jackson FilterProvider set on the request.
      Parameters:
      payload - the object to serialize (never null)
      Returns:
      the JSON body carrier
    • form

      public static RequestBody form(Map<String,String> fields)
      An application/x-www-form-urlencoded body built from the given fields (field order is preserved on the wire).
      Parameters:
      fields - the form field name/value pairs (never null; copied)
      Returns:
      the form body carrier
    • bytes

      public static RequestBody bytes(byte[] bytes, String contentType)
      A pre-encoded raw body sent verbatim with the given entity content type (e.g. a hand-built multipart/form-data payload; the request's own content-type header may carry additional parameters such as the multipart boundary).
      Parameters:
      bytes - the raw body bytes (never null; copied)
      contentType - the entity content type (may be null)
      Returns:
      the binary body carrier
    • getKind

      public RequestBody.Kind getKind()
      Returns:
      the shape of this body
    • getPayload

      public Object getPayload()
      The JSON payload object, or null for non-JSON bodies. For POST-search requests this is the live search body whose pagination state the paging pipeline advances between pages.
      Returns:
      the payload object of a RequestBody.Kind.JSON body, else null
    • getFormFields

      public Map<String,String> getFormFields()
      Returns:
      the unmodifiable form fields of a RequestBody.Kind.FORM body, else null
    • getBytes

      public byte[] getBytes()
      Returns:
      a copy of the raw bytes of a RequestBody.Kind.BINARY body, else null
    • getBinaryContentType

      public String getBinaryContentType()
      Returns:
      the entity content type of a RequestBody.Kind.BINARY body, else null