cancel
Showing results for 
Search instead for 
Did you mean: 

Access Alfresco Repository using JCR and Spring APIs

rishidx
Champ in-the-making
Champ in-the-making
Hi All,

I am new to Alfresco and only want to connect to Alfresco Repository. I am following this link:
http://wiki.alfresco.com/wiki/Introducing_the_Alfresco_Java_Content_Repository_API

I am using Eclipse Galileo for development and created a Java project on it. I have included every JAR that were available in Alfresco SDK. Initially, When I ran the code


System.out.println("Start");
ApplicationContext appctx = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
System.out.println(" ..Done");


I got error:

<em>org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [alfresco/application-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [alfresco/application-context.xml] cannot be opened because it does not exist </em>

for which I added <Alfresco-Tomcat-Folder>/WEB-INF/classes in Projects's classpath in Eclipse and this error got resolved. But now, I am getting a new Error:

<em>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'propertyValueCache' defined in class path resource [alfresco/cache-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'boolean' for property 'disableSharedCache'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value [${system.cache.disableImmutableSharedCaches}]
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
   at testPackage.Program1.main(Program1.java:19)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'boolean' for property 'disableSharedCache'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value [${system.cache.disableImmutableSharedCaches}]
   at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:467)
   at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:499)
   at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:493)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
   … 11 more
Caused by: java.lang.IllegalArgumentException: Invalid boolean value [${system.cache.disableImmutableSharedCaches}]
   at org.springframework.beans.propertyeditors.CustomBooleanEditor.setAsText(CustomBooleanEditor.java:124)
   at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:416)
   at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:388)
   at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:157)
   at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:447)
   … 17 more
</em>

I have also tried the same with Alfresco SDK by importing them to Eclipse Galileo but still getting the same error.
I am working to remove this error from past 3-4 days. Can any one please help me out.

Thanks
Rishi DX
3 REPLIES 3

mitpatoliya
Star Collaborator
Star Collaborator
which SDK example you are trying to run?
For most of the examples you need to make sure you are point to correct alf_data folder of your alfresco in alfresco-global.properties file.
If you read the instructions most of the errors you will be able to solve.
Also I hope your alfresco instance is working fine.

rishidx
Champ in-the-making
Champ in-the-making
Thanks for reply and sorry for my late reply. Alfresco version is working fine.

What do you mean by alfresco-global.properties?

I have written a simple java application in Eclipse Helios and added all JARs available in Alfresco SDK.
then, I have added C:/Alfresco/…/alfresco/application-context.xml in Eclipse classpath as well as system's classpath.
then i have ran the below code:



ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
       
        // Retrieve Repository
        Repository repository = (Repository)context.getBean("JCR.Repository");

        // Login to workspace
        // Note: Default workspace is the one used by Alfresco Web Client which contains all the Spaces
        //       and their documents
        Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

        try
        {
            // Retrieve Company Home
            Node root = session.getRootNode();
            Node companyHome = root.getNode("app:company_home");
           
            // Iterator through children of Company Home
            NodeIterator iterator = companyHome.getNodes();
            while(iterator.hasNext())
            {
                Node child = iterator.nextNode();
                System.out.println(child.getName());

                PropertyIterator propIterator = child.getProperties();
                while(propIterator.hasNext())
                {
                    Property prop = propIterator.nextProperty();
                    if (!prop.getDefinition().isMultiple())
                    {
                        System.out.println(" " + prop.getName() + " = " + prop.getString());
                    }
                }
            }
        }
        finally
        {
            session.logout();
            System.exit(0);
        }



This gave the exception which i mentioned in my above post.

When will the code access global properties file??? Am i missing something???

Thanks and Regards
Rishi

ganeshnaidu
Champ in-the-making
Champ in-the-making
If you have solved the issue, please let me know how to proceed further, even I'm facing the same error from one week