SG REST Admin API gives misleading response

Thanks to @jens I was able to solve the issue.

I also changed the prerequisites:

  • document exists already, i.e. it was created by CBL client
  • document is updated via Java http stack
/* init cluster code not included*/
String docName = "my_doc";
String urlEncodedDocName = URLEncoder.encode(docName, "UTF-8");
/* Get revision */
DocumentFragment<Lookup> result = bucket.lookupIn(docName).get("_sync.rev", SubdocOptionsBuilder.builder().xattr(true)).execute();
String rev = (String) result.content(0);
log.info("rev = " + rev);
/* Update document */
HttpClient httpClient = new DefaultHttpClient();
String uri = "http://localhost:4985/my_db/" + urlEncodedDocName + "?rev=" + rev;
log.info("uri = " + uri);
HttpPut httpPut = new HttpPut(uri);
StringEntity jsonEntity;
String payLoad = "{\"color\":\"green\"}";
jsonEntity = new StringEntity(payLoad);
httpPut.setEntity(jsonEntity);
httpPut.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(httpPut);
String s = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
log.info("response = " + s);

The responses never showed any conflict when testing. However using a curl statement without the accept header and the new_edits=true param there was still a document conflict logged. This happened about 30% of the time or so. Still the document always was updated when checking it, i.e. via Couchbase console in the browser. The code is the same as above but using curl instead of the Java http stack:

/* init cluster code not included*/
String docName = "my_doc";
String urlEncodedDocName = URLEncoder.encode(docName, "UTF-8");
/* Get revision */
DocumentFragment<Lookup> result = bucket.lookupIn(docName).get("_sync.rev", SubdocOptionsBuilder.builder().xattr(true)).execute();
String rev = (String) result.content(0);
log.info("rev = " + rev);
/* Update document */
JsonObject content = JsonObject.empty().put("color", "green");
ProcessBuilder pb = new ProcessBuilder("curl", "-X", "PUT", "http://localhost:4985/my_db/" + urlEncodedDocName +
"?rev=" + rev,
        "-H", "Content-Type: application/json", "-d", content.toString());
pb.start();
pb.redirectErrorStream(true);
Process process = pb.start();
String s = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8.name());
log.info("process = " + s);

My conclusion is that this issue is solved but there might still be an issue when using curl. I used curl as it was easy to copy-paste the command when trying it out in the SG API explorer.

Thanks!