8 Replies Latest reply on Jun 3, 2009 8:33 AM by Randall Hauch

    Error initializing repository

    Jozef Chocholáček Newbie

      Hi everybody!

      I am trying to add DNA repository to the Magnolia CMS. I am following the code in the repository example, but I am getting error when importing cars Graph from XML (config Graph is imported OK). I am using XML files from the repository examples, DNA version is 0.4.

      Any idea where the problem could be?

      My code:

      package org.jboss.labs.magnolia.modules.jcrdownloads;
      ...
      public class JcrProviderImpl implements Provider {
      ...
       public void init( RepositoryMapping arg0 ) throws RepositoryNotInitializedException {
      
       if (repository != null) return; // already started
      
       context = new ExecutionContext();
       sources = new RepositoryLibrary(context);
       InMemoryRepositorySource configSource = new InMemoryRepositorySource();
       configSource.setName("Configuration");
       sources.addSource(configSource);
      
       try {
       String location = "/tmp";
       Graph config = Graph.create("Configuration", sources, context);
       config.createWorkspace().named("default");
       config.importXmlFrom(location + "/configRepository.xml").into("/");
      
       repositoryService = new RepositoryService(sources, configSource.getName(), "default", context);
       repositoryService.getAdministrator().start();
      
       Graph cars = Graph.create("Cars", sources, context);
       cars.importXmlFrom(location + "/cars.xml").into("/"); // HERE THE ERROR APPEARS
      
       Graph aircraft = Graph.create("Aircraft", sources, context);
       aircraft.importXmlFrom(location + "/aircraft.xml").into("/");
      
       repository = new JcrRepository(context, sources, "Aircraft");
       } catch (Exception ex) {
       log.error("problem loading repository: "+ex.getMessage(), ex);
       throw new RepositoryNotInitializedException(ex);
       }
       }
      ...
      }
      


      And the exception:

      ERROR org.jboss.labs.magnolia.modules.jcrdownloads.JcrProviderImpl 21.05.2009 14:02:53 -- problem loading repository: null
      org.jboss.dna.graph.connector.RepositorySourceException
      at org.jboss.dna.graph.Graph.execute(Graph.java:239)
      at org.jboss.dna.graph.Graph$5.process(Graph.java:185)
      at org.jboss.dna.graph.request.RequestBuilder.verifyWorkspace(RequestBuilder.java:69)
      at org.jboss.dna.graph.Graph.useWorkspace(Graph.java:336)
      at org.jboss.dna.graph.Graph.getCurrentWorkspace(Graph.java:311)
      at org.jboss.dna.graph.Graph.getCurrentWorkspaceName(Graph.java:296)
      at org.jboss.dna.graph.Graph$Batch.<init>(Graph.java:2069)
      at org.jboss.dna.graph.Graph.batch(Graph.java:2033)
      at org.jboss.dna.graph.io.GraphImporter.importXml(GraphImporter.java:167)
      at org.jboss.dna.graph.io.GraphImporter.importXml(GraphImporter.java:119)
      at org.jboss.dna.graph.Graph$20.into(Graph.java:1979)
      at org.jboss.dna.graph.Graph$20.into(Graph.java:1953)
      at org.jboss.dna.graph.Graph$20.into(Graph.java:1977)
      at org.jboss.labs.magnolia.modules.jcrdownloads.JcrProviderImpl.init(JcrProviderImpl.java:73)
      at info.magnolia.cms.beans.config.ContentRepository.loadRepository(ContentRepository.java:348)
      ...



        • 1. Re: Error initializing repository
          Randall Hauch Master

          I'm not sure why the stack trace seems to be obscuring the actual RepositorySourceException message, but line 239 in the Graph.java class is throwing the exception because it is attempting and failing to obtain a connection to a repository source by name. If I had to guess, it'd be that the Graph is being created with a wrong name or with a name that doesn't match a repository source defined in the configuration file. Can you post the actual code in your JcrProviderImpl.init method?

          Best regards,

          Randall

          • 2. Re: Error initializing repository
            Jozef Chocholáček Newbie

             

            "rhauch" wrote:
            ... Can you post the actual code in your JcrProviderImpl.init method?


            Hi, the code is already there (in my first post), I only removed the comments. Or did you mean some other code?


            • 3. Re: Error initializing repository
              Randall Hauch Master

              Whoa, sorry 'bout that. My bad.

              I assume you're using the same files as provided in the examples. If so, then all the interesting configuration content is given in the "configRepository.xml" file under the "/jcr:system" XML element, which after import would correspond to that same path in the "Configuration" repository.

              Now, the RepositoryService connects to the repository named in the constructor and reads this repository to discover (among other things) the sources. And the RepositoryService starts looking for these nodes under a given path, which defaults to "/dna:system". So, unless another path is provided in the constructor, the RepositoryService will be looking under "/dna:system". But in the configuration repository, the path is "/jcr:system".

              So, to correct it, simply use the other RepositoryService constructor [1] by providing "/jcr:system" as the path to the top of the configuration repository. That should get you past this problem. Please let us know if you run into other problems.

              Clearly the example configRepository.xml file should be aligned with the default path assumed by the RepositoryService. I've logged this as a bug in JIRA [2], and we'll fix it before this week's 0.5 release. (BTW, the 0.5 release now has a vastly-improved configuration mechanism, allowing you to programmatically declare the configuration of the sources while all the service wiring is done for you. Stay tuned for that.)

              Best regards,

              Randall

              [1] http://www.jboss.org/file-access/default/members/dna/freezone/docs/0.4/apidocs/org/jboss/dna/repository/RepositoryService.html#RepositoryService(org.jboss.dna.repository.RepositoryLibrary,%20java.lang.String,%20java.lang.String,%20org.jboss.dna.graph.property.Path,%20org.jboss.dna.graph.ExecutionContext)
              [2] https://jira.jboss.org/jira/browse/DNA-436

              • 4. Re: Error initializing repository
                Jozef Chocholáček Newbie

                Well, my problem continues.

                After successfully loading repositories from XML to memory (thanks!), I am receiving another exception trying to login to the Repository:


                java.lang.IllegalArgumentException: The Credentials class "class javax.jcr.SimpleCredentials" must implement either "public LoginContext getLoginContext();" or "public AccessControlContext getAccessControlContext();".
                at org.jboss.dna.jcr.JcrRepository.login(JcrRepository.java:339)
                at info.magnolia.cms.util.WorkspaceAccessUtil.createRepositorySession(WorkspaceAccessUtil.java:123)
                at info.magnolia.cms.util.WorkspaceAccessUtil.createRepositorySession(WorkspaceAccessUtil.java:109)
                at info.magnolia.context.AbstractRepositoryStrategy.getRepositorySession(AbstractRepositoryStrategy.java:116)
                at info.magnolia.context.AbstractRepositoryStrategy.getHierarchyManager(AbstractRepositoryStrategy.java:78)
                ...


                After some code research, I realized that method JcrRepository.login(Credentials credentials, String workspaceName) from DNA expects the credentials object to implement some (strange?) methods, but Magnolia uses only javax.jcr.SimpleCredentials object, that does not implement such methods. (See getDefaultCredentials() method here: http://svn.magnolia-cms.com/view/community/magnolia/tags/magnolia-3.6.3/magnolia-core/src/main/java/info/magnolia/cms/util/WorkspaceAccessUtil.java?revision=18561&view=markup.)

                Any idea before I start to "hack" Magnolia code (which, in fact, I don't want to)?

                • 5. Re: Error initializing repository
                  Serge Emmanuel Pagop Newbie

                  The specific of acquiring the Credentials object is not specified by the JCR API, that means implementation may provide their own. Thus for now DNA JCR does not provide an Credentials implementation (there is an open discussion apropos).
                  When I take a look at this snippet code from info.magnolia.cms.util.WorkspaceAccessUtil

                  /**
                   * Login to the specified repository/default workspace using given credentials
                   * @param credentials
                   * @param repositoryName
                   * @return newly created JCR session
                   * @throws RepositoryException if login fails or workspace does not exist
                   * */
                   public Session createRepositorySession(SimpleCredentials credentials,
                   String repositoryName) throws RepositoryException {
                   return this.createRepositorySession
                   (credentials, repositoryName, ContentRepository.getDefaultWorkspace(repositoryName));
                   }


                  I can see that, you can implement your own Credentials and pass it as parameter to the createRepositorySession methods.
                  You can also take a look at our example for docs-getting-started-examples-repositories how we implement a simple JaasCredentials, that needs a LoginContext.

                  /Serge.


                  • 6. Re: Error initializing repository
                    Brian Carothers Apprentice

                    The 0.5 release will also accept javax.jcr.SimpleCredentials as well, but it still uses JAAS under the covers. The trunk has some examples of how to configure this (q.v. dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java IIRC)

                    • 7. Re: Error initializing repository
                      Jozef Chocholáček Newbie

                      When can I hope for 0.5 to be released? This can help me very much.

                      "bcarothers" wrote:
                      The 0.5 release will also accept javax.jcr.SimpleCredentials as well, but it still uses JAAS under the covers. The trunk has some examples of how to configure this (q.v. dna-jcr/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java IIRC)


                      • 8. Re: Error initializing repository
                        Randall Hauch Master

                        We're trying to close out the release by the end of this week.