tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "joelsherriff" <joelsherr...@comcast.net>
Subject Re: How to use servlet filters without modifying webapp
Date Thu, 28 Apr 2005 14:20:19 GMT
And to save anyone the trouble, I also tried substituting the url-pattern
element for a servlet-name element and named the
servlet I'm trying to filter.  Same result - ClassCastException.  I get
nothing helpful from the log, but just in case someone
with more experience can, here's a snip:

2005-04-28 10:16:59 StandardContext[/blojsom]: Starting filters
2005-04-28 10:16:59 StandardContext[/blojsom]:  Starting filter
'timerFilter'
2005-04-28 10:16:59 StandardContext[/blojsom]: Exception starting filter
timerFilter
java.lang.ClassCastException
 at
org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilter
Config.java:206)
 at
org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFil
terConfig.java:280)
 at
org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterCon
fig.java:73)
 at
org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:31
01)


----- Original Message ----- 
From: "joelsherriff" <joelsherriff@comcast.net>
To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
Sent: Thursday, April 28, 2005 10:08 AM
Subject: Re: How to use servlet filters without modifying webapp


> I've done that, thanks.  Here's what I added for the filter:
>
>     <filter>
>         <filter-name>timerFilter</filter-name>
>         <filter-class>TimerFilter</filter-class>
>     </filter>
>
>     <filter-mapping>
>         <filter-name>timerFilter</filter-name>
>         <url-pattern>/*</url-pattern>
>     </filter-mapping>
>
> to my web.xml.  It appears to be finding it properly.  If I change the
> filter name to a non-existent filter, I
> properly get a ClassNotFoundException.  So it's something IN the filter,
or
> so it would seem.  All I've
> done is copy an example filter from the web - it looks like:
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class TimerFilter implements Filter {
>
>   private FilterConfig config = null;
>
>   public void init(FilterConfig config) throws ServletException {
>     this.config = config;
>   }
>
>   public void destroy() {
>     this.config = null;
>   }
>
>   public void doFilter(ServletRequest request, ServletResponse response,
>                      FilterChain chain) throws IOException,
ServletException
> {
>     long before = System.currentTimeMillis();
>     chain.doFilter(request, response);
>     long after = System.currentTimeMillis();
>
>     String name = "";
>     if (request instanceof HttpServletRequest) {
>       name = ((HttpServletRequest)request).getRequestURI();
>     }
>     config.getServletContext().log(name + ": " + (after - before) + "ms");
>   }
> }
>
>
>
>
> ----- Original Message ----- 
> From: "Anhony" <anthonys123@comcast.net>
> To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> Sent: Thursday, April 28, 2005 9:48 AM
> Subject: Re: How to use servlet filters without modifying webapp
>
>
> > Greetings,
> >
> > Try adding a <filter> block to your web.xml. Your JSP container locates
> your
> > filters thru these sections in the web.xml. I included a small sample
> > <filter> block below.
> >
> > <filter>
> >      <filter-name>processingFilter</filter-name>
> >      <filter-class>servletFilters.ProcessingFilter</filter-class>
> > </filter>
> >
> > I hope this helps.
> >
> > Anthony-
> >
> >
> >
> > ----- Original Message ----- 
> > From: "joelsherriff" <joelsherriff@comcast.net>
> > To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> > Sent: Thursday, April 28, 2005 9:36 AM
> > Subject: How to use servlet filters without modifying webapp
> >
> >
> > Hello,
> >     I'm experimenting with applying a servlet filter to an existing
webapp
> > and I'm getting a ClassCastException upon startup.
> > Can I do this without modifying the webapp source and adding my filter
in
> > there?  If so, what else could be causing this?
> >
> > I'm not sure where it looks for the filter .class file but I put it in
the
> > webapp's WEB-INF/classes directory - I guess it finds it
> > since I'm getting this error.  The filter really does nothing, I'm just
> > trying to get A filter in place before making it more complicated.
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message