Beispiel #1
0
 // update feed
 public void updateFeed(Feed feed) throws CosmException {
   try {
     HttpPut hr =
         new HttpPut(
             API_BASE_URL_V2 + API_RESOURCE_FEEDS + "/" + feed.getId() + JSON_FILE_EXTENSION);
     hr.setEntity(new StringEntity(feed.toJSONObject().toString()));
     HttpResponse response = this.client.execute(hr);
     StatusLine statusLine = response.getStatusLine();
     if (statusLine.getStatusCode() != 200) {
       throw new CosmException(response.getStatusLine().toString());
     }
   } catch (Exception e) {
     e.printStackTrace();
     throw new CosmException("Caught exception in create Feed");
   }
 }
Beispiel #2
0
  // create feed
  public Feed createFeed(Feed feed) throws CosmException {
    try {
      HttpPost hr = new HttpPost(API_BASE_URL_V2 + API_RESOURCE_FEEDS + JSON_FILE_EXTENSION);
      hr.setEntity(new StringEntity(feed.toJSONObject().toString()));
      HttpResponse response = this.client.execute(hr);
      StatusLine statusLine = response.getStatusLine();
      if (statusLine.getStatusCode() == 201) {
        String a[] = response.getHeaders(HEADER_PARAM_LOCATION)[0].getValue().split("/");
        Integer feedid = Integer.valueOf(a[a.length - 1]);
        this.client.getBody(response);
        return this.getFeed(feedid.intValue());
      }

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