create new folder .. CMIS does not work

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2014 02:34 PM
Hi everyone,
I want to create a new folder inside my site vie CMIS but it does not work. Error is 404, and i guess parent folder does not found according to its description in the documentation. But it exists
here is my code, can anyone help me to solve this error.
public static void makeDir(String name) throws Exception {
long start = System.currentTimeMillis();
String host = "159.84.130.209";
int port = 8080; //Integer.parseInt("8080");
String username = "Admin";
String password = "admin"; //some comment
String parentFolder = "FITMAN" ; ///"Company%20Home";
String site = "Mysite"; // site exists
String container= "LMREALISATIONS"; //this is the first folder that exists in the site
String folderName = "sales3";
String description = "sales space3";
String url = "http://159.84.130.209/alfresco/s/api/site/folder/%7B'+site+'%7D/%7B'+container+'%7D";
url = url+ "?alf_ticket=TICKET_85ced5cfa6760a9eb02ef5c17b854de1ee84cf49";
String contentType = "application/atom+xml;type=entry";
String xml =
"<?xml version='1.0' encoding='utf-8'?>\n" +
"<entry xmlns='http://www.w3.org/2005/Atom' xmlns:cmis='http://www.cmis.org/2008/05'>\n" +
"<title>" + folderName + "</title>\n" +
"<summary>" + description + "</summary>\n" +
"<cmis
bject>\n"+
"<cmis
roperties>\n" +
"<cmis
ropertyString cmis:name='ObjectTypeId'>\n" +
"<cmis:value>folder</cmis:value>\n" +
"</cmis
ropertyString>\n" +
"</cmis
roperties>\n" +
"</cmis
bject>\n" +
"</entry>\n";
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(host, port),
new UsernamePasswordCredentials(username, password));
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-type", contentType);
StringEntity requestEntity = new StringEntity(xml, "UTF-8");
httppost.setEntity(requestEntity);
System.out.println("executing request" + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println("—————————————-");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content type: " + entity.getContentType());
long contentLength = entity.getContentLength();
System.out.println("Response content length: "
+ entity.getContentLength());
if (contentLength > 0) {
byte [] b = new byte[(int) contentLength];
entity.getContent().read(b);
System.out.println("Response content: " + new String(b));
}
entity.writeTo(System.out);
}
httpclient.getConnectionManager().shutdown();
long end = System.currentTimeMillis();
System.out.println("Time spend: " + (end-start) + "ms");
}
I want to create a new folder inside my site vie CMIS but it does not work. Error is 404, and i guess parent folder does not found according to its description in the documentation. But it exists
here is my code, can anyone help me to solve this error.
public static void makeDir(String name) throws Exception {
long start = System.currentTimeMillis();
String host = "159.84.130.209";
int port = 8080; //Integer.parseInt("8080");
String username = "Admin";
String password = "admin"; //some comment
String parentFolder = "FITMAN" ; ///"Company%20Home";
String site = "Mysite"; // site exists
String container= "LMREALISATIONS"; //this is the first folder that exists in the site
String folderName = "sales3";
String description = "sales space3";
String url = "http://159.84.130.209/alfresco/s/api/site/folder/%7B'+site+'%7D/%7B'+container+'%7D";
url = url+ "?alf_ticket=TICKET_85ced5cfa6760a9eb02ef5c17b854de1ee84cf49";
String contentType = "application/atom+xml;type=entry";
String xml =
"<?xml version='1.0' encoding='utf-8'?>\n" +
"<entry xmlns='http://www.w3.org/2005/Atom' xmlns:cmis='http://www.cmis.org/2008/05'>\n" +
"<title>" + folderName + "</title>\n" +
"<summary>" + description + "</summary>\n" +
"<cmis

"<cmis

"<cmis

"<cmis:value>folder</cmis:value>\n" +
"</cmis

"</cmis

"</cmis

"</entry>\n";
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(host, port),
new UsernamePasswordCredentials(username, password));
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-type", contentType);
StringEntity requestEntity = new StringEntity(xml, "UTF-8");
httppost.setEntity(requestEntity);
System.out.println("executing request" + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println("—————————————-");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content type: " + entity.getContentType());
long contentLength = entity.getContentLength();
System.out.println("Response content length: "
+ entity.getContentLength());
if (contentLength > 0) {
byte [] b = new byte[(int) contentLength];
entity.getContent().read(b);
System.out.println("Response content: " + new String(b));
}
entity.writeTo(System.out);
}
httpclient.getConnectionManager().shutdown();
long end = System.currentTimeMillis();
System.out.println("Time spend: " + (end-start) + "ms");
}
Labels:
- Labels:
-
Archive
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2015 09:42 PM
You've tagged this post as "CMIS" but you aren't using CMIS at all. I would strongly recommend that you grab the OpenCMIS Java client from Apache Chemistry and use that to create your folder. It will save you a lot of work.
Jeff
Jeff
