// update datastream public void updateDatastream(Integer feedid, String datastreamid, Datastream datastream) throws CosmException { try { HttpPut request = new HttpPut( API_BASE_URL_V2 + API_RESOURCE_FEEDS + "/" + feedid + "/datastreams/" + datastreamid + JSON_FILE_EXTENSION); request.setEntity(new StringEntity(datastream.toJSONObject().toString())); HttpResponse response = this.client.execute(request); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 200) { this.client.getBody(response); return; } throw new HttpException(statusLine.toString()); } catch (Exception e) { throw new CosmException(e.getMessage()); } }
// create datastream public Datastream createDatastream(Integer feedid, Datastream datastream) throws CosmException { try { HttpPost request = new HttpPost( API_BASE_URL_V2 + API_RESOURCE_FEEDS + "/" + feedid + "/datastreams" + JSON_FILE_EXTENSION); JSONObject jo = new JSONObject(); jo.put("version", Cosm.VERSION); JSONArray ja = new JSONArray(); ja.put(datastream.toJSONObject()); jo.put("datastreams", ja); request.setEntity(new StringEntity(jo.toString())); HttpResponse response = this.client.execute(request); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 201) { String a[] = response.getHeaders(HEADER_PARAM_LOCATION)[0].getValue().split("/"); String datastreamid = a[a.length - 1]; this.client.getBody(response); return this.getDatastream(feedid, datastreamid); } throw new HttpException(response.getStatusLine().toString()); } catch (Exception e) { e.printStackTrace(); throw new CosmException("Caught exception in create Datastream" + e.getMessage()); } }