Author: remy.maucherat(a)jboss.com
Date: 2009-09-22 09:17:34 -0400 (Tue, 22 Sep 2009)
New Revision: 1173
Modified:
trunk/java/javax/servlet/ServletContext.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
Log:
- Implementation for the restricted listeners.
Modified: trunk/java/javax/servlet/ServletContext.java
===================================================================
--- trunk/java/javax/servlet/ServletContext.java 2009-09-22 05:04:35 UTC (rev 1172)
+++ trunk/java/javax/servlet/ServletContext.java 2009-09-22 13:17:34 UTC (rev 1173)
@@ -864,8 +864,8 @@
*
* @return the new Servlet instance
*
- * @throws ServletException if an error occurs during the instantiation
- * of, or resource injection into the new Servlet
+ * @throws ServletException if the given <tt>clazz</tt> fails to be
+ * instantiated
*
* @throws UnsupportedOperationException if this ServletContext was
* passed to the {@link ServletContextListener#contextInitialized} method
@@ -1054,8 +1054,8 @@
*
* @return the new Filter instance
*
- * @throws ServletException if an error occurs during the instantiation
- * of, or resource injection into the new Filter
+ * @throws ServletException if the given <tt>clazz</tt> fails to be
+ * instantiated
*
* @throws UnsupportedOperationException if this ServletContext was
* passed to the {@link ServletContextListener#contextInitialized} method
@@ -1387,8 +1387,8 @@
*
* @return the new EventListener instance
*
- * @throws ServletException if an error occurs during the instantiation
- * of, or resource injection into the new EventListener
+ * @throws ServletException if the given <tt>clazz</tt> fails to be
+ * instantiated
*
* @throws UnsupportedOperationException if this ServletContext was
* passed to the {@link ServletContextListener#contextInitialized} method
Modified: trunk/java/org/apache/catalina/core/ApplicationContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationContext.java 2009-09-22 05:04:35 UTC
(rev 1172)
+++ trunk/java/org/apache/catalina/core/ApplicationContext.java 2009-09-22 13:17:34 UTC
(rev 1173)
@@ -188,6 +188,12 @@
private ThreadLocal<DispatchData> dispatchData =
new ThreadLocal<DispatchData>();
+
+ /**
+ * The restricted flag.
+ */
+ private boolean restricted = false;
+
// --------------------------------------------------------- Public Methods
@@ -204,6 +210,16 @@
}
+ public boolean isRestricted() {
+ return restricted;
+ }
+
+
+ public void setRestricted(boolean restricted) {
+ this.restricted = restricted;
+ }
+
+
// ------------------------------------------------- ServletContext Methods
@@ -847,7 +863,9 @@
public FilterRegistration.Dynamic addFilter(String filterName, String className)
throws IllegalArgumentException, IllegalStateException {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
if (context.isInitialized()) {
throw new
IllegalStateException(sm.getString("applicationContext.alreadyInitialized",
getContextPath()));
@@ -863,7 +881,9 @@
public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
if (context.isInitialized()) {
throw new
IllegalStateException(sm.getString("applicationContext.alreadyInitialized",
getContextPath()));
@@ -881,14 +901,18 @@
public FilterRegistration.Dynamic addFilter(String filterName,
Class<? extends Filter> filterClass) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
return addFilter(filterName, filterClass.getName());
}
public ServletRegistration.Dynamic addServlet(String servletName, String className)
throws IllegalArgumentException, IllegalStateException {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
if (context.isInitialized()) {
throw new
IllegalStateException(sm.getString("applicationContext.alreadyInitialized",
getContextPath()));
@@ -905,13 +929,17 @@
public ServletRegistration.Dynamic addServlet(String servletName,
Class<? extends Servlet> clazz) throws IllegalArgumentException,
IllegalStateException {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
return addServlet(servletName, clazz.getName());
}
public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
if (context.isInitialized()) {
throw new
IllegalStateException(sm.getString("applicationContext.alreadyInitialized",
getContextPath()));
@@ -927,7 +955,9 @@
public FilterRegistration getFilterRegistration(String filterName) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
ApplicationFilterConfig filterConfig =
context.findApplicationFilterConfig(filterName);
if (filterConfig == null) {
FilterDef filterDef = context.findFilterDef(filterName);
@@ -943,7 +973,9 @@
public ServletRegistration getServletRegistration(String servletName) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
Wrapper wrapper = (Wrapper) context.findChild(servletName);
if (wrapper != null) {
return wrapper.getFacade();
@@ -954,7 +986,9 @@
public Map<String, FilterRegistration> getFilterRegistrations() {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
HashMap<String, FilterRegistration> result =
new HashMap<String, FilterRegistration>();
ApplicationFilterConfig[] filterConfigs =
context.findApplicationFilterConfigs();
@@ -966,7 +1000,9 @@
public Map<String, ServletRegistration> getServletRegistrations() {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
HashMap<String, ServletRegistration> result =
new HashMap<String, ServletRegistration>();
Container[] wrappers = context.findChildren();
@@ -979,25 +1015,33 @@
public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
return context.getDefaultSessionTrackingModes();
}
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
return context.getSessionTrackingModes();
}
public SessionCookieConfig getSessionCookieConfig() {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
return context.getSessionCookie();
}
public <T extends Filter> T createFilter(Class<T> c)
throws ServletException {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
try {
return (T) context.getInstanceManager().newInstance(c);
} catch (Throwable e) {
@@ -1009,7 +1053,9 @@
public <T extends Servlet> T createServlet(Class<T> c)
throws ServletException {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
try {
return (T) context.getInstanceManager().newInstance(c);
} catch (Throwable e) {
@@ -1020,7 +1066,9 @@
public boolean setInitParameter(String name, String value) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
mergeParameters();
if (parameters.get(name) != null) {
return false;
@@ -1039,7 +1087,9 @@
* requested
*/
public void setSessionTrackingModes(Set<SessionTrackingMode>
sessionTrackingModes) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
if (context.getAvailable()) {
throw new IllegalStateException(
sm.getString("applicationContext.setSessionTracking.ise",
@@ -1059,7 +1109,9 @@
public void addListener(String className) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
if (context.isInitialized()) {
throw new
IllegalStateException(sm.getString("applicationContext.alreadyInitialized",
getContextPath()));
@@ -1069,7 +1121,9 @@
public <T extends EventListener> void addListener(T listener) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
if (context.isInitialized()) {
throw new
IllegalStateException(sm.getString("applicationContext.alreadyInitialized",
getContextPath()));
@@ -1079,7 +1133,9 @@
public void addListener(Class<? extends EventListener> listenerClass) {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
if (context.isInitialized()) {
throw new
IllegalStateException(sm.getString("applicationContext.alreadyInitialized",
getContextPath()));
@@ -1097,7 +1153,9 @@
public <T extends EventListener> T createListener(Class<T> clazz)
throws ServletException {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
if (context.isInitialized()) {
throw new
IllegalStateException(sm.getString("applicationContext.alreadyInitialized",
getContextPath()));
@@ -1114,13 +1172,17 @@
public ClassLoader getClassLoader() {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
return context.getLoader().getClassLoader();
}
public JspConfigDescriptor getJspConfigDescriptor() {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
ArrayList<TaglibDescriptor> taglibDescriptors = new
ArrayList<TaglibDescriptor>();
String[] taglibURIs = context.findTaglibs();
for (int i = 0; i < taglibURIs.length; i++) {
@@ -1140,13 +1202,17 @@
public int getEffectiveMajorVersion() {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
return context.getVersionMajor();
}
public int getEffectiveMinorVersion() {
- // FIXME: restricted method
+ if (restricted) {
+ throw new
UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
return context.getVersionMinor();
}
Modified: trunk/java/org/apache/catalina/core/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-09-22 05:04:35 UTC
(rev 1172)
+++ trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-09-22 13:17:34 UTC
(rev 1173)
@@ -14,6 +14,7 @@
# limitations under the License.
applicationContext.alreadyInitialized=Context {0} is already initialized.
+applicationContext.restricted=Listener that attempted to call this method is restricted.
applicationContext.attributeEvent=Exception thrown by attributes event listener
applicationContext.create=Error creating instance
applicationContext.mapping.error=Error during mapping
Modified: trunk/java/org/apache/catalina/core/StandardContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardContext.java 2009-09-22 05:04:35 UTC (rev
1172)
+++ trunk/java/org/apache/catalina/core/StandardContext.java 2009-09-22 13:17:34 UTC (rev
1173)
@@ -218,6 +218,14 @@
/**
* The set of application listener class names configured for this
+ * application that have been added from TLDs, and have a limited access to
+ * the servlet context.
+ */
+ protected HashSet<String> restrictedApplicationListeners = new
HashSet<String>();
+
+
+ /**
+ * The set of application listener class names configured for this
* application, in the order they were encountered in the web.xml file.
*/
protected EventListener applicationListenerInstances[] = new EventListener[0];
@@ -2062,15 +2070,41 @@
* @param listener Java class name of a listener class
*/
public void addApplicationListener(String listener) {
+ addApplicationListener(listener, false);
+ }
+
+
+ /**
+ * Add a new Listener class name to the set of Listeners
+ * configured for this application.
+ *
+ * @param listener Java class name of a listener class
+ */
+ protected void addApplicationListener(String listener, boolean restricted) {
String results[] = new String[applicationListeners.length + 1];
for (int i = 0; i < applicationListeners.length; i++) {
if (listener.equals(applicationListeners[i])) {
log.info(sm.getString("standardContext.duplicateListener",
listener));
+ if (!restricted &&
restrictedApplicationListeners.contains(listener)) {
+ restrictedApplicationListeners.remove(listener);
+ }
return;
}
results[i] = applicationListeners[i];
}
results[applicationListeners.length] = listener;
+ if (restricted && !restrictedApplicationListeners.contains(listener)) {
+ boolean found = false;
+ for (String check : applicationListeners) {
+ if (check.equals(listener)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ restrictedApplicationListeners.add(listener);
+ }
+ }
applicationListeners = results;
fireContainerEvent("addApplicationListener", listener);
}
@@ -2418,9 +2452,8 @@
// Add listeners specified by the taglib
String[] listeners = tagLibraryInfo.getListeners();
for (int i = 0; i < listeners.length; i++) {
- addApplicationListener(listeners[i]);
+ addApplicationListener(listeners[i], true);
}
- //System.out.println("Add TLD for URI: " + tagLibraryInfo.getUri() +
" " + tagLibraryInfo);
jspTagLibraries.put(tagLibraryInfo.getUri(), tagLibraryInfo);
}
@@ -2432,7 +2465,6 @@
* @param tagLibrayInfo the tag library info that will be added
*/
public void addJspTagLibrary(String uri, TagLibraryInfo tagLibraryInfo) {
- //System.out.println("Add TLD for implicit URI: " + uri + " "
+ tagLibraryInfo);
jspTagLibraries.put(uri, tagLibraryInfo);
}
@@ -3834,6 +3866,7 @@
ServletContextListener listener =
(ServletContextListener) instances[i];
try {
+ context.setRestricted(isRestricted(listener));
fireContainerEvent("beforeContextInitialized", listener);
listener.contextInitialized(event);
fireContainerEvent("afterContextInitialized", listener);
@@ -3843,6 +3876,8 @@
(sm.getString("standardContext.listenerStart",
instances[i].getClass().getName()), t);
ok = false;
+ } finally {
+ context.setRestricted(false);
}
}
return (ok);
@@ -4651,6 +4686,14 @@
/**
+ * Is the specified listener restricted ?
+ */
+ protected boolean isRestricted(Object listener) {
+ return restrictedApplicationListeners.contains(listener.getClass().getName());
+ }
+
+
+ /**
* Are we processing a version 2.2 deployment descriptor?
*/
protected boolean isServlet22() {