コード例 #1
4
  protected String getRallyXML(String apiUrl) throws Exception {
    String responseXML = "";

    DefaultHttpClient httpClient = new DefaultHttpClient();

    Base64 base64 = new Base64();
    String encodeString =
        new String(base64.encode((rallyApiHttpUsername + ":" + rallyApiHttpPassword).getBytes()));

    HttpGet httpGet = new HttpGet(apiUrl);
    httpGet.addHeader("Authorization", "Basic " + encodeString);
    HttpResponse response = httpClient.execute(httpGet);
    HttpEntity entity = response.getEntity();

    if (entity != null) {

      InputStreamReader reader = new InputStreamReader(entity.getContent());
      BufferedReader br = new BufferedReader(reader);

      StringBuilder sb = new StringBuilder();
      String line = "";
      while ((line = br.readLine()) != null) {
        sb.append(line);
      }

      responseXML = sb.toString();
    }

    log.debug("responseXML=" + responseXML);

    return responseXML;
  }
コード例 #2
0
  public String getEntityString(HttpEntity entity) throws Exception {
    StringBuilder sb = new StringBuilder();

    if (entity != null) {
      InputStreamReader reader = new InputStreamReader(entity.getContent());
      BufferedReader br = new BufferedReader(reader);

      String line = "";
      while ((line = br.readLine()) != null) {
        sb.append(line);
      }
    }

    return sb.toString();
  }
コード例 #3
0
  public String loadStream(InputStream is) {
    StringBuilder sb = new StringBuilder();

    try {
      InputStreamReader reader = new InputStreamReader(is);
      BufferedReader br = new BufferedReader(reader);

      String line = "";
      while ((line = br.readLine()) != null) {
        sb.append(line);
      }
    } catch (Exception e) {
      log.error("", e);
    }

    return sb.toString();
  }
コード例 #4
0
 /**
  * Preprocesses the messages from the server
  *
  * @param message
  */
 private synchronized void preprocessServerMessage(String message) {
   if (message == null) {
     this.stop();
     try {
       reader.close();
       writer.close();
     } catch (IOException ioe) {
       ioe.printStackTrace();
     }
     sendMessage(CLIENT, "Connection Closed by Server");
     _group = "";
   } else if (message.equals("") == false) processServerMessage(message);
 }
コード例 #5
0
  /** This listens forever for messages from server */
  public void run() {
    String current = "";

    while (_status == CONNECTED) {
      // Inner Loop for Mobber-Fragments
      try {
        current = reader.readLine();
      } catch (Exception ex) {
        _status = NOTCONNECTED;
        current = null;
      }
      // End Inner Loop
      preprocessServerMessage(current);
      current = null;
    }
  }