• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem writing tomcat valve

 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written a custom monitoring valve for tomcat 5.5. and tomcat 6. I added the following line after the <Engine> tag in both 5.5 and 6.


The valve works fine in tomcat 6, but the server doesn't boot in tomcat 5.5 (it flashes too quick for me to see what is happening). Does anyone have any knowledge of valves that may help me solve this problem? both versions use the same jdk.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked through the logs in the TOMCAT_INSTALL/logs directory?
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a little more info after conducting a few tests.

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?
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a little more info after conducting a few tests.

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?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by steve souza:
Shouldn't my war be able to see the classes from a jar put into server/lib?



This is not allowed by default.
To grant access to container level objects, set the 'privileged' attribute in your context to true.

Of course, doing so increases the size and scope of the sandbox in which your application runs so you might want to read up on some of the security implications of doing so.

Personally, I would only write a valve if I wanted to implement something container wide. If I wanted this behavior for one application, I would implement it as a filter. Is there any reason that you're writing it as a valve?
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Personally, I would only write a valve if I wanted to implement something container wide. If I wanted this behavior for one application, I would implement it as a filter. Is there any reason that you're writing it as a valve?



I am writing the valve to be a server wide resource. jamon.war simply displays the statistical information that is gathered at the server level. I simply dropped my jar and war in for tomcat 6, and jboss tomcat 5.5 and it worked with no problems. not sure why tomcat 5.5 from the apache site works differently.

To see what jamon war does click on the link below that shows sql statistics. The valve will display different http stats from with in this same war.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to be a classpath problem, although i don't know how to make BOTH tomcat and my war avoid ClassNotFoundExceptions.

If i put jamon.jar in common/lib the jamon viewer servlet can see the classes, however tomcat bootup code can not (and the server doesn't boot). if i put jamon.jar in shared/lib the tomcat boot process works however my viewer war can't see the classes.

Here is the stack trace i get when I put jamon.jar in common/lib

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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve,
It looks like you're getting some pretty good help from Charles Caldarale on the Tomcat user's list. Did he answer everything for you or is this a new one?

-Ben
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still having the problem. He had told me to put the jar in common/lib, and I had already tried putting the jar in all of the possible locations when he said that. None seem to work. I either get an exception in my war, or on server startup. Being as the Valve works in both tomcat 6, and jboss tomcat 5.5 I am not sure how to proceed.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you also set priviledged to true?
If your application needs to use Tomcat components, you will need to do this.
I'm not sure why it's working without this in version 6.
Admittedly, I haven't done much work with version 6 yet.

If Tomcat needs to access your classes then you would want to put your jars (or class/package directory structure) under tomcat/common/lib.
A good example of this is a JDBC driver that Tomcat's connection pool needs access to when the container starts up.

I'm guessing, since a valve is a container wide component, any dependents it has would need to be placed in tomcat/common/lib.

If within your application, you need access to Tomcat's components,
I believe you will need to set the privileged attribute to true.

From:
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html



privileged
Set to true to allow this context to use container servlets, like the manager servlet.



These seem to be two different issues you're dealing with (fighting).
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, i had set priviledge to true and that didn't seem to help. Based on help from the tomcat mailing list I had to separate my valve from the rest of my jamon.jar. That is less than ideal, but works. Here is that thread below.


****

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 <Chuck.Caldarale@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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by steve souza:
Yes, i had set priviledge to true and that didn't seem to help.



Again, I think you were dealing with two different problems (Tomcat's valve having access to your classes and your webapp having access Tomcat's internals).

It looks like you've got the two separated now.
Thanks for posting back with your solution.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic