wood burning stoves 2.0*
The moose likes Servlets and the fly likes Filter not being called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Filter not being called" Watch "Filter not being called" New topic
Author

Filter not being called

Douglas Kent
Ranch Hand

Joined: Oct 06, 2000
Posts: 171
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

Joined: Jan 10, 2002
Posts: 60732
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pradheesh manohar
Greenhorn

Joined: Oct 09, 2006
Posts: 10
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

Joined: Oct 06, 2000
Posts: 171
"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

Joined: Mar 27, 2006
Posts: 245
Not really ...

context name is never used for matching url patterns ..

You need something like this

<url-pattern>/*</url-pattern>


Vikrant Pandit
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

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.
 
Consider Paul's rocket mass heater.
 
subject: Filter not being called
 
Similar Threads
Servlet Filtering doesnt work on iPlanet 6
setting request header
web.xml: url-pattern in filter-mapping
A controller that forwards to different pages/controllers
Return to Login Page