You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2003/05/25 16:27:01 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core ApplicationFilterChain.java ApplicationFilterFactory.java StandardContext.java
remm 2003/05/25 07:27:01
Modified: catalina/src/share/org/apache/catalina/core
ApplicationFilterChain.java
ApplicationFilterFactory.java StandardContext.java
Log:
- Should optimize filter mapping (just using some region match, which should
be efficient enough).
- Small code cleanup.
- Remove some syncing (as adding a filter/servlet requires a reload of the webapp,
what's the point of the sync block ?).
Revision Changes Path
1.6 +5 -7 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java
Index: ApplicationFilterChain.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ApplicationFilterChain.java 30 Jan 2003 19:36:32 -0000 1.5
+++ ApplicationFilterChain.java 25 May 2003 14:27:01 -0000 1.6
@@ -234,9 +234,7 @@
} else {
filter.doFilter(request, response, this);
}
-
-
-
+
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response);
} catch (IOException e) {
1.9 +84 -63 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationFilterFactory.java
Index: ApplicationFilterFactory.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationFilterFactory.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ApplicationFilterFactory.java 26 Feb 2003 19:46:20 -0000 1.8
+++ ApplicationFilterFactory.java 25 May 2003 14:27:01 -0000 1.9
@@ -82,15 +82,20 @@
import org.apache.catalina.Wrapper;
/**
- * Factory for the creation and caching of Filters and creationg of Filter Chains
- *
+ * Factory for the creation and caching of Filters and creationg
+ * of Filter Chains.
*
* @author Greg Murray
+ * @author Remy Maucherat
* @version $Revision: 1.0
*/
public final class ApplicationFilterFactory {
+
+ // -------------------------------------------------------------- Constants
+
+
public static final int ERROR = 1;
public static final Integer ERROR_INTEGER = new Integer(ERROR);
public static final int FORWARD = 2;
@@ -108,6 +113,9 @@
private static final SecurityManager securityManager =
System.getSecurityManager();
+ private static ApplicationFilterFactory factory = null;;
+
+
// ----------------------------------------------------------- Constructors
@@ -118,6 +126,12 @@
}
+ // --------------------------------------------------------- Public Methods
+
+
+ /**
+ * Return the fqctory instance.
+ */
public static ApplicationFilterFactory getInstance() {
if (factory == null) {
factory = new ApplicationFilterFactory();
@@ -125,23 +139,23 @@
return factory;
}
+
/**
* Construct and return a FilterChain implementation that will wrap the
* execution of the specified servlet instance. If we should not execute
* a filter chain at all, return <code>null</code>.
- * <p>
- * <strong>FIXME</strong> - Pool the chain instances!
*
* @param request The servlet request we are processing
* @param servlet The servlet instance to be wrapped
*/
- public ApplicationFilterChain createFilterChain(ServletRequest request,
- Wrapper wrapper, Servlet servlet) {
+ public ApplicationFilterChain createFilterChain
+ (ServletRequest request, Wrapper wrapper, Servlet servlet) {
// get the dispatcher type
int dispatcher = -1;
if (request.getAttribute(DISPATCHER_TYPE_ATTR) != null) {
- Integer dispatcherInt = (Integer)request.getAttribute(DISPATCHER_TYPE_ATTR);
+ Integer dispatcherInt =
+ (Integer) request.getAttribute(DISPATCHER_TYPE_ATTR);
dispatcher = dispatcherInt.intValue();
}
String requestPath = null;
@@ -152,7 +166,8 @@
}
HttpServletRequest hreq = null;
- if (request instanceof HttpServletRequest) hreq = (HttpServletRequest)request;
+ if (request instanceof HttpServletRequest)
+ hreq = (HttpServletRequest)request;
// If there is no servlet to execute, return null
if (servlet == null)
return (null);
@@ -168,13 +183,13 @@
}
} else {
// Security: Do not recycle
- // Cannot recycle when under a request dispatcher
filterChain = new ApplicationFilterChain();
}
filterChain.setServlet(servlet);
- filterChain.setSupport(((StandardWrapper)wrapper).getInstanceSupport());
+ filterChain.setSupport
+ (((StandardWrapper)wrapper).getInstanceSupport());
// Acquire the filter mappings for this Context
StandardContext context = (StandardContext) wrapper.getParent();
@@ -191,8 +206,10 @@
// Add the relevant path-mapped filters to this filter chain
for (int i = 0; i < filterMaps.length; i++) {
-
- if (!matchFiltersURL(filterMaps[i], requestPath, dispatcher))
+ if (!matchDispatcher(filterMaps[i] ,dispatcher)) {
+ continue;
+ }
+ if (!matchFiltersURL(filterMaps[i], requestPath))
continue;
ApplicationFilterConfig filterConfig = (ApplicationFilterConfig)
context.findFilterConfig(filterMaps[i].getFilterName());
@@ -206,7 +223,10 @@
// Add filters that match on servlet name second
for (int i = 0; i < filterMaps.length; i++) {
- if (!matchFiltersServlet(filterMaps[i], servletName, dispatcher))
+ if (!matchDispatcher(filterMaps[i] ,dispatcher)) {
+ continue;
+ }
+ if (!matchFiltersServlet(filterMaps[i], servletName))
continue;
ApplicationFilterConfig filterConfig = (ApplicationFilterConfig)
context.findFilterConfig(filterMaps[i].getFilterName());
@@ -223,6 +243,10 @@
}
+
+ // -------------------------------------------------------- Private Methods
+
+
/**
* Return <code>true</code> if the context-relative request path
* matches the requirements of the specified filter mapping;
@@ -231,9 +255,7 @@
* @param filterMap Filter mapping being checked
* @param requestPath Context-relative request path of this request
*/
- private boolean matchFiltersURL(FilterMap filterMap,
- String requestPath,
- int dispatcher) {
+ private boolean matchFiltersURL(FilterMap filterMap, String requestPath) {
if (requestPath == null)
return (false);
@@ -245,20 +267,19 @@
// Case 1 - Exact Match
if (testPath.equals(requestPath))
- return (matchDispatcher(filterMap,dispatcher));
+ return (true);
// Case 2 - Path Match ("/.../*")
if (testPath.equals("/*"))
- return (matchDispatcher(filterMap,dispatcher)); // Optimize a common case
+ return (true);
if (testPath.endsWith("/*")) {
- String comparePath = requestPath;
- while (true) {
- if (testPath.equals(comparePath + "/*"))
- return (matchDispatcher(filterMap,dispatcher));
- int slash = comparePath.lastIndexOf('/');
- if (slash < 0)
- break;
- comparePath = comparePath.substring(0, slash);
+ if (testPath.regionMatches(0, requestPath, 0,
+ testPath.length() - 2)) {
+ if (requestPath.length() == (testPath.length() - 2)) {
+ return (true);
+ } else if ('/' == requestPath.charAt(testPath.length() - 2)) {
+ return (true);
+ }
}
return (false);
}
@@ -267,20 +288,46 @@
if (testPath.startsWith("*.")) {
int slash = requestPath.lastIndexOf('/');
int period = requestPath.lastIndexOf('.');
- if ((slash >= 0) && (period > slash))
- if (testPath.equals("*." +
- requestPath.substring(period + 1))) {
- return (matchDispatcher(filterMap,dispatcher));
- }
+ if ((slash >= 0) && (period > slash)
+ && (period != requestPath.length() - 1)) {
+ return (testPath.regionMatches(2, requestPath, period + 1,
+ testPath.length() - 2));
+ }
}
// Case 4 - "Default" Match
return (false); // NOTE - Not relevant for selecting filters
+
}
- /*
- * Convienience method which returns true if the dispatcher type
- * matches the dispatcher types specified in the FilterMap
+
+ /**
+ * Return <code>true</code> if the specified servlet name matches
+ * the requirements of the specified filter mapping; otherwise
+ * return <code>false</code>.
+ *
+ * @param filterMap Filter mapping being checked
+ * @param servletName Servlet name being checked
+ */
+ private boolean matchFiltersServlet(FilterMap filterMap,
+ String servletName) {
+
+ if (servletName == null) {
+ return (false);
+ } else {
+ if (servletName.equals(filterMap.getServletName())) {
+ return (true);
+ } else {
+ return false;
+ }
+ }
+
+ }
+
+
+ /**
+ * Convienience method which returns true if the dispatcher type
+ * matches the dispatcher types specified in the FilterMap
*/
private boolean matchDispatcher(FilterMap filterMap, int dispatcher) {
switch (dispatcher) {
@@ -340,31 +387,5 @@
return false;
}
- /**
- * Return <code>true</code> if the specified servlet name matches
- * the requirements of the specified filter mapping; otherwise
- * return <code>false</code>.
- *
- * @param filterMap Filter mapping being checked
- * @param servletName Servlet name being checked
- */
- private boolean matchFiltersServlet(FilterMap filterMap,
- String servletName,
- int dispatcher) {
-
-// if (debug >= 3)
-// log(" Matching servlet name '" + servletName +
-// "' against mapping " + filterMap);
-
- if (servletName == null)
- return (false);
- else
- if (servletName.equals(filterMap.getServletName()))
- return (matchDispatcher(filterMap,dispatcher));
- else return false;
-
- }
-
- private static ApplicationFilterFactory factory;
}
1.60 +2 -4 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java
Index: StandardContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- StandardContext.java 23 May 2003 10:54:35 -0000 1.59
+++ StandardContext.java 25 May 2003 14:27:01 -0000 1.60
@@ -3631,9 +3631,7 @@
*/
public FilterConfig findFilterConfig(String name) {
- synchronized (filterConfigs) {
- return ((FilterConfig) filterConfigs.get(name));
- }
+ return ((FilterConfig) filterConfigs.get(name));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org