14 Replies Latest reply on Jun 27, 2012 5:52 PM by rhauch

    How to access remote (ModeShape) JCR repository from a JBOSS AS?

    tconrad

      Hi.

       

      I have setup a JBOSS 5.1 AS and unzipped the JBOSS kit into the "default" profile. The server is up and running and when I create an initial context with the properties in [1] in a Java client I can see that the "jcr/local" JNDI is available:

       

      jcr: org.jnp.interfaces.NamingContext
           jcr/local: org.modeshape.jboss.managed.JNDIManagedRepositories

       

       

      Now I am trying to access the repository with the "ServiceLoader" approach (see [2] below).

       

      If I use the "file" protocol everything works fine.

       

      If I switch to the "jndi" protocol I get an exception "unknown protocol: jndi" and the following output:

       

      Trying to load repository using: org.modeshape.jcr.JcrRepositoryFactory@5975d6ab
      2010-10-07 13:41:57,643 [main] DEBUG org.modeshape.jcr.JcrRepositoryFactory - Trying to load ModeShape JCR Repository with parameters: {org.modeshape.jcr.URL=jndi:jcr/local?repositoryName=repository}
      2010-10-07 13:41:57,644 [main] DEBUG org.modeshape.jcr.JcrRepositoryFactory - Could not parse URL: unknown protocol: jndi
      Repository NOT found!

       

      Can anyone please shed some light on what I am doing wrong here?

       

      Thanks in advance!

       

      Cheers

      Tim

       

       

       

      ----------------------------------------------

       

      [1] Used properties:

      Context.INITIAL_CONTEXT_FACTORY = org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs = org.jboss.naming:org.jnp.interfaces
      Context.PROVIDER_URL = jnp://localhost

       

       

      [2]

      Map<String, String> parameters = new HashMap<String, String>();
      parameters.put("org.modeshape.jcr.URL", "jndi:jcr/local?repositoryName=repository");
      //parameters.put("org.modeshape.jcr.URL", "file:/modeshape-config.xml?repositoryName=repository");
                  
      Repository repository = null;
        for (RepositoryFactory aFactory : ServiceLoader.load(RepositoryFactory.class)) {
           System.out.println("Trying to load repository using: " + aFactory.toString());
             repository = aFactory.getRepository(parameters);
             if (repository != null) {
                                   System.out.println("Repository found!");
             }
         }
      if( repository == null ) System.out.println("Repository NOT found!");

        • 1. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
          rhauch

          IIUC, you have ModeShape installed (via the AS kit) into one JBoss AS 5.1 instance, and you're trying to access and use it in another VM? That's not currently possible.  Right now, the best way for you're remote client to access the ModeShape repository running inside the app server is to use the RESTful service.

           

          An alternative is to have ModeShape installed within your client application in a way that is clustered with the ModeShape instance running in JBoss AS. Just use the same JGroups configuration and ModeShape configuration. Of course, truly clustering the ModeShape instances is only required if your client wants to use search/query or events. (And your client could always query the ModeShape instance running in JBoss AS using the RESTful service, get the results, and look up the nodes in the local instance.)

           

          BTW, the error messages I think can be explained by the fact that Java SE doesn't come with a JNDI implementation and thus will not have a URL handler for the "jndi" scheme.

           

          I hope this helps and is clear.

          • 2. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
            tconrad

            Hi Randall.

             

            Thanks for your reply. That explains at least why I couldn't get it running ;-)

             

            To the clustering approach: the server machine will eventually store TBs of files (and other data) which I don't want to sync with a client (clustered) instance. Is it possible to tell the client instance to not sync fully with the server instance but only, say, the meta data for look ups?

             

            Cheers

            Tim

            • 3. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
              rhauch

              First, all of the ModeShape engines running in a cluster need to have the same configuration, which means they all need to use the same connectors configured in the same way, and those connectors need to be able to access the same underlying store(s).

               

              Second, just because the ModeShape engines all have access to the same content store does not mean that all data will be loaded into each engine! For example, if you're using a database for one content store, that database should be accessible from multiple machines, and no synchronization of the data is required. Same thing for a file system connector that accesses a networked file system.

               

              There are a few ways to try setting up ModeShape, depending upon whether you need/want query support.

               

              If you do NOT need/want queries, then this is pretty easy: set up the cluster of ModeShape instances so they can all access the shared store, but disable query support. Each ModeShape instance (running in the server or the client applications) will be able to access the data needed by its sessions via the connector/store, and only the change events will be sent via JGroups from one machine to the others. (If you aren't using observation and don't dynamically register namespaces or node types, you actually might get away with not using clustering at all. Basically, each ModeShape instance relies upon the underlying store to manage and share access to the content.)

               

              If you DO need/want queries, then I would set up the ModeShape instances on the server machine(s) in a cluster, but configure these to support queries (specifying where the search indexes should be stored). Also, make sure the RESTful service is deployed. Then, on the client machines, configure the ModeShape instances to have the same configuration except disable the query support. Your client application can submit queries to the RESTful service, and when the results are returned simply extract the results and, if your client application needs to load any Nodes, use the paths in the query results to look up the Node objects using the local Session.

               

              Again, a more "traditional" alternative to all of this is to simply set up ModeShape on the server (or servers using clustering), and have your client application use the RESTful service to remotely access the content.

               

              I do wish it were easier to set up ModeShape in a heterogeneous configuration. But when all the engines do have access to the underlying store(s), it's pretty easy to accomplish with careful configuration.

               

              Best regards,

              Randall

              • 4. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                tconrad

                OK, thanks. We will look into the RESTful service approach and do some benchmark testing =)

                 

                Cheers

                Tim

                • 5. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                  tconrad

                  Hi.

                   

                  Is there a simple way to add nodes through the RESTful service api?

                   

                  In the manual (http://docs.jboss.org/modeshape/latest/manuals/reference/html/web_access.html#modeshape_rest_client_api) I only found how to do it by sending JSON requests.

                   

                  Cheers

                  Tim

                  • 6. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                    rhauch

                    Tim, how you would represent/describe the node you want to add without using something like JSON (or XML)?

                    • 7. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                      tconrad

                      Well, you need (in this case) JSON. The JSONRestClient (http://docs.jboss.org/modeshape/2.2.0.Final/xref/org/modeshape/web/jcr/rest/client/json/JsonRestClient.html) contains methods for the creation of nodes of type "folder" or "file. This is done by creating a new FileNode object which obviously can return its JSON description.

                       

                      I was wondering whether there are other methods that I didn't find yet that generalize this concept, e.g. an object is generated by initializing it with JSONArray / JSONObjects that can do the same, i.e. can return it's JSON description.

                      • 8. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                        rhauch

                        Gotcha. Yes, at this time the REST client library isn't generic or capable enough to use for accessing or modifying any content. We definitely want to improve this, and have created MODE-888. If you have any suggestions or use cases or requirements, please add them to that issue.

                        • 9. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                          emiste

                          Is there any update about this topic . I'm facing the same problem with Modeshape 3.0.0.Alpha6 .Actually, my need is to access a repository started in a web app via JNDI .

                          Best regards and thank you for your help 

                          • 10. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                            rhauch

                            Is there any update about this topic . I'm facing the same problem with Modeshape 3.0.0.Alpha6 .Actually, my need is to access a repository started in a web app via JNDI .

                            Best regards and thank you for your help 

                            Can you be more specific about what you're trying to do? It certainly is possible for your web application to access a JCR repository running in the same process (see our documentation). But the standard JCR API is simply not capable of remotely invoking operations, so it's not possible to remotely access a JCR repository using the JCR API. ModeShape provides the REST service (see our documentation) that you can access using our REST Client library (which is still somewhat limited) or by writing your own REST client that uses simple HTTP requests.

                            • 11. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                              emiste

                              My need is to find a way that lets a JSE client access remotely a repository started within a web app ( obviously in different JVM).  But based on your response you confirmed to me that I can't access remotly a JCR repository without using a REST or  Webdav server.

                              Best regards

                              • 12. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                                rhauch

                                My need is to find a way that lets a JSE client access remotely a repository started within a web app ( obviously in different JVM).  But based on your response you confirmed to me that I can't access remotly a JCR repository without using a REST or  Webdav server.

                                Those are the ways ModeShape provides out of the box. Note that our REST service is more capable than our REST Client, which was never intended to be a general purpose client library that exposed all repository capabilities. You could pretty easily build a client library that just used HTTP requests to interact with our REST service.

                                 

                                We do have a remote JCR layer feature slated for 3.1, but that doesn't help you now.

                                 

                                Perhaps if the REST service doesn't suit your needs, you could build a custom web service that did.

                                 

                                Sorry we don't have a better solution.

                                • 13. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                                  emiste

                                  Thank you for your quick replay . Just one last question, when - even approximately -  is planned  the version 3.1 ?

                                  • 14. Re: How to access remote (ModeShape) JCR repository from a JBOSS AS?
                                    rhauch

                                    Probably fall-ish. Gotta get 3.0 out the door first. And honestly, the highest priority feature for 3.1 is federation (which this feature will use), so it's quite possible this feature could be bumped to 3.2 without contributors to pick it up.