Class BaseResponseHandler

java.lang.Object
io.vantiq.client.BaseResponseHandler
All Implemented Interfaces:
ResponseHandler

public class BaseResponseHandler extends Object implements ResponseHandler
This is the base class for response handlers that stores the response data and provides access to the standard headers.
  • Constructor Details

    • BaseResponseHandler

      public BaseResponseHandler()
  • Method Details

    • onSuccess

      public void onSuccess(Object body, okhttp3.Response response)
      Description copied from interface: ResponseHandler
      This is called when a successful HTTP response is returned from the server. The type of the body is determined by the Content-Type of the response. For JSON responses, the body will be a Gson JsonElement. Otherwise, a string is returned.
      Specified by:
      onSuccess in interface ResponseHandler
      Parameters:
      body - The parsed response from the server. The type of the response is determined by SDK method being called.
      response - The raw response from the server. This provides access to the HTTP status code, headers, and raw body.
    • onError

      public void onError(List<VantiqError> errors, okhttp3.Response response)
      Description copied from interface: ResponseHandler
      Called if a server error is returned (e.g. HTTP 4xx or 5xx status codes), then the status code is returned along with the errors that were found.
      Specified by:
      onError in interface ResponseHandler
      Parameters:
      errors - The errors returned by the Vantiq server.
      response - The raw response from the server. This provides access to the HTTP status code, headers, and raw body.
    • onFailure

      public void onFailure(Throwable exception)
      Description copied from interface: ResponseHandler
      Called if a client side exception occurs during the request or response processing.
      Specified by:
      onFailure in interface ResponseHandler
      Parameters:
      exception - The exception thrown during the client-side processing.
    • getResponse

      public VantiqResponse getResponse()
      Returns the response
      Returns:
      The response from the Vantiq server.
    • completionHook

      public void completionHook(boolean success)
      Method that is called when the response has completed either successfully, in error, or through an exception.
      Parameters:
      success - true if onSuccess was called, otherwise, false
    • hasErrors

      public boolean hasErrors()
      Returns true if at least one error was returned from the server
      Returns:
      true if at least one error exists
    • hasException

      public boolean hasException()
      Returns true if an exception occurred during the client processing
      Returns:
      true if an exception was thrown
    • getException

      public Throwable getException()
      Returns the exception if hasException() returned true
      Returns:
      The exception that was thrown or null
    • getErrors

      public List<VantiqError> getErrors()
      Returns the errors if hasErrors() returned true
      Returns:
      The errors returned from the Vantiq server or null
    • getCount

      public int getCount()
      Returns the count from the "X-Total-Count" header. If the header wasn't present, then the count returns -1.
      Returns:
      The returned count or -1 if no count header was present.
    • getContentType

      public String getContentType()
      Returns the content type from the "Content-Type" HTTP response header.
      Returns:
      The content type of the response
    • getStatusCode

      public int getStatusCode()
      Returns the HTTP status code returned from the response
      Returns:
      The HTTP status code for the response
    • getBody

      public Object getBody()
      Returns the response body. If there was an exception or error, then no body will exist.
      Returns:
      The parsed response body
    • getBodyAsJsonObject

      public com.google.gson.JsonObject getBodyAsJsonObject()
      Returns the body as a JsonObject or null if the body is not a JsonObject
      Returns:
      The parsed body as a JsonObject or null if not a JsonObject
    • getBodyAsList

      public List<com.google.gson.JsonObject> getBodyAsList()
      Returns the body as a list of JsonObjects or null if the body is not a List.
      Returns:
      The parsed body as a List of JsonObjects or null if not a list
    • getBodyAsString

      public String getBodyAsString()
      Returns the body as a String or null if the body is not a String
      Returns:
      The parsed body as a String or null if not a String
    • getBodyAsInt

      public int getBodyAsInt()
      Returns the body as an int or 0 if the body is not an int
      Returns:
      The parsed body as a int or 0 if not an int
    • getBodyAsBoolean

      public boolean getBodyAsBoolean()
      Returns the body as a boolean or false if the body is not a boolean
      Returns:
      The parsed body as a boolean or false if not a boolean