Package io.vantiq.client
Class BaseResponseHandler
java.lang.Object
io.vantiq.client.BaseResponseHandler
- All Implemented Interfaces:
ResponseHandler
This is the base class for response handlers that stores the
response data and provides access to the standard headers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcompletionHook(boolean success) Method that is called when the response has completed either successfully, in error, or through an exception.getBody()Returns the response body.booleanReturns the body as a boolean or false if the body is not a booleanintReturns the body as an int or 0 if the body is not an intcom.google.gson.JsonObjectReturns the body as a JsonObject or null if the body is not a JsonObjectList<com.google.gson.JsonObject>Returns the body as a list of JsonObjects or null if the body is not a List.Returns the body as a String or null if the body is not a StringReturns the content type from the "Content-Type" HTTP response header.intgetCount()Returns the count from the "X-Total-Count" header.Returns the errors ifhasErrors()returned trueReturns the exception ifhasException()returned trueReturns the responseintReturns the HTTP status code returned from the responsebooleanReturns true if at least one error was returned from the serverbooleanReturns true if an exception occurred during the client processingvoidonError(List<VantiqError> errors, okhttp3.Response response) Called if a server error is returned (e.g.voidCalled if a client side exception occurs during the request or response processing.voidThis is called when a successful HTTP response is returned from the server.
-
Constructor Details
-
BaseResponseHandler
public BaseResponseHandler()
-
-
Method Details
-
onSuccess
Description copied from interface:ResponseHandlerThis 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:
onSuccessin interfaceResponseHandler- 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
Description copied from interface:ResponseHandlerCalled 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:
onErrorin interfaceResponseHandler- 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
Description copied from interface:ResponseHandlerCalled if a client side exception occurs during the request or response processing.- Specified by:
onFailurein interfaceResponseHandler- Parameters:
exception- The exception thrown during the client-side processing.
-
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
Returns the exception ifhasException()returned true- Returns:
- The exception that was thrown or null
-
getErrors
Returns the errors ifhasErrors()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
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
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
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
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
-