Package com.auth0.net

Class MultipartRequest<T>

java.lang.Object
com.auth0.net.BaseRequest<T>
com.auth0.net.MultipartRequest<T>
Type Parameters:
T - The type expected to be received as part of the response.
All Implemented Interfaces:
Request<T>

public class MultipartRequest<T> extends BaseRequest<T>
Request class that accepts parts to be sent encoded in a form. The content type of this request is "multipart/form-data".

This class is not thread-safe: It makes use of HashMap for storing the parameters. Make sure to not modify headers or the parameters from a different or un-synchronized thread.

See Also:
  • Constructor Details

  • Method Details

    • getContentType

      protected String getContentType()
      Description copied from class: BaseRequest
      Getter for the content-type header value to use on this request
      Overrides:
      getContentType in class BaseRequest<T>
      Returns:
      the content-type
    • createRequestBody

      protected HttpRequestBody createRequestBody() throws IOException
      Description copied from class: BaseRequest
      Responsible for creating the payload that will be set as body on this request.
      Overrides:
      createRequestBody in class BaseRequest<T>
      Returns:
      the body to send as part of the request.
      Throws:
      IOException - if an error is raised during the creation of the body.
    • readResponseBody

      protected T readResponseBody(Auth0HttpResponse response) throws IOException
      Description copied from class: BaseRequest
      Responsible for parsing the payload that is received as part of the response.
      Overrides:
      readResponseBody in class BaseRequest<T>
      Parameters:
      response - the received response. The body buffer will automatically closed.
      Returns:
      the instance of type T, result of interpreting the payload.
      Throws:
      IOException - if an error is raised during the parsing of the body.
    • addHeader

      public MultipartRequest<T> addHeader(String name, String value)
      Description copied from class: BaseRequest
      Adds an HTTP header to the request
      Specified by:
      addHeader in interface Request<T>
      Overrides:
      addHeader in class BaseRequest<T>
      Parameters:
      name - the name of the header
      value - the value of the header
      Returns:
      this same request instance
    • addPart

      public MultipartRequest<T> addPart(String name, File file, String mediaType)
      Adds a file part to the form of this request
      Parameters:
      name - the name of the part
      file - the file contents to send in this part
      mediaType - the file contents media type
      Returns:
      this same request instance
    • addPart

      public MultipartRequest<T> addPart(String name, String value)
      Adds a key-value part to the form of this request
      Parameters:
      name - the name of the part
      value - the value of the part
      Returns:
      this same request instance