• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter not being called

 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Have coded a Filter to authenticate users. I've got log4j going to trace what's happening. It records the "init" method, but the trace statement in the doFilter method never gets called--it's the first statement in the method. The filter-mapping, url-pattern element in the app's web.xml looks like: <url-pattern>/tomcat-docs/*</tomcat-docs> (I'm filtering the tomcat-docs as proof-of-concept) Also, am using tomcat 5.5. Anyone have any idea why the doFilter method apparently never gets called? Also, turned on request tracing, and the log shows that the tomcat-docs are getting requested. Have the class jarred up and placed in the tomcat-docs/WEB-INF/lib directory. Also, coded the doFilter method to throw an exception after logging statement. Not getting called.
Thanks in advance!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tomcat-docs is its own web application is it not?

Are you adding the filter def to the tomcat-docs web app? If so, then the context path is not part of the url pattern.
 
pradheesh manohar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi doug

have ya added the filter tag to your web.xml.lik this?

<filter>
<filter-name>AuthenticateFilter</filter-name>
<filter-class>packagename.AuthenticateFilter</filter-class>
</filter>
[ October 31, 2006: Message edited by: pradheesh manohar ]
 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"tomcat-docs" is the context path, right? So "/tomcat-docs/*" should match every request for a resource in the tomcat-docs context...I think. Here's what I have in the web.xml of the tomcat-docs app:
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really ...

context name is never used for matching url patterns ..

You need something like this

<url-pattern>/*</url-pattern>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Douglas Kent:
"tomcat-docs" is the context path, right? So "/tomcat-docs/*" should match every request


As I said, and Vivek has repeated, the context path is not part of the URL that you can match on. In order to keep web apps indepenedent of their context path (which should be hard-coded nowhere in the app), matching happens on everything after the context path.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic