Hi Mark,
After some research and thought about internal application flow, I think
the 'cleanest' is have TC's default servlet handle the *.html requests and
use the assigned filter to restrict the access as desired. Is there a
better approach? On that plan, I have this mapping for TC's default
servlet and init:
Filter AppFilterAccessLog's servlet mapping:
Servlet name: default , registered class:
org.apache.catalina.servlets.DefaultServlet.
Servlet default's mapping:
/img/*
/css/*
/WEB-INF/*
/js/*
Servlet default's init parameters:
listings: false
debug: 0
If I use *.html instead of /WEB-INF/*, it goes into infinite loop
redirecting / forwarding until exception is thrown (I think that root cause
is servlets' startup ordering). Below are what my access log filter see
for HttpServletRequest:
Attributes:
javax.servlet.forward.request_uri=/erm-0.0.1-SNAPSHOT/
javax.servlet.forward.context_path=/erm-0.0.1-SNAPSHOT
javax.servlet.forward.servlet_path=
javax.servlet.forward.path_info=/
javax.servlet.forward.mapping=org.apache.catalina.core.ApplicationMapping$MappingImpl@7fc1f887
org.apache.logging.log4j.web.Log4jServletFilter.FILTERED=true
Class: org.apache.catalina.core.ApplicationHttpRequest
DispatcherType: FORWARD [javax.servlet.DispatcherType]
HttpServletMapping:
Class: org.apache.catalina.core.ApplicationMapping$MappingImpl
MappingMatch: PATH
MatchValue: setup/step_0.html
Pattern: /WEB-INF/*
ServletName: default
Below is from the actual filter assigned to TC's default servlet intended
to restrict access:
ContextPath: /erm-0.0.1-SNAPSHOT
DispatcherType: FORWARD
PathInfo: /setup/step_0.html
PathTranslated:
D:\apache-tomcat-9.0.21\webapps\erm-0.0.1-SNAPSHOT\setup\step_0.html
Method: GET
RequestURI: /erm-0.0.1-SNAPSHOT/WEB-INF/setup/step_0.html
RequestURL:
http://localhost:8080/erm-0.0.1-SNAPSHOT/WEB-INF/setup/step_0.html
ServletPath: /WEB-INF
ServletContext.ServletContextName: erm
response: org.apache.catalina.connector.ResponseFacade
I think everything seems correct except the PathTranslated. It should be:
D:\apache-tomcat-9.0.21\webapps\erm-0.0.1-SNAPSHOT\WEB-INF\setup\step_0.html
where the file is. I'm unable to find out why it's wrong after a couple
hours of searching since the the browser shows an empty page... The string
"/WEB-INF/setup/step_0.html" was passed to request.getRequestDispatcher().
According to the doc [1], " If the path begins with a "/" it is interpreted
as relative to the current context root." everything is as it should be
right, other than PathTranslated? Or did I misunderstood the usage of
getRequestDispatcher().forward()? Currently, I have 4 filters in place and
all are in passive monitoring mode. None of them have the code logic to
perform their intended functions. 3 filters mapped to URL /* and one
assigned to TC's default servlet. I'll work out their filtering order
before the intended functions are implemented.
Thanks,
Tommy
[1]
http://tomcat.apache.org/tomcat-9.0-doc/servletapi/javax/servlet/ServletRequest.html#getRequestDispatcher-java.lang.String-