6 Replies Latest reply on Oct 16, 2017 8:41 AM by Asim Khalil

    Wild Rabbits: A Question about Jackrabbit and Wildfly

    Alex Renger Newbie

      Hey Everyone, I promise I have scoured this forum and others -- for days -- and I'm out of ideas.  I think I'm close to getting this working, and I would be very grateful for any suggestions. My goal is to get Jackrabbit deployed within Wildfly 8.1.0.Final using an Oracle DB on the backside.  I have successfully deployed jackrabbit-jca-2.8.0.rar, but cannot get my simple webapp to connect to it. It seems like a simple JNDI "wiring" problem, but I don't know, of course. Shown below are the exact steps I've taken and the error I receive.

       

      Starting with a fresh wildfly-8.1.0.Final.tar.gz (md5 46caf74201245742a99f8a3eaac7e647), I added the jcr module. Here's where I put it, and the contents of the module file:

       

      $ pwd

      /media/homespace/wildfly-8.1.0.Final/modules

      $ find javax -type f

      javax/jcr/main/jcr-2.0.jar

      javax/jcr/main/module.xml

      $ cat javax/jcr/main/module.xml

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

      <module xmlns="urn:jboss:module:1.1" name="javax.jcr">

        <resources>

        <resource-root path="jcr-2.0.jar"/>

        </resources>

        <dependencies>

        <module name="javax.transaction.api" export="true"/>

        </dependencies>

      </module>

      $

       

      I then added a module for ojdbc:

       

      $ find com -type f

      com/oracle/db/main/ojdbc6.jar

      com/oracle/db/main/module.xml

      $ cat com/oracle/db/main/module.xml

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

      <module xmlns="urn:jboss:module:1.1" name="com.oracle.db">

        <resources>

        <resource-root path="ojdbc6.jar"/>

        </resources>

        <dependencies>

        <module name="javax.api"/>

        <module name="javax.transaction.api"/>

        </dependencies>

      </module>

      $

       

      I used jboss-cli to register ojdbc as a core module:

       

      [standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=oracle:add(driver-name=oracle,driver-module-name=com.oracle.db,driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource)

      {"outcome" => "success"}

      [standalone@localhost:9990 /]

       

      I then added an admin user and made the following modifications to standalone/configuration/standalone.xml via the html console/ui (to ensure up-to-date syntax, etc). First, I added a new datasource and tested it. All good. Here's the subsystem configuration:

       

      <subsystem xmlns="urn:jboss:domain:datasources:2.0">

        <datasources>

        <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">

        <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>

        <driver>h2</driver>

        <security>

        <user-name>sa</user-name>

        <password>sa</password>

        </security>

        </datasource>

        <datasource jta="false" jndi-name="java:/jdbc/DocumentStoreDS" pool-name="DocumentStoreDS" enabled="true" use-ccm="false">

        <connection-url>jdbc:oracle:thin:@10.0.0.5:1521:xe</connection-url>

        <driver-class>oracle.jdbc.OracleDriver</driver-class>

        <driver>oracle</driver>

        <security>

        <user-name>rabbit</user-name>

        <password>rabbit</password>

        </security>

        <validation>

        <validate-on-match>false</validate-on-match>

        <background-validation>false</background-validation>

        </validation>

        <statement>

        <share-prepared-statements>false</share-prepared-statements>

        </statement>

        </datasource>

        <drivers>

        <driver name="h2" module="com.h2database.h2">

        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>

        </driver>

        <driver name="oracle" module="com.oracle.db">

        <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>

        </driver>

        </drivers>

        </datasources>

      </subsystem>

       

      I then disabled JCA validation:

       

        <subsystem xmlns="urn:jboss:domain:jca:2.0">

        <archive-validation enabled="false" fail-on-error="true" fail-on-wa

        <bean-validation enabled="true"/>

      ...

       

      I then added the resource adapter:

       

      <subsystem xmlns="urn:jboss:domain:resource-adapters:2.0">

        <resource-adapters>

        <resource-adapter id="jackrabbit-jca-2.8.0.rar">

        <archive>

        jackrabbit-jca-2.8.0.rar

        </archive>

        <transaction-support>XATransaction</transaction-support>

        <connection-definitions>

        <connection-definition class-name="org.apache.jackrabbit.jca.JCAManagedConnectionFactory" jndi-name="java:/jca/DocumentStore" enabled="true" pool-name="RabbitAdapter">

        <config-property name="ConfigFile">

        /media/homespace/field/repository.xml

        </config-property>

        <config-property name="HomeDir">

        /media/homespace/field

        </config-property>

        <security>

        <application/>

        </security>

        <validation>

        <background-validation>false</background-validation>

        </validation>

        </connection-definition>

        </connection-definitions>

        </resource-adapter>

        </resource-adapters>

      </subsystem>

       

      I've attached a copy of my repository.xml file. I had to make the same modifications to jackrabbit-jca-2.8.0.rar, as described in the helpful post by Brian Wallis. That is, I removed the two logging jars, and added the dependencies line to MANIFEST.MF. At this point if I deploy jackrabbit-jca-2.8.0.rar, it complains about being unable to find the oracle driver. After wrestling with that for a bit I gave up and just put the ojdbc6.jar inside the rar file to make it happy. I know that's a hack but I'll come back to that later. My main question is about deploying a simple webapp that uses the adapter. With the ojdbc6 jar thrown in there, jackrabbit-jca-2.8.0.rar now deploys fine, connects to my oracle database, and creates all the tables and such without error.

       

      Here's the web.xml for my simple webapp, dubbed conejo:

       

      <?xml version="1.0" encoding="ISO-8859-1"?>

      <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

        <resource-env-ref>

        <description>Content Repository</description>

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

        <resource-env-ref-type>javax.jcr.Repository</resource-env-ref-type>

        </resource-env-ref>

      </web-app>

       

      And here's the code snippet that attempts to obtain a connection to the repository:

       

      InitialContext context = new InitialContext();

      Context environment = (Context) context.lookup("java:comp/env");

      repository = (Repository) environment.lookup("jcr/repository");

       

      Finally, here's the error that shows up in server.log upon depoyment of my conejo.war file:

       

      2014-07-28 15:48:29,647 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "conejo.war")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.conejo.conejo.env.jcr.repository is missing [jboss.naming.context.java.jboss.resources.jcr.repository]"]}

      2014-07-28 15:48:29,679 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "conejo.war" (runtime-name : "conejo.war")

      2014-07-28 15:48:29,680 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report

      JBAS014775: New missing/unsatisfied dependencies:

        service jboss.naming.context.java.jboss.resources.jcr.repository (missing) dependents: [service jboss.naming.context.java.module.conejo.conejo.env.jcr.repository]

       

      I'll buy you pizza if you can tell me what's wrong here! OK not really, but I'll be very thankful.

       

      Alex

        • 1. Re: Wild Rabbits: A Question about Jackrabbit and Wildfly
          Tomaz Cerar Master

          can you post also full server.log of server boot  (just zip it)

          • 2. Re: Wild Rabbits: A Question about Jackrabbit and Wildfly
            Alex Renger Newbie

            Hello Tomaz, thank you for your interest in helping!  I've attached a compressed server.log as you requested.

            • 3. Re: Wild Rabbits: A Question about Jackrabbit and Wildfly
              Alex Renger Newbie

              I got it to work.  It was a JNDI issue, as I suspected.  It seems that my current solution involves a non-standard approach to JNDI naming, which annoys me -- but it works.  For anyone who might benefit from my notes, I have detailed below my changes that got it to work.  I would still appreciate help from anyone with JNDI experience, to refine/correct my naming approach.

               

              * I changed the jndi-name of my resource adapter to "java:global/jca/DocumentStore"

              * I changed the resource-env-ref-name in web.xml of my webapp to match (i.e. "java:global/jca/DocumentStore").

              * I changed the code that gets a Repository instance to this:


              InitialContext context = new InitialContext();

              Context environment = (Context) context.lookup("java:global");

              repository = (Repository) environment.lookup( "jca/DocumentStore");

               

              * Lastly, I made sure that the MANIEST.MF file in my own webapp.war file lists its dependency on javax.jcr

              • 4. Re: Re: Wild Rabbits: A Question about Jackrabbit and Wildfly
                jaikiran pai Master

                Actually, that's not the right way to do it. The only thing that you missed in your configurations in the first post was that you only told the container to bind a resource within the web application's environment naming context, but you didn't tell it where to find that resource which you want bound. So all you have to do is add the lookup-name element to your resource-env-ref and point it to the JNDI name of your connection factory (on a slightly related note, you should be using a resource-ref instead of resource-env-ref):

                 

                 

                <resource-env-ref>
                  <description>Content Repository</description>
                  <resource-env-ref-name>jcr/repository</resource-env-ref-name>
                  <resource-env-ref-type>javax.jcr.Repository</resource-env-ref-type>
                  <!-- Point to the configured connection factory's JNDI name -->
                
                  <lookup-name>java:/jca/DocumentStore</lookup-name>
                
                </resource-env-ref>
                
                • 5. Re: Wild Rabbits: A Question about Jackrabbit and Wildfly
                  Alex Renger Newbie

                  Awesome.  Thank you, Jaikiran!  I figured it must be some small tweak to my JNDI setup but I didn't know what it was.  My "global" approach was a hack and I am glad to know the correct way to do it.  Thank you!

                  • 6. Re: Wild Rabbits: A Question about Jackrabbit and Wildfly
                    Asim Khalil Newbie

                    HI I have done the above configuration too look up the JCR remote repository using JNDI name.

                     

                    I am using wildfly 10.1.0 final and JCR Adapter is 2.14.3

                     

                    I am using following initial context configurations

                     

                    Properties prop = new Properties();        

                        prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");       

                        prop.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");       

                        prop.put("jboss.naming.client.ejb.context", "true");        

                        prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

                        InitialContext context = new InitialContext(prop);

                        Context environment = (Context) context.lookup("java:comp/env");

                        Repository repository = (Repository) environment.lookup("jcr/repository");

                     

                    But I am getting following exception

                     

                       [java] Exception in thread "main" javax.naming.CommunicationException: Could not obtain connection to any of these urls: http-remoting://localhost:8080 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server http-remoting:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server http-remoting:1099 [Root exception is java.net.UnknownHostException: http-remoting]]]

                         [java]     at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1562)

                         [java]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:634)

                         [java]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)

                         [java]     at javax.naming.InitialContext.lookup(InitialContext.java:417)

                         [java]     at com.os.sp.installer.folders.SystemFoldersInstaller.init(SystemFoldersInstaller.java:52)

                         [java]     at com.os.sp.installer.BaseInstaller.run(BaseInstaller.java:83)

                         [java]     at com.os.sp.installer.folders.SystemFoldersInstaller.main(SystemFoldersInstaller.java:37)

                         [java] Caused by: javax.naming.CommunicationException: Failed to connect to server http-remoting:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server http-remoting:1099 [Root exception is java.net.UnknownHostException: http-remoting]]

                         [java]     at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:274)

                         [java]     at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533)

                         [java]     ... 6 more

                         [java] Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server http-remoting:1099 [Root exception is java.net.UnknownHostException: http-remoting]

                         [java]     at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:248)

                         [java]     ... 7 more

                         [java] Caused by: java.net.UnknownHostException: http-remoting

                         [java]     at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)

                         [java]     at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)

                         [java]     at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)

                         [java]     at java.net.InetAddress.getAllByName0(InetAddress.java:1276)

                         [java]     at java.net.InetAddress.getAllByName(InetAddress.java:1192)

                         [java]     at java.net.InetAddress.getAllByName(InetAddress.java:1126)

                         [java]     at java.net.InetAddress.getByName(InetAddress.java:1076)

                         [java]     at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:76)

                         [java]     at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:244)

                         [java]     ... 7 more

                     

                    Please help!