Author: remy.maucherat(a)jboss.com
Date: 2009-03-12 12:05:46 -0400 (Thu, 12 Mar 2009)
New Revision: 956
Modified:
trunk/java/org/apache/catalina/Context.java
trunk/java/org/apache/catalina/core/ApplicationContext.java
trunk/java/org/apache/catalina/core/LocalStrings.properties
trunk/java/org/apache/catalina/core/StandardContext.java
trunk/java/org/apache/catalina/core/StandardFilterFacade.java
trunk/java/org/apache/catalina/deploy/FilterDef.java
Log:
- Do the filter registration stuff.
Modified: trunk/java/org/apache/catalina/Context.java
===================================================================
--- trunk/java/org/apache/catalina/Context.java 2009-03-12 12:49:14 UTC (rev 955)
+++ trunk/java/org/apache/catalina/Context.java 2009-03-12 16:05:46 UTC (rev 956)
@@ -499,6 +499,14 @@
/**
+ * Add a filter mapping to this Context before current mappings.
+ *
+ * @param filterMap The filter mapping to be added
+ */
+ public void addFilterMapBefore(FilterMap filterMap);
+
+
+ /**
* Add the classname of an InstanceListener to be added to each
* Wrapper appended to this Context.
*
@@ -1013,6 +1021,16 @@
/**
+ * Return true if the Context has been initialized. This is lifecycle-ish, but
+ * needed by more and more Servlet API operations which are only permitted until
+ * the Context is initialized.
+ * @return true if the context is initialized.
+ *
+ */
+ public boolean isInitialized();
+
+
+ /**
* Set the validation feature of the XML parser used when
* parsing xml instances.
* @param xmlValidation true to enable xml instance validation
Modified: trunk/java/org/apache/catalina/core/ApplicationContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationContext.java 2009-03-12 12:49:14 UTC
(rev 955)
+++ trunk/java/org/apache/catalina/core/ApplicationContext.java 2009-03-12 16:05:46 UTC
(rev 956)
@@ -811,78 +811,6 @@
// FIXME: removed
- public void addFilter(String filterName, String description,
- String className, Map<String, String> initParameters,
- boolean isAsyncSupported) {
-
- if (context.initialized) {
- //TODO Spec breaking enhancement to ignore this restriction
- throw new IllegalStateException(
- sm.getString("applicationContext.addFilter.ise",
- getContextPath()));
- }
- FilterDef filterDef = new FilterDef();
- filterDef.setFilterName(filterName);
- filterDef.setDescription(description);
- filterDef.setFilterClass(className);
- filterDef.getParameterMap().putAll(initParameters);
- context.addFilterDef(filterDef);
- // TODO SERVLET3 - ASync support
- }
-
-
- // FIXME: removed
- public void addFilterMappingForServletNames(String filterName,
- EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
- String... servletNames) {
- if (context.initialized) {
- //TODO Spec breaking enhancement to ignore this restriction
- throw new IllegalStateException(sm.getString(
- "applicationContext.addFilterMapping", getContextPath()));
- }
- FilterMap filterMap = new FilterMap();
- for (String servletName : servletNames) {
- filterMap.addServletName(servletName);
- }
- filterMap.setFilterName(filterName);
- for (DispatcherType dispatcherType: dispatcherTypes) {
- filterMap.setDispatcher(dispatcherType.name());
- }
- if (isMatchAfter) {
- context.addFilterMap(filterMap);
- } else {
- context.addFilterMapBefore(filterMap);
- }
- }
-
-
- // FIXME: removed
- public void addFilterMappingForUrlPatterns(String filterName,
- EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
- String... urlPatterns) {
-
- if (context.initialized) {
- //TODO Spec breaking enhancement to ignore this restriction
- throw new IllegalStateException(sm.getString(
- "applicationContext.addFilterMapping", getContextPath()));
- }
- FilterMap filterMap = new FilterMap();
- for (String urlPattern : urlPatterns) {
- filterMap.addURLPattern(urlPattern);
- }
- filterMap.setFilterName(filterName);
- for (DispatcherType dispatcherType: dispatcherTypes) {
- filterMap.setDispatcher(dispatcherType.name());
- }
- if (isMatchAfter) {
- context.addFilterMap(filterMap);
- } else {
- context.addFilterMapBefore(filterMap);
- }
- }
-
-
- // FIXME: removed
public void addServletMapping(String servletName, String[] urlPatterns) {
if (context.initialized) {
//TODO Spec breaking enhancement to ignore this restriction
@@ -898,8 +826,15 @@
public FilterRegistration addFilter(String filterName, String className)
throws IllegalArgumentException, IllegalStateException {
- // TODO Auto-generated method stub
- return null;
+ if (context.isInitialized()) {
+ throw new
IllegalStateException(sm.getString("applicationContext.addFilter.ise",
+ getContextPath()));
+ }
+ FilterDef filterDef = new FilterDef();
+ filterDef.setFilterName(filterName);
+ filterDef.setFilterClass(className);
+ context.addFilterDef(filterDef);
+ return new StandardFilterFacade(context, filterDef);
}
@@ -911,8 +846,12 @@
public FilterRegistration findFilterRegistration(String filterName) {
- // TODO Auto-generated method stub
- return null;
+ FilterDef filterDef = context.findFilterDef(filterName);
+ if (filterDef == null) {
+ return null;
+ } else {
+ return new StandardFilterFacade(context, filterDef);
+ }
}
Modified: trunk/java/org/apache/catalina/core/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-03-12 12:49:14 UTC
(rev 955)
+++ trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-03-12 16:05:46 UTC
(rev 956)
@@ -14,8 +14,6 @@
# limitations under the License.
applicationContext.addFilter.ise=Filters can not be added to context {0} at this time.
See SRV.4.4.
-applicationContext.addFilterMapping.ise=Filter mappings can not be added to context {0}
at this time. See SRV.4.4.
-applicationContext.addServletMapping.ise=Servlet mappings can not be added to context {0}
at this time. See SRV.4.4.
applicationContext.attributeEvent=Exception thrown by attributes event listener
applicationContext.mapping.error=Error during mapping
applicationContext.requestDispatcher.iae=Path {0} does not start with a "/"
character
@@ -219,4 +217,7 @@
defaultInstanceManager.privilegedServlet=Servlet of class {0} is privileged and cannot be
loaded by this web application
defaultInstanceManager.restrictedFiltersResource=Restricted filters property file not
found
defaultInstanceManager.privilegedFilter=Filter of class {0} is privileged and cannot be
loaded by this web application
-defaultInstanceManager.restrictedListenersResources="Restricted listeners property
file not found
\ No newline at end of file
+defaultInstanceManager.restrictedListenersResources="Restricted listeners property
file not found
+
+filterRegistration.addFilterMapping.ise=Filter mappings can not be added to context {0}
at this time. See SRV.4.4.
+servletRegistration.addServletMapping.ise=Servlet mappings can not be added to context
{0} at this time. See SRV.4.4.
Modified: trunk/java/org/apache/catalina/core/StandardContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardContext.java 2009-03-12 12:49:14 UTC (rev
955)
+++ trunk/java/org/apache/catalina/core/StandardContext.java 2009-03-12 16:05:46 UTC (rev
956)
@@ -5533,6 +5533,12 @@
}
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+
public ObjectName getParentName() throws MalformedObjectNameException {
// "Life" update
String path=oname.getKeyProperty("name");
Modified: trunk/java/org/apache/catalina/core/StandardFilterFacade.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardFilterFacade.java 2009-03-12 12:49:14 UTC
(rev 955)
+++ trunk/java/org/apache/catalina/core/StandardFilterFacade.java 2009-03-12 16:05:46 UTC
(rev 956)
@@ -20,6 +20,7 @@
import java.util.EnumSet;
+import java.util.Iterator;
import java.util.Map;
import javax.servlet.DispatcherType;
@@ -27,11 +28,14 @@
import org.apache.catalina.Context;
import org.apache.catalina.deploy.FilterDef;
+import org.apache.catalina.deploy.FilterMap;
+import org.apache.catalina.util.StringManager;
/**
* Facade for the <b>FilterDef</b> object, with a hook to the Context to
- * store them automatically.
+ * store them automatically. The name of the class is not accurate, since
+ * there is no StandardFilter, but for consistency with StandardWrapper.
*
* @author Remy Maucharat
* @version $Revision: 947 $ $Date: 2009-03-10 05:02:22 +0100 (Tue, 10 Mar 2009) $
@@ -41,11 +45,18 @@
implements FilterRegistration {
+ /**
+ * The string manager for this package.
+ */
+ private static final StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+
// ----------------------------------------------------------- Constructors
/**
- * Create a new facede around a StandardWrapper.
+ * Create a new facade around a FilterDef.
*/
public StandardFilterFacade(Context context, FilterDef filterDef) {
@@ -74,43 +85,77 @@
// --------------------------------------------- FilterRegistration Methods
- public void addMappingForServletNames(
- EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
- String... servletNames) {
- // TODO Auto-generated method stub
-
+ public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes,
+ boolean isMatchAfter, String... servletNames) {
+ if (context.isInitialized()) {
+ throw new
IllegalStateException(sm.getString("filterRegistration.addFilterMapping.ise",
context.getPath()));
+ }
+ FilterMap filterMap = new FilterMap();
+ for (String servletName : servletNames) {
+ filterMap.addServletName(servletName);
+ }
+ filterMap.setFilterName(filterDef.getFilterName());
+ for (DispatcherType dispatcherType: dispatcherTypes) {
+ filterMap.setDispatcher(dispatcherType.name());
+ }
+ if (isMatchAfter) {
+ context.addFilterMap(filterMap);
+ } else {
+ context.addFilterMapBefore(filterMap);
+ }
}
public void addMappingForUrlPatterns(
EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
String... urlPatterns) {
- // TODO Auto-generated method stub
-
+ if (context.isInitialized()) {
+ throw new
IllegalStateException(sm.getString("filterRegistration.addFilterMapping.ise",
context.getPath()));
+ }
+ FilterMap filterMap = new FilterMap();
+ for (String urlPattern : urlPatterns) {
+ filterMap.addURLPattern(urlPattern);
+ }
+ filterMap.setFilterName(filterDef.getFilterName());
+ for (DispatcherType dispatcherType: dispatcherTypes) {
+ filterMap.setDispatcher(dispatcherType.name());
+ }
+ if (isMatchAfter) {
+ context.addFilterMap(filterMap);
+ } else {
+ context.addFilterMapBefore(filterMap);
+ }
}
public void setAsyncSupported(boolean asyncSupported) {
- // TODO Auto-generated method stub
-
+ filterDef.setAsyncSupported(asyncSupported);
+ context.addFilterDef(filterDef);
}
public boolean setDescription(String description) {
- // TODO Auto-generated method stub
- return false;
+ filterDef.setDescription(description);
+ context.addFilterDef(filterDef);
+ // FIXME: return value ???
+ return true;
}
public boolean setInitParameter(String name, String value) {
- // TODO Auto-generated method stub
- return false;
+ filterDef.addInitParameter(name, value);
+ context.addFilterDef(filterDef);
+ // FIXME: return value ???
+ return true;
}
public void setInitParameters(Map<String, String> initParameters) {
- // TODO Auto-generated method stub
-
+ Iterator<String> parameterNames = initParameters.keySet().iterator();
+ while (parameterNames.hasNext()) {
+ String parameterName = parameterNames.next();
+ filterDef.addInitParameter(parameterName,
initParameters.get(parameterName));
+ }
}
Modified: trunk/java/org/apache/catalina/deploy/FilterDef.java
===================================================================
--- trunk/java/org/apache/catalina/deploy/FilterDef.java 2009-03-12 12:49:14 UTC (rev
955)
+++ trunk/java/org/apache/catalina/deploy/FilterDef.java 2009-03-12 16:05:46 UTC (rev
956)
@@ -35,10 +35,27 @@
public class FilterDef implements Serializable {
+ private static final long serialVersionUID = 8703643991210305617L;
+
+
// ------------------------------------------------------------- Properties
/**
+ * Async supported.
+ */
+ private boolean asyncSupported = false;
+
+ public boolean getAsyncSupported() {
+ return (this.asyncSupported);
+ }
+
+ public void setAsyncSupported(boolean asyncSupported) {
+ this.asyncSupported = asyncSupported;
+ }
+
+
+ /**
* The description of this filter.
*/
private String description = null;