11-07-2013 04:45 PM
11-08-2013 12:55 AM
11-08-2013 11:17 AM
11-09-2013 05:25 AM
package com.kayne.local.java.webscripts;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.json.JSONObject;
public class UpdatePersonTest {
public static void main(String[] args) {
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("localhost", 8080, "Alfresco"),
new UsernamePasswordCredentials("admin", "admin"));
String userName = "kayne";
String apiurl = "http://localhost:8080/alfresco/service/api/people/'+userName;
PutMethod put = new PutMethod(apiurl);
try {
JSONObject person = new JSONObject();
person.put("firstName", "kayne");
person.put("lastName", "zhang");
person.put("mobile", "12343424342");
person.put("location", "N.A");
System.out.println(person.toString());
put.setDoAuthentication(true);
put.setRequestHeader("Content-Type", "application/json");
put.setRequestEntity(new StringRequestEntity(person.toString(),
"application/json", "UTF-8"));
int status = client.executeMethod(put);
if (status != HttpStatus.SC_OK) {
System.err.println("Method failed: " + put.getStatusLine());
}
String resultString = put.getResponseBodyAsString();
System.out.println(resultString);
} catch (Exception e) {
e.printStackTrace();
} finally {
put.releaseConnection();
}
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.