ApplicationFilterChainpublic final class ApplicationFilterChain extends Object implements org.apache.catalina.CometFilterChain, FilterChainImplementation of javax.servlet.FilterChain used to manage
the execution of a set of filters for a particular request. When the
set of defined filters has all been executed, the next call to
doFilter() will execute the servlet's service()
method itself. |
Fields Summary |
---|
private static final ThreadLocal | lastServicedRequest | private static final ThreadLocal | lastServicedResponse | public static final int | INCREMENT | private ApplicationFilterConfig[] | filtersFilters. | private int | posThe int which is used to maintain the current position
in the filter chain. | private int | nThe int which gives the current number of filters in the chain. | private Servlet | servletThe servlet instance to be executed by this chain. | private static final org.apache.catalina.util.StringManager | smThe string manager for our package. | private org.apache.catalina.util.InstanceSupport | supportThe InstanceSupport instance associated with our Wrapper (used to
send "before filter" and "after filter" events. | private static Class[] | classTypeStatic class array used when the SecurityManager is turned on and
doFilter is invoked. | private static Class[] | classTypeUsedInServiceStatic class array used when the SecurityManager is turned on and
service is invoked. | private static Class[] | cometClassTypeStatic class array used when the SecurityManager is turned on and
doFilterEvent is invoked. | private static Class[] | classTypeUsedInEventStatic class array used when the SecurityManager is turned on and
event is invoked. |
Constructors Summary |
---|
public ApplicationFilterChain()Construct a new chain instance with no defined filters.
// ----------------------------------------------------------- Constructors
super();
|
Methods Summary |
---|
void | addFilter(ApplicationFilterConfig filterConfig)Add a filter to the set of filters that will be executed in this chain.
if (n == filters.length) {
ApplicationFilterConfig[] newFilters =
new ApplicationFilterConfig[n + INCREMENT];
System.arraycopy(filters, 0, newFilters, 0, n);
filters = newFilters;
}
filters[n++] = filterConfig;
| public void | doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)Invoke the next filter in this chain, passing the specified request
and response. If there are no more filters in this chain, invoke
the service() method of the servlet itself.
// ---------------------------------------------------- FilterChain Methods
if( Globals.IS_SECURITY_ENABLED ) {
final ServletRequest req = request;
final ServletResponse res = response;
try {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedExceptionAction() {
public Object run()
throws ServletException, IOException {
internalDoFilter(req,res);
return null;
}
}
);
} catch( PrivilegedActionException pe) {
Exception e = pe.getException();
if (e instanceof ServletException)
throw (ServletException) e;
else if (e instanceof IOException)
throw (IOException) e;
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new ServletException(e.getMessage(), e);
}
} else {
internalDoFilter(request,response);
}
| public void | doFilterEvent(org.apache.catalina.CometEvent event)Invoke the next filter in this chain, passing the specified request
and response. If there are no more filters in this chain, invoke
the service() method of the servlet itself.
if( Globals.IS_SECURITY_ENABLED ) {
final CometEvent ev = event;
try {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedExceptionAction() {
public Object run()
throws ServletException, IOException {
internalDoFilterEvent(ev);
return null;
}
}
);
} catch( PrivilegedActionException pe) {
Exception e = pe.getException();
if (e instanceof ServletException)
throw (ServletException) e;
else if (e instanceof IOException)
throw (IOException) e;
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new ServletException(e.getMessage(), e);
}
} else {
internalDoFilterEvent(event);
}
| public static javax.servlet.ServletRequest | getLastServicedRequest()The last request passed to a servlet for servicing from the current
thread.
return (ServletRequest) lastServicedRequest.get();
| public static javax.servlet.ServletResponse | getLastServicedResponse()The last response passed to a servlet for servicing from the current
thread.
return (ServletResponse) lastServicedResponse.get();
| private void | internalDoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
// Call the next filter if there is one
if (pos < n) {
ApplicationFilterConfig filterConfig = filters[pos++];
Filter filter = null;
try {
filter = filterConfig.getFilter();
support.fireInstanceEvent(InstanceEvent.BEFORE_FILTER_EVENT,
filter, request, response);
if( Globals.IS_SECURITY_ENABLED ) {
final ServletRequest req = request;
final ServletResponse res = response;
Principal principal =
((HttpServletRequest) req).getUserPrincipal();
Object[] args = new Object[]{req, res, this};
SecurityUtil.doAsPrivilege
("doFilter", filter, classType, args);
args = null;
} else {
filter.doFilter(request, response, this);
}
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response);
} catch (IOException e) {
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response, e);
throw e;
} catch (ServletException e) {
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response, e);
throw e;
} catch (RuntimeException e) {
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response, e);
throw e;
} catch (Throwable e) {
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response, e);
throw new ServletException
(sm.getString("filterChain.filter"), e);
}
return;
}
// We fell off the end of the chain -- call the servlet instance
try {
if (Globals.STRICT_SERVLET_COMPLIANCE) {
lastServicedRequest.set(request);
lastServicedResponse.set(response);
}
support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
servlet, request, response);
if ((request instanceof HttpServletRequest) &&
(response instanceof HttpServletResponse)) {
if( Globals.IS_SECURITY_ENABLED ) {
final ServletRequest req = request;
final ServletResponse res = response;
Principal principal =
((HttpServletRequest) req).getUserPrincipal();
Object[] args = new Object[]{req, res};
SecurityUtil.doAsPrivilege("service",
servlet,
classTypeUsedInService,
args,
principal);
args = null;
} else {
servlet.service((HttpServletRequest) request,
(HttpServletResponse) response);
}
} else {
servlet.service(request, response);
}
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response);
} catch (IOException e) {
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
throw e;
} catch (ServletException e) {
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
throw e;
} catch (RuntimeException e) {
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
throw e;
} catch (Throwable e) {
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
throw new ServletException
(sm.getString("filterChain.servlet"), e);
} finally {
if (Globals.STRICT_SERVLET_COMPLIANCE) {
lastServicedRequest.set(null);
lastServicedResponse.set(null);
}
}
| private void | internalDoFilterEvent(org.apache.catalina.CometEvent event)
// Call the next filter if there is one
if (pos < n) {
ApplicationFilterConfig filterConfig = filters[pos++];
CometFilter filter = null;
try {
filter = (CometFilter) filterConfig.getFilter();
// FIXME: No instance listener processing for events for now
/*
support.fireInstanceEvent(InstanceEvent.BEFORE_FILTER_EVENT,
filter, event);
*/
if( Globals.IS_SECURITY_ENABLED ) {
final CometEvent ev = event;
Principal principal =
ev.getHttpServletRequest().getUserPrincipal();
Object[] args = new Object[]{ev, this};
SecurityUtil.doAsPrivilege
("doFilterEvent", (Filter) filter, cometClassType, args);
args = null;
} else {
filter.doFilterEvent(event, this);
}
/*support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, event);*/
} catch (IOException e) {
/*
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, event, e);
*/
throw e;
} catch (ServletException e) {
/*
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, event, e);
*/
throw e;
} catch (RuntimeException e) {
/*
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, event, e);
*/
throw e;
} catch (Throwable e) {
/*if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, event, e);*/
throw new ServletException
(sm.getString("filterChain.filter"), e);
}
return;
}
// We fell off the end of the chain -- call the servlet instance
try {
/*
support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
servlet, request, response);
*/
if( Globals.IS_SECURITY_ENABLED ) {
final CometEvent ev = event;
Principal principal =
ev.getHttpServletRequest().getUserPrincipal();
Object[] args = new Object[]{ ev };
SecurityUtil.doAsPrivilege("event",
servlet,
classTypeUsedInEvent,
args,
principal);
args = null;
} else {
((CometProcessor) servlet).event(event);
}
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response);*/
} catch (IOException e) {
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
*/
throw e;
} catch (ServletException e) {
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
*/
throw e;
} catch (RuntimeException e) {
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
*/
throw e;
} catch (Throwable e) {
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
*/
throw new ServletException
(sm.getString("filterChain.servlet"), e);
}
| void | release()Release references to the filters and wrapper executed by this chain.
for (int i = 0; i < n; i++) {
filters[i] = null;
}
n = 0;
pos = 0;
servlet = null;
support = null;
| void | reuse()Prepare for reuse of the filters and wrapper executed by this chain.
pos = 0;
| void | setServlet(javax.servlet.Servlet servlet)Set the servlet that will be executed at the end of this chain.
this.servlet = servlet;
| void | setSupport(org.apache.catalina.util.InstanceSupport support)Set the InstanceSupport object used for event notifications
for this filter chain.
this.support = support;
|
|