/** * Performs a HTTP PUT request, saves or updates a document. * * @return {@link Response} */ Response put(URI uri, Object object, boolean newEntity) { assertNotEmpty(object, "object"); HttpResponse response = null; try { JsonObject json = getGson().toJsonTree(object).getAsJsonObject(); String id = getElement(json, "_id"); String rev = getElement(json, "_rev"); if (newEntity) { // save assertNull(rev, "revision"); id = (id == null) ? generateUUID() : id; } else { // update assertNotEmpty(id, "id"); assertNotEmpty(rev, "revision"); } HttpPut put = new HttpPut(builder(uri).path(id).build()); setEntity(put, json.toString()); response = executeRequest(put); return getResponse(response); } finally { close(response); } }
/** * Performs a HTTP POST request. * * @return {@link HttpResponse} */ HttpResponse post(URI uri, String json) { HttpPost post = new HttpPost(uri); setEntity(post, json); return executeRequest(post); }