11 Replies Latest reply on May 16, 2012 2:37 PM by rhauch

    JBoss AS6 installation - cannot get repository reference

    bwallis42

      I've downloaded the JBoss AS6 kit for ModeShape 2.8.1 and deployed it by copying the contents of the lib, deploy and conf directories over an existing server/default directory in a clean jboss AS 6.1.0.Final installation.

       

      I've changed the modeshape-config.xml file in modeshape-services.jar to the following:

       

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

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

                xmlns:jcr="http://www.jcp.org/jcr/1.0">

                <!-- Define the JCR repositories -->

                <mode:repositories>

                          <mode:repository jcr:name="DocumentStore"

                                    mode:source="JPA Store">

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

                                              <mode:option jcr:name="projectNodeTypes" mode:value="true" />

                                              <systemSourceName jcr:primaryType="mode:option"

                                                        mode:value="system@JPA Store" />

                                              <queryIndexDirectory jcr:primaryType="mode:option"

                                                        mode:value="${jboss.server.data.dir}/modeshape/repositories/store/indexes" />

                                              <mode:option jcr:name="queryIndexesRebuiltSynchronously"

                                                        mode:value="false" />

                                              <!-- specifies the strategy (always or ifMissing) used to determine which

                                                        query indexes need to be rebuilt when the repository restarts -->

                                              <mode:option jcr:name="rebuildQueryIndexOnStartup"

                                                        mode:value="ifMissing" />

                                    </mode:options>

                          </mode:repository>

                </mode:repositories>

                <!-- Define the sources used by the repository (or repositories) to store

                          and access the content -->

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

                          <!-- The 'IMR Store' repository is an in-memory source with a single default

                                    workspace (though others could be created, too). -->

                          <mode:source jcr:name="IMR Store"

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

                                    mode:description="The repository for our content"

                                    mode:defaultWorkspaceName="default">

                                    <!-- <mode:predefinedWorkspaceNames>staging </mode:predefinedWorkspaceNames>

                                              <mode:predefinedWorkspaceNames>dev</mode:predefinedWorkspaceNames> -->

                          </mode:source>

                          <mode:source jcr:name="JPA Store"

                                    mode:classname="org.modeshape.connector.store.jpa.JpaSource"

                              mode:dataSourceJndiName="java:jdbc/DocumentStoreDS"

                              mode:model="Simple"

                                    mode:dialect="org.hibernate.dialect.PostgreSQLDialect"

                                    mode:referentialIntegrityEnforced="true"

                                    mode:largeValueSizeInBytes="10000"

                                    mode:retryLimit="3"

                                    mode:compressData="false"

                                    mode:predefinedWorkspaceNames="default,system"

                                    mode:showSql="false"

                                    mode:autoGenerateSchema="validate"

                                    mode:creatingWorkspacesAllowed="true"

                                    mode:defaultWorkspaceName="default">

                          </mode:source>

                </mode:sources>

                <mode:sequencers>

                </mode:sequencers>

      </configuration>{code}

       

      and also updated the modeshape-jdbc-ds.xml file to reference my repository (not that I'm using jdbc at the moment)

       

      {code}

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

      <datasources>

        <local-tx-datasource>

          <jndi-name>ModeShapeDS</jndi-name>

          <connection-url>jdbc:jcr:jndi:jcr/local?repositoryName=DocumentStore</connection-url>

          <driver-class>org.modeshape.jdbc.LocalJcrDriver</driver-class>

          <user-name>admin</user-name>

          <password>admin</password>

            <metadata>

               <type-mapping>jcrrepo</type-mapping>

            </metadata>

        </local-tx-datasource>

      </datasources>

      {code}

       

      I have a singleton session bean that trys to get a reference to the repository defined in modeshape-config.xml (DocumentStore) but I always end up with a null pointer.

       

      I had a read of the post at https://community.jboss.org/thread/171222 and tried various forms of URL to lookup the repository but no luck.

       

      {code}

              Repository repository=null;

             

              String configUrl = "jndi:jcr/local/DocumentStore"// Note this URL!

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

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

                  repository = factory.getRepository(parameters);

                  if (repository != null) break;

              }{code}

       

      I also tried the seam injection with the org.jboss.seam.jcr package like so

       

      {code}

          @Inject @JcrConfiguration(name="org.modeshape.jcr.URL",

                                                value="jndi:jcr/local?repositoryName=DocumentStore")

                Repository repository;{code}

       

      but I assume it probably does the same thing under the covers and I just get a null pointer anyway.

       

      So, what have I missed?

       

      thanks

        • 1. Re: JBoss AS6 installation - cannot get repository reference
          bwallis42

          Turned on some debugging and when I execute the factory.getRepository(parameters) code I get the following in the log:

           

          {noformat}

          12:06:54,773 DEBUG [org.modeshape.jcr.JcrRepositoryFactory] Trying to load ModeShape JCR Repository with parameters: {org.modeshape.jcr.URL=jndi:jcr/local/DocumentStore}

          12:06:54,773 DEBUG [org.modeshape.jcr.JcrRepositoryFactory] Could not load engine from URL: jndi:jcr/local/DocumentStore

          {noformat}

          • 2. Re: JBoss AS6 installation - cannot get repository reference
            bwallis42

            And chased this down with the debugger.

             

            Using the jndi:jcr/local reference returns an instance of org.modeshape.jboss.managed.JNDIManagedRepositories but the JcrRepositoryFactory that is returned from the service loader is not expecting one of those, it wants a org.modeshape.jcr.api.Repositories.

             

            But ... JNDIManagedRepositories implements Repositories.

             

            Fee fi fo fum, I smell a JBoss class loading problem...!

             

            Thwack (sound of hand against forehead). The modeshape dependency for my project should be marked "<scope>provided</scope>"! There are *two* copies on the classpath. When the instance returned from the ServiceLoader is compared to my applications version of the Repositories class, they have been loaded by different class loaders. They might look like the same class but they are not.

             

            I have had to change my lookup code to include the repository name as a separate parameter like so:

             

            {code}

                    String configUrl = "jndi:jcr/local"// Note this URL!

                    String repoName = "DocumentStore";

                    Map<String, String> parameters = new HashMap<String,String>();

                    parameters.put("org.modeshape.jcr.URL", configUrl);

                    parameters.put("org.modeshape.jcr.RepositoryName", repoName);

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

                        repository = factory.getRepository(parameters);

                        if (repository != null) break;

                    }

            {code}

             

            Which seems a bit odd but the jndi:jcr/local/DocumentStore or jndi:jcr/local?repositoryName=DocumentStore URLs do not work for me.

             

            The seam injection still doesn't work though.

            1 of 1 people found this helpful
            • 3. Re: JBoss AS6 installation - cannot get repository reference
              rhauch

              It does sound like a classloading problem. When I've done similar things with the 3.0 codebase, I noticed that the ServiceLoader.load(RepositoryFactory.class) call returns our RepositoryFactory implementation from each classloader, and then the first one that's called is able to respond to the two JNDI URLs by finding/creating the repository, whereas when you supply the URL plus RepositoryName the first RepositoryFactory implementation can't use that (not sure why) so the second RepositoryFactory implementation gets a chance and returns the right URL.

               

              And I suspect the Seam injection doesn't work because it only can use the URL and can't use the RepositoryName property.

               

              (In 3.0 we actually split the single RepositoryFactory implementation into two: one that handles URLs to configuration files, and one that handles nothing but JNDI. We did this because we needed the JNDI one to be in our public API on a modular environment like AS7, but in a regular Java SE environment a client will see both.)

              • 4. Re: JBoss AS6 installation - cannot get repository reference
                edcorners

                Hi, seems like I'm having the same issue, despite Brian's alternative.

                 

                Using: JBoss AS6 kit for ModeShape 2.8.1 + clean jboss AS 6.1.0.Final installation + seam 2.2 client app. EJB client:

                 

                        String configUrl = "jndi:jcr/local"; 
                        String repoName = "repository";
                        javax.jcr.Repository repository=null;
                        Map<String, String> parameters = new HashMap<String,String>();
                        parameters.put("org.modeshape.jcr.URL", configUrl);
                        parameters.put("org.modeshape.jcr.RepositoryName", repoName);
                        for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
                            try {
                                                        repository = factory.getRepository(parameters);
                                              } catch (RepositoryException e) {
                                                        // TODO Auto-generated catch block
                                                        e.printStackTrace();
                                              }
                            if (repository != null) break;
                        }
                

                 

                On execution log shows:

                 

                Caused by: java.util.ServiceConfigurationError: javax.jcr.RepositoryFactory: Provider org.modeshape.jcr.JcrRepositoryFactory could not be instantiated: java.lang.ClassCastException
                

                 

                Tried the old Context.lookup() way, but it returns a NameNotFoundException .

                Any help/hint is appreciated. I would really like to have an option other than Jackrabbit.

                • 5. Re: JBoss AS6 installation - cannot get repository reference
                  rhauch

                  Ed, can you provide a stack trace for the ClassCastException?

                  • 6. Re: JBoss AS6 installation - cannot get repository reference
                    edcorners

                    Sure Randall here it is..

                     

                     java.lang.RuntimeException: java.util.ServiceConfigurationError: javax.jcr.RepositoryFactory: Provider org.modeshape.jcr.JcrRepositoryFactory could not be instantiated: java.lang.ClassCastException
                              at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:135) [:1.1.3]
                              at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44) [:2.2.2.Final]
                              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) [:2.2.2.Final]
                              at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) [:2.2.2.Final]
                              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [:2.2.2.Final]
                              at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:65) [:2.2.2.Final]
                              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [:2.2.2.Final]
                              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) [:2.2.2.Final]
                              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [:2.2.2.Final]
                              at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29) [:2.2.2.Final]
                              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [:2.2.2.Final]
                              at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30) [:2.2.2.Final]
                              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [:2.2.2.Final]
                              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) [:2.2.2.Final]
                              at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50) [:2.2.2.Final]
                              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_32]
                              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_32]
                              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_32]
                              at java.lang.reflect.Method.invoke(Unknown Source) [:1.6.0_32]
                              at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:80) [:1.1.3]
                              at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:71) [:1.1.3]
                              at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:62) [:1.1.3]
                              at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:76) [:1.1.3]
                              at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:62) [:1.1.3]
                              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_32]
                              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_32]
                              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_32]
                              at java.lang.reflect.Method.invoke(Unknown Source) [:1.6.0_32]
                              at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:74) [:1.1.3]
                              at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_30628850.invoke(InvocationContextInterceptor_z_fillMethod_30628850.java)
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:90) [:1.1.3]
                              at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_30628850.invoke(InvocationContextInterceptor_z_setup_30628850.java)
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.async.impl.interceptor.AsynchronousServerInterceptor.invoke(AsynchronousServerInterceptor.java:128) [:1.7.21]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62) [:1.7.21]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:60) [:1.7.21]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56) [:1.7.21]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.stateful.SessionSynchronizationInterceptor.invoke(SessionSynchronizationInterceptor.java:252) [:1.7.21]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) [:1.7.21]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42) [:1.0.4]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.stateful.StatefulCacheInterceptor.invoke(StatefulCacheInterceptor.java:65) [:1.7.21]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.concurrency.aop.interceptor.ContainerManagedConcurrencyInterceptor.invoke(ContainerManagedConcurrencyInterceptor.java:181) [:1.0.0-alpha-4]
                              at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:86) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.stateful.StatefulInstanceAssociationInterceptor.invoke(StatefulInstanceAssociationInterceptor.java:55) [:1.7.21]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.core.context.SessionInvocationContextAdapter.proceed(SessionInvocationContextAdapter.java:95) [:1.7.21]
                              at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:223) [:0.0.2]
                              ... 110 more
                    Caused by: java.util.ServiceConfigurationError: javax.jcr.RepositoryFactory: Provider org.modeshape.jcr.JcrRepositoryFactory could not be instantiated: java.lang.ClassCastException
                              at java.util.ServiceLoader.fail(Unknown Source) [:1.6.0_32]
                              at java.util.ServiceLoader.access$100(Unknown Source) [:1.6.0_32]
                              at java.util.ServiceLoader$LazyIterator.next(Unknown Source) [:1.6.0_32]
                              at java.util.ServiceLoader$1.next(Unknown Source) [:1.6.0_32]
                              at org.domain.mshape.session.RepositoryClientBean.connect(RepositoryClientBean.java:58) [:]
                              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_32]
                              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_32]
                              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_32]
                              at java.lang.reflect.Method.invoke(Unknown Source) [:1.6.0_32]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111) [jboss-aop.jar:2.2.2.GA]
                              at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:72) [:1.1.3]
                              at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:127) [:1.1.3]
                              ... 168 more
                    Caused by: java.lang.ClassCastException
                              at java.lang.Class.cast(Unknown Source) [:1.6.0_32]
                              ... 179 more
                    

                     

                    Thanks in advance!

                    • 7. Re: JBoss AS6 installation - cannot get repository reference
                      bwallis42

                      Should the lookup using just the URL work? Should I be able to do the following:

                       

                       

                      {code}

                                Repository repository=null;

                       

                             String configUrl = "jndi:jcr/local/DocumentStore";

                             Map<String, String> parameters = new HashMap<String,String>();

                             parameters.put("org.modeshape.jcr.URL", configUrl);

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

                                 repository = factory.getRepository(parameters);

                                 if (repository != null) break;

                             }

                      {code}

                       

                      or

                       

                      {code}

                         @Inject @JcrConfiguration(name="org.modeshape.jcr.URL",

                                                          value="jndi:jcr/local/DocumentStore")

                         Repository repository;

                      {code}

                       

                      Is there a bug in 2.8.1 that is preventing this from working?

                       

                      Also, the name string is modeshape specific which is not quite portable. In the ideal situation I should be able to just deploy jackrabbit and have it register its version of the repository in jndi with the name jcr/local/DocumentStore and have the code work.

                      • 8. Re: JBoss AS6 installation - cannot get repository reference
                        rhauch

                        Brian,

                         

                        ModeShape 2.8.1 (when used as a service with JBoss AS 5 or 6) uses the URL of the form "jndi:name/in/jndi?repositoryName=MyRepository", as we describe in our Getting Started guide and our Reference Guide. Unfortunately, the JBoss AS service in ModeShape 2.x does not register the javax.jcr.Repository instance in JNDI directly. That's something we've corrected in 3.0 (see below).

                         

                        Also, the name string is modeshape specific which is not quite portable. In the ideal situation I should be able to just deploy jackrabbit and have it register its version of the repository in jndi with the name jcr/local/DocumentStore and have the code work.

                         

                        Well, it's portable insofar as the code can be exactly the same regardless of which JCR implemntation you're using, and you can use a properties file to extract out the parameters passed to JCR's RepositoryFactory. I'll grant you that ModeShape 2.x's integration with JBoss AS7 does not play terribly well with the JCR 1.0-style approach of just looking up the Repository instance in JNDI.

                         

                        ModeShape 3.0, on the other hand, will work either way: the older URL style (with the "repositoryName" query parameter) will still work, but also each Repository registers itself into JNDI. The name defaults to "jcr/local/repositoryName", though this can be specified in the repository's configuration and can even be explicitly disabled. Plus, this will happen in all environments where ModeShape is used, including JBoss AS7, Tomcat, Glassfish, or any other environment that has JNDI.

                        • 9. Re: JBoss AS6 installation - cannot get repository reference
                          rhauch

                          Ed,

                           

                          Thanks for posting the stack trace. The ClassCastException when attempting to cast the JcrRepositoryFactory instance to a 'javax.jcr.RepositoryFactory' reference sounds to me like you've still got a classloader issue, and that you have two (or more) copies of the JCR API JAR on your classpath. The implementation is finding one, and the JcrRepositoryFactory is being instantiated with that 'javax.jcr.RepositoryFactory' Class object, while your application (and Seam) is using another instance of 'javax.jcr.RepositoryFactory Class object. Since the two Class objects are not the same instance, an instance of one cannot be cast to an instance of the other.

                           

                          Hope that helps,

                           

                          Randall

                          • 10. Re: JBoss AS6 installation - cannot get repository reference
                            edcorners

                            I was including jcr and modeshape jars into my "EarContent/lib" but they were already into JBoss' "server\default\lib". Problem solved, JNDI access works fine now!.

                            Thanks Randall.

                            • 11. Re: JBoss AS6 installation - cannot get repository reference
                              rhauch

                              Ed Corners wrote:

                               

                              I was including jcr and modeshape jars into my "EarContent/lib" but they were already into JBoss' "server\default\lib". Problem solved, JNDI access works fine now!.

                              Thanks Randall.

                              You're welcome, Ed. I'm glad you're back up and running.