Beispiel #1
0
  @SuppressWarnings("unchecked")
  @Override
  protected Object doInBackground(Ajax... ajaxs) {
    Object data = null;
    final Ajax ajax = mAjax;

    if (ajax == null) return null;

    HttpRequest mHttpRequest = ajax.getHttpRequest();
    if (ajax.getOnProgressListener() != null) {
      mHttpRequest.setOnProgressListener(this);
    }

    if (mAjax.getParser() == null && ajax.getOnSuccessListener() == null) {
      mHttpRequest.setIsNeedResponse(false);
    }

    isError = !mHttpRequest.send();

    if (!isError
        && !isCanceled
        && ajax.getOnSuccessListener() != null
        && mHttpRequest.getHttpStatus() == HttpStatus.SC_OK) {
      @SuppressWarnings("rawtypes")
      final Parser parser = mAjax.getParser();
      try {
        if (parser == null) {
          Log.e(LOG_TAG, "you have set onSuccessListener, but the parser is null");
        } else {
          data = parser.parse(mHttpRequest.getResponseData(), mHttpRequest.getCharset());
        }
      } catch (Exception ex) {
        if (null != parser && TextUtils.isEmpty(parser.getErrMsg())) {
          parser.setErrMsg(IcsonApplication.app.getString(R.string.parser_error_msg));
        }

        isError = true;
        if (Config.DEBUG) {
          Log.e(LOG_TAG, ToolUtil.getStackTraceString(ex));
        }
      }
    }

    return data;
  }