cancel
Showing results for 
Search instead for 
Did you mean: 

Use of Repository service APIs

abhicog123
Champ in-the-making
Champ in-the-making
Hello,

I was planning to do simple application that will have my own UI page. At the backend servlet I want to use the Alfresco repository content management API. I was researching and found that there is one such class AvmRepository available in sdk..it has apis such as create-file() ..etc.. Is there any SDK example as to how exactly we should use class.

thanks,
Abhijit
13 REPLIES 13

zaizi
Champ in-the-making
Champ in-the-making
Are you sure you want to use AVM as opposed to the normal Alfresco repository code?

pmonks
Star Contributor
Star Contributor
I'd suggest you investigate an out-of-process architecture for your UI, where the UI is implemented as a separate application and interacts with the Alfresco repository via Web Scripts (http://wiki.alfresco.com/wiki/Web_Scripts).  This is the design the Alfresco Share and ADW UIs use, and is a model that's been implemented by a number of Alfresco users as well.

Cheers,
Peter

abhicog123
Champ in-the-making
Champ in-the-making
Zaizi,

To be honest, I am not sure about the difference between the normal repository code and the AVM. Actually I would be able to decide once I am able to look at sample examples of how these classes are used. I was reading through Java foundation APIs and the javadoc link given there.

http://wiki.alfresco.com/wiki/Java_Foundation_API
http://dev.alfresco.com/resource/docs/java/repository/index.html

I was hoping that the AVMrepository class would provide the APIs for content mangement of a document..i.e.provide APIs that would allow to maintain versions of document.

let me know if there is any sample example for for using the Java foundation APIs.

zaizi
Champ in-the-making
Champ in-the-making
Download the Alfresco SDK and set it up. It has sample code examples. http://wiki.alfresco.com/wiki/Alfresco_SDK

List of sample projects: http://wiki.alfresco.com/wiki/Alfresco_SDK#Explore_the_Sample_Projects

However, I would refer you to the previous post by Peter. Using web scripts would be best option for integrating with an Alfresco Repository. Further information available at http://wiki.alfresco.com/wiki/Web_Scripts. The Alfresco Share UI integrates a remote Alfresco Repository via web scripts (in the default install it is within the same Tomcat but you can install it on a remote machine(s).

If you still want to do a custom UI and want to use java api, then can try and share the spring context between Alfresco and your custom webapp. You can google to find details of how to do this: http://www.google.co.uk/search?q=share+spring+context

abhicog123
Champ in-the-making
Champ in-the-making
Ok.. I have downloaded the SDK and imported the projects in eclipse. However I do not know how to execute the FirstFoundationClient. I tried running it but got following error. Other SDk samples, like customlogin provide integrate-extension in the build.xml which puts the sdk code into the alfresco.war. But it is not present in the FirstFoundationclient.so my guess is it is to be run differently. As you might have guessed I am newbie to Spring and web concepts   Smiley Happy . If there is any list of basic level steps for running  FirstFoundation please let me know.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverConnector' defined in class path resource [alfresco/core-services-context.xml]: Invocation of init method failed; nested exception is java.io.IOException: Cannot bind to URL [rmi://localhost:50500/alfresco/jmxrmi]: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]
Caused by: java.io.IOException: Cannot bind to URL [rmi://localhost:50500/alfresco/jmxrmi]: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]
   at javax.management.remote.rmi.RMIConnectorServer.newIOException(Unknown Source)
   at javax.management.remote.rmi.RMIConnectorServer.start(Unknown Source)

zaizi
Champ in-the-making
Champ in-the-making
The FirstFoundationClient tries to connect to the remote Alfresco Repository using RMI (in this case on the localhost port 50500). Have you got an Alfresco install running on the local machine? It should create some sample content within Company Home.

If you are newbie to Spring etc, I would strongly recommend you look at Web scripts. These simple REST web services can be called from PHP, Ruby, JSP, .Net, Java script etc. It might make developing your custom UI much easier.

If you found this post useful, please rate it.

pmonks
Star Contributor
Star Contributor
Actually the FirstFoundationClient demonstrates the use of an embedded Alfresco repository, so you don't need to have any Alfresco servers running for it to function (in fact doing so while likely cause problems due to port conflicts - perhaps that's the issue here?).  If you've imported the Eclipse projects (as described at http://wiki.alfresco.com/wiki/Alfresco_SDK#Import_the_Alfresco_Eclipse_Projects), then you should be able to just run FirstFoundationClient as a standard Java application from within Eclipse.

What would help is to describe more precisely the steps you followed, what you expected to happen, and what actually happened instead.

Cheers,
Peter

abhicog123
Champ in-the-making
Champ in-the-making
Hi Peter,

I have Alfresco installed. I had run the setup for AlfrescoEnterprise-2.2.0-Setup ..It is the normal ECM( not WCM).

I imported the SDK project in eclipse. I started the Alfresco server. I could access Alfresco through its web client. Then I ran the FirstFoundationClient as a standard Java project in eclipse. I got the following error.


11:11:02,448 ERROR [transform.magick.AbstractImageMagickContentTransformer] ImageMagickContentTransformer not available: Failed to perform ImageMagick transformation:
Execution result:
   os:         Windows XP
   command:    imconvert "C:\DOCUME~1\ABHIJI~1\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_source_44070.gif"  "C:\DOCUME~1\ABHIJI~1\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_target_44071.png"
   succeeded:  false
   exit code:  1
   out:       
   err:        CreateProcess: imconvert "C:\DOCUME~1\ABHIJI~1\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_source_44070.gif" "C:\DOCUME~1\ABHIJI~1\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_target_44071.png" error=2
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverConnector' defined in class path resource [alfresco/core-services-context.xml]: Invocation of init method failed; nested exception is java.io.IOException: Cannot bind to URL [rmi://localhost:50500/alfresco/jmxrmi]: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]
Caused by: java.io.IOException: Cannot bind to URL [rmi://localhost:50500/alfresco/jmxrmi]: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]
   at javax.management.remote.rmi.RMIConnectorServer.newIOException(Unknown Source)
   at javax.management.remote.rmi.RMIConnectorServer.start(Unknown Source)
   at org.springframework.jmx.support.ConnectorServerFactoryBean.afterPropertiesSet(ConnectorServerFactoryBean.java:168)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1118)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
   at org.alfresco.util.ApplicationContextHelper.getApplicationContext(ApplicationContextHelper.java:55)
   at org.alfresco.sample.FirstFoundationClient.main(FirstFoundationClient.java:69)
Caused by: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]
   at com.sun.jndi.rmi.registry.RegistryContext.bind(Unknown Source)
   at com.sun.jndi.toolkit.url.GenericURLContext.bind(Unknown Source)
   at javax.naming.InitialContext.bind(Unknown Source)
   at javax.management.remote.rmi.RMIConnectorServer.bind(Unknown Source)
   … 15 more
Caused by: java.rmi.AlreadyBoundException: alfresco/jmxrmi
   at sun.rmi.registry.RegistryImpl.bind(RegistryImpl.java:123)
   at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
   at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:375)
   at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
   at sun.rmi.transport.Transport$1.run(Transport.java:153)
   at java.security.AccessController.doPrivileged(Native Method)
   at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
   at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
   at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
   at java.lang.Thread.run(Thread.java:595)
   at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
   at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
   at sun.rmi.server.UnicastRef.invoke(Unknown Source)
   at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
   … 19 more



The I shut down the Alfresco server and ran the firstFoundationclient ..and got the following error.


11:20:36,287 ERROR [transform.magick.AbstractImageMagickContentTransformer] ImageMagickContentTransformer not available: Failed to perform ImageMagick transformation:
Execution result:
   os:         Windows XP
   command:    imconvert "C:\DOCUME~1\ABHIJI~1\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_source_30451.gif"  "C:\DOCUME~1\ABHIJI~1\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_target_30452.png"
   succeeded:  false
   exit code:  1
   out:       
   err:        CreateProcess: imconvert "C:\DOCUME~1\ABHIJI~1\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_source_30451.gif" "C:\DOCUME~1\ABHIJI~1\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_target_30452.png" error=2
11:20:39,585 WARN  [remoting.rmi.RmiRegistryFactoryBean] Could not detect RMI registry - creating new one
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictionaryRepositoryBootstrap' defined in class path resource [alfresco/core-services-context.xml]: Invocation of init method failed; nested exception is org.alfresco.error.AlfrescoRuntimeException: Failure during rollback: org.alfresco.repo.dictionary.DictionaryRepositoryBootstrap$1@497536
Caused by: org.alfresco.error.AlfrescoRuntimeException: Failure during rollback: org.alfresco.repo.dictionary.DictionaryRepositoryBootstrap$1@497536
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:281)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:155)
   at org.alfresco.repo.dictionary.DictionaryRepositoryBootstrap.bootstrap(DictionaryRepositoryBootstrap.java:134)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1160)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1122)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:273)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
   at org.alfresco.util.ApplicationContextHelper.getApplicationContext(ApplicationContextHelper.java:55)
   at org.alfresco.sample.FirstFoundationClient.main(FirstFoundationClient.java:69)
Caused by: java.lang.IllegalStateException: No user transaction is active
   at org.alfresco.util.transaction.SpringAwareUserTransaction.rollback(SpringAwareUserTransaction.java:479)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:276)
   … 20 more



Are you sure we need to shut down the Alfresco server? The explanation text in the FirstFoundationClient Program states the following..Since it says we need to re-start the web-client..i was guessing that it puts some data in company home folder which is accessible though webclient and so we need the Alfresco server on while we are running the FirstFoundationClient.

/**
* Simple client example demonstrating the use of the Alfresco Foundation Java APIs.
*
* The client creates a content node in the "Company Home" folder.  The content
* may be viewed and operated on within the Alfresco Web Client.  Note: the web client
* will need to be re-started after executing this sample to see the changes in
* effect.
*


Please let me know what you think.

jpfi
Champ in-the-making
Champ in-the-making
Hi,
as Peter said, JavaFoundationClient use the alfresco repository in embedded mode. The Java Foundation Services API is an in-process and NOT a Remote API.
Therefore you  can't reuse a running Alfresco on a Tomcat.
but I don't know where your second error comes from…Are you trying to reuse your alfdata-directory or database without the other one?
Cheers, Jan