Re: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Jon Wingfield
An invocation of a Tomcat Valve gives you a Request object. This is a 
facade to a ServletRequest, which you can access via the getRequest() 
method. You could set your info object as an attribute on the 
ServletRequest. This should then be visible to your filter.

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/catalina/docs/api/index.html
Just curious, why the custom Valve?
Jon
Rui Zhang wrote:
 Hi all,

   I'm trying to pass some info (say, as an Object) between a valve and a
 filter. Is anyone aware of a effective way to do this within the context
 of Tomcat?

   Many thanks.

 Best,

 Rui

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Rui Zhang

Hi Jon  All,

   Thanks for your information. It's very helpful. I've been looking at
ValveContext but did not find anything useful.

   Yes, I tried to pass the info object along as an attribute of
ServletRequest. But problem occured with the retrieval of the object in
the Filter, where ServletRequest.getAttribute() successfully located my
attribute, but promtted a ClassCastException when the returned Object was
casted back to the original info class. It seems Tomcat somehow lost the
class structure of the original info class...? Anyone got a clue of this?

   Many thanks.

Rui


On Fri, 21 May 2004, Jon Wingfield wrote:

 An invocation of a Tomcat Valve gives you a Request object. This is a
 facade to a ServletRequest, which you can access via the getRequest()
 method. You could set your info object as an attribute on the
 ServletRequest. This should then be visible to your filter.

 http://jakarta.apache.org/tomcat/tomcat-4.1-doc/catalina/docs/api/index.html

 Just curious, why the custom Valve?

 Jon

 Rui Zhang wrote:

   Hi all,
  
 I'm trying to pass some info (say, as an Object) between a valve and a
   filter. Is anyone aware of a effective way to do this within the context
   of Tomcat?
  
 Many thanks.
  
   Best,
  
   Rui
  


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Rui Zhang
Jon,

To answer your query, I'm using a custom valve to instrument Tomcat with
response time monitoring, as part of the project I'm working on...

http://web.comlab.ox.ac.uk/oucl/research/areas/softeng/eWLM/

Cheers,

Rui

On Fri, 21 May 2004, Jon Wingfield wrote:

 An invocation of a Tomcat Valve gives you a Request object. This is a
 facade to a ServletRequest, which you can access via the getRequest()
 method. You could set your info object as an attribute on the
 ServletRequest. This should then be visible to your filter.

 http://jakarta.apache.org/tomcat/tomcat-4.1-doc/catalina/docs/api/index.html

 Just curious, why the custom Valve?

 Jon

 Rui Zhang wrote:

   Hi all,
  
 I'm trying to pass some info (say, as an Object) between a valve and a
   filter. Is anyone aware of a effective way to do this within the context
   of Tomcat?
  
 Many thanks.
  
   Best,
  
   Rui
  


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Ralph Einfeldt

One possible cause:

The component that store your object find the class through 
a different classloader than the component that tries to 
retrieve the object.

Where do you store the class/jar for the stored object ?


 -Original Message-
 From: Rui Zhang [mailto:[EMAIL PROTECTED]
 Sent: Friday, May 21, 2004 6:53 PM
 To: Tomcat Users List
 Cc: [EMAIL PROTECTED]
 Subject: Re: Pass info between Tomcat Valve and Filter
 
 
 
 Hi Jon  All,
 
Thanks for your information. It's very helpful. I've been 
 looking at
 ValveContext but did not find anything useful.
 
Yes, I tried to pass the info object along as an attribute of
 ServletRequest. But problem occured with the retrieval of the 
 object in
 the Filter, where ServletRequest.getAttribute() successfully 
 located my
 attribute, but promtted a ClassCastException when the 
 returned Object was
 casted back to the original info class. It seems Tomcat 
 somehow lost the
 class structure of the original info class...? Anyone got a 
 clue of this?
 
Many thanks.
 
 Rui
 
 
 On Fri, 21 May 2004, Jon Wingfield wrote:
 
  An invocation of a Tomcat Valve gives you a Request object. 
 This is a
  facade to a ServletRequest, which you can access via the 
 getRequest()
  method. You could set your info object as an attribute on the
  ServletRequest. This should then be visible to your filter.
 
  
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/catalina/docs/api/index.html

 Just curious, why the custom Valve?

 Jon

 Rui Zhang wrote:

   Hi all,
  
 I'm trying to pass some info (say, as an Object) between a valve and a
   filter. Is anyone aware of a effective way to do this within the context
   of Tomcat?
  
 Many thanks.
  
   Best,
  
   Rui
  


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Carl Howells
Rui Zhang wrote:
Hi Jon  All,
   Thanks for your information. It's very helpful. I've been looking at
ValveContext but did not find anything useful.
   Yes, I tried to pass the info object along as an attribute of
ServletRequest. But problem occured with the retrieval of the object in
the Filter, where ServletRequest.getAttribute() successfully located my
attribute, but promtted a ClassCastException when the returned Object was
casted back to the original info class. It seems Tomcat somehow lost the
class structure of the original info class...? Anyone got a clue of this?
Sounds like a ClassLoader problem.  The valve is going to use tomcat's 
libraries.  The filter will use the webapps's libraries, in preference 
to tomcat's libraries.  If the class is in the webapp's libraries, it's 
going to try to cast it to an instance of the webapp version of the 
class, which will be different from the version the valve created. 
(Classes with different classloaders are different, even if they happen 
to be identical.)

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Rui Zhang
Yes, indeed. I got around it by retrieving the info using getClass(),
getField() etc.

Thanks again.

Rui

On Fri, 21 May 2004, Carl Howells wrote:

 Rui Zhang wrote:
  Hi Jon  All,
 
 Thanks for your information. It's very helpful. I've been looking at
  ValveContext but did not find anything useful.
 
 Yes, I tried to pass the info object along as an attribute of
  ServletRequest. But problem occured with the retrieval of the object in
  the Filter, where ServletRequest.getAttribute() successfully located my
  attribute, but promtted a ClassCastException when the returned Object was
  casted back to the original info class. It seems Tomcat somehow lost the
  class structure of the original info class...? Anyone got a clue of this?

 Sounds like a ClassLoader problem.  The valve is going to use tomcat's
 libraries.  The filter will use the webapps's libraries, in preference
 to tomcat's libraries.  If the class is in the webapp's libraries, it's
 going to try to cast it to an instance of the webapp version of the
 class, which will be different from the version the valve created.
 (Classes with different classloaders are different, even if they happen
 to be identical.)

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Jon Wingfield
Cool. I guess a Valve is good for that type of thing :)
I think Carl and Ralph are right about the ClassClassException being a 
ClassLoader issue. I've seen similar things before when using custom 
Realms, JNDI resources etc.
Our build process generates a minimal jar for deploying to common/lib 
which contains all the classes needed by the container classloaders. 
These classes are excluded from the webapp jars and all is happy. You 
have to be really careful about dependencies though or virtually all 
your webapp ends up in common/lib.
Try jarring up your info object and putting in common/lib (or 
common/classes).

Or you could use reflection as I've just read in your reply to Ralph ;)
Good weekend all,
Jon

Rui Zhang wrote:
Jon,
To answer your query, I'm using a custom valve to instrument Tomcat with
response time monitoring, as part of the project I'm working on...
http://web.comlab.ox.ac.uk/oucl/research/areas/softeng/eWLM/
Cheers,
Rui
On Fri, 21 May 2004, Jon Wingfield wrote:

An invocation of a Tomcat Valve gives you a Request object. This is a
facade to a ServletRequest, which you can access via the getRequest()
method. You could set your info object as an attribute on the
ServletRequest. This should then be visible to your filter.
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/catalina/docs/api/index.html
Just curious, why the custom Valve?
Jon
Rui Zhang wrote:
 Hi all,

   I'm trying to pass some info (say, as an Object) between a valve and a
 filter. Is anyone aware of a effective way to do this within the context
 of Tomcat?

   Many thanks.

 Best,

 Rui

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Rui Zhang
Hi All,

  Thanks very much for your incisive comments.

  Similar problem, but it seems much trickier to pass info from a Filter
to a Valve. No attribute is associated with a ServletResponse. And when I
try to cast it to HttpServletResponse to make use of its addHeader()
method, my program simply hangs...

   Any clue?

   Thanks again.

Best,

Rui


On Fri, 21 May 2004, Jon Wingfield wrote:

 Cool. I guess a Valve is good for that type of thing :)

 I think Carl and Ralph are right about the ClassClassException being a
 ClassLoader issue. I've seen similar things before when using custom
 Realms, JNDI resources etc.
 Our build process generates a minimal jar for deploying to common/lib
 which contains all the classes needed by the container classloaders.
 These classes are excluded from the webapp jars and all is happy. You
 have to be really careful about dependencies though or virtually all
 your webapp ends up in common/lib.
 Try jarring up your info object and putting in common/lib (or
 common/classes).

 Or you could use reflection as I've just read in your reply to Ralph ;)

 Good weekend all,

 Jon



 Rui Zhang wrote:

  Jon,
 
  To answer your query, I'm using a custom valve to instrument Tomcat with
  response time monitoring, as part of the project I'm working on...
 
  http://web.comlab.ox.ac.uk/oucl/research/areas/softeng/eWLM/
 
  Cheers,
 
  Rui
 
  On Fri, 21 May 2004, Jon Wingfield wrote:
 
 
 An invocation of a Tomcat Valve gives you a Request object. This is a
 facade to a ServletRequest, which you can access via the getRequest()
 method. You could set your info object as an attribute on the
 ServletRequest. This should then be visible to your filter.
 
 http://jakarta.apache.org/tomcat/tomcat-4.1-doc/catalina/docs/api/index.html
 
 Just curious, why the custom Valve?
 
 Jon
 
 Rui Zhang wrote:
 
   Hi all,
  
 I'm trying to pass some info (say, as an Object) between a valve and a
   filter. Is anyone aware of a effective way to do this within the context
   of Tomcat?
  
 Many thanks.
  
   Best,
  
   Rui
  
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 



 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Rui Zhang
Maybe the failure of addHeader() is because the response has already been
committed by the time it reaches the Filter?

but, still, how can i pass info from a fliter back to a valve?

Cheers,

Rui

On Fri, 21 May 2004, Rui Zhang wrote:

 Hi All,

   Thanks very much for your incisive comments.

   Similar problem, but it seems much trickier to pass info from a Filter
 to a Valve. No attribute is associated with a ServletResponse. And when I
 try to cast it to HttpServletResponse to make use of its addHeader()
 method, my program simply hangs...

Any clue?

Thanks again.

 Best,

 Rui


 On Fri, 21 May 2004, Jon Wingfield wrote:

  Cool. I guess a Valve is good for that type of thing :)
 
  I think Carl and Ralph are right about the ClassClassException being a
  ClassLoader issue. I've seen similar things before when using custom
  Realms, JNDI resources etc.
  Our build process generates a minimal jar for deploying to common/lib
  which contains all the classes needed by the container classloaders.
  These classes are excluded from the webapp jars and all is happy. You
  have to be really careful about dependencies though or virtually all
  your webapp ends up in common/lib.
  Try jarring up your info object and putting in common/lib (or
  common/classes).
 
  Or you could use reflection as I've just read in your reply to Ralph ;)
 
  Good weekend all,
 
  Jon
 
 
 
  Rui Zhang wrote:
 
   Jon,
  
   To answer your query, I'm using a custom valve to instrument Tomcat with
   response time monitoring, as part of the project I'm working on...
  
   http://web.comlab.ox.ac.uk/oucl/research/areas/softeng/eWLM/
  
   Cheers,
  
   Rui
  
   On Fri, 21 May 2004, Jon Wingfield wrote:
  
  
  An invocation of a Tomcat Valve gives you a Request object. This is a
  facade to a ServletRequest, which you can access via the getRequest()
  method. You could set your info object as an attribute on the
  ServletRequest. This should then be visible to your filter.
  
  http://jakarta.apache.org/tomcat/tomcat-4.1-doc/catalina/docs/api/index.html
  
  Just curious, why the custom Valve?
  
  Jon
  
  Rui Zhang wrote:
  
Hi all,
   
  I'm trying to pass some info (say, as an Object) between a valve and a
filter. Is anyone aware of a effective way to do this within the context
of Tomcat?
   
  Many thanks.
   
Best,
   
Rui
   
  
  
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  
  
  
  
   -
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
  
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Pass info between Tomcat Valve and Filter

2004-05-21 Thread Rui Zhang
Never mind, I've found a not very tidy way around it by customizing the
output stream of the response.

But if anyone knows about a better way of doing it, pls let me know.

Thanks.

Rui


On Fri, 21 May 2004, Rui Zhang wrote:

 Maybe the failure of addHeader() is because the response has already been
 committed by the time it reaches the Filter?

 but, still, how can i pass info from a fliter back to a valve?

 Cheers,

 Rui

 On Fri, 21 May 2004, Rui Zhang wrote:

  Hi All,
 
Thanks very much for your incisive comments.
 
Similar problem, but it seems much trickier to pass info from a Filter
  to a Valve. No attribute is associated with a ServletResponse. And when I
  try to cast it to HttpServletResponse to make use of its addHeader()
  method, my program simply hangs...
 
 Any clue?
 
 Thanks again.
 
  Best,
 
  Rui
 
 
  On Fri, 21 May 2004, Jon Wingfield wrote:
 
   Cool. I guess a Valve is good for that type of thing :)
  
   I think Carl and Ralph are right about the ClassClassException being a
   ClassLoader issue. I've seen similar things before when using custom
   Realms, JNDI resources etc.
   Our build process generates a minimal jar for deploying to common/lib
   which contains all the classes needed by the container classloaders.
   These classes are excluded from the webapp jars and all is happy. You
   have to be really careful about dependencies though or virtually all
   your webapp ends up in common/lib.
   Try jarring up your info object and putting in common/lib (or
   common/classes).
  
   Or you could use reflection as I've just read in your reply to Ralph ;)
  
   Good weekend all,
  
   Jon
  
  
  
   Rui Zhang wrote:
  
Jon,
   
To answer your query, I'm using a custom valve to instrument Tomcat with
response time monitoring, as part of the project I'm working on...
   
http://web.comlab.ox.ac.uk/oucl/research/areas/softeng/eWLM/
   
Cheers,
   
Rui
   
On Fri, 21 May 2004, Jon Wingfield wrote:
   
   
   An invocation of a Tomcat Valve gives you a Request object. This is a
   facade to a ServletRequest, which you can access via the getRequest()
   method. You could set your info object as an attribute on the
   ServletRequest. This should then be visible to your filter.
   
   http://jakarta.apache.org/tomcat/tomcat-4.1-doc/catalina/docs/api/index.html
   
   Just curious, why the custom Valve?
   
   Jon
   
   Rui Zhang wrote:
   
 Hi all,

   I'm trying to pass some info (say, as an Object) between a valve and a
 filter. Is anyone aware of a effective way to do this within the context
 of Tomcat?

   Many thanks.

 Best,

 Rui

   
   
   -
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
   
   
   
   
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
   
  
  
  
   -
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
  
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]