You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Mark Slater <li...@humanesoftware.com> on 2006/02/13 02:50:02 UTC

Model-2 Deployment example and test app

Hello,

I'm new to Jackrabbit, so the first thing I'm trying to do is put  
together a Model-2 (shared J2EE resource) deployment on Tomcat 5.5  
and an example webapp (servlet) that confirms the deployment has been  
correctly configured. I figured this would be a good way for me to  
get acquainted with using Jackrabbit, and possibly provide an example  
that could be distributed by the project. Unfortunately, I haven't  
gotten very far.

Following the instructions on the website for the Resource  
configuration, I've added the following lines to my $TOMCAT_HOME/conf/ 
server.xml:

======= Begin Tomcat server.xml =======
   <GlobalNamingResources>
     ...

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

   </GlobalNamingResources>
======= End Tomcat server.xml =======



And I've added this configuration to the <test-app>/WEB-INF/web.xml:

======= Begin web app web.xml =======
     <resource-env-ref>
         <description>Jackrabbit Repository</description>
         <resource-env-ref-name>jcr/globalRepository</resource-env- 
ref-name>
         <resource-env-ref-type>javax.jcr.Repository</resource-env- 
ref-type>
     </resource-env-ref>
======= End web app web.xml =======



Next, I tried creating a <test-app>/WEB-INF/context.xml file that  
looks like this:

======= Begin web app context.xml =======
<Context>
	
     <ResourceLink
         glabal="jcr/globalRepository" name="jcr/globalRepository"  
type="javax.jcr.Repository" />

     <Manager pathname="" />

</Context>
======= End web app context.xml =======



However, when I run my servlet, I get:

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.doGet 
(JackrabbitTest.java:100)
	....

So, I tried using the $TOMCAT_HOME/conf/context.xml, and made it look  
like this:

======= Begin Tomcat context.xml =======
<!-- The contents of this file will be loaded for each web  
application -->
<Context>

     <!-- Default set of monitored resources -->
     <WatchedResource>WEB-INF/web.xml</WatchedResource>
	
     <ResourceLink
         glabal="jcr/globalRepository" name="jcr/globalRepository"  
type="javax.jcr.Repository" />

     <!-- Uncomment this to disable session persistence across Tomcat  
restarts -->
     <!--
     <Manager pathname="" />
     -->

</Context>
======= End Tomcat context.xml =======



That works better, in that I don't get an exception. Instead the  
lookup() request returns null.

The servlet code currently looks like this:

======= Begin source code =======
     public void doGet( HttpServletRequest request,  
HttpServletResponse response )
         throws IOException, ServletException
     {
         boolean skipping = false;

         response.setContentType("text/html");
         PrintWriter out = response.getWriter();
         out.println("<html>");
         out.println("<head>");
         out.println("<title>Jackrabbit Configuration Testing</title>");
         out.println("</head>");
         out.println("<body>");

         if( !skipping )
         {
             out.println("<h3>Getting the Jackrabbit reference via  
JNDI</h3>");

             try
             {
             // Get the initial context
                 Context initialContext = new InitialContext();

                 out.println( "<p>Got initial context</p>" );

                 NamingEnumeration<NameClassPair> contextEntries = null;

                 contextEntries = initialContext.list( "java:comp/ 
env" );

                 // snip - printing entries

                 contextEntries = initialContext.list( "java:comp/env/ 
jcr" );

                 // snip - printing entries


             // Get the environment context
                 Context environmentContext = (Context)  
initialContext.lookup( "java:comp/env" );

                 out.println( "<p>Got environment context</p>" );

                 contextEntries = environmentContext.list( "/" );

                 // snip - printing entries

                 contextEntries = environmentContext.list( "/jcr" );

                 // snip - printing entries


             // get values out of the context.
                 jackrabbitRepository =
                     (Repository) environmentContext.lookup( "jcr/ 
globalRepository" );

                 out.println( "<p>jackrabbitRepository = " +  
jackrabbitRepository + "</p>" );
             }
             catch( Exception e )
             {
                 out.println("<p>Exception thrown: <pre>" );
                 e.printStackTrace( out );
                 out.println("</pre></p>");
             }
         }


         out.println("</body>");
         out.println("</html>");
     }
======= End source code =======



And the web page generated looks like this:

======= Begin HTML output =======
Getting the Jackrabbit reference via JNDI

Got initial context

Entries in java:comp/env:

jcr: org.apache.naming.NamingContext
Entries in java:comp/env/jcr:

globalRepository: org.apache.naming.ResourceLinkRef
Got environment context

Entries in /:

jcr: org.apache.naming.NamingContext
Entries in /jcr:

globalRepository: org.apache.naming.ResourceLinkRef
jackrabbitRepository = null

======= End HTML output =======



So I can see the reference to Jackrabbit is there, but I'm not able  
to get it. Perhaps the BindableRepositoryFactory is returning a null  
repository? For all I know, this is a JNDI issue with Tomcat. Even  
the author of http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource- 
examples-howto.html seems to have had trouble configuring a  
PostgreSQL data source to be global. But if anybody could suggest a  
way of debugging this, or flat out knows what the problem is, I'd  
love some help. Of course, if such an example already exists  
someplace, that'd be great to know too. I found the First Steps  
example, but that uses an embedded version... I'm intending to code  
essentially the same example, but as a servlet that includes output  
showing the success or failure of the various steps (which will  
hopefully give users an indication of where their configuration has  
failed).

Thanks,

Mark

Re: Model-2 Deployment example and test app [Fixed, with suggestions for updated docs]

Posted by Mark Slater <li...@humanesoftware.com>.
I filed JCR-318 for this issue, and tried to explain it as best I  
could. I didn't find a way to set the issue links (first time using  
Jira), but there's a few:

JCR-120
JCR-243
JCR-245

Mark

On Feb 15, 2006, at 2:11 AM, Jukka Zitting wrote:

> Hi,
>
> On 2/15/06, Mark Slater <li...@humanesoftware.com> wrote:
>> I spoke too soon. The repository is, in fact, shut down when the web
>> app is undeployed or redeployed while Tomcat is running. However it
>> cannot be started again without restarting Tomcat entirely.
>
> I figure that the repository instance is left hanging loose somewhere
> when the local JNDI context is rebuilt during redeployment. There is a
> lock mechanism that prevents two Jackrabbit instances from running
> simultaneously on a repository.
>
>> Looks like I may have to wait until the transient capabilities are
>> merged into the BindableRepository.
>
> You may want to file a Jira issue for that to better track the  
> progress.
>
> BR,
>
> Jukka Zitting
>
> --
> Yukatan - http://yukatan.fi/ - info@yukatan.fi
> Software craftmanship, JCR consulting, and Java development


Re: Model-2 Deployment example and test app [Fixed, with suggestions for updated docs]

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 2/15/06, Mark Slater <li...@humanesoftware.com> wrote:
> I spoke too soon. The repository is, in fact, shut down when the web
> app is undeployed or redeployed while Tomcat is running. However it
> cannot be started again without restarting Tomcat entirely.

I figure that the repository instance is left hanging loose somewhere
when the local JNDI context is rebuilt during redeployment. There is a
lock mechanism that prevents two Jackrabbit instances from running
simultaneously on a repository.

> Looks like I may have to wait until the transient capabilities are
> merged into the BindableRepository.

You may want to file a Jira issue for that to better track the progress.

BR,

Jukka Zitting

--
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftmanship, JCR consulting, and Java development

Re: Model-2 Deployment example and test app [Fixed, with suggestions for updated docs]

Posted by Mark Slater <li...@humanesoftware.com>.
I spoke too soon. The repository is, in fact, shut down when the web  
app is undeployed or redeployed while Tomcat is running. However it  
cannot be started again without restarting Tomcat entirely. I'm not  
sure what kind of data corruption risks are being run by not shutting  
it down nicely, but I know having to restart Tomcat to redeploy a  
webapp is onerous.

Looks like I may have to wait until the transient capabilities are  
merged into the BindableRepository.

Mark

On Feb 15, 2006, at 1:39 AM, Mark Slater wrote:

>
> On Feb 14, 2006, at 5:23 AM, Jukka Zitting wrote:
>
>>> I did find one other potential documentation bug in the howto-
>>> model1.xml page. The text says
>>> [...]
>>> I set up a model 1 repository in the same servlet (but with  
>>> different
>>> repository settings) and tried to follow these directions. The
>>> problem that I ran into is that the shutdown() method is not in the
>>> javax.jcr.Repository interface, and BindableRepository is package
>>> protected so I can't even cast the object returned by the Context to
>>> a BindableRepository. Without that, I wasn't able to see how the
>>> shutdown() method could be called from my servlet's destroy()  
>>> method.
>>
>> Good point. Nowadays there's an alternative Repository frontend  
>> called
>> TransientRepository that solves the shutdown problem by automatically
>> closing the repository when all the sessions are closed, but it  
>> hasn't
>> yet been integrated with BindableRepository. I'll take a look at
>> fixing this.
>
> It seems there's an interface in org.apache.jackrabbit.api called  
> JackrabbitRepository. Its only method is the prototype for the  
> shutdown() method that needs to be called. I tried changing  
> BindableRepository implement that, and made the method made public.  
> When I did my web app could cast the object it got from the JNDI  
> context to a JackrabbitRepository and things worked just fine.
>
> Mark
>
> Index: src/main/java/org/apache/jackrabbit/core/jndi/ 
> BindableRepository.java
> ===================================================================
> --- src/main/java/org/apache/jackrabbit/core/jndi/ 
> BindableRepository.java       (revision 377972)
> +++ src/main/java/org/apache/jackrabbit/core/jndi/ 
> BindableRepository.java       (working copy)
> @@ -16,6 +16,7 @@
>   */
> package org.apache.jackrabbit.core.jndi;
> +import org.apache.jackrabbit.api.JackrabbitRepository;
> import org.apache.jackrabbit.core.RepositoryImpl;
> import org.apache.jackrabbit.core.config.RepositoryConfig;
> @@ -59,7 +60,7 @@
>   * method should be used to explicitly close the repository if
>   * needed.
>   */
> -class BindableRepository implements Repository, Referenceable,  
> Serializable {
> +class BindableRepository implements Repository,  
> JackrabbitRepository, Referenceable, Serializable {
>      /** The serialization UID of this class. */
>      static final long serialVersionUID = -2298220550793843166L;
> @@ -253,7 +254,7 @@
>      /**
>       * Delegated to the underlying repository instance.
>       */
> -    void shutdown() {
> +    public void shutdown() {
>          ((RepositoryImpl) delegatee).shutdown();
>          try {
>              Runtime.getRuntime().removeShutdownHook(hook);
>
>


Re: Model-2 Deployment example and test app [Fixed, with suggestions for updated docs]

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 2/15/06, Mark Slater <li...@humanesoftware.com> wrote:
> It seems there's an interface in org.apache.jackrabbit.api called
> JackrabbitRepository. Its only method is the prototype for the
> shutdown() method that needs to be called.

That's true. We added the JackrabbitRepository interface just recently
as a public interface for the Jackrabbit-specific extension on the
standard JCR Repository interface.

> I tried changing BindableRepository implement that, and made the
> method made public. When I did my web app could cast the object
> it got from the JNDI context to a JackrabbitRepository and things
> worked just fine.

That's a possible approach, but there is a conceptual problem with
taking a JNDI resource and shutting it down explicitly. For example
you might want to later on change the deployment model in which case
your application would no longer be in charge of shutting down the
repository. A better alternative would be to either directly
instantiate and shutdown the repository directly within the web
application or to add support for the TransientRepository class in
BindableRepository.

I agree that the existing documentation doesn't cover these issues
very well. I hope that this discussion leads to improvements for these
issues. :-)

PS. See the Jira issue JCR-245 (and the related issues) for backround
on the TransientRepository class and repository shutdown problems.

BR,

Jukka Zitting

--
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftmanship, JCR consulting, and Java development

Re: Model-2 Deployment example and test app [Fixed, with suggestions for updated docs]

Posted by Mark Slater <li...@humanesoftware.com>.
On Feb 14, 2006, at 5:23 AM, Jukka Zitting wrote:

>> I did find one other potential documentation bug in the howto-
>> model1.xml page. The text says
>> [...]
>> I set up a model 1 repository in the same servlet (but with different
>> repository settings) and tried to follow these directions. The
>> problem that I ran into is that the shutdown() method is not in the
>> javax.jcr.Repository interface, and BindableRepository is package
>> protected so I can't even cast the object returned by the Context to
>> a BindableRepository. Without that, I wasn't able to see how the
>> shutdown() method could be called from my servlet's destroy() method.
>
> Good point. Nowadays there's an alternative Repository frontend called
> TransientRepository that solves the shutdown problem by automatically
> closing the repository when all the sessions are closed, but it hasn't
> yet been integrated with BindableRepository. I'll take a look at
> fixing this.

It seems there's an interface in org.apache.jackrabbit.api called  
JackrabbitRepository. Its only method is the prototype for the  
shutdown() method that needs to be called. I tried changing  
BindableRepository implement that, and made the method made public.  
When I did my web app could cast the object it got from the JNDI  
context to a JackrabbitRepository and things worked just fine.

Mark

Index: src/main/java/org/apache/jackrabbit/core/jndi/ 
BindableRepository.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/jndi/ 
BindableRepository.java       (revision 377972)
+++ src/main/java/org/apache/jackrabbit/core/jndi/ 
BindableRepository.java       (working copy)
@@ -16,6 +16,7 @@
   */
package org.apache.jackrabbit.core.jndi;
+import org.apache.jackrabbit.api.JackrabbitRepository;
import org.apache.jackrabbit.core.RepositoryImpl;
import org.apache.jackrabbit.core.config.RepositoryConfig;
@@ -59,7 +60,7 @@
   * method should be used to explicitly close the repository if
   * needed.
   */
-class BindableRepository implements Repository, Referenceable,  
Serializable {
+class BindableRepository implements Repository,  
JackrabbitRepository, Referenceable, Serializable {
      /** The serialization UID of this class. */
      static final long serialVersionUID = -2298220550793843166L;
@@ -253,7 +254,7 @@
      /**
       * Delegated to the underlying repository instance.
       */
-    void shutdown() {
+    public void shutdown() {
          ((RepositoryImpl) delegatee).shutdown();
          try {
              Runtime.getRuntime().removeShutdownHook(hook);


Re: Model-2 Deployment example and test app [Fixed, with suggestions for updated docs]

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 2/14/06, Mark Slater <li...@humanesoftware.com> wrote:
> I've finally got the servlet working (up to the point where it gets
> the repository that was configured in the Context).

Good to hear that. And thanks for following up with the troubleshooting results!

> From what I've seen on other mailing lists and web forums, I'm not
> the only one who's had trouble figuring out where to put the Context
> information. I'd suggest the following diffs to the site
> documentation, just to make the alternate context location more
> prominent.

Thanks! I applied your patch in revision 377720.

> I did find one other potential documentation bug in the howto-
> model1.xml page. The text says
> [...]
> I set up a model 1 repository in the same servlet (but with different
> repository settings) and tried to follow these directions. The
> problem that I ran into is that the shutdown() method is not in the
> javax.jcr.Repository interface, and BindableRepository is package
> protected so I can't even cast the object returned by the Context to
> a BindableRepository. Without that, I wasn't able to see how the
> shutdown() method could be called from my servlet's destroy() method.

Good point. Nowadays there's an alternative Repository frontend called
TransientRepository that solves the shutdown problem by automatically
closing the repository when all the sessions are closed, but it hasn't
yet been integrated with BindableRepository. I'll take a look at
fixing this.

BR,

Jukka Zitting

--
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftmanship, JCR consulting, and Java development

Re: Model-2 Deployment example and test app [Fixed, with suggestions for updated docs]

Posted by Mark Slater <li...@humanesoftware.com>.
I've finally got the servlet working (up to the point where it gets  
the repository that was configured in the Context). For whatever  
reason, using WEB-INF/context.xml (as suggested by the Tomcat and  
Jackrabbit docs) didn't work, but $CATALINA_HOME/conf/[enginename]/ 
[hostname]/[webappname].xml did. Also I had the same string in both  
the name attribute and global attribute of my ResourceLink.

 From what I've seen on other mailing lists and web forums, I'm not  
the only one who's had trouble figuring out where to put the Context  
information. I'd suggest the following diffs to the site  
documentation, just to make the alternate context location more  
prominent.

Index: src/site/xdoc/doc/deploy/howto-model2.xml
===================================================================
--- src/site/xdoc/doc/deploy/howto-model2.xml   (revision 377679)
+++ src/site/xdoc/doc/deploy/howto-model2.xml   (working copy)
@@ -106,8 +106,10 @@
            In Tomcat versions 4.x and 5.0, add the following snippet
            in <code>server.xml</code> under the <code>Context</code>  
element
            of your web application. In Tomcat version 5.5, add the  
snippet
-          in your application's <code>context.xml</code> file (or in  
the
-          <code>server.xml</code> file if you prefer central  
configuration).
+          in your application's <code>context.xml</code> or
+          <code>$CATALINA_HOME/conf/[enginename]/[hostname]/ 
[webappname].xml</code>.
+          If you prefer central configuration, you can add the  
configuration
+          to the Host Context section in the <code>server.xml</code>.
          </p>
          <source><![CDATA[
<ResourceLink name="jcr/repository"
Index: src/site/xdoc/doc/deploy/howto-model1.xml
===================================================================
--- src/site/xdoc/doc/deploy/howto-model1.xml   (revision 377679)
+++ src/site/xdoc/doc/deploy/howto-model1.xml   (working copy)
@@ -104,8 +104,10 @@
]]></source>
          <p>
            In Tomcat 5.5, add the following snippet in your  
application's
-          <code>context.xml</code> file (or in the <code>server.xml</ 
code>
-          file if you prefer central configuration).
+          <code>WEB-INF/context.xml</code> or
+          <code>$CATALINA_HOME/conf/[enginename]/[hostname]/ 
[webappname].xml</code>.
+          If you prefer central configuration, you can add the  
configuration
+          to the Host Context section in the <code>server.xml</code>.
          </p>
          <source><![CDATA[
<Resource name="jcr/repository"


I did find one other potential documentation bug in the howto- 
model1.xml page. The text says

       <p>
         <strong>Limitations:</strong> the application should not be
         redeployed during the same JVM process to avoid creating  
duplicate
         Jackrabbit instances with the same configuration. In case  
you want
         to redeploy your application be sure to shutdown the repository
         when your application is undeployed. It can be done by calling
         RepositoryImpl.shutdown() (e.g. in the destroy() method of a
         servlet).
       </p>

I set up a model 1 repository in the same servlet (but with different  
repository settings) and tried to follow these directions. The  
problem that I ran into is that the shutdown() method is not in the  
javax.jcr.Repository interface, and BindableRepository is package  
protected so I can't even cast the object returned by the Context to  
a BindableRepository. Without that, I wasn't able to see how the  
shutdown() method could be called from my servlet's destroy() method.

Mark

On Feb 13, 2006, at 7:29 PM, Mark Slater wrote:

> Another update. I added the log4j.properties to tomcat and am now  
> able to watch it initialize the repository; there are no errors  
> during the process. Unfortunately, none of the jackrabbit code  
> seems to be executed when I try to get the BindableRepository from  
> the context. I'm assuming at this point its a Tomcat configuration  
> issue, because I've tried a fair number of configurations (embedded- 
> model-1, shared-model-2, both, defined in global context, defined  
> in local context, defined in server.xml, etc.) and am no closer to  
> a solution. I've posted to the Tomcat's users for help, but if  
> anyone here has a spare cycle to point me in the right direction,  
> I'd really appreciate it.
>
> In the most recent trial (embedded repository defined in  
> servlet.xml) I'm able to get an Integer value stored in the  
> context, but when I try to get the jackrabbit repository, I get a  
> class not found exception on BindableRepositoryFactory. This is  
> despite having the jackrabbit jar file in both the webapp's WEB-INF/ 
> lib/ and Tomcat's server/lib/.
>
>
> Mark
>
> On Feb 13, 2006, at 8:15 AM, Mark Slater wrote:
>
>> Nope. There's no errors in any of the log files. I tried moving  
>> Jackrabbit jar files (and dependencies) to server/lib (they had  
>> all been in common/lib) leaving only jcr-1.0.jar in common/lib ...  
>> restarted Tomcat ... no change in results.
>>
>> I know Jackrabbit is being initialized because, over the weekend,  
>> as soon as I'd put all the dependencies into common/lib I stopped  
>> getting exceptions during Tomcat's initialization and the  
>> repository got initialized (the local file system and the database  
>> tables). That's when I started writing the servlet.
>>
>> The only mention of Jackrabbit in the catalina.out file is at the  
>> very start of Tomcat's initialization, I get these lines:
>>
>> log4j:WARN No appenders could be found for logger  
>> (org.apache.jackrabbit.core.fs.local.LocalFileSystem).
>> log4j:WARN Please initialize the log4j system properly.
>>
>> I'd worry about the log4j configuration but the exception doesn't  
>> show any Jackrabbit code in the stack... its mostly tomcat,  
>> catalina, and naming packages, with a few calls to java/javax code  
>> and my doGet() servlet function.
>>
>> Mark
>>
>> On Feb 13, 2006, at 2:04 AM, Jukka Zitting wrote:
>>
>>> Hi,
>>>
>>> On 2/13/06, Mark Slater <li...@humanesoftware.com> wrote:
>>>> However, when I run my servlet, I get:
>>>>
>>>> javax.naming.NamingException: Cannot create resource instance
>>>
>>> Do you have some errors showing up in the Tomcat error log? One
>>> possible cause for this problem is that you don't have the  
>>> Jackrabbit
>>> jar files in the correct place. A safe alternative is to just put  
>>> all
>>> the jars in common/lib, but a more correct way would be to put only
>>> the jcr-1.0.jar in the common class loader and the Jackrabbit jar  
>>> file
>>> (and the dependencies) in the server class loader.
>>>
>>> BR,
>>>
>>> Jukka Zitting
>>>
>>> --
>>> Yukatan - http://yukatan.fi/ - info@yukatan.fi
>>> Software craftmanship, JCR consulting, and Java development
>>
>>
>
>


Re: Model-2 Deployment example and test app

Posted by Mark Slater <li...@humanesoftware.com>.
Another update. I added the log4j.properties to tomcat and am now  
able to watch it initialize the repository; there are no errors  
during the process. Unfortunately, none of the jackrabbit code seems  
to be executed when I try to get the BindableRepository from the  
context. I'm assuming at this point its a Tomcat configuration issue,  
because I've tried a fair number of configurations (embedded-model-1,  
shared-model-2, both, defined in global context, defined in local  
context, defined in server.xml, etc.) and am no closer to a solution.  
I've posted to the Tomcat's users for help, but if anyone here has a  
spare cycle to point me in the right direction, I'd really appreciate  
it.

In the most recent trial (embedded repository defined in servlet.xml)  
I'm able to get an Integer value stored in the context, but when I  
try to get the jackrabbit repository, I get a class not found  
exception on BindableRepositoryFactory. This is despite having the  
jackrabbit jar file in both the webapp's WEB-INF/lib/ and Tomcat's  
server/lib/.


Mark

On Feb 13, 2006, at 8:15 AM, Mark Slater wrote:

> Nope. There's no errors in any of the log files. I tried moving  
> Jackrabbit jar files (and dependencies) to server/lib (they had all  
> been in common/lib) leaving only jcr-1.0.jar in common/lib ...  
> restarted Tomcat ... no change in results.
>
> I know Jackrabbit is being initialized because, over the weekend,  
> as soon as I'd put all the dependencies into common/lib I stopped  
> getting exceptions during Tomcat's initialization and the  
> repository got initialized (the local file system and the database  
> tables). That's when I started writing the servlet.
>
> The only mention of Jackrabbit in the catalina.out file is at the  
> very start of Tomcat's initialization, I get these lines:
>
> log4j:WARN No appenders could be found for logger  
> (org.apache.jackrabbit.core.fs.local.LocalFileSystem).
> log4j:WARN Please initialize the log4j system properly.
>
> I'd worry about the log4j configuration but the exception doesn't  
> show any Jackrabbit code in the stack... its mostly tomcat,  
> catalina, and naming packages, with a few calls to java/javax code  
> and my doGet() servlet function.
>
> Mark
>
> On Feb 13, 2006, at 2:04 AM, Jukka Zitting wrote:
>
>> Hi,
>>
>> On 2/13/06, Mark Slater <li...@humanesoftware.com> wrote:
>>> However, when I run my servlet, I get:
>>>
>>> javax.naming.NamingException: Cannot create resource instance
>>
>> Do you have some errors showing up in the Tomcat error log? One
>> possible cause for this problem is that you don't have the Jackrabbit
>> jar files in the correct place. A safe alternative is to just put all
>> the jars in common/lib, but a more correct way would be to put only
>> the jcr-1.0.jar in the common class loader and the Jackrabbit jar  
>> file
>> (and the dependencies) in the server class loader.
>>
>> BR,
>>
>> Jukka Zitting
>>
>> --
>> Yukatan - http://yukatan.fi/ - info@yukatan.fi
>> Software craftmanship, JCR consulting, and Java development
>
>


Re: Model-2 Deployment example and test app

Posted by Mark Slater <li...@humanesoftware.com>.
Nope. There's no errors in any of the log files. I tried moving  
Jackrabbit jar files (and dependencies) to server/lib (they had all  
been in common/lib) leaving only jcr-1.0.jar in common/lib ...  
restarted Tomcat ... no change in results.

I know Jackrabbit is being initialized because, over the weekend, as  
soon as I'd put all the dependencies into common/lib I stopped  
getting exceptions during Tomcat's initialization and the repository  
got initialized (the local file system and the database tables).  
That's when I started writing the servlet.

The only mention of Jackrabbit in the catalina.out file is at the  
very start of Tomcat's initialization, I get these lines:

log4j:WARN No appenders could be found for logger  
(org.apache.jackrabbit.core.fs.local.LocalFileSystem).
log4j:WARN Please initialize the log4j system properly.

I'd worry about the log4j configuration but the exception doesn't  
show any Jackrabbit code in the stack... its mostly tomcat, catalina,  
and naming packages, with a few calls to java/javax code and my doGet 
() servlet function.

Mark

On Feb 13, 2006, at 2:04 AM, Jukka Zitting wrote:

> Hi,
>
> On 2/13/06, Mark Slater <li...@humanesoftware.com> wrote:
>> However, when I run my servlet, I get:
>>
>> javax.naming.NamingException: Cannot create resource instance
>
> Do you have some errors showing up in the Tomcat error log? One
> possible cause for this problem is that you don't have the Jackrabbit
> jar files in the correct place. A safe alternative is to just put all
> the jars in common/lib, but a more correct way would be to put only
> the jcr-1.0.jar in the common class loader and the Jackrabbit jar file
> (and the dependencies) in the server class loader.
>
> BR,
>
> Jukka Zitting
>
> --
> Yukatan - http://yukatan.fi/ - info@yukatan.fi
> Software craftmanship, JCR consulting, and Java development


Re: Model-2 Deployment example and test app

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 2/13/06, Mark Slater <li...@humanesoftware.com> wrote:
> However, when I run my servlet, I get:
>
> javax.naming.NamingException: Cannot create resource instance

Do you have some errors showing up in the Tomcat error log? One
possible cause for this problem is that you don't have the Jackrabbit
jar files in the correct place. A safe alternative is to just put all
the jars in common/lib, but a more correct way would be to put only
the jcr-1.0.jar in the common class loader and the Jackrabbit jar file
(and the dependencies) in the server class loader.

BR,

Jukka Zitting

--
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftmanship, JCR consulting, and Java development

Re: Model-2 Deployment example and test app

Posted by Mark Slater <li...@humanesoftware.com>.
A small update: The servlet code and Resource configuration block  
works fine if its an embedded resource (Model 1; a non-null  
BindableRepository object is returned. Maybe Tomcat just has issues  
with working on weekends?

Mark

On Feb 12, 2006, at 5:50 PM, Mark Slater wrote:

> Hello,
>
> I'm new to Jackrabbit, so the first thing I'm trying to do is put  
> together a Model-2 (shared J2EE resource) deployment on Tomcat 5.5  
> and an example webapp (servlet) that confirms the deployment has  
> been correctly configured. I figured this would be a good way for  
> me to get acquainted with using Jackrabbit, and possibly provide an  
> example that could be distributed by the project. Unfortunately, I  
> haven't gotten very far.
>
> Following the instructions on the website for the Resource  
> configuration, I've added the following lines to my $TOMCAT_HOME/ 
> conf/server.xml:
>
> ======= Begin Tomcat server.xml =======
>   <GlobalNamingResources>
>     ...
>
>     <Resource name="jcr/globalRepository"
>         auth="Container"
>         type="javax.jcr.Repository"
>          
> factory="org.apache.jackrabbit.core.jndi.BindableRepositoryFactory"
>         configFilePath="conf/repository.xml"
>         repHomeDir="shared/jackrabbit" />
>     ...
>
>   </GlobalNamingResources>
> ======= End Tomcat server.xml =======
>
>
>
> And I've added this configuration to the <test-app>/WEB-INF/web.xml:
>
> ======= Begin web app web.xml =======
>     <resource-env-ref>
>         <description>Jackrabbit Repository</description>
>         <resource-env-ref-name>jcr/globalRepository</resource-env- 
> ref-name>
>         <resource-env-ref-type>javax.jcr.Repository</resource-env- 
> ref-type>
>     </resource-env-ref>
> ======= End web app web.xml =======
>
>
>
> Next, I tried creating a <test-app>/WEB-INF/context.xml file that  
> looks like this:
>
> ======= Begin web app context.xml =======
> <Context>
> 	
>     <ResourceLink
>         glabal="jcr/globalRepository" name="jcr/globalRepository"  
> type="javax.jcr.Repository" />
>
>     <Manager pathname="" />
>
> </Context>
> ======= End web app context.xml =======
>
>
>
> However, when I run my servlet, I get:
>
> 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.doGet 
> (JackrabbitTest.java:100)
> 	....
>
> So, I tried using the $TOMCAT_HOME/conf/context.xml, and made it  
> look like this:
>
> ======= Begin Tomcat context.xml =======
> <!-- The contents of this file will be loaded for each web  
> application -->
> <Context>
>
>     <!-- Default set of monitored resources -->
>     <WatchedResource>WEB-INF/web.xml</WatchedResource>
> 	
>     <ResourceLink
>         glabal="jcr/globalRepository" name="jcr/globalRepository"  
> type="javax.jcr.Repository" />
>
>     <!-- Uncomment this to disable session persistence across  
> Tomcat restarts -->
>     <!--
>     <Manager pathname="" />
>     -->
>
> </Context>
> ======= End Tomcat context.xml =======
>
>
>
> That works better, in that I don't get an exception. Instead the  
> lookup() request returns null.
>
> The servlet code currently looks like this:
>
> ======= Begin source code =======
>     public void doGet( HttpServletRequest request,  
> HttpServletResponse response )
>         throws IOException, ServletException
>     {
>         boolean skipping = false;
>
>         response.setContentType("text/html");
>         PrintWriter out = response.getWriter();
>         out.println("<html>");
>         out.println("<head>");
>         out.println("<title>Jackrabbit Configuration Testing</ 
> title>");
>         out.println("</head>");
>         out.println("<body>");
>
>         if( !skipping )
>         {
>             out.println("<h3>Getting the Jackrabbit reference via  
> JNDI</h3>");
>
>             try
>             {
>             // Get the initial context
>                 Context initialContext = new InitialContext();
>
>                 out.println( "<p>Got initial context</p>" );
>
>                 NamingEnumeration<NameClassPair> contextEntries =  
> null;
>
>                 contextEntries = initialContext.list( "java:comp/ 
> env" );
>
>                 // snip - printing entries
>
>                 contextEntries = initialContext.list( "java:comp/ 
> env/jcr" );
>
>                 // snip - printing entries
>
>
>             // Get the environment context
>                 Context environmentContext = (Context)  
> initialContext.lookup( "java:comp/env" );
>
>                 out.println( "<p>Got environment context</p>" );
>
>                 contextEntries = environmentContext.list( "/" );
>
>                 // snip - printing entries
>
>                 contextEntries = environmentContext.list( "/jcr" );
>
>                 // snip - printing entries
>
>
>             // get values out of the context.
>                 jackrabbitRepository =
>                     (Repository) environmentContext.lookup( "jcr/ 
> globalRepository" );
>
>                 out.println( "<p>jackrabbitRepository = " +  
> jackrabbitRepository + "</p>" );
>             }
>             catch( Exception e )
>             {
>                 out.println("<p>Exception thrown: <pre>" );
>                 e.printStackTrace( out );
>                 out.println("</pre></p>");
>             }
>         }
>
>
>         out.println("</body>");
>         out.println("</html>");
>     }
> ======= End source code =======
>
>
>
> And the web page generated looks like this:
>
> ======= Begin HTML output =======
> Getting the Jackrabbit reference via JNDI
>
> Got initial context
>
> Entries in java:comp/env:
>
> jcr: org.apache.naming.NamingContext
> Entries in java:comp/env/jcr:
>
> globalRepository: org.apache.naming.ResourceLinkRef
> Got environment context
>
> Entries in /:
>
> jcr: org.apache.naming.NamingContext
> Entries in /jcr:
>
> globalRepository: org.apache.naming.ResourceLinkRef
> jackrabbitRepository = null
>
> ======= End HTML output =======
>
>
>
> So I can see the reference to Jackrabbit is there, but I'm not able  
> to get it. Perhaps the BindableRepositoryFactory is returning a  
> null repository? For all I know, this is a JNDI issue with Tomcat.  
> Even the author of http://tomcat.apache.org/tomcat-5.5-doc/jndi- 
> datasource-examples-howto.html seems to have had trouble  
> configuring a PostgreSQL data source to be global. But if anybody  
> could suggest a way of debugging this, or flat out knows what the  
> problem is, I'd love some help. Of course, if such an example  
> already exists someplace, that'd be great to know too. I found the  
> First Steps example, but that uses an embedded version... I'm  
> intending to code essentially the same example, but as a servlet  
> that includes output showing the success or failure of the various  
> steps (which will hopefully give users an indication of where their  
> configuration has failed).
>
> Thanks,
>
> Mark
>