users@jersey.java.net

Re: [Jersey] [PATCH] SpringServlet doesn't quite work with Servlet Filters

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 16 Feb 2009 17:36:29 +0100

On Feb 16, 2009, at 2:31 PM, James Strachan wrote:

> 2009/2/16 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>>
>> On Feb 16, 2009, at 11:37 AM, James Strachan wrote:
>>
>>> Just a heads up - I spotted this when trying to use SpringServlet
>>> as a
>>> Servlet Filter and have submitted a fairly minor patch to fix it...
>>> https://jersey.dev.java.net/issues/show_bug.cgi?id=217
>>>
>>> Its a fairly minor issue - mostly due to WebComponent having a
>>> different ServletContext field to ServletContainer which should
>>> maybe
>>> be refactored a little to avoid similar issues surfacing.
>>>
>>
>> Thanks. Doh, that is embarrassing.
>>
>> I am going to fix this a long with another issue related to Guice
>> integration that Gili found [1], which requires that an HTTP servlet
>> implementation implement HttpServlet, which IMHO is wrong because
>> Servlet is
>> the contract for invocations not HttpServlet and the latter IIUC is
>> not MUST
>> requirement.
>>
>> Given the Guice discussion i doubt the Guice developers will change
>> things.
>> So i am going to make ServletContainer re-implement HttpServlet and
>> encapsulate WebComponent.
>
> Great stuff thanks!
>
> BTW I spotted one more minor issue; when using the SpringServlet as a
> servlet filter, the regex pattern never seems to be initialised.
>
> I had to add this extra if clause into the configure() method of
> ServletContainer (which takes a FilterConfig)
>
> String regex =
> (String)rc.getProperty(PROPERTY_WEB_PAGE_CONTENT_REGEX);
> if (regex == null || regex.length() == 0) {
> regex =
> fc.getInitParameter(PROPERTY_WEB_PAGE_CONTENT_REGEX);
> }
>
> as the rc.getProperty() was returning null. Not sure if this is
> evidence of other issues when using servlet filters; e.g. should all
> the Filter's init parameter values be copied into the ResourceConfig
> abstraction or something?
>

Hmm.... i just tested with my re-factored stuff and it works fine. I
temporarily modified the spring-annotations sample to be a filter with
init-param.

We need some unit tests within the test framework... need to work out
how to configure Grizzly to work with filters.

Not quite sure why it fails for you as the SpringServlet does not
modify that behavior, and the init params should get added if they are
associated with the ServlerConfig or the FilterConfig as abstracted by
the WebConfig instance created for the init of Servlet or Filter
respectively, the code path to add them is the same.

I just committed fixes for issues 217 and 219.

Paul.