cancel
Showing results for 
Search instead for 
Did you mean: 

Use of CMIS web scripts

lakshya
Champ in-the-making
Champ in-the-making
I got the link for using CMIS web script.
I want to create document / folder by hitting the URL provided by
http://wiki.alfresco.com/wiki/CMIS_Web_Scripts_Reference#Create_folder_or_document_.28createDocument...

The URL provided for it is
http://localhost:8080/alfresco/service/api/path/%7Bstore_type%7D/%7Bstore_id%7D/%7Bid%7D/descendants

How can i pass parameters like "new folder name", "location", etc in this url.

Because on hit of this url I just get the list of children  of Company Home.

Can anyone answer it quickly.. . .
23 REPLIES 23

lakshya
Champ in-the-making
Champ in-the-making
Sorry,
Please read these two lines
String filePath = "C:/temp/test.txt";
String contentType = "text/plain";

as

String filePath = "C:/temp/test.xml";
String contentType = "application/atom+xml";


My xml file is :
       <?xml version='1.0' encoding='utf-8'?>
        <entry xmlns='http://www.w3.org/2005/Atom' xmlns:cmis='http://www.cmis.org/2008/05'>
         <title>Mytitle</title>
         <summary>Mysummary</summary>
         <cmisSmiley Surprisedbject>
          <cmisSmiley Tongueroperties>
           <cmisSmiley TongueropertyString cmis:name='ObjectTypeId'><cmis:value>document</cmis:value></cmisSmiley TongueropertyString>
          </cmisSmiley Tongueroperties>
         </cmisSmiley Surprisedbject>
       </entry>


Can u now give some pointer, I am still getting same error.

I am doing this from the reference of
http://wiki.alfresco.com/wiki/CMIS_Web_Scripts_Reference#Create_folder_or_document_.28createDocument...


I am using Alfresco Labs 3 B Release.

mikeh
Star Contributor
Star Contributor
/alfresco/service/api/node/{store_type}/{store_id}/{id}/descendants

"Company Home" is not an {id}. You need the GUID part of the node reference in it's place.

Mike

lakshya
Champ in-the-making
Champ in-the-making
We can use either
http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/7018a7e3-d366-4389-84c6-bd79d793c270/children/

or
http://localhost:8080/alfresco/service/api/path/workspace/SpacesStore/Company%20Home/children/


both are correct ways . .

But now, as per your suggestion I am using
http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/7018a7e3-d366-4389-84c6-bd79d793c270/children/

Still no hopes Smiley Sad

lakshya
Champ in-the-making
Champ in-the-making
Can anyone give me one example code for calling
POST /alfresco/service/api/node/{store_type}/{store_id}/{id}/descendants

RestApi directly through HttpClient

I am doing it in this way :
String URL = "http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/7018a7e3-d366-4389-84c6-bd79d7...";
  PostMethod post = new PostMethod(URL);
  NameValuePair[] data = {  new NameValuePair("typeId", "folder")    };
  post.setRequestBody(data);
int statusCode1 = client.executeMethod(post);

It gives me 400 error code i.e. Bad request

An when I give  (/ at last of URL)
String URL = "http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/7018a7e3-d366-4389-84c6-bd79d7.../";

It gives 405 - Method Not Allowed


I am using  alfresco  Lab 3 (http://wiki.alfresco.com/wiki/Alfresco_Labs_3#Alfresco_Draft_CMIS_Implementation)

RestApi bindings  - http://wiki.alfresco.com/wiki/CMIS#REST_API_Binding


and call to restApi is taken from http://wiki.alfresco.com/wiki/CMIS_Web_Scripts_Reference#Create_folder_or_document_.28createDocument...

Am i not taking correct version or something is missing in the code ?

I am not able to call all the POST methods. But GET and DELETE from the same link is working properly.

I would be great if someone will share the code snippet to call cmis RestApi fo ALfresco.

Thanks in advance.

lakshya
Champ in-the-making
Champ in-the-making
Please Please Please  . . .
I am stuck from long time  :<

can anyone reply with code snippet . ..

lakshya
Champ in-the-making
Champ in-the-making
Can anyone help me out

lakshya
Champ in-the-making
Champ in-the-making

jpotts
World-Class Innovator
World-Class Innovator
I know this is an old thread but I thought it might help someone else looking for the answer. If you go look at the "children" web scripts, which are located in $TOMCAT_HOME/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository/store, you'll notice there are two controllers. One is called children.post.js. The other is called children.post.atom.js. The web script framework is selecting the controller based on the mime type of the content being posted. If you look at the children.post.js, you'll see that it immediately returns an error 400 whereas the children.post.atom.js actually does the work of creating a new node based on the ATOM entry.

Long story short: Change the mime type of the data you are posting to "application/atom+xml" and it should work.

ianjamesmorgan
Champ in-the-making
Champ in-the-making
I thinks it because your content type is still not correct

should be "application/atom+xml;type=entry"

see this alternative post on the forum - http://forums.alfresco.com/en/viewtopic.php?f=36&t=15438

It worked for me - full Java code is:

import java.io.File;
import java.io.FileInputStream;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.bouncycastle.util.encoders.Base64;


public class PostToAlfresco {

  public static void main (String[] args) {
    
     try {
         String url = "http://localhost:8080/alfresco/service/api/path/workspace/SpacesStore/Company%20Home/children";
         String creds = "admin" + ":" + "admin";
         HttpClient httpClient = new HttpClient();
         PostMethod method = new PostMethod(url);
         method.setRequestHeader("Authorization", "Basic "
               + new String(Base64.encode(creds.getBytes())));

         String filePath = "D:\\devtools\\AlfrescoSDK\\samples\\FirstWebServiceClient\\source\\testDoc.xml";
         String contentType = "application/atom+xml;type=entry";
         File upload = new File(filePath);
         method.setRequestHeader("name", upload.getName());
         method.setRequestHeader("Content-type", contentType);
         method.setRequestBody(new FileInputStream(upload));
         httpClient.executeMethod(method);
         System.out.println(method.getResponseBodyAsString());
      } catch (Exception e) {
         e.printStackTrace();
      }
}
}

the file is

<?xml version='1.0' encoding='utf-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:cmis='http://www.cmis.org/2008/05'>
<title>REST doc example2</title>
<summary>Summary</summary>
<content type="text">this is some data</content>
<cmisSmiley Surprisedbject>
<cmisSmiley Tongueroperties>
<cmisSmiley TongueropertyString cmis:name='ObjectTypeId'><cmis:value>document</cmis:value></cmisSmiley TongueropertyString>

</cmisSmiley Tongueroperties>
</cmisSmiley Surprisedbject>
</entry>

erictice
Champ in-the-making
Champ in-the-making
Did anyone answer this for you?  If not let me know.