AnsweredAssumed Answered

Alfresco Access via JCR

Question asked by sisao on Oct 10, 2008
Hello folks,
getting myself into random issues while trying to interface Alfresco with my protocol via the JCR Api as it 'll be really useful.
I've got Alfresco 30-day trial (tomcat bundle + WCM) installed successfully on a mac machine, properly edited custom-* files in /shared/…/extensions/ path.
i'm using a remote oracle DB without any problem, i can use all alfresco functionalities by the web interface.
I'm not familiar with JCR, i'm trying to test some initial simple routine using the Eclipse IDE.
I've imported in my project the whole /WEB-INF/classes/alfresco folder with the application-context.xml file…and customized the repository.properties and hibernate.cfg files….in the same way i did for the custom-*.

This is the session sample i'm testing:

import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;



public class AlfrescoLogin {


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

      ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");

      Repository repository = (Repository)context.getBean("JCR.Repository");

       //LOGIN SESSION STARTING

      Session session = repository.login(new SimpleCredentials("admin","admin".toCharArray()));
      
      try{
         Node root = session.getRootNode();
         System.out.println("Root node: path=" + root.getPath() + ", type=" + root.getPrimaryNodeType().getName());

      }  finally{
         System.exit(0);
         }
      
   }

}

It works correctly if use a copy of the alf_data folder placed somewhere else than the default /alfresco/alf_data location, i get a Permission Denied problem in lucene-indexes folder if i leave it in the default location (may be caused by a wrong permission rule in oracle).
That's not a big issue to me and i can avoid this but that's something unclear to me in the way JCR works.
Am i running a second alfresco instance compiling the code above, apart from the main instance that i normally run with "alfresco.sh start"? In fact, it does run well even if i dont start alfresco…and the execution time is quite similar to the time alfresco needs to initialize the repository as i guess it has to explode all the xml files provided in the build path.
If so, howto get a session and work with it (writing to and reading from the repository) using an already running alfresco installation?

Regards,
Francesco.

Outcomes