AnsweredAssumed Answered

Step by Step - Access Alfresco JSR 170 From another Portlet

Question asked by trupoet on Sep 14, 2006
Latest reply on Sep 15, 2006 by trupoet
So I've successfully deployed JBoss / JBoss Portal and Alfresco.

Now I'm trying to write a portlet that simply accesses the Alfresco repository to display content.

I've read some forum threads and wiki pages about setting it up as a web service and looked into some of the SDK code and tried to implement some of it via a portlet unsuccessfully.

I guess I'm just looking for some step-by-step help to implement this as a webservice or however it should be done.

I started with the FirstJCRClient class and made it into a portlet but I'm not sure exactly what needs to be included in the portlet war that I'm deploying. So far, I have the repository and spring jar files, and the jcr-api-context.xml file (also tried the application-context.xml file) but both of them seem to want to point towards some alfresco context within the same web application. But I want to point to the Alfresco portlet context that's not contained within the same web app.

Now I'm running into an exception saying it cannot find the AlfrescoRuntimeException class so I'm guessing I need to include the alfresco api jar(s) in the web app too but I've seen previous problems with including the same jars in different web apps before so wondering how that will affect this.

Any help appreciated.

Basic code is:


public class FirstJCRClient extends GenericPortlet
{
   
    protected void doView(RenderRequest rRequest, RenderResponse rResponse)
       throws PortletException, IOException, UnavailableException
   {
       // access the Alfresco JCR Repository (here it's via programmatic approach, but it could also be injected)
       ApplicationContext context = new ClassPathXmlApplicationContext("classpath:jcr-api-context.xml");
       Repository repository = (Repository)context.getBean("JCR.Repository");
   
       // login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
       Session session = null;
       try
       {
          session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
           // first, access the company home
           Node rootNode = session.getRootNode();
           Node companyHome = rootNode.getNode("app:company_home/index.html");
             
           rResponse.setContentType("text/html");
          
           PrintWriter writer = rResponse.getWriter();
           String content = companyHome.getProperty("cm:content").toString();
          
           writer.write("Content:<P>");
           writer.write(content);
           writer.close();
           session.save();
       }
       catch(RepositoryException re)
       {
          
       }
       finally
       {
           session.logout();
           System.exit(0);
       }
   }

Outcomes