11-04-2010 05:47 AM
if (!json.isNull("lastName"))
{
person.properties["lastName"] = json.get("lastName");
}
so if I want to call that script to change the lastname…How would I call the webscript?11-04-2010 07:10 AM
11-04-2010 12:13 PM
HttpClient client = new HttpClient();
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
client.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
GetMethod get = new GetMethod("http://localhost:8080/alfresco/service/api/people/Jhon");
get.setDoAuthentication(true);
try {
// execute the GET
int status = client.executeMethod(get);
// print the status and response
System.out.println(status + "\n" +
get.getResponseBodyAsString());
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// release any connection resources used by the method
get.releaseConnection();
}
HttpClient client = new HttpClient();
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
client.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
PutMethod put = new PutMethod("http://localhost:8080/alfresco/service/api/people/Jhon");
// put.addRequestHeader(new Header("lastName", "newLastName"));
put.setDoAuthentication(true);
try {
// execute the PUT
int status = client.executeMethod(put);
// print the status and response
System.out.println(status + "\n" +
put.getResponseBodyAsString());
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// release any connection resources used by the method
put.releaseConnection();
}
200
{
"url": "\/alfresco\/service\/api\/person\/admin",
"userName": "admin",
"enabled": true,
"firstName": "Administrator",
"lastName": "",
"jobtitle": null,
"organization": null,
"location": null,
"telephone": null,
"mobile": null,
"email": "admin@alfresco.com",
"companyaddress1": null,
"companyaddress2": null,
"companyaddress3": null,
"companypostcode": null,
"companytelephone": null,
"companyfax": null,
"companyemail": null,
"skype": null,
"instantmsg": null,
"quota": -1,
"sizeCurrent": 12760934,
"persondescription": null
}
11-05-2010 05:15 AM
private JSONObject updatePerson(String userName, String title, String firstName, String lastName,
String organisation, String jobTitle, String email, String bio, String avatarUrl, int expectedStatus)
throws Exception
{
// switch to admin user to create a person
String currentUser = this.authenticationComponent.getCurrentUserName();
String adminUser = this.authenticationComponent.getSystemUserName();
this.authenticationComponent.setCurrentUser(adminUser);
JSONObject person = new JSONObject();
person.put("userName", userName);
person.put("title", title);
person.put("firstName", firstName);
person.put("lastName", lastName);
person.put("organisation", organisation);
person.put("jobtitle", jobTitle);
person.put("email", email);
Response response = sendRequest(new PutRequest(URL_PEOPLE + "/" + userName, person.toString(), "application/json"), expectedStatus);
// switch back to non-admin user
this.authenticationComponent.setCurrentUser(currentUser);
return new JSONObject(response.getContentAsString());
}
11-09-2010 06:44 AM
JSONObject person = new JSONObject();
person.put("lastName","NEW_LAST_NAME");
put.setRequestEntity(new StringRequestEntity(person.toString(),"application/json", null));
then execute the method and finally it works!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.