Filters are only run on the incoming request. They can run on include() and
forward() to but you need to see configure that in web.xml.
If you are renaming the servlet path - you can't call chain.doFilter() and
get the results you expect. YOu need to get a new RequestDistpatcher for the
location your rewriting to and perform a forward()
-Tim
Maurice Yarrow wrote:
Hello Tomcat users
I am attempting to use a Filter to first modify
a portion of the incoming URL (request.getServletPath())
and next, to send this filtered request on to the
tomcat DefaultServlet. The filter is indeed called
and I am able to complete the first goal of modifying
the incoming URL. I then used a Decorater pattern by
sub-classing HttpServletRequestWrapper and override
the getPathInfo() method because tomcat's
DefaultServlet calls this method out of its
getRelativePath method. I also set the following
attributes because the DefaultServlet.getRelativePath()
also looks at an attribute named
"javax.servlet.include.request_uri", as well as two others,
all of which I set to the modified URL path in my wrapper
class. I then filterChain.doFilter(myReqWrapper, res);
to pass this wrapped req obj to DefaultServlet.
However, the DefaultServlet does not seem to be called.
Here are the filter config mappings which I placed in
my web apps web.xml before the servlet mappings:
<!-- the filter -->
<filter>
<filter-name>ImageRequestFilter</filter-name>
<filter-class>getimg.servlets.ImageRequestFilter</filter-class>
</filter>
<!-- incoming: what the filter sees -->
<filter-mapping>
<filter-name>ImageRequestFilter</filter-name>
<url-pattern>/ImageRequest/*</url-pattern>
</filter-mapping>
<!-- outgoing: where the filter passes to -->
<filter-mapping>
<filter-name>ImageRequestFilter</filter-name>
<servlet-name>default</servlet-name>
</filter-mapping>
For the outgoing, I also tried:
<filter-mapping>
<filter-name>ImageRequestFilter</filter-name>
<servlet-name>org.apache.catalina.servlets.DefaultServlet</servlet-name>
</filter-mapping>
But I still was unable to get the request passed to the
tomcat DefaultServlet.
Does anyone see what I am doing wrong?
(I can send additional pieces of the relevant code,
if anyone would like to see that also, so please do not
hesitate to ask.)
Maurice Yarrow
Tim Funk wrote:
I think this should work in your own web.xml:
<filter-mapping>
<filter-name>MyFilter</filter-name>
<servlet-name>default</servlet-name>
</filter-mapping>
-Tim
Maurice Yarrow wrote:
Tim
So, my question is: can I request that a filter be applied to all
static page requests that are going to DefaultServlet? Or is this
done with a Valve?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]