08-27-2013 09:18 AM
08-28-2013 03:05 AM
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();
}
08-28-2013 06:06 AM
String apiurl = "http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/'+uid+'/comments?alf_ticket=TI...";
08-28-2013 07:10 AM
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);
}
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.