You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steve Souza <ja...@gmail.com> on 2007/09/10 16:43:18 UTC

classpath problems with a custom valve

I posted a question earlier, but now have some more info....

I have a custom valve that monitors page accesses in tomcat.  It works in
tomcat 6, and under tomcat 5.5 that comes bundled with jboss. I can not get
it to work in tomcat 5.5.25.  I put the jar in server/lib and the war I
install that reads the monitoring data gets calls def not found errors on
the classes in my jar when it tries to display the data.  Shouldn't my war
be able to see the classes from a jar put into server/lib?  I noticed that
the management wars were put under server/webapps.  Do I need to do
something along these lines?

The original message is below.


---------- Forwarded message ----------
From: Steve Souza <ja...@gmail.com>
Date: Sep 9, 2007 10:48 PM
Subject: problems with custom valve in tomcat 5.5
To: users-help@tomcat.apache.org

I have written a custom valve that should work in tomcat 5.5. and tomcat 6.
It does work in tomcat 6 and jboss's tomcat 5.5. The valve monitors http
requests with JAMon (http://www.jamonapi.com ).  I put the following valve
line in server.xml   (engine is show to give location context).  When I
startup tomcat 5.5 (non jboss version) the server flashes something on the
screen I can't read and then exits.   I remove the valve line and the server
boots fine.  Does anyone have any ideas?  Does it matter where I put my jar
in tomcat 5.5?  Does it need to be in some classpath?  Thanks.

<Engine name="Catalina" defaultHost="localhost">
<Valve className="com.jamonapi.http.JAMonTomcatValve"/>

RE: classpath problems with a custom valve

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Steve Souza [mailto:jamonapi@gmail.com] 
> Subject: Re: classpath problems with a custom valve
> 
> What is confusing to me is why when i put my jar into 
> server/lib, the web app doesn't also have access to 
> classes loaded from there. 

Look at the 5.5 classloader hierarchy:

      Bootstrap
          |
       System
          |
       Common
      /      \
 Catalina   Shared
             /   \
        Webapp1  Webapp2 ... 

The server/lib directory (Catalina in the above picture) isn't visible
to webapps.

> Someone mentioned that i may be able to use the context 
> property of 'priviledged' to do this.

That deals with accessibility, not visibility.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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


Re: classpath problems with a custom valve

Posted by Steve Souza <ja...@gmail.com>.
To answer a couple of your questions.

I am getting ready to release jamon 2.7 which will monitor performance of
tomcat 5.5 and tomcat 6 and other http related stats for the server and have
them viewable in a searchable/sortable webpage.  It will have summary stats
like which pages are currently executing, what was max/min/avg time for each
page, as well as being able to track the N slowest page requests and also be
able to show stack traces via the web page and much more.

jamon comes with choices on how you want to monitor your app including a
servlet filter, and a valve.  I work in an environment where i can't enforce
developers to use the servlet filters, but can change the valve.  Others
have the opposite situation so both valves and filters are useful.   I had
already gotten the valve to work in tomcat 6, but also know there are a lot
of users that won't be able to upgrade to tomcat 6 for a while.

What is confusing to me is why when i put my jar into server/lib, the web
app doesn't also have access to classes loaded from there. Other server
products I have used in the past allowed you to put jars at the server level
and all web apps could see any classes loaded by the server class loader.

Someone mentioned that i may be able to use the context property of
'priviledged' to do this.  I tried it and it didn't seem to help though I
may have missed something.  Should that work?

On 9/10/07, Caldarale, Charles R <Ch...@unisys.com> wrote:
>
> > From: Steve Souza [mailto:jamonapi@gmail.com]
> > Subject: Re: classpath problems with a custom valve
> >
> > It is still a bit mysterious and not ideal as installation
> > requires a class put in server/classes as well as the jar in
> > common/lib, but it will do.
>
> Using a valve is by necessity tying you into Tomcat internals.  If you
> could use a filter instead, you would avoid that dependency and make
> what you're doing more portable.
>
> > If  there is a better way to do this let me know.
>
> Move to Tomcat 6 - life's a lot simpler (and faster).
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: classpath problems with a custom valve

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Steve Souza [mailto:jamonapi@gmail.com] 
> Subject: Re: classpath problems with a custom valve
> 
> It is still a bit mysterious and not ideal as installation
> requires a class put in server/classes as well as the jar in
> common/lib, but it will do.

Using a valve is by necessity tying you into Tomcat internals.  If you
could use a filter instead, you would avoid that dependency and make
what you're doing more portable.

> If  there is a better way to do this let me know.

Move to Tomcat 6 - life's a lot simpler (and faster).

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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


Re: classpath problems with a custom valve

Posted by Steve Souza <ja...@gmail.com>.
That worked.  I created my valve as a single class and put it in
server/classes.  I kept my jar in common/lib.  I tried inheriting from the
valve in my jar and that didn't work, so i copied that code into a new
package and it worked fine.  It is still a bit mysterious and not ideal as
installation requires a class put in server/classes as well as the jar in
common/lib, but it will do.  If  there is a better way to do this let me
know.  Thanks for your help charles.

On 9/10/07, Caldarale, Charles R <Ch...@unisys.com> wrote:
>
> > From: Steve Souza [mailto:jamonapi@gmail.com]
> > Subject: Re: classpath problems with a custom valve
> >
> > I get the following exception which seems odd as I saw the missing
> class in
> > catalina.jar and I compiled against it.
>
> Java classloading hierarchy is not bidirectional - classes can see only
> up the tree (unless you're using reflection).  For Tomcat 5.5, I think
> you'll need to refactor your code, separating the valve and the part
> needed by both the valve and the webapp.  The jar containing valve
> proper should be placed in server/lib, and the jar holding the common
> bits into common/lib.
>
> If you moved up to Tomcat 6, the classloading hierarchy is much simpler;
> your existing jar would just go into the single lib directory.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: classpath problems with a custom valve

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Steve Souza [mailto:jamonapi@gmail.com] 
> Subject: Re: classpath problems with a custom valve
> 
> I get the following exception which seems odd as I saw the missing
class in
> catalina.jar and I compiled against it.

Java classloading hierarchy is not bidirectional - classes can see only
up the tree (unless you're using reflection).  For Tomcat 5.5, I think
you'll need to refactor your code, separating the valve and the part
needed by both the valve and the webapp.  The jar containing valve
proper should be placed in server/lib, and the jar holding the common
bits into common/lib.

If you moved up to Tomcat 6, the classloading hierarchy is much simpler;
your existing jar would just go into the single lib directory.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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


Re: classpath problems with a custom valve

Posted by Steve Souza <ja...@gmail.com>.
ok, my reading skills are lacking.  I put the jar in common/lib.  I get the
following exception which seems odd as I saw the missing class in
catalina.jar and I compiled against it.

Sep 10, 2007 2:24:03 PM org.apache.tomcat.util.digester.DigesterstartElement
SEVERE: Begin event threw error
java.lang.NoClassDefFoundError: org/apache/catalina/valves/ValveBase
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java
:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at org.apache.tomcat.util.digester.ObjectCreateRule.begin(
ObjectCreateRule.java:205)
    at org.apache.tomcat.util.digester.Rule.begin(Rule.java:153)
    at org.apache.tomcat.util.digester.Digester.startElement(Digester.java
:1276)
    at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(
AbstractSAXParser.java:533)
    at
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement
(AbstractXMLDocumentParser.java:220)
    at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement
(XMLDocumentFragmentScannerImpl.java:872)
    at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch
(XMLDocumentFragmentScannerImpl.java:1693)
    at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument
(XMLDocumentFragmentScannerImpl.java:368)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(
XML11Configuration.java:834)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(
XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(
XMLParser.java:148)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(
AbstractSAXParser.java:1242)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1562)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:490)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:524)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:267)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)


On 9/10/07, Caldarale, Charles R <Ch...@unisys.com> wrote:
>
> > From: Steve Souza [mailto:jamonapi@gmail.com]
> > Subject: Re: classpath problems with a custom valve
> >
> > common/lib is for jars are only needed by web apps whereas
> > shared/lib is for web apps AND tomcat.
>
> Read the doc again - you have it backwards.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: classpath problems with a custom valve

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Steve Souza [mailto:jamonapi@gmail.com] 
> Subject: Re: classpath problems with a custom valve
> 
> common/lib is for jars are only needed by web apps whereas 
> shared/lib is for web apps AND tomcat.

Read the doc again - you have it backwards.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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


Re: classpath problems with a custom valve

Posted by Steve Souza <ja...@gmail.com>.
i apologize for the typo.  I actually meant to say i put the jar in
shared/lib.  Based on the documentation I think that is where it should go.
common/lib is for jars are only needed by web apps whereas shared/lib is for
web apps AND tomcat.   Being as the valve should be used by tomcat i put it
in shared/lib.

If I put the jar in shared/lib my war which references some of the classes
to display the data gets a ClassNotFoundException.  I also tried putting it
in common/lib then the server doesn't boot and i get a
ClassNotFoundException on my valve.

>From the link:
http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html

*Shared* - This class loader is the place to put classes and resources that
you wish to share across *ALL* web applications (unless Tomcat internal
classes also need access, in which case you should put them in the
*Common*class loader instead).All unpacked classes and resources in
$CATALINA_BASE/shared/classes, as well as classes and resources in JAR files
under $CATALINA_BASE/shared/lib, are made visible through this class loader.
If multiple Tomcat instances are run from the same binary using the
$CATALINA_BASE environment variable, then this classloader repositories are
relative to $CATALINA_BASE rather than $CATALINA_HOME.

On 9/10/07, Caldarale, Charles R <Ch...@unisys.com> wrote:
>
> > From: Steve Souza [mailto:jamonapi@gmail.com]
> > Subject: Re: classpath problems with a custom valve
> >
> > based on this document I placed my jar in server/lib as both
> > web apps and tomcat need access to the classes in this jar.
>
> What part of the Tomcat doc led you to that conclusion?  It's clear from
> even a cursory reading (or just looking at the picture) that classes in
> server/lib are not available to webapps.  As I said before, put your jar
> in common/lib.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: classpath problems with a custom valve

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Steve Souza [mailto:jamonapi@gmail.com] 
> Subject: Re: classpath problems with a custom valve
> 
> based on this document I placed my jar in server/lib as both 
> web apps and tomcat need access to the classes in this jar.

What part of the Tomcat doc led you to that conclusion?  It's clear from
even a cursory reading (or just looking at the picture) that classes in
server/lib are not available to webapps.  As I said before, put your jar
in common/lib.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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


Re: classpath problems with a custom valve

Posted by Steve Souza <ja...@gmail.com>.
based on this document I placed my jar in server/lib as both web apps and
tomcat need access to the classes in this jar.   Still it will not boot.  If
i use a servlet filter that is in the same jar everything works fine, so it
has something to do with the Valve.

WARNING: Catalina.start using conf/server.xml:
java.lang.ClassNotFoundException: com.jamonapi.http.JAMonTomcatValve
    at org.apache.tomcat.util.digester.Digester.createSAXException(
Digester.java:2726)
    at org.apache.tomcat.util.digester.Digester.createSAXException(
Digester.java:2752)
    at org.apache.tomcat.util.digester.Digester.startElement(Digester.java
:1279)
    at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(
AbstractSAXParser.java:533)
    at
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement
(AbstractXMLDocumentParser.java:220)
    at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement
(XMLDocumentFragmentScannerImpl.java:872)
    at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch
(XMLDocumentFragmentScannerImpl.java:1693)
    at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument
(XMLDocumentFragmentScannerImpl.java:368)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(
XML11Configuration.java:834)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(
XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(
XMLParser.java:148)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(
AbstractSAXParser.java:1242)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1562)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:490)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:544)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Sep 10, 2007 1:11:45 PM org.apache.catalina.startup.Catalina start

On 9/10/07, Caldarale, Charles R <Ch...@unisys.com> wrote:
>
> > From: Steve Souza [mailto:jamonapi@gmail.com]
> > Subject: classpath problems with a custom valve
> >
> > Shouldn't my war be able to see the classes from a jar
> > put into server/lib?
>
> No - read the doc:
> http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
>
> You probably need to put your jar in common/lib.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: classpath problems with a custom valve

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Steve Souza [mailto:jamonapi@gmail.com] 
> Subject: classpath problems with a custom valve
> 
> Shouldn't my war be able to see the classes from a jar 
> put into server/lib?

No - read the doc:
http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html

You probably need to put your jar in common/lib.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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