AnsweredAssumed Answered

SpringMVC + JCR Exception

Question asked by clayton on Oct 14, 2009
I'm using Alfresco 3.2 Community on OSX Snow Leopard, mysql-5.1.37-osx10.5-x86.  Alfresco works fine.

I have an AMP module that contains some JSPs that are are dispatched by a dispatcher servlet that is declared in web.xml.  It loads without problem using the MMT script in the exploded alfresco.war.  In the web.xml:


<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/sword/*</url-pattern>
    <load-on-startup>2</load-on-startup>
</servlet-mapping>

My requests to the jsps using:

http://localhost:8080/alfresco/sword/myjsp

go through the dispatcher with no problems and the jsps render with JSTL and El working fine, data objects and form command objects binding OK.

When an attempt is made through a form controller onSubmit() to use JCR to create content in the repository an exception is thrown.

The code is almost identical to an example given in the SDK and the method call is from a class created in the form controller.


private String makeDeposit(String fileName, byte[] fileContents, String mimeType) throws Exception
    {
        // initialise app content
        ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
        ServiceRegistry registry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
        NodeService nodeService = (NodeService)registry.getNodeService();
        Repository repository = (Repository)ctx.getBean("JCR.Repository");
        Node content = null;

        //
        // authenticate
       //
        javax.jcr.Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));


        //
        // locate the company home node
        //
        try
        {
            // Retrieve Company Home
            Node root = session.getRootNode();
            Node companyHome = root.getNode("app:company_home");

            String name = fileName + System.currentTimeMillis() + ")";
       content = companyHome.addNode("cm:" + name, "cm:content");
       content.setProperty("cm:name", name);

       // add titled aspect (for Web Client display)
       content.addMixin("cm:titled");
       content.setProperty("cm:title", name);
       content.setProperty("cm:description", name);

       //
       // write some content to new node
       //
           // for testing, use test string rather than uploaded byte array

            content.setProperty("cm:content", "Ah, sweet mystery of life at last I've found you…");

       //
       // To set the content mime type, we need to use an Alfresco native service
       // as there isn't an equivalent call in JCR
       //
       setMimeType(ctx, content, MimetypeMap.MIMETYPE_TEXT_PLAIN);

       // save changes
       session.save();
        }
        finally
        {
            session.logout();
        }

        return content.getUUID();

    }

    private static void setMimeType(ApplicationContext context, Node node, String mimeType)
       throws RepositoryException
    {
        // retrieve service registry
        ServiceRegistry serviceRegistry = (ServiceRegistry) context.getBean(ServiceRegistry.SERVICE_REGISTRY);
        NodeService nodeService = serviceRegistry.getNodeService();

   // convert the JCR Node to an Alfresco Node Reference
   NodeRef nodeRef = JCRNodeRef.getNodeRef(node);

   // retrieve the Content Property (represented as a ContentData object in Alfresco)
   ContentData content = (ContentData)nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);

   // update the Mimetype
   content = ContentData.setMimetype(content, mimeType);
   nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, content);
    }


The following exception is thrown:

13:41:19,262 User:admin INFO  [alfresco.config.JndiPropertiesFactoryBean] Loading properties file from class path resource [alfresco/repository.properties]
13:41:19,263 User:admin INFO  [alfresco.config.JndiPropertiesFactoryBean] Loading properties file from class path resource [alfresco/domain/transaction.properties]
13:41:19,263 User:admin INFO  [alfresco.config.JndiPropertiesFactoryBean] Loading properties file from URL [file:/usr/local/Alfresco/tomcat/shared/classes/alfresco-global.properties]
13:41:19,352 User:admin INFO  [alfresco.config.JndiPropertyPlaceholderConfigurer] Loading properties file from class path resource [alfresco/alfresco-shared.properties]
Error creating bean with name 'workflowScheduler' defined in class path resource [alfresco/bootstrap-context.xml]: Cannot resolve reference to bean 'jbpm_template' while setting bean property 'JBPMTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_template' defined in class path resource [alfresco/workflow-context.xml]: Cannot resolve reference to bean 'jbpm_configuration' while setting constructor argument with index 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'workflowScheduler' defined in class path resource [alfresco/bootstrap-context.xml]: Cannot resolve reference to bean 'jbpm_template' while setting bean property 'JBPMTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_template' defined in class path resource [alfresco/workflow-context.xml]: Cannot resolve reference to bean 'jbpm_configuration' while setting constructor argument with index 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_template' defined in class path resource [alfresco/workflow-context.xml]: Cannot resolve reference to bean 'jbpm_configuration' while setting constructor argument with index 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
Caused by: java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
        at org.springmodules.workflow.jbpm31.JbpmFactoryLocator.addToMap(JbpmFactoryLocator.java:108)
        at org.springmodules.workflow.jbpm31.JbpmFactoryLocator.setBeanFactory(JbpmFactoryLocator.java:76)
        at org.alfresco.repo.workflow.jbpm.AlfrescoJbpmConfigurationFactoryBean.setBeanFactory(AlfrescoJbpmConfigurationFactoryBean.java:70)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1163)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:267)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)
        at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:385)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:121)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:800)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:718)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:386)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:267)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:248)
        at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:820)
        at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:597)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:349)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
        at alfresco.module.sword.service.AlfrescoFoundationDepositManager.makeDeposit(AlfrescoFoundationDepositManager.java:107)
        at alfresco.module.sword.service.AlfrescoFoundationDepositManager.depositByteArray(AlfrescoFoundationDepositManager.java:88)
        at alfresco.module.sword.mvc.controller.DepositSubmitFormController.onSubmit(DepositSubmitFormController.java:137)
        at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
        at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
        at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:859)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:793)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:637)

As can be seen, the errors come from trying to create workflow beans.  It seems that the beans have been created before?

I tried before using pure Foundation Java and I got an exception that has been referred to in the lists before in a different context in which the application cant find the mysql Resource .  Could this be related, the context not making the mysql datasource available.  I have added no configuration entry regarding mysql bar giving the root password at install.  I presumed that the dataSource referred to in the web.xml would do.


   <resource-ref>
      <description>The Alfresco database connection</description>
      <res-ref-name>jdbc/dataSource</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Unshareable</res-sharing-scope>
   </resource-ref>

Any help would be appreciated.

Regards,

Clayton

Outcomes