tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Slater <li...@humanesoftware.com>
Subject Trouble accessing Resources in my Context
Date Tue, 14 Feb 2006 02:23:08 GMT
I'm running Tomcat 5.5.9 with JVM 1.5.0_05-83 on MacOS X 10.4.4. I'm  
trying to build an example webapp that shows the configuration for  
two Jackrabbit resources: one configured as an embedded resource for  
that web app and another configured as a shared resource for the  
entire host. I've tried to define the resources in a variety of  
places and haven't been able to get any of them to work.

My context files are defined like this....

$TOMCAT_HOME/conf/context.xml:

<Context>
     <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>


webapp/WEB-INF/context.xml:

<Context docBase="jackrabbit_config_test" reloadable="false">

     <Resource name="jcr/model1Repository"
         auth="Container"
         type="javax.jcr.Repository"
          
factory="org.apache.jackrabbit.core.jndi.BindableRepositoryFactory"
         configFilePath="conf/repository_model1.xml"
         repHomeDir="shared/jackrabbit_model1" />
	
     <Environment name="testNum" value="10"
          type="java.lang.Integer" override="false"/>

</Context>

I've got the following setup in server.xml:

   <GlobalNamingResources>
     ...
     <Resource name="jcr/model2Repository"
         auth="Container"
         type="javax.jcr.Repository"
          
factory="org.apache.jackrabbit.core.jndi.BindableRepositoryFactory"
         configFilePath="conf/repository_model2.xml"
         repHomeDir="shared/jackrabbit_model2" />

   </GlobalNamingResources>

And in my web.xml, I've got the following references:

<web-app>
     ...
     <resource-ref>
         <description>Jackrabbit Model 1 Repository</description>
         <res-ref-name>jcr/model1Repository</res-ref-name>
         <res-type>javax.jcr.Repository</res-type>
         <res-auth>Container</res-auth>
     </resource-ref>

     <resource-env-ref>
         <description>Jackrabbit Model 2 Repository</description>
         <resource-env-ref-name>jcr/model2Repository</resource-env- 
ref-name>
         <resource-env-ref-type>javax.jcr.Repository</resource-env- 
ref-type>
     </resource-env-ref>

     <resource-ref>
         <description>Test Number</description>
         <res-ref-name>testNum</res-ref-name>
         <res-type>java.lang.Integer</res-type>
         <res-auth>Container</res-auth>
     </resource-ref>
</web-app>


I know tomcat is finding the jcr/model2Repository resource because if  
I delete all of the database entries and repository files, and then  
restart Tomcat, upon restart the database and repository files are  
recreated. There's also log output in catalina.out about jackrabbit  
initializing itself for the model2Repository.

When I get to my servlet, I've got some code that prints the context  
entries for the initial context and the environment's context to the  
output webpage. Then I try to access both repositories. For good  
measure, I also try to access the testNum I defined in my webapp's  
context.xml. None of the objects are accessible. The locally defined  
objects (those in webapp/WEB-INF/context.xml) throw an exception:

javax.naming.NamingException: Cannot create resource instance
	at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance 
(ResourceEnvFactory.java:99)
	at javax.naming.spi.NamingManager.getObjectInstance 
(NamingManager.java:304)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:792)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:139)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:780)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
	at  
edu.ucsc.whisper.jackrabbit_test.JackrabbitTest.getObjectFromContext 
(JackrabbitTest.java:85)
	at edu.ucsc.whisper.jackrabbit_test.JackrabbitTest.doGet 
(JackrabbitTest.java:54)

The shared repository object (defined in the server.xml and global  
context.xml) simply comes back null when I call context.lookup( "jcr/ 
model2Repository" ) without throwing an exception.

I tried moving the configuration in the {webapp}/WEB-INF/context.xml  
to server.xml's <Host> section, as below:

         <Context path="/jackrabbit_config_test"  
docBase="jackrabbit_config_test">
             <Resource name="jcr/model1Repository"
                 auth="Container"
                 type="javax.jcr.Repository"
                  
factory="org.apache.jackrabbit.core.jndi.BindableRepositoryFactory"
                 configFilePath="conf/repository_model1.xml"
                 repHomeDir="shared/jackrabbit_model1" />

             <Environment name="testNum" value="10"
                  type="java.lang.Integer" override="false"/>
         </Context>

Doing this made the servlet able to find the testNum environment  
variable and the jcr/model2Repository was still null. But accessing  
jcr/model1Repository  seems to be worse because I got a ClassNotFound  
exception on  
org.apache.jackrabbit.core.jndi.BindableRepositoryFactory calling  
context.lookup() on it. But the jackrabbit.jar is in both {webapp}/ 
WEB-INF/lib and $TOMCAT_HOME/server/lib, so I don't know why the  
factory wouldn't be found. And, in the logs when the server starts  
using this configuration, the jcr/model2Repository is still getting  
initialized. But even if this configuration did work, my  
understanding is that with Tomcat 5.5, this is really *not* the  
preferred way of handling web-app specific context data.

Other information that might be helpful. I've got log4j configured  
for the server and my webapp to print out all logging info for the  
jackrabbit project and no errors are being reported. I've tried using  
just one of the repositories at a time (commenting the other out) and  
even without the risk of them interfering with each other, I get the  
same failures. I'm using maven's war target to build the webapp.

I've spent most of the day trying to work this out, using the Tomcat  
5.5 docs, the jackrabbit web pages (where the format for the resource  
came from), and some other webapps for reference and I'm just about  
at my wits end. Any pointers or tips would be very helpful and  
appreciated.

Thanks,

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message