tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Slater <li...@humanesoftware.com>
Subject Re: Trouble accessing Resources in my Context
Date Tue, 14 Feb 2006 09:53:40 GMT
I've got my servlet working now, without resorting to using a Context  
element inside the server.xml. I found that putting the Context in  
$TOMCAT_HOME/conf/Catalina/localhost/jackrabbit_config_test.xml works  
fine.

<Context>
     <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" />

     <ResourceLink
         name="sharedJCRRepository" global="jcr/model2Repository"  
type="javax.jcr.Repository" />

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

And then in my web app, I have these lines:

     <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>sharedJCRRepository</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>


I also finally realized that the <ResourceLink>'s name attribute  
can't be the same as the the global attribute. That took care of the  
null pointer I was getting trying to access that object.

So, while this works acceptably (the context information for the  
webapp is not included in server.xml), I would *much* prefer to use  
the WEB-INF/context.xml the Tomcat docs say I can (the fourth bullet  
on this page - http://tomcat.apache.org/tomcat-5.5-doc/config/ 
context.html). If someone could explain why that doesn't work, I'd be  
really appreciative. Is this possibly a known issue?

Thanks,

Mark

On Feb 13, 2006, at 9:40 PM, Mark Slater wrote:

> I've solved part of the problem... or at least made it less  
> complicated (I hope). The ClassNotFound exception mentioned at the  
> bottom is due to the jackrabbit jars being located in server/lib as  
> opposed to common/lib. I'd placed them in server lib on the advice  
> of someone more familiar with jackrabbit than I. I'd assumed that,  
> as long as the jar was included in the web app, this would not be a  
> problem; obviously that was incorrect. So after putting jackrabbit  
> and its dependencies in common/lib, here's what I've got:
>
> If the context for web-app only resources and environment variables  
> (jcr/model1Repository and testNum in the code below) are placed in  
> <Host><Context> in $TOMCAT_HOME/conf/server.xml, the web app is  
> able to find them.
>
> If they are placed in the web-app's WEB-INF/context.xml, an  
> exception is thrown (javax.naming.NamingException: Cannot create  
> resource instance).
>
> As the latter is definitely the preferred option (by tomcat  
> documentation and myself), I'd really like to get that to work.  
> I've also confirmed that I get the same errors on a newly  
> downloaded and configured Tomcat 5.5.15.
>
> Mark
>
> On Feb 13, 2006, at 6:23 PM, Mark Slater wrote:
>
>> 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
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


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


Mime
View raw message