PDA

View Full Version : Manage Servlet Filter


desmax
Aug 22nd, 2005, 10:17 AM
I have the necessity to manage the behavior of a servlet filter, but i have a doubt how to proceed.
The filter it's not a bean, to register with a MBean with Spring JMX, perhaps FilterToBeanProxy used in Acegi can help me ?
Someone has suggestions ?

kdkooter
Aug 23rd, 2005, 10:49 AM
Just a sugestion: delegate the filter behaviour to a pojo that is controlled (and publsihed as an MBean) by spring. In the intialization of the filter you get a reference to this bean using WebApplicationContextUtils. getWebApplicationContext(servletContext).getBean("yourBean")

Costin Leau
Aug 25th, 2005, 03:22 AM
You need to find some way of communicating with the filter instance(s) which are not under Spring control. First of all see what the specs say about filters - do they create only one instance per server or per request(I think it's this one).
If that's the case then you'd better find some way of externalizing the configuration - use JNDI to publish a configuration object; the filters will read it or smth while your JMX bean will act directly on it, forcing the filters to act as they should.
In case you want just a read-only access it's pretty easy, if you want write also then you get into some synchronization issues.