On Aug 28, 2009, at 10:10 PM, DirkM wrote:
>
>
> Paul Sandoz wrote:
>>
>>
>> public class MyRFF implements ResourceFilterFactory {
>> private final HttpServletRequest hsr;
>>
>> public ResourceFilterFactory(@Context HttpServletRequest hsr) {
>> this.hsr = hsr;
>> }
>>
>> ...
>>
>
> Are you sure this will work?
Yes. What will be injected is a thread local proxy. If you try to
invoke methods on that will a request is not in scope an
IllegalStateException will be thrown.
Alan wants to get access to the HttpServletRequest because he has one
or more servlet filters that will add attributes to the
HttpServletRequest.
Paul.
> I thought that ResourceFilterFactories were
> created at server start-up time, not when the request is received,
> which
> means that attempting to use the HttpServletRequest parameter
> wouldn't make
> sense.
>
> In the
> https://jersey.dev.java.net/nonav/apidocs/1.1.1-ea/jersey/com/sun/jersey/spi/container/ContainerRequestFilter.html
> ContainerRequestFilter interface , the filter method already passes
> the
> ContainerRequest object as a parameter. (ContainerRequest implements
> HttpRequestContext)
>
> For example:
>
> public class MyFilterFactory implements ResourceFilterFactory {
>
> private class Filter implements ResourceFilter,
> ContainerRequestFilter {
> @Override
> public ContainerRequestFilter getRequestFilter() {
> return this;
> }
>
> @Override
> public ContainerResponseFilter getResponseFilter() {
> return null;
> }
>
> @Override
> public ContainerRequest filter(ContainerRequest request) {
> // ... do stuff here ...
> return request;
> }
> }
>
>
> @Override
> public List<ResourceFilter> create(AbstractMethod am) {
> return Collections.<ResourceFilter>singletonList(new Filter());
> }
> }
>
>
> --
> View this message in context: http://n2.nabble.com/ResourceFilter-to-execute-after-the-ServletFilters-tp3534429p3537184.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>