Author: remy.maucherat(a)jboss.com
Date: 2015-04-23 09:24:45 -0400 (Thu, 23 Apr 2015)
New Revision: 2608
Modified:
branches/7.5.x/src/main/java/org/apache/catalina/Wrapper.java
branches/7.5.x/src/main/java/org/apache/catalina/core/ApplicationContext.java
branches/7.5.x/src/main/java/org/apache/catalina/core/StandardWrapper.java
branches/7.5.x/src/main/java/org/apache/catalina/core/StandardWrapperFacade.java
Log:
BZ1196513: Add patch to allow overriding servlets. Submitted by James Livingston.
Modified: branches/7.5.x/src/main/java/org/apache/catalina/Wrapper.java
===================================================================
--- branches/7.5.x/src/main/java/org/apache/catalina/Wrapper.java 2015-04-17 00:34:57 UTC
(rev 2607)
+++ branches/7.5.x/src/main/java/org/apache/catalina/Wrapper.java 2015-04-23 13:24:45 UTC
(rev 2608)
@@ -440,4 +440,14 @@
*/
public ServletSecurityElement getServletSecurity();
+ /**
+ * Is the Servlet overridable by a ServletContainerInitializer?
+ */
+ public boolean isOverridable();
+
+ /**
+ * Sets the overridable attribute for this Servlet.
+ */
+ public void setOverridable(boolean overridable);
+
}
Modified: branches/7.5.x/src/main/java/org/apache/catalina/core/ApplicationContext.java
===================================================================
---
branches/7.5.x/src/main/java/org/apache/catalina/core/ApplicationContext.java 2015-04-17
00:34:57 UTC (rev 2607)
+++
branches/7.5.x/src/main/java/org/apache/catalina/core/ApplicationContext.java 2015-04-23
13:24:45 UTC (rev 2608)
@@ -900,8 +900,13 @@
if (!context.isStarting()) {
throw MESSAGES.contextAlreadyInitialized(getContextPath());
}
- if (context.findChild(servletName) != null) {
- return null;
+ Wrapper existingWrapper = (Wrapper)context.findChild(servletName);
+ if (existingWrapper != null) {
+ if (existingWrapper.isOverridable()) {
+ existingWrapper.setOverridable(false);
+ } else {
+ return null;
+ }
}
Wrapper wrapper = context.createWrapper();
wrapper.setDynamic(true);
@@ -926,8 +931,13 @@
if (!context.isStarting()) {
throw MESSAGES.contextAlreadyInitialized(getContextPath());
}
- if (context.findChild(servletName) != null) {
- return null;
+ Wrapper existingWrapper = (Wrapper)context.findChild(servletName);
+ if (existingWrapper != null) {
+ if (existingWrapper.isOverridable()) {
+ existingWrapper.setOverridable(false);
+ } else {
+ return null;
+ }
}
// Servlet instance unicity
for (Container container : context.getParent().findChildren()) {
@@ -969,7 +979,7 @@
if (restricted) {
throw MESSAGES.restrictedListenerCannotCallMethod();
}
- Wrapper wrapper = (Wrapper) context.findChild(servletName);
+ Wrapper wrapper = (Wrapper)context.findChild(servletName);
if (wrapper != null) {
return wrapper.getFacade();
} else {
Modified: branches/7.5.x/src/main/java/org/apache/catalina/core/StandardWrapper.java
===================================================================
--- branches/7.5.x/src/main/java/org/apache/catalina/core/StandardWrapper.java 2015-04-17
00:34:57 UTC (rev 2607)
+++ branches/7.5.x/src/main/java/org/apache/catalina/core/StandardWrapper.java 2015-04-23
13:24:45 UTC (rev 2608)
@@ -113,7 +113,9 @@
*/
protected boolean dynamic = false;
+ private boolean overridable = false;
+
/**
* Enabled flag.
*/
@@ -311,7 +313,17 @@
// ------------------------------------------------------------- Properties
+
+ @Override
+ public boolean isOverridable() {
+ return overridable;
+ }
+ @Override
+ public void setOverridable(boolean overridable) {
+ this.overridable = overridable;
+ }
+
/**
* Return the async supported value.
*/
Modified:
branches/7.5.x/src/main/java/org/apache/catalina/core/StandardWrapperFacade.java
===================================================================
---
branches/7.5.x/src/main/java/org/apache/catalina/core/StandardWrapperFacade.java 2015-04-17
00:34:57 UTC (rev 2607)
+++
branches/7.5.x/src/main/java/org/apache/catalina/core/StandardWrapperFacade.java 2015-04-23
13:24:45 UTC (rev 2608)
@@ -38,6 +38,7 @@
import org.apache.catalina.Context;
import org.apache.catalina.deploy.Multipart;
+import org.apache.catalina.Wrapper;
/**
@@ -127,9 +128,18 @@
throw MESSAGES.invalidServletRegistrationArguments();
}
for (String urlPattern : urlPatterns) {
- if (((Context) wrapper.getParent()).findServletMapping(urlPattern) != null)
{
- conflicts.add(urlPattern);
- }
+ Context context = ((Context) wrapper.getParent());
+ String wrapperName = context.findServletMapping(urlPattern);
+ if (wrapperName != null) {
+ Wrapper servletWrapper = (Wrapper) context.findChild(wrapperName);
+ if (servletWrapper.isOverridable()) {
+ // Some Wrappers (from global and host web.xml) may be
+ // overridden rather than generating a conflict
+ context.removeServletMapping(urlPattern);
+ } else {
+ conflicts.add(urlPattern);
+ }
+ }
}
if (conflicts.isEmpty()) {
for (String urlPattern : urlPatterns) {
Show replies by date