cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Via RMI

rdanner
Champ in-the-making
Champ in-the-making
For those interested:

I have put alfresco behind the JCR-RMI library from jackrabbit.
All i had to do was make a simple bean to register the repository and then leverage their client on the remote end.


I have a build for just the RMI-JCR and the additional alfresco config and classes.

I had done a significant portion of an RMI wrapper before I ran in to jackrabbit (I should be looking a little harder before i leap).

Works like a charm.  Their library does not use remote activation which I would like to include for robustness sake.
62 REPLIES 62

rdanner
Champ in-the-making
Champ in-the-making
Hi, Russ,

I'm trying to get RMI access as well. I was trying to get to your download (http://www.posit-group.org/cache/jcr-rmi-alfresco.zip) but the link's broken, any chance you could make it available somewhere else?

Cheers,

Fraser

Download the following

http://devartisan.org/jcr-rmi-alfresco.zip 
this is the things you need to change in alfresco to expose the JCR.  This is just a proof of concept.  if you are going to actually use RMI you are going to want to make the thing robust.  Possibly use some sort of activation, make sure you have a listener to unbind when you unload your context ect.  I am not worried about that at the moment but I will be at some point.  You can either wait for me or help me out by getting to that stuff before i do.

This can be exploded as a project right along side alfresco, running the build will just copy files "over" alfresco files.  yuo might want to back your original up first especially if you are working with a newer alfresco release. 

http://devartisan.org/jcr-rmi.zip
This is jackrabbit with a build around it,  you can scrap the build or use it

under workbench there is a pison_readme.txt that should help out setting up the build.  This build harness needs a lot of work.  It could benifit from some of the new ant features.  We also want to get rid of some of the junk in it but anyway…. its there.. it will build.

I think previous posts should point out any trouble spot. I remember correcting the circular reference in the context xml but I could be wrong.. too many long hours these days Smiley Happy

leon
Champ in-the-making
Champ in-the-making
hi,
I have downloaded the package,and find there is not a directory named 'web client',which is quoted in build.bat

plz help me about the web client to access RMI service

regards,
    Leon

Download the following

http://devartisan.org/jcr-rmi-alfresco.zip 
this is the things you need to change in alfresco to expose the JCR. …

s0110655
Champ in-the-making
Champ in-the-making
Hi,

I'm a student in the computerscience and I'm using Alfresco for my thesis. I would like to access the JCR through a java application.  So far I haven't been able to retrieve a Session object with the code from the example of the tutorial.  I would like to try this with your rmi library, but I don't know what exactly where I should put the files from the jcr-rmi-alfresco.zip file.  Do I have to rebuild the Alfresco.war again with your files added, or can I just add them when I already deployed Alfresco.  I use Tomcat 5.5.12.

Can you help me out?

Thanks
Steven

rdanner
Champ in-the-making
Champ in-the-making
Hi,

I'm a student in the computerscience and I'm using Alfresco for my thesis. I would like to access the JCR through a java application.  So far I haven't been able to retrieve a Session object with the code from the example of the tutorial.  I would like to try this with your rmi library, but I don't know what exactly where I should put the files from the jcr-rmi-alfresco.zip file.  Do I have to rebuild the Alfresco.war again with your files added, or can I just add them when I already deployed Alfresco.  I use Tomcat 5.5.12.

Can you help me out?

Thanks
Steven


Steven,

I will  be able to help out…

One note though.  This code was written for version 1.1 and I tested it against one 1.2.  The thing is I don't know if it is still relevant.  I have not kept a close eye on alfresco in terms of RMI in a while.  I was using it for a few proof of concepts a while back.  It is possible that alfresco loads jackrabbit on its own at this point (or something like jackrabbit).

Tomorrow I will download the current release and get back to you.  RMI is easy to get working so don't sweat it, it's as good as working.

s0110655
Champ in-the-making
Champ in-the-making
Hi,

Thank you for your time and help.  You probably have better things to do than helping a student with his problems, so I really appreciate your help. I'll hope to hear from you soon.

Thanks in advance!
Steven

rdanner
Champ in-the-making
Champ in-the-making
Hi,

Thank you for your time and help.  You probably have better things to do than helping a student with his problems, so I really appreciate your help. I'll hope to hear from you soon.

Thanks in advance!
Steven

Hi Steve,

I took a look at the alfresco 1.2  release and I dont see any additional code there to handle RMI.   I started looking at RMI because it looked like you were wondering how to use the RMI zipfile up on devartisan.org.

We can take one of two approaches here.  One we can user JCR over RMI or we can just use JCR.

Alfresco can be built to support JCR without RMI.  RMI is one technology that enables you to build your application without having to be concerned with building Alfresco all the time. When I was building my proof of concepts I to start the repository and forget it.


RMI is probably not the best technology to use for remoting long term.. you know the deal firewalls, and technology specific, communication heavy interface etc.  If you run with RMI you are going to have to start a registry as well as your container (if your using tomcat).


So what are we working on JCR over RMI or your application built in to the alfresco deployment (in which case we get JCR objects right from spring locally)?

s0110655
Champ in-the-making
Champ in-the-making
Hi Russ,

I originally wanted to access Alfresco through JCR (with the example code from the tutorial), but I had some difficulties and I decided to take a different road.  Then I found your post from the RMI library and I thought this might work with me to.  Maybe I should give you some background on my project.  I made a java application on top of jackrabbit using the JSR-170 standard.  The only thing that I use the content management system for is to persist my data.  Now I would like to put another content management system (Alfresco) under my application. If my application keeps working without changing any of my code, that would be a nice conclusion for my thesis and would also defend the use of the JSR-170 standard. So I would like to get JCRobjects the easiest way possible.

I'll tell you how I currently access Alfresco and which errors I get, and maybe you can help me out then.  This is the code of a simple testprogram I made to check my JCR connection with Alfresco:

System.setProperty("java.rmi.server.useCodebaseOnly", "true");
         ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/jcr-context.xml");
         Repository repository = (Repository)context.getBean("JCR.Repository");
          Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()), null);
         
          try{
             rn = session.getRootNode();
             Node testNode = rn.addNode("Test2");
                                                testNode.addNode("Test4");
             session.save();
          }catch (Exception e){
             e.printStackTrace();
          }

This is the error I receive:

javax.jcr.RepositoryException: Cannot determine node type for child within parent workspace://SpacesStore/b06a1ec1-be95-11da-b3fa-dbcbf8133280: Cannot determine node type for child within parent workspace://SpacesStore/b06a1ec1-be95-11da-b3fa-dbcbf8133280
   at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:167)
   at $Proxy67.addNode(Unknown Source)
   at Remote_Test.main(Remote_Test.java:58)
Caused by: org.alfresco.error.AlfrescoRuntimeException: Cannot determine node type for child within parent workspace://SpacesStore/b06a1ec1-be95-11da-b3fa-dbcbf8133280
   at org.alfresco.jcr.item.NodeImpl.getDefaultChildAssocDefForParent(NodeImpl.java:209)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:177)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:133)
   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.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:130)
   … 2 more
org.alfresco.error.AlfrescoRuntimeException: Cannot determine node type for child within parent workspace://SpacesStore/b06a1ec1-be95-11da-b3fa-dbcbf8133280
   at org.alfresco.jcr.item.NodeImpl.getDefaultChildAssocDefForParent(NodeImpl.java:209)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:177)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:133)
   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.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:130)
   at $Proxy67.addNode(Unknown Source)
   at Remote_Test.main(Remote_Test.java:58)

I don't understand, since the code I run works fine in Jackrabbit.  Do you know what the problem might be?

Further I'm working with Eclipse as editor, and I get these strange errors only when I run my program in debug mode.

JDI thread evaluations (Error: Exception processing async thread queue)

I don't know if this is a problem with eclipse or with the connection to Alfresco, but I just mention it (maybe you also know the cause of these errors).  When I just run my program (no debug mode) I don't get these erros.

Can you help me?

Thanks!
Steven

rdanner
Champ in-the-making
Champ in-the-making
Hi Russ,

I originally wanted to access Alfresco through JCR (with the example code from the tutorial), but I had some difficulties and I decided to take a different road.  Then I found your post from the RMI library and I thought this might work with me to.  Maybe I should give you some background on my project.  I made a java application on top of jackrabbit using the JSR-170 standard.  The only thing that I use the content management system for is to persist my data.  Now I would like to put another content management system (Alfresco) under my application. If my application keeps working without changing any of my code, that would be a nice conclusion for my thesis and would also defend the use of the JSR-170 standard. So I would like to get JCRobjects the easiest way possible.

I'll tell you how I currently access Alfresco and which errors I get, and maybe you can help me out then.  This is the code of a simple testprogram I made to check my JCR connection with Alfresco:

System.setProperty("java.rmi.server.useCodebaseOnly", "true");
         ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/jcr-context.xml");
         Repository repository = (Repository)context.getBean("JCR.Repository");
          Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()), null);
         
          try{
             rn = session.getRootNode();
             Node testNode = rn.addNode("Test2");
                                                testNode.addNode("Test4");
             session.save();
          }catch (Exception e){
             e.printStackTrace();
          }

This is the error I receive:

javax.jcr.RepositoryException: Cannot determine node type for child within parent workspace://SpacesStore/b06a1ec1-be95-11da-b3fa-dbcbf8133280: Cannot determine node type for child within parent workspace://SpacesStore/b06a1ec1-be95-11da-b3fa-dbcbf8133280
   at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:167)
   at $Proxy67.addNode(Unknown Source)
   at Remote_Test.main(Remote_Test.java:58)
Caused by: org.alfresco.error.AlfrescoRuntimeException: Cannot determine node type for child within parent workspace://SpacesStore/b06a1ec1-be95-11da-b3fa-dbcbf8133280
   at org.alfresco.jcr.item.NodeImpl.getDefaultChildAssocDefForParent(NodeImpl.java:209)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:177)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:133)
   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.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:130)
   … 2 more
org.alfresco.error.AlfrescoRuntimeException: Cannot determine node type for child within parent workspace://SpacesStore/b06a1ec1-be95-11da-b3fa-dbcbf8133280
   at org.alfresco.jcr.item.NodeImpl.getDefaultChildAssocDefForParent(NodeImpl.java:209)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:177)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:133)
   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.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:130)
   at $Proxy67.addNode(Unknown Source)
   at Remote_Test.main(Remote_Test.java:58)

I don't understand, since the code I run works fine in Jackrabbit.  Do you know what the problem might be?

Further I'm working with Eclipse as editor, and I get these strange errors only when I run my program in debug mode.

JDI thread evaluations (Error: Exception processing async thread queue)

I don't know if this is a problem with eclipse or with the connection to Alfresco, but I just mention it (maybe you also know the cause of these errors).  When I just run my program (no debug mode) I don't get these erros.

Can you help me?

Thanks!
Steven



Hi Steve

You run this code against jackrabbit and it works? It looks like alfresco specific code (because it is relying on alfresco spring configuration).

Well you apparently are making a connection.  You would be getting a different error if you where not.  You would never be able to get as far as add node without a session.

The next problem I see is that you are missing a transaction.  This may be something spring is doing for you or that Alfresco has fixed.  When I was working with Alfresco JCR transactions were still being implemented.

Also you will want to traverse in to the alfrescos company home space (at least before adding a node)

Try using add node with the following parameters:

Node vCompanyHomeNode = vSession.getRootNode().getNode("app:company_home");
vCompanyHomeNode.addNode("Test2", "cm:content");


On the company home bit.  I know you are looking to use alfresco as just a JCR repository so it is likely that you will need use a different model and bootstrap then what comes "out of the box".

The company home bit is just there if you are trying to see some action in the web client that ships with alfresco.

Hope this helps.  I will take a closer look at the exception but I wanted to give my gut instinct on the subject.

s0110655
Champ in-the-making
Champ in-the-making
Hi Russ,

Thanks for the quick reply… I made a mistake in the previous reply.  The code to get a session object indeed differs from the jackrabbit implementation, but what I actually meaned was once I received a session object I run the same code.  I mean that when I do testNode.addNode("Test4") it works fine in Jackrabbit but not in Alfresco.  I see in your example code that you also give a nodeType as a second argument in this method. Well in all my code I just give the name as argument and that works in jackrabbit and apparentlt not in Alfresco. I read in the JSR-170 spec that the inheritance of nodeTypes to childnodes is implementation specific, so my guess is that jackrabbit automatically gives a nodeType on creation of a node and with Alfresco you have to specify it in the second argument. I also tested the setProperty("Test","TestValue") method which also gives an error. It seems that Alfresco implements the JSR-170 standard differently than Jackrabbit.

I'm kind of a newbie in the whole Alfresco repository environment so I don't really know what you mean with a different data model and bootstrap. Can you explain this to me? In jackrabbit you can just start adding nodes under the rootNode and that what I'm doing in my application, so I can't really change my code since I want it to be backwards compatible with the jackrabbit JCR interface. I already have a data structure that works in jackrabbit and I would like to use exactly the same datastructure in Alfresco.

Thanks for all your effort,
Steven

rdanner
Champ in-the-making
Champ in-the-making
Hi Russ,

Thanks for the quick reply… I made a mistake in the previous reply.  The code to get a session object indeed differs from the jackrabbit implementation, but what I actually meaned was once I received a session object I run the same code.  I mean that when I do testNode.addNode("Test4") it works fine in Jackrabbit but not in Alfresco.  I see in your example code that you also give a nodeType as a second argument in this method. Well in all my code I just give the name as argument and that works in jackrabbit and apparentlt not in Alfresco. I read in the JSR-170 spec that the inheritance of nodeTypes to childnodes is implementation specific, so my guess is that jackrabbit automatically gives a nodeType on creation of a node and with Alfresco you have to specify it in the second argument. I also tested the setProperty("Test","TestValue") method which also gives an error. It seems that Alfresco implements the JSR-170 standard differently than Jackrabbit.

I'm kind of a newbie in the whole Alfresco repository environment so I don't really know what you mean with a different data model and bootstrap. Can you explain this to me? In jackrabbit you can just start adding nodes under the rootNode and that what I'm doing in my application, so I can't really change my code since I want it to be backwards compatible with the jackrabbit JCR interface. I already have a data structure that works in jackrabbit and I would like to use exactly the same datastructure in Alfresco.

Thanks for all your effort,
Steven


In alfresco comes with a bootstrap configuration which sets up a default repository and several default workspaces  (company home, taxonomy etc)


Your application may not be interested in these.

Alfresco is also able to support custom models (custom node and mixin types).  It comes with a default set which may/not be useful.

To use your data structures you would keep the jcr model and replace the alfresco model with your model.  There is some learning curve there but it is not too bad and there is information on the alfresco wikki.

Node.add(Str x);

calls Node.addNode(x, null);

which gets the default type from the parent node (based on the dictionary service) 

You are operating with the root node. I will have to go dig up what that means in terms of what is resolved when


    /**
     * Get the default child association definition for the specified node
     *
     * @param nodeService   node service
     * @param dictionaryService  dictionary service
     * @param nodeRef  node reference
     * @return  child association definition
     */
    private ChildAssociationDefinition getDefaultChildAssocDefForParent(NodeService nodeService, DictionaryService dictionaryService, NodeRef nodeRef)
    {
        QName type = nodeService.getType(nodeRef);
        Set<QName> aspects = nodeService.getAspects(nodeRef);
        ClassDefinition classDef = dictionaryService.getAnonymousType(type, aspects);
        Map<QName, ChildAssociationDefinition> childAssocs = classDef.getChildAssociations();
        if (childAssocs.size() != 1)
        {
            throw new AlfrescoRuntimeException("Cannot determine node type for child within parent " + nodeRef);
        }
        ChildAssociationDefinition childAssocDef = childAssocs.values().iterator().next();
        return childAssocDef;
    }


is called with session.getRootNode() as the last parameter.



To kind of make this clear let me point you in the direction

What you want to look at is

alfresco_1_2_0\projects\jcr\config\alfresco\model\jcrModel.xml

The reason why I am saying this is because you will reconize the types and mixins in this file (its very basic JCR stuff) but you can make the jump between the model config and JCR

this model is part of what Alfresco calls the M2 model.

There are two models M1 and M2
M1 is a model which basically descibes a simple node structure (the foundation of the repository).

The M2 model lets the repository know how the M1 is going to be used to do something interesting (to model some interesting thing).


Alfrescos default models M1 and M2 are located at:
alfresco\alfresco_1_2_0\projects\repository\config\alfresco\model

When you look at these file you will see that there are models xml files which are application specific and others like (systemModel) which are more fundamental.

Get familiar with these.  Alfresco is JCR compliant but it needs to be configured to suite your needs in terms of application