users@jersey.java.net

Re: ResourceFilterFactory and Spring _at_Autowired

From: Davide Gurgone <davide.gurgone_at_gmail.com>
Date: Tue, 5 Oct 2010 08:34:55 -0700 (PDT)

Hi Paul,
thanks a lot for your reply,

I tried Autowiring SecurityFilter directly in SecuredFilterFactory.

        @Autowired
        SecurityFilter securityFilter;

It works fine, but I think is not a great idea, because I instantiate filter
also when not needed..

So, following your suggestion, I programmatically instantiate filter, using
Spring API's.

Here is the Factory code:

@Component
public class SecuredFilterFactory implements ResourceFilterFactory{

    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public List<ResourceFilter> create(AbstractMethod am) {
        // Here the code is not changed
    }
    
    private class SecurityResourceFilter implements ResourceFilter {
            
            @Override
            public ContainerRequestFilter getRequestFilter() {
            // Here I instantiate using Spring API
            return (SecurityFilter)
applicationContext.getBean("securityFilter");
            }

            @Override
            public ContainerResponseFilter getResponseFilter() {
                return null;
            }
    }
}

Thanks again,
Davide.
-- 
View this message in context: http://jersey.576304.n2.nabble.com/ResourceFilterFactory-and-Spring-Autowired-tp5603279p5603628.html
Sent from the Jersey mailing list archive at Nabble.com.