cancel
Showing results for 
Search instead for 
Did you mean: 

Action Executor fails to get application context

bkucuk
Champ in-the-making
Champ in-the-making
We want to use the action web service to start some content processing which uses the JCR API. Our action implementation successfully calls the Action Executer's executeImpl() method. However,executeImpl() returns the error message shown below when accessing the context as follows:

ApplicationContext context = ApplicationContextHelper.getApplicationContext();


AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString:
faultActor:
faultNode:
faultDetail:
   {http://www.alfresco.org/ws/service/authentication/1.0}AuthenticationFault:<ns1:errorCode>0</ns1:errorCode><ns1:message>The org.alfresco.cache.ticketsCache Cache is not alive.</ns1:message>
   {http://xml.apache.org/axis/}exceptionNameSmiley Surprisedrg.alfresco.repo.webservice.authentication.AuthenticationFa...
   {http://xml.apache.org/axis/}stackTrace:
   at org.alfresco.repo.webservice.authentication.AuthenticationWebService.endSession(AuthenticationWebService.java:111)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Many thanks,
Bulent
1 REPLY 1

jharrop
Champ in-the-making
Champ in-the-making
Here is some code which should help:

package org.alfresco.repo.webservice;

import javax.jcr.RepositoryException;
import javax.jcr.Session;

import javax.servlet.ServletException;
import javax.xml.rpc.server.ServiceLifecycle;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.server.ServletEndpointContext;

import org.alfresco.jcr.item.NodeImpl;
import org.alfresco.jcr.session.SessionImpl;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.apache.log4j.Logger;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class PlutextWebService  implements ServiceLifecycle {

   WebApplicationContext webAppContext = null;
   
   private static Logger log = Logger.getLogger(PlutextWebService.class);
   
    // Root node
    protected NodeRef m_rootNodeRef;
   
    FileFolderService m_fileFolderService;
    AuthenticationService authService;
   
    // Init parameter names
    // In web.xml, you need to copy the init params from the WebDAV servlet
    // and make them context wide.  Reason being, can't seem to get at
    // the init params for the WebDAV servlet or even the Axis servlet!
    public static final String KEY_STORE = "store";
    public static final String KEY_ROOT_PATH = "rootPath";
   
    public void init(Object servletEndpointContext) throws ServiceException {
      
       log.info("init start..");
       
       // Axis 1
        servletContext = ((ServletEndpointContext) servletEndpointContext).getServletContext();
       
       
        // Borrowed from org.alfresco.repo.webdav.WebDAVServlet
        webAppContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        ServiceRegistry m_serviceRegistry = (ServiceRegistry)webAppContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
       
        TransactionService m_transactionService = m_serviceRegistry.getTransactionService();

        // We need to be able to convert WebDAV paths to JCR paths
        // Borrowed from org.alfresco.repo.webdav.WebDAVServlet
        authService = (AuthenticationService) webAppContext.getBean("authenticationService");
        NodeService nodeService = (NodeService) webAppContext.getBean("NodeService");
        SearchService searchService = (SearchService) webAppContext.getBean("SearchService");
        NamespaceService namespaceService = (NamespaceService) webAppContext.getBean("NamespaceService");
       
        m_fileFolderService = m_serviceRegistry.getFileFolderService();
       
        String storeValue = servletContext.getInitParameter(KEY_STORE);
        String m_rootPath = servletContext.getInitParameter(KEY_ROOT_PATH);
                       
        try {
            AuthenticationComponent authComponent = (AuthenticationComponent) webAppContext.getBean("authenticationComponent");
            net.sf.acegisecurity.Authentication savedClientAuth = authComponent.getCurrentAuthentication();                                  
           
            // Will be done as system user
         m_rootNodeRef = org.alfresco.repo.webdav.WebDAVServlet.getRootNode(storeValue, m_rootPath,
               webAppContext, nodeService, searchService,
               namespaceService, m_transactionService);
         
         // Log the client back in again
         authComponent.setCurrentAuthentication(savedClientAuth);
         
      } catch (ServletException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
      }
      
       log.info(" .. init done."); 
       
    }

    public Session getJcrSession() {
   
        try {
           
           return getJcrSession(webAppContext, authService);
           
            // log.info("JCR root path=" + jcrSession.getRootNode().getPath() );
      } catch (RepositoryException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         return null;
      }
       
    }

    public javax.jcr.Session getJcrSession(WebApplicationContext context, AuthenticationService authService) throws javax.jcr.RepositoryException {
       
      
      logger.info("Getting JCR Repository and Session" );
      
      // JCR
        javax.jcr.Repository repository = (javax.jcr.Repository)context.getBean("JCR.Repository");

        // construct the session       
        SessionImpl sessionImpl = new SessionImpl((org.alfresco.jcr.repository.RepositoryImpl)repository);

        // initialise the session
        String ticket = authService.getCurrentTicket();
        String sessionWorkspace = "SpacesStore";
        sessionImpl.init(ticket, sessionWorkspace, null);

        logger.info("JCR Repository and Session .. SUCCESS .. returning Session" );
       
        return (javax.jcr.Session)sessionImpl;
       
    }


Your client should first call the Alfresco authentication web service to get a ticket, then it can call your web service using that ticket.