コード例 #1
0
ファイル: HttpUtility.java プロジェクト: zhenlonghe/weiciyuan
  private String dealWithError(HttpResponse httpResponse) throws WeiboException {

    StatusLine status = httpResponse.getStatusLine();
    int statusCode = status.getStatusCode();

    String result = "";

    if (statusCode != HttpStatus.SC_OK) {

      result = readResult(httpResponse);
      String err = null;
      int errCode = 0;
      try {
        JSONObject json = new JSONObject(result);
        err = json.getString("error");
        errCode = json.getInt("error_code");
        WeiboException exception = new WeiboException();
        exception.setError_code(errCode);
        exception.setOriError(err);
        throw exception;

      } catch (JSONException e) {
        e.printStackTrace();
      }
    }

    return result;
  }
コード例 #2
0
ファイル: HttpUtility.java プロジェクト: zhenlonghe/weiciyuan
  private String dealWithResponse(HttpResponse httpResponse) throws WeiboException {

    StatusLine status = httpResponse.getStatusLine();
    int statusCode = status.getStatusCode();

    if (statusCode != HttpStatus.SC_OK) {
      return dealWithError(httpResponse);
    }

    return readResult(httpResponse);
  }
コード例 #3
0
  public Multistatus handleResponse(HttpResponse response) throws SardineException, IOException {
    super.validateResponse(response);

    // Process the response from the server.
    HttpEntity entity = response.getEntity();
    StatusLine statusLine = response.getStatusLine();
    if (entity == null) {
      throw new SardineException(
          "No entity found in response", statusLine.getStatusCode(), statusLine.getReasonPhrase());
    }
    return this.getMultistatus(entity.getContent());
  }
コード例 #4
0
  // Interface to AsyncHttpRequest
  void sendResponseMessage(HttpResponse response) {
    StatusLine status = response.getStatusLine();
    String responseBody = null;
    try {
      HttpEntity entity = null;
      HttpEntity temp = response.getEntity();
      if (temp != null) {
        entity = new BufferedHttpEntity(temp);
        responseBody = EntityUtils.toString(entity, "UTF-8");
      }
    } catch (IOException e) {
      sendFailureMessage(e, (String) null);
    }

    if (status.getStatusCode() >= 300) {
      sendFailureMessage(
          new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()),
          responseBody);
    } else {
      sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
    }
  }