Exemple #1
0
  // get group
  public Group getGroup(String groupid) throws CosmException {
    try {
      HttpGet hr = new HttpGet(API_BASE_URL_V2 + "groups/" + groupid + JSON_FILE_EXTENSION);
      HttpResponse response = this.client.execute(hr);
      StatusLine statusLine = response.getStatusLine();
      if (statusLine.getStatusCode() == 200) {
        return CosmFactory.toGroup(this.client.getBody(response));
      }

      throw new CosmException(response.getStatusLine().toString());
    } catch (Exception e) {
      e.printStackTrace();
      throw new CosmException("Caught exception in getGroup" + e.getMessage());
    }
  }
Exemple #2
0
  // create group
  public Group createGroup(Group group) throws CosmException {
    try {
      HttpPost hr = new HttpPost(API_BASE_URL_V2 + "groups" + JSON_FILE_EXTENSION);
      hr.setEntity(new StringEntity(group.toJSONObject().toString()));
      HttpResponse response = this.client.execute(hr);
      StatusLine statusLine = response.getStatusLine();
      if (statusLine.getStatusCode() == 201) {
        return CosmFactory.toGroup(this.client.getBody(response));
      }

      throw new CosmException(response.getStatusLine().toString());
    } catch (Exception e) {
      e.printStackTrace();
      throw new CosmException("Caught exception in create Group" + e.getMessage());
    }
  }