You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Aaron Mulder <am...@alumni.princeton.edu> on 2007/11/29 18:05:04 UTC

Inserting a filter into the web container

Is there some good way to insert a filter/interceptor into the web
container request processing chain that would work for both Tomcat and
Jetty?  For example, let's say you wanted to apply some particular
request validation/auditing functionality to every application,
without changing the application configuration (e.g. without updating
web.xml).  It would be easy to write a little request filter or
interceptor to do it -- I'm just not sure what the best way is to hook
that in so it gets executed, and whether we have common
filters/interceptors for Tomcat and Jetty or whether you'd have to do
something different for each.

Thanks,
       Aaron

Re: Inserting a filter into the web container

Posted by Jeff Genender <jg...@apache.org>.

Aaron Mulder wrote:
> To me, AOP seems like it would be better if the application were doing
> it, rather than trying to do it at the server configuration level.

Yeah..but looking at the response by DJ, looks like the app server is
gonna have to do it anyways ;-)

My answer was similar to DJs in that an AOP adapter could pick something
up from a JAR that it recognizes...just a different take on the same
problem ;-)

Jeff

> 
> Thanks,
>       Aaron
> 
> On Nov 29, 2007 1:48 PM, Jeff Genender <jg...@apache.org> wrote:
>> Have you considered AOP?
>>
>> Jeff
>>
>>
>> Aaron Mulder wrote:
>>> Is there some good way to insert a filter/interceptor into the web
>>> container request processing chain that would work for both Tomcat and
>>> Jetty?  For example, let's say you wanted to apply some particular
>>> request validation/auditing functionality to every application,
>>> without changing the application configuration (e.g. without updating
>>> web.xml).  It would be easy to write a little request filter or
>>> interceptor to do it -- I'm just not sure what the best way is to hook
>>> that in so it gets executed, and whether we have common
>>> filters/interceptors for Tomcat and Jetty or whether you'd have to do
>>> something different for each.
>>>
>>> Thanks,
>>>        Aaron
>>

Re: Inserting a filter into the web container

Posted by Aaron Mulder <am...@alumni.princeton.edu>.
To me, AOP seems like it would be better if the application were doing
it, rather than trying to do it at the server configuration level.

Thanks,
      Aaron

On Nov 29, 2007 1:48 PM, Jeff Genender <jg...@apache.org> wrote:
> Have you considered AOP?
>
> Jeff
>
>
> Aaron Mulder wrote:
> > Is there some good way to insert a filter/interceptor into the web
> > container request processing chain that would work for both Tomcat and
> > Jetty?  For example, let's say you wanted to apply some particular
> > request validation/auditing functionality to every application,
> > without changing the application configuration (e.g. without updating
> > web.xml).  It would be easy to write a little request filter or
> > interceptor to do it -- I'm just not sure what the best way is to hook
> > that in so it gets executed, and whether we have common
> > filters/interceptors for Tomcat and Jetty or whether you'd have to do
> > something different for each.
> >
> > Thanks,
> >        Aaron
>
>

Re: Inserting a filter into the web container

Posted by Jeff Genender <jg...@apache.org>.
Have you considered AOP?

Jeff

Aaron Mulder wrote:
> Is there some good way to insert a filter/interceptor into the web
> container request processing chain that would work for both Tomcat and
> Jetty?  For example, let's say you wanted to apply some particular
> request validation/auditing functionality to every application,
> without changing the application configuration (e.g. without updating
> web.xml).  It would be easy to write a little request filter or
> interceptor to do it -- I'm just not sure what the best way is to hook
> that in so it gets executed, and whether we have common
> filters/interceptors for Tomcat and Jetty or whether you'd have to do
> something different for each.
> 
> Thanks,
>        Aaron

Re: Inserting a filter into the web container

Posted by Aaron Mulder <am...@alumni.princeton.edu>.
OK, after an IRC chat, it seems like an alternative would be:

For Tomcat, update the "base web app" configuration to add a servlet
filter to the default config.

For Jetty, a similar "default filter" and "default filter mapping"
feature was planned but not yet finished.  That could be finished and
then a similar thing could be done for Jetty.

That way, the code would be the same, it would just be the web
container configuration to invoke it that would be different.

On the other hand, it's not yet clear how to get the JAR with the
filter into the class path for the web app.  For example, changing the
base web app in Tomcat might take affect soon (say, next restart), but
any previously-deployed apps wouldn't have the JAR on their class
path, which could cause the app to fail.  In any case, apps to be
deployed in the future could use a modified deployer default
environment to add the JAR.

So...  some more investigation necessary, but a promising start.

Thanks,
       Aaron

On Nov 29, 2007 12:20 PM, David Jencks <da...@yahoo.com> wrote:
> I guess you could write a ModuleBuilderExtension that modified
> web.xml to add the filter and appropriate filter mapping.  I think
> you'd need to do the work in the initContext method.  I'm not sure if
> I'd call this method "good" or not but its all I can think of right now.
>
> In the createModule method you can add the jar containing your filter
> to the dependencies so the web app can actually find the filter...
>
> hope this helps
> david jencks
>
>
> On Nov 29, 2007, at 9:05 AM, Aaron Mulder wrote:
>
> > Is there some good way to insert a filter/interceptor into the web
> > container request processing chain that would work for both Tomcat and
> > Jetty?  For example, let's say you wanted to apply some particular
> > request validation/auditing functionality to every application,
> > without changing the application configuration (e.g. without updating
> > web.xml).  It would be easy to write a little request filter or
> > interceptor to do it -- I'm just not sure what the best way is to hook
> > that in so it gets executed, and whether we have common
> > filters/interceptors for Tomcat and Jetty or whether you'd have to do
> > something different for each.
> >
> > Thanks,
> >        Aaron
>
>
>

Re: Inserting a filter into the web container

Posted by David Jencks <da...@yahoo.com>.
I guess you could write a ModuleBuilderExtension that modified  
web.xml to add the filter and appropriate filter mapping.  I think  
you'd need to do the work in the initContext method.  I'm not sure if  
I'd call this method "good" or not but its all I can think of right now.

In the createModule method you can add the jar containing your filter  
to the dependencies so the web app can actually find the filter...

hope this helps
david jencks

On Nov 29, 2007, at 9:05 AM, Aaron Mulder wrote:

> Is there some good way to insert a filter/interceptor into the web
> container request processing chain that would work for both Tomcat and
> Jetty?  For example, let's say you wanted to apply some particular
> request validation/auditing functionality to every application,
> without changing the application configuration (e.g. without updating
> web.xml).  It would be easy to write a little request filter or
> interceptor to do it -- I'm just not sure what the best way is to hook
> that in so it gets executed, and whether we have common
> filters/interceptors for Tomcat and Jetty or whether you'd have to do
> something different for each.
>
> Thanks,
>        Aaron