Exemplo n.º 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;
  }
Exemplo n.º 2
0
 private boolean fetchApp(String url, String username, String password) throws JSONException {
   try {
     if (username == "null") {
       username = null;
     }
     if (password == "null") {
       password = null;
     }
     HttpResponse response = makeRequest(url, username, password);
     StatusLine sl = response.getStatusLine();
     int code = sl.getStatusCode();
     HttpEntity entity = response.getEntity();
     InputStream content = entity.getContent();
     if (code != 200) {
       return false;
     } else {
       ZipInputStream data = new ZipInputStream(content);
       return saveAndVerify(data);
     }
   } catch (ClientProtocolException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return false;
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return false;
   }
 }
Exemplo n.º 3
0
 public void process(final HttpResponse response, final HttpContext context)
     throws HttpException, IOException {
   HttpEntity entity = response.getEntity();
   if (entity != null) {
     Header ceheader = entity.getContentEncoding();
     if (ceheader != null) {
       HeaderElement[] codecs = ceheader.getElements();
       for (HeaderElement h : codecs) {
         if (h.getName().equalsIgnoreCase("deflate")) {
           response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
           return;
         }
       }
     }
   }
 }
Exemplo n.º 4
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();
  }