cancel
Showing results for 
Search instead for 
Did you mean: 

Creation of a Alfresco Webservice for Enterprise System

rv_a_sharma
Champ in-the-making
Champ in-the-making
Hello All,

I am totally unaware of development capabilities on Alfresco.
I am looking to implement a web service in Java the interface is given to me in a WSDL file . This WSDL will be later on used provide a Enterprise System the information from Alfresco systems.

Questions :
1. What is the development web server that we should use for this ?
2. What is the development IDE usually used.
3. I have to provide the information of the Schema of Alfresco in this webservice how to go about it ?

Regards,
Ravi
16 REPLIES 16

rv_a_sharma
Champ in-the-making
Champ in-the-making
Thanks for your support.

I have written following code. To browse through the nodes to find out the properties.
It was given in the Samples .

But now the problem is  : This runtime error.
Which says no Bean named JCR.Repository found.

How to solve this problem now ???

Now in the Application-context.xml -> import of JCR-API-Context.xml is done and in JCR-API-Context.xml the following code is written :
 
<?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE beans (View Source for full doctype…)>
- <beans default-lazy-init="false" default-autowire="no" default-dependency-check="none">
- <bean id="JCR.Repository" class="org.alfresco.jcr.repository.RepositoryImpl" init-method="init" lazy-init="default" autowire="default" dependency-check="default">
- <property name="serviceRegistry">
  <ref bean="ServiceRegistry" />
  </property>
- <property name="importerComponent">
  <ref bean="importerComponent" />
  </property>
- <property name="defaultWorkspace">
  <value>SpacesStore</value>
  </property>
  </bean>
- <bean id="JCR.DictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap" lazy-init="default" autowire="default" dependency-check="default">
- <property name="models">
- <list>
  <value>alfresco/model/jcrModel.xml</value>
  </list>
  </property>
  </bean>
  </beans>


Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'JCR.Repository' is defined
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:356)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:916)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:243)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
   at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:733)
   at com.sap.alfresco.AlfrescoMetaModel.main(AlfrescoMetaModel.java:34)


/**
*
*/
package com.sap.alfresco;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;



/**
* Simple Example that demonstrates login and retrieval of top-level Spaces
* under Company Home.
*
* @author David Caruana
*/
public class AlfrescoMetaModel
{

    public static void main(String[] args)
        throws Exception
    {
        // Setup Spring and Transaction Service
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:alfresco/application-context.xml");
       
        // 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");
           
            // Iterator through children of Company Home
            NodeIterator iterator = companyHome.getNodes();
            while(iterator.hasNext())
            {
                Node child = iterator.nextNode();
                System.out.println(child.getName());

                PropertyIterator propIterator = child.getProperties();
                while(propIterator.hasNext())
                {
                    Property prop = propIterator.nextProperty();
                    if (!prop.getDefinition().isMultiple())
                    {
                        System.out.println(" " + prop.getName() + " = " + prop.getString());
                    }
                }
            }
        }
        finally
        {
            session.logout();
            System.exit(0);
        }
       
    }
   
}

openpj
Elite Collaborator
Elite Collaborator
Maybe in your class you have used inversion of control.
If you have added as a property JCR.Repository in your Spring context in this way:

<bean id="myBean" class="myBeanImplementation">
  <property name="JCRRepository"><ref bean="JCR.Repository"/></property>
  …
</bean>

You must add a public setter method in your class to get this resource, in this way:

public void setJCRRepository(Repository repository)
   {
      this.repository = repository;
   }

Hope this helps.

rv_a_sharma
Champ in-the-making
Champ in-the-making
I have not created any bean  I am using the one provide in alfresco-repository.jar file .

Kindly suggest.

Regards,
Ravi Sharma

openpj
Elite Collaborator
Elite Collaborator
Maybe there is a problem with Spring initialization.
What type of application is this app?
Is a War, a Jar or an Ear.

I think it could be a problem with Spring context listener  Smiley Indifferent

rv_a_sharma
Champ in-the-making
Champ in-the-making
At the moment this is a Plain Java File . But our goal is to put the code in a Bean which will be part of EAR .

Regards,
Ravi Sharma

openpj
Elite Collaborator
Elite Collaborator
To deploy JCR you must have a packaged application with Alfresco classes and xml configuration files.

If you want a lightweight way you can use Alfresco Web Service client and you can use it in your application:
http://wiki.alfresco.com/wiki/Alfresco_Content_Management_Web_Services

Alfresco Web Service client:
http://wiki.alfresco.com/wiki/Labs_3_Final_download_files#Alfresco_Web_Service_Client

Here you can see a Java example of how use it in your application:
http://wiki.alfresco.com/wiki/Web_Service_Samples_for_Java

rv_a_sharma
Champ in-the-making
Champ in-the-making
Alright … Thanks for the help. Credit given to you for the effort Smiley Happy

But I don't understand if I am just trying the SampleExample.java file distributed along with the Alfresco content.

Its a plain java file and trying to get the Application context.
I can get it like .
 
// Setup Spring and Transaction Service
       ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:alfresco/application-context.xml");

Now using this context I want to get he handle on Repository . This is done in the sample code.
But how come its not accepting it . At compile time i have defined that this is going to be the dependency.

But how can i define at the run time that one has to use a class which is available in the package

public class RepositoryImpl implements Repository

I dont understand now what should i do to make this standalone sample java run ?

Regards,
Ravi Sharma