9 Replies Latest reply on Jan 4, 2012 5:23 AM by stedud.1

    ModeShape 2.7 and Tomcat 7 - JNDI

    stedud.1

      Hi,

       

      I had a look at several threads about this, but I'm still not able to use ModeShape on Tomcat with JNDI.

      My configuration is the following :

      - Tomcat 7

      - Modeshape 2.7

      - context.xml:

      <Resource name="jcr/local"

                auth="Container"

                type="org.modeshape.jcr.api.Repositories"

                factory="org.modeshape.jcr.JndiRepositoryFactory"

                configFile="C:\Users\stedud\Documents\eclipse_workspace\JCR_ModeShape\WebContent\configRepository.xml"/>

       

      - web.xml:

      <resource-env-ref>

         <description>ModeShape Engine</description>

         <resource-env-ref-name>jcr/local</resource-env-ref-name>

         <resource-env-ref-type>org.modeshape.jcr.api.Repositories</resource-env-ref-type>

      </resource-env-ref>

      - configRepository.xml

      <?xml version="1.0" encoding="UTF-8"?>

       

      - configRepository.xml

      <configuration xmlns:mode="http://www.modeshape.org/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">

            <mode:repositories>

                <mode:repository jcr:name="Documents" mode:source="Documents">

       

                    <mode:options jcr:primaryType="mode:options">

                        <jaasLoginConfigName jcr:primaryType="mode:option" mode:value="modeshape-jcr"/>

                    </mode:options>

                </mode:repository>

            </mode:repositories>

          <mode:sources jcr:primaryType="nt:unstructured">

              <mode:source jcr:name="Documents"

                          mode:classname="org.modeshape.graph.connector.inmemory.InMemoryRepositorySource"

                          mode:retryLimit="3" mode:defaultWorkspaceName="workspace1">

                  <predefinedWorkspaceNames>system</predefinedWorkspaceNames>

              </mode:source>

          </mode:sources>

          <mode:mimeTypeDetectors>

              <mode:mimeTypeDetector jcr:name="Detector"

                       mode:description="Standard extension-based MIME type detector"/>

          </mode:mimeTypeDetectors>

      </configuration>

       

      - Retrieving the repository:

      String configUrl = "jndi:jcr/local?repositoryName=Documents";

              Repository repository = null;

              Map<String, String> parameters = Collections.singletonMap("org.modeshape.jcr.URL", configUrl);

              for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {

                   try

                  {

                      repository = factory.getRepository(parameters);

                  }

                  catch (RepositoryException e)

                  { e.printStackTrace(); }

                    if (repository != null) { break; }

              }

              System.out.println("Repository : " + repository);

       

      I'm using Eclipse to develop, here is the message I have in the log :

      **********************************

      (...)

      2 janv. 2012 19:02:17 org.apache.coyote.AbstractProtocolHandler start

      INFO: Starting ProtocolHandler ["ajp-bio-8009"]

      2 janv. 2012 19:02:17 org.apache.catalina.startup.Catalina start

      INFO: Server startup in 8249 ms

      2 janv. 2012 19:02:17 com.vaadin.terminal.gwt.server.AbstractApplicationServlet checkProductionMode

      (...)

      19:02:19.056 ["http-bio-9090"-exec-4] DEBUG o.modeshape.jcr.JcrRepositoryFactory - Trying to load ModeShape JCR Repository with parameters: {org.modeshape.jcr.URL=jndi:jcr/local?repositoryName=Documents}

      19:02:19.064 ["http-bio-9090"-exec-4] DEBUG o.modeshape.jcr.JcrRepositoryFactory - Could not load engine from URL: jndi:jcr/local?repositoryName=Documents

      Repository : null

      **********************************

       

      I tried more or less all the configurations I found in ModeShape forums (including JCR 1.0 mode) : nothing to do, my repository is always null.

       

      Thanks per advance to anybody who could help me finding where I'm wrong...

       

      Regards,

       

      //Stéphane

        • 1. Re: ModeShape 2.7 and Tomcat 7 - JNDI
          aakil

          2.7 on Jboss seems to have the same problem.

          • 2. Re: ModeShape 2.7 and Tomcat 7 - JNDI
            stedud.1

            Hello,

             

            So you suggest this could be a problem specific to 2.7 version ?

            I heard about some issues regarding JNDI problems but they had to be fixed in 2.6, I naïvely thought the fix would be forwarded in 2.7 :-)

             

            //Stéphane

            • 3. Re: ModeShape 2.7 and Tomcat 7 - JNDI
              aakil

              Sorry about my useless comment, basically me being frustrated after struggling for so long trying to connect via JNDI.

               

              No i do not know if it is a 2.7 problem. Downloaded the source tried to build it and the build failed, so now basically still trying to figure out from the source code why it is not working, or what I am doing wrong. Will post an update if I find something.

              • 4. Re: ModeShape 2.7 and Tomcat 7 - JNDI
                stedud.1

                ok thanks :-)

                //Stéphane

                • 5. Re: ModeShape 2.7 and Tomcat 7 - JNDI
                  aakil

                  Ok this is what I have done to get the problem and what i have figured out so far, still do not have the answer but maybe it helps you.

                   

                  I copied the contents of modeshape-2.7.0.Final-jbossas-6-dist to my Jboss 6.1 instance.

                   

                  Then i tried to connect via JNDI.

                   

                  I always get no repository back.

                   

                  The class that is entered is JcrRepositoryFactory and in this method is where the problem is.

                   

                  private Repositories getRepositoriesFromJndi( String engineJndiName,

                                                                    Map<String, String> parameters ) {

                          try {

                              if (parameters == null) parameters = Collections.emptyMap();

                              InitialContext ic = new InitialContext(hashtable(parameters));

                   

                              Object ob = ic.lookup(engineJndiName);

                              if (ob instanceof Repositories) {

                                  return (Repositories)ob;

                              }

                              return null;

                          } catch (NamingException ne) {

                              return null;

                          }

                      }

                   

                  it checks for instanceof Repositories which fails as it is an instance of org.modeshape.jboss.managed.JNDIManagedRepositories and therefore returns a null.

                   

                  Still trying to figure out what I have to do different to make it work.

                  • 6. Re: ModeShape 2.7 and Tomcat 7 - JNDI
                    rhauch

                    Sorry for the delay; I'm still trying to catch up from my long holiday break.

                    it checks for instanceof Repositories which fails as it is an instance of org.modeshape.jboss.managed.JNDIManagedRepositories and therefore returns a null.

                     

                    Still trying to figure out what I have to do different to make it work.

                     

                    The org.modeshape.jboss.managed.JNDIManagedRepositories class actually does implement org.modeshape.jcr.api.Repositories. So if that line is failing, then you have multiple "modeshape-jcr-api" jars on your classpath. The service should be using the one that's in the global classpath, and your application should see that, too. But I'm guessing that you have this JAR in your web application as well. So I think the problem isn't the same on AS6 as it is on Tomcat.

                     

                    UPDATE: I originally dismissed the problem you're seeing on AS6 as being different, but maybe I shouldn't be that quick to dismiss a duplicate JAR on the classpath as the problem (I've not yet used Tomcat 7).

                    • 7. Re: ModeShape 2.7 and Tomcat 7 - JNDI
                      stedud.1

                      Hello,

                       

                      Thanks for your response.

                      As far as I know I only have one jar copy but I'm going to double check tomorrow.

                       

                      Regards,

                       

                      //Stéphane

                      • 8. Re: ModeShape 2.7 and Tomcat 7 - JNDI
                        aakil

                        Stéphane sorry that I highjacked your thread :-)

                         

                        Randall thanks yes that was my problem, when I gave up last night I realised it was a class loading issue. Changed to <scope>provided</scope> in maven and it is now finding the repository.

                         

                        Thanks

                         

                        Now if I can just get the log4j stuff to work in JBoss 6, it would not take so much effort again to find the problem :-)

                        • 9. Re: ModeShape 2.7 and Tomcat 7 - JNDI
                          stedud.1

                          Don't worry ;-)

                          I think I'm going to switch to JackRabbit, it's easier to startup on Tomcat with it. Perhaps I'll see later how to run on ModeShape again...

                           

                          Regards,

                           

                          //Stéphane