cancel
Showing results for 
Search instead for 
Did you mean: 

How to deal with ServiceRegistry

robobot
Champ in-the-making
Champ in-the-making
Hello,
i can't help myself. I dont have any glue how i can use the alfresco services. also i could not get a hint from similar topics 😞
when i try to run simple example i get the followig error:

package org.alfresco.sample.jcr;
import org.alfresco.service.ServiceRegistry;
public class SimpleExample
{

    public static void main(String[] args) throws Exception
    {
        ServiceRegistry registry = (ServiceRegistry )java.rmi.Naming.lookup("ServiceRegistry");
    }
   
}

Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 192.168.20.103; nested exception is: 
   java.net.ConnectException: Connection refused: connect
   at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
   at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
   at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
   at sun.rmi.server.UnicastRef.newCall(Unknown Source)
   at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
   at java.rmi.Naming.lookup(Unknown Source)
   at org.alfresco.sample.jcr.SimpleExample.main(SimpleExample.java:23)
Caused by: java.net.ConnectException: Connection refused: connect
   at java.net.PlainSocketImpl.socketConnect(Native Method)
   at java.net.PlainSocketImpl.doConnect(Unknown Source)
   at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
   at java.net.PlainSocketImpl.connect(Unknown Source)
   at java.net.SocksSocketImpl.connect(Unknown Source)
   at java.net.Socket.connect(Unknown Source)
   at java.net.Socket.connect(Unknown Source)
   at java.net.Socket.<init>(Unknown Source)
   at java.net.Socket.<init>(Unknown Source)
   at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
   at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
   … 7 more

is there a step by step guide available ? i rember that i spent a lots of time in the past to get the spring services work 😕

please help, santa claus will thank you.
regards.
5 REPLIES 5

mrogers
Star Contributor
Star Contributor
Before you spread your confusion what are you attempting to do?

Why are you trying to lookup the ServiceRegistry in JNDI?

robobot
Champ in-the-making
Champ in-the-making
i try to use the Spring Services depending on the problem

http://forums.alfresco.com/en/viewtopic.php?f=4&t=23856

i tried to run the Examples from the SDK JRCSamples Project. Here is the Sample Class.


/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception.  You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.sample.jcr;

import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.alfresco.jcr.api.JCRNodeRef;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;



/**
* Example that demonstrate use of JCR and Alfresco API calls.
*
* @author David Caruana
*/
public class MixedExample
{

    public static void main(String[] args)
        throws Exception
    {
        // Setup Spring and Transaction Service
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
        ServiceRegistry registry = (ServiceRegistry)context.getBean(ServiceRegistry.SERVICE_REGISTRY);
        NodeService nodeService = (NodeService)registry.getNodeService();
       
        // 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");

            // Read Company Home Name
            Property name = companyHome.getProperty("cm:name");
            System.out.println("Name = " + name.getString());
           
            // Update Node via Alfresco Node Service API
            NodeRef companyHomeRef = JCRNodeRef.getNodeRef(companyHome);
            nodeService.setProperty(companyHomeRef, ContentModel.PROP_NAME, "Updated Company Home Name");
           
            // Re-read via JCR
            System.out.println("Updated name = " + name.getString());
        }
        finally
        {
            session.logout();
            System.exit(0);
        }
    }
   
}

I get the following error:


Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexerComponent' defined in class path resource [alfresco/core-services-context.xml]: Cannot resolve reference to bean '&indexerAndSearcherFactory' while setting bean property 'storeRedirectorProxyFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexerAndSearcherFactory' defined in class path resource [alfresco/core-services-context.xml]: Cannot resolve reference to bean 'admLuceneIndexerAndSearcherFactory' while setting bean property 'defaultBinding'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'admLuceneIndexerAndSearcherFactory' defined in class path resource [alfresco/core-services-context.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/SystemException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexerAndSearcherFactory' defined in class path resource [alfresco/core-services-context.xml]: Cannot resolve reference to bean 'admLuceneIndexerAndSearcherFactory' while setting bean property 'defaultBinding'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'admLuceneIndexerAndSearcherFactory' defined in class path resource [alfresco/core-services-context.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/SystemException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'admLuceneIndexerAndSearcherFactory' defined in class path resource [alfresco/core-services-context.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/SystemException
Caused by: java.lang.NoClassDefFoundError: javax/transaction/SystemException
   at java.lang.Class.getDeclaredConstructors0(Native Method)
   at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
   at java.lang.Class.getConstructor0(Unknown Source)
   at java.lang.Class.getDeclaredConstructor(Unknown Source)
   at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:54)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:757)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:722)
   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.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 org.alfresco.sample.jcr.MixedExample.main(MixedExample.java:55)
Caused by: java.lang.ClassNotFoundException: javax.transaction.SystemException
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
   … 37 more


Please, what do i have to do ? It seems that the Problem is alreaday here:


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

robobot
Champ in-the-making
Champ in-the-making
after hours i made one step into the right direction…

        // Setup Spring and Transaction Service
       // ok
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:alfresco/application-context.xml");                  
       // error
        ServiceRegistry registry = (ServiceRegistry)context.getBean(ServiceRegistry.SERVICE_REGISTRY);

–> Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ServiceRegistry' is defined

System.out.println("beans: "+context.getBeanDefinitionCount()); –> 0

what do i have to do ?

thanks in advance

rogier_oudshoor
Champ in-the-making
Champ in-the-making
Have you read this WIki Page? It does roughly what you're attempting: http://wiki.alfresco.com/wiki/Java_Foundation_API

The best way to work would be to have your class managed by Spring, and use dependency injection to retrieve the ServiceRegistry bean for you. In fact, using this method, you will be able to access all of Alfrescos service classes directly.

robobot
Champ in-the-making
Champ in-the-making
hello,
yes i have already read this short article. once again, step by step:

1. after downloading the latest alfresco sdk i carefully added all the libs found in "SDK AlfrescoEmbedded" in its build path.
2. I added the project to the build path of "SDK JCRSamples". In this project i modified the  file "custom-repository.properties" as follows:

dir.root=C:/Alfresco/alf_data

3. i copied the 3 files from the  SDK JCRSamples Project into the alfresco extension folder


C:\Alfresco\tomcat\shared\classes\alfresco\extension

    custom-alfresco-shared.properties
    custom-repository-context.xml
    custom-repository.properties

4. i started my local alfresco 3.2 installation at 

http://localhost:8080/alfresco

5. i run MixedExample from the eclipse workspace and until this point i am happy.


Now i want to use this with an remote alfresco installation.

Alfresco runs for example at http://192.168.20.144:8080/alfresco/

To keep my question simple: how can "MixedExamples" communicate with "http://192.168.20.144:8080/alfresco/" instead of  "http://localhost:8080/alfresco"