Package com.auth0.net

Class BaseRequest<T>

java.lang.Object
com.auth0.net.BaseRequest<T>
Type Parameters:
T - The type expected to be received as part of the response.
All Implemented Interfaces:
Request<T>
Direct Known Subclasses:
EmptyBodyRequest, FormBodyRequest, MultipartRequest, SignUpRequest, TokenRequest, VoidRequest

public class BaseRequest<T> extends Object implements Request<T>
A request class that is able to interact fluently with the Auth0 server. The default content type of this request is "application/json".

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.

  • Constructor Details

  • Method Details

    • createRequest

      protected Auth0HttpRequest createRequest(String apiToken) throws Auth0Exception
      Throws:
      Auth0Exception
    • parseResponseBody

      protected T parseResponseBody(Auth0HttpResponse response) throws Auth0Exception
      Throws:
      Auth0Exception
    • createRequestBody

      protected HttpRequestBody createRequestBody() throws IOException
      Responsible for creating the payload that will be set as body on this request.
      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
      Responsible for parsing the payload that is received as part of the response.
      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.
    • getParameters

      protected Map<String,Object> getParameters()
    • execute

      public Response<T> execute() throws Auth0Exception
      Executes this request.
      Specified by:
      execute in interface Request<T>
      Returns:
      the response body JSON decoded as T
      Throws:
      Auth0Exception - if the request execution fails.
    • executeAsync

      public CompletableFuture<Response<T>> executeAsync()
      Description copied from interface: Request
      Executes this request asynchronously.
      Specified by:
      executeAsync in interface Request<T>
      Returns:
      a CompletableFuture representing the specified request.
    • getContentType

      protected String getContentType()
      Getter for the content-type header value to use on this request
      Returns:
      the content-type
    • createResponseException

      protected Auth0Exception createResponseException(Auth0HttpResponse response)
      Responsible for parsing an unsuccessful request (status code other than 200) and generating a developer-friendly exception with the error details.
      Parameters:
      response - the unsuccessful response, as received. If its body is accessed, the buffer must be closed.
      Returns:
      the exception with the error details.
    • addHeader

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

      public BaseRequest<T> addParameter(String name, Object value)
      Description copied from interface: Request
      Adds an body parameter to the request
      Specified by:
      addParameter in interface Request<T>
      Parameters:
      name - the name of the parameter
      value - the value of the parameter
      Returns:
      this same request instance
    • setBody

      public BaseRequest<T> setBody(Object value)
      Description copied from interface: Request
      Sets the response's body directly
      Specified by:
      setBody in interface Request<T>
      Parameters:
      value - the value to set as body
      Returns:
      this same request instance