cancel
Showing results for 
Search instead for 
Did you mean: 

create new folder .. CMIS does not work

fahad
Champ in-the-making
Champ in-the-making
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" +
         "<cmisSmiley Surprisedbject>\n"+
         "<cmisSmiley Tongueroperties>\n" +
         "<cmisSmiley TongueropertyString cmis:name='ObjectTypeId'>\n" +
         "<cmis:value>folder</cmis:value>\n" +
         "</cmisSmiley TongueropertyString>\n" +
         "</cmisSmiley Tongueroperties>\n" +
         "</cmisSmiley Surprisedbject>\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");
   }
1 REPLY 1

jpotts
World-Class Innovator
World-Class Innovator
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