コード例 #1
0
ファイル: ApiHandler.java プロジェクト: mksh/jicofo
  /**
   * Send Conference POST request to API endpoint which is used for allocating new conferences in
   * reservation system.
   *
   * @param ownerEmail email of new conference owner
   * @param mucRoomName full name of MUC room that is hosting the conference.
   *     {room_name}@{muc.server.net}
   * @return <tt>ApiResult</tt> that contains system response. It will contain <tt>Conference</tt>
   *     instance filled with data from the reservation system if everything goes OK.
   * @throws FaultTolerantRESTRequest.RetryExhaustedException When the number of retries to submit
   *     the request for the conference data is reached
   * @throws UnsupportedEncodingException When the room data have the encoding that does not play
   *     with UTF8 standard
   */
  public ApiResult createNewConference(String ownerEmail, String mucRoomName)
      throws FaultTolerantRESTRequest.RetryExhaustedException, UnsupportedEncodingException {
    Conference conference = new Conference(mucRoomName, ownerEmail, new Date());

    HttpPost post = new HttpPost(baseUrl + "/conference");

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
    Map<String, Object> jsonMap = conference.createJSonMap();

    for (Map.Entry<String, Object> entry : jsonMap.entrySet()) {
      nameValuePairs.add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
    }

    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF8"));

    logger.info("Sending post: " + jsonMap);

    CreateConferenceResponseParser conferenceResponseParser =
        new CreateConferenceResponseParser(conference);

    FaultTolerantRESTRequest faultTolerantRESTRequest =
        new FaultTolerantRESTRequest(post, conferenceResponseParser, retriesCreate, httpClient);

    return faultTolerantRESTRequest.submit();
  }
コード例 #2
0
  // create http request
  private HttpRequestBase getHttpRequest() {
    HttpRequestBase httpRequest = null;

    if (method == null) {
      method = RestMethod.GET;
    }

    // set method
    switch (method) {
      case GET:
        httpRequest = new HttpGet(getFinalURL().toString());
        break;
      case DELETE:
        httpRequest = new HttpDelete(getFinalURL().toString());
        break;
      case POST:
        HttpPost postRequest = new HttpPost(getFinalURL().toString());
        if (multipartEntity != null) {
          postRequest.setEntity(multipartEntity);
        } else {
          postRequest.setEntity(getBody());
        }
        httpRequest = postRequest;
        break;
      case PUT:
        HttpPut putRequest = new HttpPut(getFinalURL().toString());
        putRequest.setEntity(getBody());
        httpRequest = putRequest;
        break;
      default:
        break;
    }

    // set headers
    if (headers != null) {
      for (String key : headers.keySet()) {
        httpRequest.addHeader(key, headers.get(key));
      }
    }

    return httpRequest;
  }
コード例 #3
0
  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;
  }