Android Client SDK
com.verivo.akula.http.handler.AKJsonHttpResponseHandler Class Reference

The AKJsonHttpResponseHandler class is an HTTP response handler which automatically checks the HTTP response code and, if successful, returns the response body either as a JSONObject or a JSONArray, depending on the JSON string being handled. More...

Inheritance diagram for com.verivo.akula.http.handler.AKJsonHttpResponseHandler:
Inheritance graph

Public Member Functions

 AKJsonHttpResponseHandler ()
 Create a new AKJsonHttpResponseHandler. More...
 
void onFailure (Throwable e, JSONObject responseObject)
 Override to handle a failed response that returns a JSONObject as its response data. More...
 
void onFailure (Throwable e, JSONArray responseArray)
 Override to handle a failed response that returns a JSONArray as its response data. More...
 
void onSuccess (JSONObject responseObject)
 Override to handle a JSONObject response. More...
 
void onSuccess (JSONObject responseObject, int statusCode)
 Override to handle a JSONObject response along with the HTTP response status code. More...
 
void onSuccess (JSONArray responseArray)
 Override to handle a JSONArray response. More...
 
void onSuccess (JSONArray responseArray, int statusCode)
 Override to handle a JSONArray response along with the HTTP response status code. More...
 
- Public Member Functions inherited from com.verivo.akula.http.handler.AKTextHttpResponseHandler
 AKTextHttpResponseHandler ()
 Create a new AKTextHttpResponseHandler. More...
 
void handleDone ()
 Handler classes implement this method to be handle when all response processing is complete. More...
 
void handleFailure (Throwable e)
 Handler classes implement this method to handle a local exception from a request. More...
 
void handleResponse (HttpResponse response)
 Handler classes implement this method to handle a returned HttpResponse from a request. More...
 
void onFailure (Throwable e)
 Override to handle a failed response. More...
 
void onFailure (Throwable e, String responseText)
 Override to handle a failed response that returns a String as its response data. More...
 
void onSuccess (String responseText)
 Override to handle a String response. More...
 
void onSuccess (String responseText, int statusCode)
 Override to handle a String response along with the HTTP response status code. More...
 
- Public Member Functions inherited from com.verivo.akula.http.handler.AKBaseHttpResponseHandler
void onDone ()
 Internal class used to carry response data from the background thread to the calling thread. More...
 

Static Public Member Functions

static Object parseJson (String text) throws JSONException
 Return a JSONObject or JSONArray based on the input text. More...
 

Protected Member Functions

void handleMessage (Message msg)
 Handle a message on the calling thread. More...
 
void processFailure (Throwable e, String responseText)
 Process the failure on the background thread, parsing the response text (if available) into the appropriate native JSONObject or JSONArray and send a failure message to the calling thread (if applicable). More...
 
void processSuccess (String responseText, int statusCode)
 Process the response on the background thread, parsing the response text into the appropriate native JSONObject or JSONArray and send a success message to the calling thread (if applicable). More...
 
- Protected Member Functions inherited from com.verivo.akula.http.handler.AKTextHttpResponseHandler
void handleMessage (Message msg)
 Handle a message on the calling thread. More...
 
void processDone ()
 Perform any final processing on the background thread before sending a done message to the calling thread (if applicable). More...
 
void processFailure (Throwable e, String responseText)
 Process the error on the background thread, and send a failure message to the calling thread (if applicable). More...
 
void processResponse (HttpResponse response)
 Process the HTTP response on the background thread, parsing out the response text and checking the HTTP status code to determine whether the response was successful or not. More...
 
void processSuccess (String responseText, int statusCode)
 Process the response text on the background thread and send a success message to the calling thread (if applicable). More...
 
- Protected Member Functions inherited from com.verivo.akula.http.handler.AKBaseHttpResponseHandler
 AKBaseHttpResponseHandler ()
 Constructor. More...
 
boolean isSuccessfulHttpResponse (HttpResponse response)
 Determine if this HttpResponse object represents a successful request. More...
 
Message obtainMessage (int what, Object data)
 Create a new message to pass to the calling thread, if possible. More...
 
void sendMessage (Message msg)
 Send a message to the calling thread, if possible. More...
 

Additional Inherited Members

- Static Protected Attributes inherited from com.verivo.akula.http.handler.AKBaseHttpResponseHandler
static final int RESPONSE_FAIL = -1
 Static constant representing a response failure status. More...
 
static final int RESPONSE_FINISH = 0
 Static constant representing a response completion status. More...
 
static final int RESPONSE_SUCCESS = 1
 Static constant representing a response success status. More...
 

Detailed Description

The AKJsonHttpResponseHandler class is an HTTP response handler which automatically checks the HTTP response code and, if successful, returns the response body either as a JSONObject or a JSONArray, depending on the JSON string being handled.

See Also
AKHttpAgent

Constructor & Destructor Documentation

com.verivo.akula.http.handler.AKJsonHttpResponseHandler.AKJsonHttpResponseHandler ( )

Create a new AKJsonHttpResponseHandler.

Override onSuccess, onFailure, and onDone methods to handle response data.

Version
1.0

Member Function Documentation

void com.verivo.akula.http.handler.AKJsonHttpResponseHandler.handleMessage ( Message  msg)
protectedvirtual

Handle a message on the calling thread.

Parameters
msgThe Message object representing the message.
Version
1.0

Implements com.verivo.akula.http.handler.AKBaseHttpResponseHandler.

void com.verivo.akula.http.handler.AKJsonHttpResponseHandler.onFailure ( Throwable  e,
JSONObject  responseObject 
)

Override to handle a failed response that returns a JSONObject as its response data.

Parameters
eThe reason for the failure.
responseObjectThe response object.
Version
1.0
void com.verivo.akula.http.handler.AKJsonHttpResponseHandler.onFailure ( Throwable  e,
JSONArray  responseArray 
)

Override to handle a failed response that returns a JSONArray as its response data.

Parameters
eThe reason for the failure.
responseArrayThe response array.
Version
1.0
void com.verivo.akula.http.handler.AKJsonHttpResponseHandler.onSuccess ( JSONObject  responseObject)

Override to handle a JSONObject response.

Note: If the HTTP response is successful, but the response data is null, this method is called with a null value.

Parameters
responseObject
Version
1.0
void com.verivo.akula.http.handler.AKJsonHttpResponseHandler.onSuccess ( JSONObject  responseObject,
int  statusCode 
)

Override to handle a JSONObject response along with the HTTP response status code.

If not overridden, call onSuccess(JSONObject).

Note: If the HTTP response is successful, but the response data is null, this method is called with a null value.

Parameters
responseObject
statusCode
Version
1.0
void com.verivo.akula.http.handler.AKJsonHttpResponseHandler.onSuccess ( JSONArray  responseArray)

Override to handle a JSONArray response.

Parameters
responseArrayThe JSON array.
Version
1.0
void com.verivo.akula.http.handler.AKJsonHttpResponseHandler.onSuccess ( JSONArray  responseArray,
int  statusCode 
)

Override to handle a JSONArray response along with the HTTP response status code.

If this is not overridden, call onSuccess(JSONArray).

Parameters
responseArray
statusCode
Version
1.0
static Object com.verivo.akula.http.handler.AKJsonHttpResponseHandler.parseJson ( String  text) throws JSONException
static

Return a JSONObject or JSONArray based on the input text.

Parameters
text
Returns
Exceptions
JSONExceptionif the text is not a valid JSON object or array.
Version
1.0
void com.verivo.akula.http.handler.AKJsonHttpResponseHandler.processFailure ( Throwable  e,
String  responseText 
)
protected

Process the failure on the background thread, parsing the response text (if available) into the appropriate native JSONObject or JSONArray and send a failure message to the calling thread (if applicable).

Parameters
eThe exception causing the failure.
responseTextThe text from the response, if available.
Version
1.0
void com.verivo.akula.http.handler.AKJsonHttpResponseHandler.processSuccess ( String  responseText,
int  statusCode 
)
protected

Process the response on the background thread, parsing the response text into the appropriate native JSONObject or JSONArray and send a success message to the calling thread (if applicable).

Parameters
responseText
statusCode
Version
1.0