09-24-2013 08:39 AM
09-24-2013 11:15 AM
package com.kayne.cmis.webscript;
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.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.json.JSONObject;
public class CreateSiteTest {
public static void main(String[] args) {
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("localhost", 8080, "Alfresco"),
new UsernamePasswordCredentials("admin", "admin"));
String apiurl = "http://localhost:8080/alfresco/service/api/sites";
PostMethod post = new PostMethod(apiurl);
try {
JSONObject site = new JSONObject();
site.put("shortName", "newsite");
site.put("sitePreset", "site-dashboard");
site.put("title", "newsite");
site.put("description", "newsite");
site.put("visibility", "PUBLIC");
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();
}
}
}
09-25-2013 02:21 AM
09-26-2013 07:41 AM
02-05-2015 04:53 AM
09-26-2013 08:10 PM
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.