/**
  * Fired when a request returns successfully, override to handle in your own code
  *
  * @param statusCode the status code of the response
  * @param headers return headers, if any
  * @param responseBody the body of the HTTP response from the server
  */
 public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
   try {
     String response = responseBody == null ? null : new String(responseBody, getCharset());
     onSuccess(statusCode, headers, response);
   } catch (UnsupportedEncodingException e) {
     Log.e(LOG_TAG, e.toString());
     onFailure(statusCode, headers, e, null);
   }
 }
  // Methods which emulate android's Handler and Message methods
  protected void handleMessage(Message msg) {
    Object[] response;

    switch (msg.what) {
      case SUCCESS_MESSAGE:
        response = (Object[]) msg.obj;
        if (response != null && response.length >= 3) {
          onSuccess((Integer) response[0], (Header[]) response[1], (byte[]) response[2]);
        } else {
          Log.e(LOG_TAG, "SUCCESS_MESSAGE didn't got enough params");
        }
        break;
      case FAILURE_MESSAGE:
        response = (Object[]) msg.obj;
        if (response != null && response.length >= 4) {
          onFailure(
              (Integer) response[0],
              (Header[]) response[1],
              (byte[]) response[2],
              (Throwable) response[3]);
        } else {
          Log.e(LOG_TAG, "FAILURE_MESSAGE didn't got enough params");
        }
        break;
      case START_MESSAGE:
        onStart();
        break;
      case FINISH_MESSAGE:
        onFinish();
        break;
      case PROGRESS_MESSAGE:
        response = (Object[]) msg.obj;
        if (response != null && response.length >= 2) {
          try {
            onProgress((Integer) response[0], (Integer) response[1]);
          } catch (Throwable t) {
            Log.e(LOG_TAG, "custom onProgress contains an error", t);
          }
        } else {
          Log.e(LOG_TAG, "PROGRESS_MESSAGE didn't got enough params");
        }
        break;
      case RETRY_MESSAGE:
        onRetry();
        break;
    }
  }
 /**
  * Fired when a request returns successfully, override to handle in your own code
  *
  * @param statusCode the status code of the response
  * @param content the body of the HTTP response from the server
  * @deprecated use {@link #onSuccess(int, Header[], byte[])}
  */
 @Deprecated
 public void onSuccess(int statusCode, String content) {
   onSuccess(content);
 }
 /**
  * Fired when a request returns successfully, override to handle in your own code
  *
  * @param statusCode the status code of the response
  * @param headers the headers of the HTTP response
  * @param content the body of the HTTP response from the server
  * @deprecated use {@link #onSuccess(int, Header[], byte[])}
  */
 @Deprecated
 public void onSuccess(int statusCode, Header[] headers, String content) {
   onSuccess(statusCode, content);
 }