cancel
Showing results for 
Search instead for 
Did you mean: 

cmis

sunitha
Champ in-the-making
Champ in-the-making
Hi ..

I am new to alfresco.I am trying to connect to the alfresco repository by using cmis api.
My program showing some errors at the atompub line..
could you people help me in regarding this area.
my source code..



import java.util.HashMap;
import java.util.Map;

import javax.xml.ws.BindingType;

import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;


public class Third {
   
   public static void main(String arg[]) throws Exception{
      
      
      Map<String, String> parameter = new HashMap<String, String>();

      // Set the user credentials
      parameter.put(SessionParameter.USER, "admin");
      parameter.put(SessionParameter.PASSWORD, "admin");

      // Specify the connection settings
      parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8070/alfresco/service/cmis");
      parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

      // Set the alfresco object factory
      parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

      // Create a session
      SessionFactory factory = SessionFactoryImpl.newInstance();
      Session session = factory.getRepositories(parameter).get(0).createSession();
       System.out.println("Connected to repository:");
   }

}



Thanks,
Sunitha..
22 REPLIES 22

muralidharand
Star Contributor
Star Contributor
Hi Sunitha,
Your import statement is wrong.
Use this
 import org.apache.chemistry.opencmis.commons.enums.BindingType; 


instead of this
 import javax.xml.ws.BindingType; 

Hi murali..
i import the statement..it doesn't showing any error messages in my ecclipse..
but i am trying to run my program it showing some exception ..i think it may be related any jar files which i have to add to the lib folder..
have a look at my exception and give me a solution..




Exception in thread "main" java.lang.IllegalArgumentException: Unable to create object factory: java.lang.ClassNotFoundException: org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.createObjectFactory(SessionImpl.java:207)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.<init>(SessionImpl.java:153)
   at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.createSession(SessionFactoryImpl.java:89)
   at org.apache.chemistry.opencmis.client.runtime.repository.RepositoryImpl.createSession(RepositoryImpl.java:62)
   at Third.main(Third.java:34)
Caused by: java.lang.ClassNotFoundException: org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl
   at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
   at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Class.java:186)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.createObjectFactory(SessionImpl.java:195)
   … 4 more



Thanks..

Hi Sunitha,
Can you add "commons-logging-1.1.1.jar"  in your classpath. It will be there in the alfresco SDK itself.
 C:\alfresco_sdk_4_1\lib\server\dependencies\commons\commons-logging-1.1.1.jar

The below code is working for me.

<java>

import java.util.HashMap;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;


public class Third {

   
   private static final String ALFRSCO_ATOMPUB_URL = "http://localhost:8080/alfresco/service/cmis";
   private static final String REPOSITORY_ID = "4a062557-7e96-4d09-b928-6274762e2d22";

   
   public static void main(String arg[]) throws Exception{


      Map<String, String> parameter = new HashMap<String, String>();
      
      // Set the user credentials
      parameter.put(SessionParameter.USER, "admin");
      parameter.put(SessionParameter.PASSWORD, "admin");

      // Specify the connection settings
      parameter.put(SessionParameter.ATOMPUB_URL, ALFRSCO_ATOMPUB_URL);
      parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
 
      //Add repository Id
      parameter.put(SessionParameter.REPOSITORY_ID, REPOSITORY_ID);
      // Create a session
      SessionFactory factory = SessionFactoryImpl.newInstance();
      Session session = factory.getRepositories(parameter).get(0).createSession();
      System.out.println("Connected to repository:" + session.getRepositoryInfo().getName());
      
   }

}

</java>

Hi…

how can i get my repository id…

Thanks…

Hi Sunitha,
Please check the below url.
http://localhost:8080/alfresco/service/cmis/index.html

Once this is page is loaded, please click "CMIS Repository Information" to know your repository ID.

Hope this helps you !

mtw999
Champ in-the-making
Champ in-the-making
Hello Sunitha,

What errors are you seeing? This code runs fine for me using my port & host.

Mike

sunitha
Champ in-the-making
Champ in-the-making
Hi..
Thanks for your reply..
where is your code …i didn't see your code..
can you post your code..

Thanks..

mtw999
Champ in-the-making
Champ in-the-making
Yes Murali, I failed to mention I had the import statement you were referring to because ATOMPUB.value() would not resolve in my code. I'm working in Eclipse so I incorrectly assumed Sunitha was only seeing issues at runtime

Mike

sunitha
Champ in-the-making
Champ in-the-making
Hi..

I am new to alfresco..when i try to create a folder by using cmis,but it is not creating..my code was compiling successfully,folder is not creating..
could you help me in this regard..
my code is…



import java.util.HashMap;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.ItemIterable;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.client.api.*;

public class First{
   
   private static final String ALFRSCO_ATOMPUB_URL = "http://localhost:8070/alfresco/service/cmis";
   //private static final Folder root = null;
   //private static Folder root;

   public static void main(String arg[]){
      
      
      Map<String, String> parameter = new HashMap<String, String>();
      
      // Set the user credentials
      parameter.put(SessionParameter.USER, "admin");
      parameter.put(SessionParameter.PASSWORD, "admin");

      // Specify the connection settings
      parameter.put(SessionParameter.ATOMPUB_URL, ALFRSCO_ATOMPUB_URL);
      parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

      //Add repository Id
      //parameter.put(SessionParameter.REPOSITORY_ID, REPOSITORY_ID);
      // Create a session
      SessionFactory factory = SessionFactoryImpl.newInstance();
      Session session = factory.getRepositories(parameter).get(0).createSession();
      System.out.println("Connected to repository:" + session.getRepositoryInfo().getName());
      System.out.println("Repository id:"+session.getRepositoryInfo().getId());
      
      
      System.out.println("Creating 'SAMPLE1' in the root folder");
      Map<String, String> newFolderProps = new HashMap<String, String>();
      newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
      newFolderProps.put(PropertyIds.NAME, "SAMPLE1");
      System.out.println("folder is creating");

   
      Folder newFolder = root.createFolder(newFolderProps);
      System.out.println("success:"+newFolder);
      }
}



Thanks,
Sunitha..