java - Why Servlet filter causing error in working application -
in working application, servlet filter has been placed. filter causing errors in existing application.
currently proof of concept purposes filter logs, no code has been implemented.
no exceptions found. on tomcat access log clue resources returning 304
[18/nov/2014:17:18:34 -0500] 10.93.161.0 (0ms) 52d40ef309a3eb46f1c5de3fb1d063bd.application.1 /secure/application/application/sc/skins/enterprise/images/window/window_tl.png http/1.1 : 304
as mentioned without filter in place application works fine.
when filter in place, logs show filter logging application not work properly, seems filter interfering somehow, don't want interference, except of implemented code in dofilter method.
below filter declaration in web.xml
<filter> <filter-name>sessionfilter</filter-name> <filter-class>com.company.filter.sessionfilter</filter-class> </filter> <filter-mapping> <filter-name>sessionfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
below filter class
public class sessionfilter implements filter{ private static final log log = logfactory.getlog(sessionfilter.class); @override public void destroy() { log.info("sessionfilter destroyed."); } @override public void dofilter(servletrequest req, servletresponse res, filterchain arg2) throws ioexception, servletexception { log.info("sessionfilter filtering."); log.info("test session"); } @override public void init(filterconfig arg0) throws servletexception { log.info("sessionfilter initialized."); } }
please let me know ideas.
thank you
in dofilter()
method of filter
have chain or forward request on chain, else other filters not called , request not forwarded servlet
.
qutoing form javadoc of filter.dofilter()
:
a typical implementation of method follow following pattern:-
- examine request
- optionally wrap request object custom implementation filter content or headers input filtering
- optionally wrap response object custom implementation filter content or headers output filtering
- a) either invoke next entity in chain using filterchain object (chain.dofilter()),
- b) or not pass on request/response pair next entity in filter chain block request processing
- directly set headers on response after invocation of next entity in filter chain.
do this:
chain.dofilter(request, response);
the reason why filter
system implemented way because filter
may decide break chain, e.g. because sending error; or filter
may wrap request and/or response , wrapper must lended onward other filters , servlets.
if don't call chail.dofilter()
, indicates servlet container don't want involve other filters , servlets in serving request.
Comments
Post a Comment