05-06-2014 01:26 AM
/alfresco/service/api/blog/site/{site}/{container}/posts
{
"status": {
"code": 500,
"name": "Internal Error",
"description": "An error inside the HTTP server which prevented it from fulfilling the request."
},
"message": "04060020 Wrapped Exception (with status template): null",
"exception": "org.springframework.extensions.webscripts.WebScriptException - 04060020 Wrapped Exception (with status template): null",
"callstack": [
"",
"java.lang.NullPointerException",
"org.alfresco.repo.web.scripts.blogs.posts.BlogPostsPost.parsePostParams(BlogPostsPost.java:95)",
"org.alfresco.repo.web.scripts.blogs.posts.BlogPostsPost.executeImpl(BlogPostsPost.java:72)",
"org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript.executeImpl(AbstractBlogWebScript.java:294)",
"org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)",
"org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:429)",
"org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:450)",
"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:491)",
"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:529)",
"org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:341)",
"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)",
"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)",
"org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)",
"javax.servlet.http.HttpServlet.service(HttpServlet.java:727)",
05-06-2014 02:32 AM
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("localhost", 8080, "Alfresco"),
new UsernamePasswordCredentials("admin", "admin"));
String site = "kaynezhang";
String container = "blog";
String apiurl = "http://localhost:8080/alfresco/service/api/blog/site/'+ site + "/" + container + "/posts";
PostMethod post = new PostMethod(apiurl);
try {
JSONObject blog = new JSONObject();
blog.put("title", "title");
blog.put("content", "content");
JSONArray arr = new JSONArray();
arr.put("tag1");
arr.put("tag2");
blog.put("tags", arr);
blog.put("draft", false);
post.setDoAuthentication(true);
post.setRequestHeader("Content-Type", "application/json");// make sure set content type to application/json
post.setRequestEntity(new StringRequestEntity(blog.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();
}
05-06-2014 02:37 AM
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.