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;
  }
  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();
  }
Beispiel #3
0
 public Either<IOException, String> apply(HttpResponse response) {
   BufferedReader reader = null;
   try {
     StringBuilder builder = new StringBuilder();
     reader =
         new BufferedReader(
             new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
     while (true) {
       String read = reader.readLine();
       if (read == null) break;
       builder.append(read);
     }
     return new Right<IOException, String>(builder.toString());
   } catch (IOException e) {
     return new Left<IOException, String>(e);
   }
 }
  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();
  }
Beispiel #5
0
 private CIJob getJob(ApplicationInfo appInfo) throws PhrescoException {
   Gson gson = new Gson();
   try {
     BufferedReader br = new BufferedReader(new FileReader(getCIJobPath(appInfo)));
     CIJob job = gson.fromJson(br, CIJob.class);
     br.close();
     return job;
   } catch (FileNotFoundException e) {
     S_LOGGER.debug(e.getLocalizedMessage());
     return null;
   } catch (com.google.gson.JsonParseException e) {
     S_LOGGER.debug("it is already adpted project !!!!! " + e.getLocalizedMessage());
     return null;
   } catch (IOException e) {
     S_LOGGER.debug(e.getLocalizedMessage());
     return null;
   }
 }
  public @Nonnull Document parseResponse(
      @Nonnull InputStream responseBodyAsStream, boolean withWireLogging)
      throws CloudException, InternalException {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(responseBodyAsStream));
      StringBuilder sb = new StringBuilder();
      String line;

      while ((line = in.readLine()) != null) {
        sb.append(line);
        sb.append("\n");
      }
      in.close();
      return parseResponse(sb.toString(), withWireLogging);
    } catch (IOException e) {
      throw new CloudException(e);
    }
  }
Beispiel #7
0
 public List<CIJob> getJobs(ApplicationInfo appInfo) throws PhrescoException {
   S_LOGGER.debug("GetJobs Called!");
   try {
     boolean adaptedProject = adaptExistingJobs(appInfo);
     S_LOGGER.debug("Project adapted for new feature => " + adaptedProject);
     Gson gson = new Gson();
     BufferedReader br = new BufferedReader(new FileReader(getCIJobPath(appInfo)));
     Type type = new TypeToken<List<CIJob>>() {}.getType();
     List<CIJob> jobs = gson.fromJson(br, type);
     br.close();
     return jobs;
   } catch (FileNotFoundException e) {
     S_LOGGER.debug("FileNotFoundException");
     return null;
   } catch (IOException e) {
     S_LOGGER.debug("IOException");
     throw new PhrescoException(e);
   }
 }