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;
  }
 /**
  * Returns the lock token, which must be retained to unlock the resource
  *
  * @param uri - must be encoded
  * @param owner
  * @return
  * @throws com.ettrema.httpclient.HttpException
  */
 public synchronized String doLock(String uri)
     throws com.ettrema.httpclient.HttpException, NotAuthorizedException, ConflictException,
         BadRequestException, NotFoundException, URISyntaxException {
   notifyStartRequest();
   LockMethod p = new LockMethod(uri);
   try {
     String lockXml = LOCK_XML.replace("${owner}", user);
     HttpEntity requestEntity = new StringEntity(lockXml, "UTF-8");
     p.setEntity(requestEntity);
     HttpResponse resp = host().client.execute(p);
     int result = resp.getStatusLine().getStatusCode();
     Utils.processResultCode(result, uri);
     return p.getLockToken(resp);
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   } finally {
     notifyFinishRequest();
   }
 }
 /**
  * @param newUri - must be fully qualified and correctly encoded
  * @return
  * @throws com.ettrema.httpclient.HttpException
  */
 public synchronized int doMkCol(String newUri)
     throws com.ettrema.httpclient.HttpException, NotAuthorizedException, ConflictException,
         BadRequestException, NotFoundException, URISyntaxException {
   notifyStartRequest();
   MkColMethod p = new MkColMethod(newUri);
   try {
     HttpResponse resp = host().client.execute(p);
     int result = resp.getStatusLine().getStatusCode();
     if (result == 409) {
       // probably means the folder already exists
       return result;
     }
     Utils.processResultCode(result, newUri);
     return result;
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   } finally {
     notifyFinishRequest();
   }
 }
  protected String postRallyXML(String apiUrl, String requestXML) throws Exception {
    String responseXML = "";

    DefaultHttpClient httpClient = new DefaultHttpClient();

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

    HttpPost httpPost = new HttpPost(apiUrl);
    httpPost.addHeader("Authorization", "Basic " + encodeString);

    httpPost.setEntity(new StringEntity(requestXML));

    HttpResponse response = httpClient.execute(httpPost);
    HttpEntity entity = response.getEntity();

    responseXML = getEntityString(entity);

    return responseXML;
  }