David Blevins wrote:
> 
> 
> On Jul 14, 2009, at 1:16 PM, Allan Lykke Christensen wrote:
> 
>> Thanks for your response.  I realised that I was trying to over- 
>> engineer my code by having dynamic binding and look-up of objects  
>> using JNDI. It was not needed for the purpose of my application.  
>> Instead I've gone back to using a Resource Adapter for connecting to  
>> a Java Content Repository (JCR). Specifically, I'm using the  
>> Jackrabbit Content Repository. A JCA component was already provided  
>> (although a pain to install on Mac because of filename case issues)  
>> and I've managed to install it on GlassFish. This got me back to my  
>> original test case. Using the Resource Adapter (JCA 1.0), requires  
>> me to set-up a a Connector connection pool and resource which I  
>> bound to a JNDI name. The repository would then be available using  
>> the following DI:
>>
>> @Resource(mappedName="jcr/repository",  
>> type=javax.jcr.Repository.class) private Repository rep;
>>
>> But how do I tell OpenEJB about the resource so that I can add my  
>> own dummy repository before running my tests? Is it possible?
> 
> Sure, you can plug in any J2EE compliant Resource Adapter.  The  
> process for doing that in a Maven test environment is as a described  
> an email or two back.
> 
> As described in that other email, Maven will not add rar files  
> (Resource Adapter aRchives) to the classpath for some very stubborn  
> reason, so you have to sort of unwrap it by creating a module with the  
> same dependencies as the rar file and with the ra.xml file from the  
> rar extracted to src/resources/META-INF/ra.xml.  Fortunately  
> Jackrabbit uses maven and everything is up in maven repositories, so  
> the setup is much easier.  This worked for me:
> 
>    jackrabbit-rar
>    jackrabbit-rar/pom.xml
>    jackrabbit-rar/src
>    jackrabbit-rar/src/main
>    jackrabbit-rar/src/main/resources
>    jackrabbit-rar/src/main/resources/META-INF
>    jackrabbit-rar/src/main/resources/META-INF/ra.xml
> 
>    --pom.xml-------------
>    <?xml version="1.0" encoding="UTF-8"?>
>    <project xmlns="http://maven.apache.org/POM/4.0.0";
>      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
>      http://maven.apache.org/maven-v4_0_0.xsd";>
> 
>      <groupId>your.package</groupId>
>      <artifactId>jackrabbit-rar</artifactId>
>      <version>1.0-SNAPSHOT</version>
>      <modelVersion>4.0.0</modelVersion>
>      <packaging>jar</packaging>
>      <name>Jackrabbit Resource Adapter</name>
> 
>      <dependencies>
>        <dependency>
>          <groupId>org.apache.jackrabbit</groupId>
>          <artifactId>jackrabbit-jca</artifactId>
>          <version>1.5.6</version>
>        </dependency>
>        <dependency>
>          <groupId>javax.jcr</groupId>
>          <artifactId>jcr</artifactId>
>          <version>1.0</version>
>        </dependency>
>      </dependencies>
>    </project>
>    ----------------------
> 
> Adjust the <groupId> from "your.package" to whatever groupId you use  
> for your own modules.  Change the jackrabbit version to whatever you  
> are using.  Also remember the ra.xml file needs to be extracted from  
> the jackrabbit-jca.rar file.
> 
> Then you should add the "<module>jackrabbit-rar</module>" to your  
> parent pom.  Anywhere that needs to use the Jackrabbit Resource  
> Adapter just needs to declare a maven dependency on it like so:
> 
>      <dependency>
>        <groupId>your.package</groupId>
>        <artifactId>jackrabbit-rar</artifactId>
>        <version>1.0-SNAPSHOT</version>
>        <scope>provided</provided>
>      </dependency>
> 
> Once that is declared in your modules that use the Jackrabbit Resource  
> Adapter, all the injection points should work.  You should see some  
> log lines like the following that indicate the Resource Adapter (aka  
> Connector) is being found and deployed:
> 
>    INFO - Found ConnectorModule in classpath: /Users/dblevins/work/ 
> openejb3/examples/ear-testing/jackrabbit-rar/target/jackrabbit-rar-1.0- 
> SNAPSHOT.jar
>    ...
>    INFO - Beginning load: /Users/dblevins/work/openejb3/examples/ear- 
> testing/jackrabbit-rar/target/jackrabbit-rar-1.0-SNAPSHOT.jar
>    ...
>    INFO - Configuring Service(id=jackrabbit-rar-1.0-SNAPSHOT.jarRA,  
> type=Resource, provider-id=jackrabbit-rar-1.0-SNAPSHOT.jarRA)
>    INFO - Configuring Service(id=jackrabbit-rar-1.0-SNAPSHOT.jar,  
> type=Resource, provider-id=jackrabbit-rar-1.0-SNAPSHOT.jar)
>    ...
>    INFO - Enterprise application "classpath.ear" loaded.
> 
> I gave the above setup a try and it did deploy for me.  I don't know  
> what it takes to configure and use Jackrabbit itself, but this will  
> get you past the Maven limitation and allow OpenEJB to see and deploy  
> the rar like it would any compliant Resource Adapter.
> 
> Hope this helps!
> 
> -David
> 
> 
> 


Hello David,

I have followed your instructions and it worked great. Unfortunately, I
haven't been able to find a way to expose jackrabbit as a JNDI resource.
This was possible in JBoss by defining a *-ds file like the following:

<connection-factories> 
        <tx-connection-factory>
                <jndi-name>jcr/local</jndi-name> 
                <xa-transaction/>
                <rar-name>etask-jackrabbit-jca.rar</rar-name>
                
<connection-definition>javax.jcr.Repository</connection-definition>
                <config-property name="homeDir"
type="java.lang.String">C:/path/to/repository</config-property>
                <config-property name="configFile"
type="java.lang.String">classpath:repository.xml</config-property>
                <config-property name="bindSessionToTransaction"
type="java.lang.Boolean">true</config-property>
        </tx-connection-factory>
</connection-factories>

I didn't find any documentation as to the way to deploy such a resource (the
repository). Do you know of any site where I can find this?

Regards,

Camilo.
-- 
View this message in context: 
http://www.nabble.com/Unit-testing-code-containing-DirContext-resource-injection-tp24101774p24836874.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to