The command of property update uses PUT method. The URL is the same as the one for reading properties, the difference is only in the HTTP method used. The body of the request must be an Atom document with specified properties.
Sending of content stream can be executed via PUT or POST requests. Content-type of the request must be a "multipart/form-data".
Update properties:
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
String url = "http://localhost:8080/rest/private/cmisatom/";
url += repository;
url += "/object/";
url += obj_id;
HttpClient client = new HttpClient();
client.getHttpConnectionManager().
getParams().setConnectionTimeout(10000);
String atomDoc = "<?xml version='1.0' encoding='utf-8'?>"
+ "<entry xmlns='http://www.w3.org/2005/Atom'"
+ " xmlns:cmis='http://docs.oasis-open.org/ns/cmis/core/200908/'"
+ " xmlns:cmisra='http://docs.oasis-open.org/ns/cmis/restatom/200908/'>"
+ "<cmisra:object><cmis:properties>"
+ "<cmis:propertyString queryName='cmis:name' localName='cmis:name' propertyDefinitionId='cmis:name'>"
+ "<cmis:value>newName</cmis:value>"
+ "</cmis:propertyString>"
+ "</cmis:properties></cmisra:object>"
+ "</entry>";
PutMethod put = new PutMethod(url);
RequestEntity entity = new StringRequestEntity(atomDoc, "text/xml", "utf-8");
put.setRequestEntity(entity);
try {
int result = client.executeMethod(put);
final String strResponse = put.getResponseBodyAsString();
} finally {
put.releaseConnection();
}
Set content stream:
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
String url = "http://localhost:8080/rest/private/cmisatom/";
url += repository;
url += "/file/";
url += obj_id;
HttpClient client = new HttpClient();
client.getHttpConnectionManager().
getParams().setConnectionTimeout(10000);
PostMethod post = new PostMethod(url);
RequestEntity entity = new InputStreamRequestEntity(inputStream, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
try {
int result = client.executeMethod(post);
final String strResponse = post.getResponseBodyAsString();
} finally {
post.releaseConnection();
}
Update properties:
var url = "http://localhost:8080/rest/private/cmisatom/";
url += repository;
url += "/object/";
url += obj_id;
//constructing document
String atomDoc = "<?xml version='1.0' encoding='utf-8'?>";
atomDoc += "<entry xmlns='http://www.w3.org/2005/Atom'";
atomDoc += " xmlns:cmis='http://docs.oasis-open.org/ns/cmis/core/200908/'";
atomDoc += " xmlns:cmisra='http://docs.oasis-open.org/ns/cmis/restatom/200908/'>";
atomDoc += "<cmisra:object><cmis:properties>";
atomDoc += "<cmis:propertyString queryName='cmis:name' localName='cmis:name' propertyDefinitionId='cmis:name'>";
atomDoc += "<cmis:value>newName</cmis:value>";
atomDoc += "</cmis:propertyString>";
atomDoc += "</cmis:properties></cmisra:object></entry>";
var params = {};
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.PUT;
params[gadgets.io.RequestParameters.POST_DATA] = atomDoc;
gadgets.io.makeRequest(url, handler, params);
Set content stream:
var url = "http://localhost:8080/rest/private/cmisatom/";
url += repository;
url += "/file/";
url += obj_id;
var params = {};
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
params[gadgets.io.RequestParameters.CONTENT_TYPE] = "multipart/form-data";
params[gadgets.io.RequestParameters.POST_DATA] = contentStream;
gadgets.io.makeRequest(url, handler, params);