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.
HttpClient client = new HttpClient(); client.getState().setCredentials( new AuthScope("localhost", 8080, "Alfresco"), new UsernamePasswordCredentials("admin", "admin")); String uid = "51920ee3-14c0-4477-a637-ab82a0d8df70"; String apiurl = "http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/'+uid+'/comments"; PostMethod post = new PostMethod(apiurl); try { JSONObject site = new JSONObject(); site.put("title", "this is a test title"); site.put("content", "this is a test content"); System.out.println(site.toString()); post.setDoAuthentication(true); post.setRequestHeader("Content-Type", "application/json"); post.setRequestEntity(new StringRequestEntity(site.toString(), "application/json", "UTF-8")); int status = client.executeMethod(post); if (status != HttpStatus.SC_OK) { System.err.println("Method failed: " + post.getStatusLine()); } String resultString = post.getResponseBodyAsString(); System.out.println(resultString); } catch (Exception e) { e.printStackTrace(); } finally { post.releaseConnection(); }
String apiurl = "http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/'+uid+'/comments?alf_ticket=TICKET_699c56c2b5149a77b2c6ecd47cdfc5998444a77d";
public String login() { String ticket = null; HttpClient client = new HttpClient(); String apiurl = "http://localhost:8080/alfresco/service/api/login"; PostMethod post = new PostMethod(apiurl); try { JSONObject login = new JSONObject(); login.put("username", "admin"); login.put("password", "admin"); //System.out.println(login.toString()); post.setDoAuthentication(true); post.setRequestHeader("Content-Type", "application/json"); post.setRequestEntity(new StringRequestEntity(login.toString(), "application/json", "UTF-8")); int status = client.executeMethod(post); if (status != HttpStatus.SC_OK) { System.err.println("Method failed: " + post.getStatusLine()); } String responseData = post.getResponseBodyAsString(); System.out.println(responseData); JSONObject response = new JSONObject(responseData); ticket = response.getJSONObject("data").getString("ticket"); } catch (Exception e) { e.printStackTrace(); } finally { post.releaseConnection(); } return ticket; } public void addCommment(String ticket){ HttpClient client = new HttpClient(); /* client.getState().setCredentials( new AuthScope("localhost", 8080, "Alfresco"), new UsernamePasswordCredentials("admin", "admin"));*/ String uid = "17372462-1062-40ea-a470-6c27ac395d3e"; String apiurl = "http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/" + uid + "/comments"+"?alf_ticket="+ticket; PostMethod post = new PostMethod(apiurl); try { JSONObject comment = new JSONObject(); comment.put("title", "this is a test title"); comment.put("content", "this is a test content"); System.out.println(comment.toString()); post.setDoAuthentication(true); post.setRequestHeader("Content-Type", "application/json"); post.setRequestEntity(new StringRequestEntity(comment.toString(), "application/json", "UTF-8")); int status = client.executeMethod(post); if (status != HttpStatus.SC_OK) { System.err.println("Method failed: " + post.getStatusLine()); } String resultString = post.getResponseBodyAsString(); System.out.println(resultString); } catch (Exception e) { e.printStackTrace(); } finally { post.releaseConnection(); } } public static void main(String[] args) { LoginAddCommentTest t = new LoginAddCommentTest(); String ticket = t.login(); t.addCommment(ticket); }