[jboss-jira] [JBoss JIRA] (AS7-5802) New instance of the filter in always created
Cheng Fang (JIRA)
jira-events at lists.jboss.org
Tue Oct 23 10:57:01 EDT 2012
[ https://issues.jboss.org/browse/AS7-5802?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12728630#comment-12728630 ]
Cheng Fang commented on AS7-5802:
---------------------------------
ServletContext javadoc http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#addFilter(java.lang.String,%20javax.servlet.Filter) says
Registers the given filter instance with this ServletContext under the given filterName.
---------------
Currently AS 7 always uses the container-managed instance (instantiated with default no-arg constructor), instead of the application-created filter instance, to perform doFilter. In most cases, this is ok, but if the filter has instance-specific state, things can go wrong.
The application-created filter instance is not used and GC'ed once it's out of scope, even before undeployment.
> New instance of the filter in always created
> --------------------------------------------
>
> Key: AS7-5802
> URL: https://issues.jboss.org/browse/AS7-5802
> Project: Application Server 7
> Issue Type: Bug
> Components: Web
> Affects Versions: 7.1.1.Final
> Reporter: Martin Vanek
> Assignee: Remy Maucherat
> Labels: filter
> Attachments: filtertest-0.0.1-SNAPSHOT.war, filtertest.zip
>
>
> I have created Servlet 3.0 filter in WebApplicationInitializer.onStartup() for example the following way:
> public void onStartup(ServletContext servletContext) throws ServletException {
> String servletName = "someServlet";
> String[] mappings = new String[] {"*.html"};
> Servlet servlet = FooServlet();
> ServletRegistration.Dynamic s = servletContext.addServlet(servletName, servlet);
> s.setLoadOnStartup(1);
> s.addMapping(mappings);
> Filter filter = new FooFilter("argument");
> String[] servletNames = new String[] {servletName};
> FilterRegistration.Dynamic f = servletContext.addFilter("fooFilter", filter);
> f.addMappingForServletNames(null, false, servletNames);
> }
> My problem is that jboss-web implemntation 7.0.13+ in StartdardContext.filterStart() along with ApplicationFilterConfig.getFilter() always tries to create new instance of the Filter via default constructor.
> My FooFilter does not have default constructor and therefore my application cannot be deployed.
> Please, check current implementation in Tomcat 7.0.32, which does not contain this problem.
> Also I have found that ApplicationFilterConfig has two similar atributes named filter and filterInstance. I guess it is quite wrong implementation and it is related to my problem.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list