예제 #1
0
파일: Cosm.java 프로젝트: nuest/JCosmAPI
 // update trigger
 public void updateTrigger(Trigger trigger) throws CosmException {
   try {
     HttpPut request =
         new HttpPut(API_BASE_URL_V2 + "triggers/" + trigger.getId() + JSON_FILE_EXTENSION);
     request.setEntity(new StringEntity(trigger.toJSONObject().toString()));
     HttpResponse response = this.client.execute(request);
     StatusLine statusLine = response.getStatusLine();
     String body = this.client.getBody(response);
     if (statusLine.getStatusCode() != 200) {
       if (body.length() > 0) {
         JSONObject ej = new JSONObject(body);
         throw new CosmException(ej.getString("errors"));
       }
       throw new CosmException(statusLine.toString());
     }
   } catch (Exception e) {
     throw new CosmException("Caught exception in update trigger: " + e.getMessage());
   }
 }
예제 #2
0
파일: Cosm.java 프로젝트: nuest/JCosmAPI
 // create trigger
 public Trigger createTrigger(Trigger trigger) throws CosmException {
   try {
     HttpPost request = new HttpPost(API_BASE_URL_V2 + "triggers" + JSON_FILE_EXTENSION);
     request.setEntity(new StringEntity(trigger.toJSONObject().toString()));
     HttpResponse response = this.client.execute(request);
     StatusLine statusLine = response.getStatusLine();
     String body = this.client.getBody(response);
     if (statusLine.getStatusCode() == 201) {
       String a[] = response.getHeaders(HEADER_PARAM_LOCATION)[0].getValue().split("/");
       Integer id = Integer.valueOf(a[a.length - 1]);
       return this.getTrigger(id);
     }
     throw new Exception(body);
   } catch (Exception e) {
     e.printStackTrace();
     throw new CosmException("error while creating new apikey");
   }
 }