views:

92

answers:

3

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)
+1  A: 

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.

matt b
I added the stacktrace. It looks like Tomcat is invoking the doFilter(), but I can't find anywhere that states a filter loads at startup beyond being initialized. My code is not within the init(). I can certainly add a condition around everything in doFilter(), but I wanted to make sure there wasn't a configuration option first before doing that.
hal10001
A: 

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...

kschneid
+2  A: 

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.

BalusC
I am indeed running the application as ROOT through Eclipse. If you don't mind me asking another question, where did you read that Tomcat fires a GET request at ROOT on startup? Thanks!
hal10001
It is actually the Eclipse Tomcat plugin which does that. I've observed this behaviour before and I can confirm the behaviour you're seeing.
BalusC