user4903
user4903

Reputation:

How do I get servlet filters to stop loading on application startup in Tomcat?

Below is my deployment descriptor. I'm using Spring MVC, but I've got a url rewrite filter in place that is supposed to run, and then forward to the appropriate controller. For some reason this filter is loading on startup, trying to get the path translated, and throwing a nullpointerexception because there is no path. I never knew filters loaded at startup, but that looks like what is happening.

<!-- SERVLETS -->

<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/index.html</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<!-- FILTERS -->

<filter>
    <filter-name>URLRewriteFilter</filter-name>
    <filter-class>com.ecomm.filters.URLRewriteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>URLRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

EDIT:

Aug 17, 2010 11:28:12 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at com.ecomm.helpers.TranslateURLHelper.executeController(TranslateURLHelper.java:47)
    at com.ecomm.filters.URLRewriteFilter.doFilter(URLRewriteFilter.java:41)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)

Upvotes: 1

Views: 3269

Answers (3)

BalusC
BalusC

Reputation: 1109162

It look like that you're deploying the webapp on the ROOT context using Eclipse. The Tomcat plugin of Eclipse does indeed a self-test on startup by firing a GET request on the ROOT.

Just ignore it or fix the code so that it doesn't throw NPE. This is IMO definitely a bug in the com.ecomm.filters.URLRewriteFilter. Empty paths should not be counted as exceptional cases. Endusers could fire them as good.

Upvotes: 5

kschneid
kschneid

Reputation: 5694

I never knew filters loaded at startup...

I guess it depends on how you define "loaded". An instance will be constructed and its init(FilterConfig) method invoked before ever acting upon a request, so there are a couple of opportunities for its code to execute "at startup". As requested, please post the actual exception...

Upvotes: 1

matt b
matt b

Reputation: 139971

That doesn't make much sense. Filters apply to requests only. Are you sure there is nothing in your Spring config that is resulting in either 1) the filter class being invoked or 2) firing off an http request?

What does the stacktrace of the NPE in the filter show?

I think you'll want to figure out where these requests are coming from in order to understand how to solve the problem.

Upvotes: 1

Related Questions