As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
if (!json.isNull("lastName")) { person.properties["lastName"] = json.get("lastName"); }
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 }
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()); }
JSONObject person = new JSONObject(); person.put("lastName","NEW_LAST_NAME"); put.setRequestEntity(new StringRequestEntity(person.toString(),"application/json", null));