AnsweredAssumed Answered

Posting a folder results in a document without content

Question asked by mgagnon on Jan 11, 2010
Latest reply on Jul 5, 2012 by jpotts
I've seen a few posts with this same problem.  I'm trying to create a folder but instead it creates a document.

In the related posts they solved their problem by changing the namespace in the xml
xmlns:cmis='http://www.cmis.org/2008/05'>

I tried that but no-go.  Any help would be appreciated.


Here is my post code
——————————-

    //———————————————–
    public void PostInfo()
    {
       
        StringWriter sw = new StringWriter();
        PrintWriter  pw = new PrintWriter(sw);
   
       try
       {
          String xmlData = "<?xml version='1.0' encoding='utf-8'?>"+
          "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:app='http://www.w3.org/2007/app' xmlns:cmis='http://docs.oasis-open.org/ns/cmis/core/200901' xmlns:alf='http://www.alfresco.org'>"+
          "<title>445_123</title>"+
          "<summary>445_123</summary>"+
          "<cmis:object>"+
          "<cmis:properties>"+
          "<cmis:propertyId cmis:name='ObjectTypeId'><cmis:value>folder</cmis:value></cmis:propertyId>"+
          "</cmis:properties>"+
          "</cmis:object>"+
          "</entry>";     
       
          String href = "http://cmis.alfresco.com:80/service/cmis/s/workspace:SpacesStore/i/998e23c5-570f-4fc8-a86a-e895e019c048/children";
         
       
          URL url = new URL (href);   
          String userPassword = "admin:admin";   
           // Encode String
            String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
           // Need to work with URLConnection to set request property
            URLConnection uc = url.openConnection();
            uc.setDoOutput(true);
              uc.setDoInput(true); //Only if you expect to read a response…
           //   uc.setUseCaches(false); //Highly recommended…
            //uc.setRequestProperty("Content-Type", "application/atom+xml");
              uc.setRequestProperty("Content-Type", "application/atom+xml;type=entry");
            uc.setRequestProperty  ("Authorization", "Basic " + encoding);
           
            OutputStreamWriter out = new OutputStreamWriter(uc.getOutputStream());
            out.write(xmlData);
            out.close();
           
            BufferedReader in = new BufferedReader(
                  new InputStreamReader(
                        uc.getInputStream()));
           
            String decodedString;
           
            while ((decodedString = in.readLine()) != null) {
               System.out.println(decodedString);
            }
            in.close();
      
        }
          catch (MalformedURLException e)
          {
          pw.println ("Invalid URL");
        }
          catch (Exception e)
        {
          System.out.println ("Error reading URL"+e.getMessage());       
        }
          
    }

Outcomes