You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Manak Bisht <ma...@iiitd.ac.in> on 2024/01/26 10:46:33 UTC

How to access the request URL in a custom valve implementation?

Hi,
I am trying to extend the AccessLogValve to modify logging behaviour for
certain URLs. However, I don't have access to the request object in the
AccessLogValve API. So, I am left with regex matching on the CharArrayWriter
message object. Is there a better way to do this?

Sincerely,
Manak Bisht

Re: How to access the request URL in a custom valve implementation?

Posted by Tim Funk <fu...@apache.org>.
See AbstractAccessLogValve (which AccessLogValve overrides)

Then you could override AbstractAccessLogValve.createAccessLogElement()
which has
        case 'q':
            return new QueryElement();

To possible do doing something like
        case 'q':
            return new ObfuscatedQueryElement();

Where ObfuscatedQueryElement is much like the existing QueryElement with
your additional requirements.
 They both would implement AccessLogElement which has access to the
Request object

-Tim

On Fri, Jan 26, 2024 at 7:58 AM Manak Bisht <ma...@iiitd.ac.in> wrote:

> I want to obfuscate values of query params for certain URLs, however, I
> would still like to log the request. Therefore, I cannot use the existing
> conditionif/conditionunless attributes that AccessLogValve provides.
>
>

Re: How to access the request URL in a custom valve implementation?

Posted by Manak Bisht <ma...@iiitd.ac.in>.
I want to obfuscate values of query params for certain URLs, however, I
would still like to log the request. Therefore, I cannot use the existing
conditionif/conditionunless attributes that AccessLogValve provides.

Sincerely,
Manak Bisht

On Fri, Jan 26, 2024 at 6:18 PM Mark Thomas <ma...@apache.org> wrote:

> On 26/01/2024 10:46, Manak Bisht wrote:
> > Hi,
> > I am trying to extend the AccessLogValve to modify logging behaviour for
> > certain URLs. However, I don't have access to the request object in the
> > AccessLogValve API. So, I am left with regex matching on the
> CharArrayWriter
> > message object. Is there a better way to do this?
>
> It depends what you are trying to do - which you haven't explained.
>
> You have direct access to the request object in the invoke() method.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: How to access the request URL in a custom valve implementation?

Posted by Mark Thomas <ma...@apache.org>.
On 26/01/2024 10:46, Manak Bisht wrote:
> Hi,
> I am trying to extend the AccessLogValve to modify logging behaviour for
> certain URLs. However, I don't have access to the request object in the
> AccessLogValve API. So, I am left with regex matching on the CharArrayWriter
> message object. Is there a better way to do this?

It depends what you are trying to do - which you haven't explained.

You have direct access to the request object in the invoke() method.

Mark

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


Re: How to access the request URL in a custom valve implementation?

Posted by Tim Funk <fu...@apache.org>.
My bad - AccessLogValve also supports that feature too

   - *%{xxx}r* write value of ServletRequest attribute with name xxx (escaped
   if required, value ?? if request is null)

https://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Access_Logging

-Tim


On Fri, Jan 26, 2024 at 7:23 AM Tim Funk <fu...@apache.org> wrote:

> It depends on what you are trying to accomplish. ExtendedAccessLogValve is
> a
> little more flexible where you can write out arbitrary request
> attributes but still format the request like the standard access
> log. So you could have a filter set the value and not need to
> write your own access logger.
>
> -Tim
>
> On Fri, Jan 26, 2024 at 5:47 AM Manak Bisht <ma...@iiitd.ac.in>
> wrote:
>
>> Hi,
>> I am trying to extend the AccessLogValve to modify logging behaviour for
>> certain URLs. However, I don't have access to the request object in the
>> AccessLogValve API. So, I am left with regex matching on the
>> CharArrayWriter
>> message object. Is there a better way to do this?
>>
>

Re: How to access the request URL in a custom valve implementation?

Posted by Tim Funk <fu...@apache.org>.
It depends on what you are trying to accomplish. ExtendedAccessLogValve is
a
little more flexible where you can write out arbitrary request
attributes but still format the request like the standard access
log. So you could have a filter set the value and not need to
write your own access logger.

-Tim

On Fri, Jan 26, 2024 at 5:47 AM Manak Bisht <ma...@iiitd.ac.in> wrote:

> Hi,
> I am trying to extend the AccessLogValve to modify logging behaviour for
> certain URLs. However, I don't have access to the request object in the
> AccessLogValve API. So, I am left with regex matching on the
> CharArrayWriter
> message object. Is there a better way to do this?
>