412934 Ignore any re-definition of an init-param within a descriptor

Also tidy of code.
This commit is contained in:
Jan Bartel 2013-08-20 09:43:44 +10:00
parent f08aa88fbd
commit ccf59bf75d
1 changed files with 38 additions and 78 deletions

View File

@ -26,7 +26,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.servlet.DispatcherType;
@ -42,11 +41,10 @@ import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.FilterMapping;
import org.eclipse.jetty.servlet.Holder;
import org.eclipse.jetty.servlet.JspPropertyGroupServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletContextHandler.JspConfig;
import org.eclipse.jetty.servlet.ServletContextHandler.JspPropertyGroup;
import org.eclipse.jetty.servlet.ServletContextHandler.TagLib;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletMapping;
import org.eclipse.jetty.util.ArrayUtil;
@ -127,8 +125,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
{
String name = node.getString("param-name", false, true);
String value = node.getString("param-value", false, true);
Origin o = context.getMetaData().getOrigin("context-param."+name);
switch (o)
switch (context.getMetaData().getOrigin("context-param."+name))
{
case NotSet:
{
@ -213,36 +210,36 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
XmlParser.Node paramNode = (XmlParser.Node) iParamsIter.next();
String pname = paramNode.getString("param-name", false, true);
String pvalue = paramNode.getString("param-value", false, true);
String originName = servlet_name+".servlet.init-param."+pname;
Origin origin = context.getMetaData().getOrigin(servlet_name+".servlet.init-param."+pname);
switch (origin)
Descriptor originDescriptor = context.getMetaData().getOriginDescriptor(originName);
switch (context.getMetaData().getOrigin(originName))
{
case NotSet:
{
//init-param not already set, so set it
holder.setInitParameter(pname, pvalue);
context.getMetaData().setOrigin(servlet_name+".servlet.init-param."+pname, descriptor);
context.getMetaData().setOrigin(originName, descriptor);
break;
}
case WebXml:
case WebDefaults:
case WebOverride:
{
//previously set by a web xml descriptor, if we're parsing another web xml descriptor allow override
//previously set by a web xml descriptor, if we're parsing another web xml descriptor allow override as long as it is from a different descriptor
//ie ignore setting more than once within the same descriptor
//otherwise just ignore it
if (!(descriptor instanceof FragmentDescriptor))
if (!(descriptor instanceof FragmentDescriptor) && (descriptor!=originDescriptor))
{
holder.setInitParameter(pname, pvalue);
context.getMetaData().setOrigin(servlet_name+".servlet.init-param."+pname, descriptor);
context.getMetaData().setOrigin(originName, descriptor);
}
break;
}
case WebFragment:
{
//previously set by a web-fragment, make sure that the value matches, otherwise its an error
if (!holder.getInitParameter(pname).equals(pvalue))
if ((descriptor != originDescriptor) && !holder.getInitParameter(pname).equals(pvalue))
throw new IllegalStateException("Mismatching init-param "+pname+"="+pvalue+" in "+descriptor.getResource());
break;
}
@ -283,9 +280,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (servlet_class != null)
{
((WebDescriptor)descriptor).addClassName(servlet_class);
Origin o = context.getMetaData().getOrigin(servlet_name+".servlet.servlet-class");
switch (o)
switch (context.getMetaData().getOrigin(servlet_name+".servlet.servlet-class"))
{
case NotSet:
{
@ -350,8 +345,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
Origin o = context.getMetaData().getOrigin(servlet_name+".servlet.load-on-startup");
switch (o)
switch (context.getMetaData().getOrigin(servlet_name+".servlet.load-on-startup"))
{
case NotSet:
{
@ -391,8 +385,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (roleName != null && roleName.length() > 0 && roleLink != null && roleLink.length() > 0)
{
if (LOG.isDebugEnabled()) LOG.debug("link role " + roleName + " to " + roleLink + " for " + this);
Origin o = context.getMetaData().getOrigin(servlet_name+".servlet.role-name."+roleName);
switch (o)
switch (context.getMetaData().getOrigin(servlet_name+".servlet.role-name."+roleName))
{
case NotSet:
{
@ -435,8 +428,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (roleName != null)
{
Origin o = context.getMetaData().getOrigin(servlet_name+".servlet.run-as");
switch (o)
switch (context.getMetaData().getOrigin(servlet_name+".servlet.run-as"))
{
case NotSet:
{
@ -472,8 +464,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (async!=null)
{
boolean val = async.length()==0||Boolean.valueOf(async);
Origin o =context.getMetaData().getOrigin(servlet_name+".servlet.async-supported");
switch (o)
switch (context.getMetaData().getOrigin(servlet_name+".servlet.async-supported"))
{
case NotSet:
{
@ -508,8 +499,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (enabled!=null)
{
boolean is_enabled = enabled.length()==0||Boolean.valueOf(enabled);
Origin o = context.getMetaData().getOrigin(servlet_name+".servlet.enabled");
switch (o)
switch (context.getMetaData().getOrigin(servlet_name+".servlet.enabled"))
{
case NotSet:
{
@ -557,8 +547,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
(maxRequest==null||"".equals(maxRequest)?-1L:Long.parseLong(maxRequest)),
(threshold==null||"".equals(threshold)?0:Integer.parseInt(threshold)));
Origin o = context.getMetaData().getOrigin(servlet_name+".servlet.multipart-config");
switch (o)
switch (context.getMetaData().getOrigin(servlet_name+".servlet.multipart-config"))
{
case NotSet:
{
@ -615,9 +604,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
// <servlet-mapping> declared in web.xml overrides the mapping for the servlet specified in the web-fragment.xml
String servlet_name = node.getString("servlet-name", false, true);
Origin origin = context.getMetaData().getOrigin(servlet_name+".servlet.mappings");
switch (origin)
switch (context.getMetaData().getOrigin(servlet_name+".servlet.mappings"))
{
case NotSet:
{
@ -686,8 +673,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String name = cookieConfig.getString("name", false, true);
if (name != null)
{
Origin o = context.getMetaData().getOrigin("cookie-config.name");
switch (o)
switch (context.getMetaData().getOrigin("cookie-config.name"))
{
case NotSet:
{
@ -722,8 +708,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String domain = cookieConfig.getString("domain", false, true);
if (domain != null)
{
Origin o = context.getMetaData().getOrigin("cookie-config.domain");
switch (o)
switch (context.getMetaData().getOrigin("cookie-config.domain"))
{
case NotSet:
{
@ -758,8 +743,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String path = cookieConfig.getString("path", false, true);
if (path != null)
{
Origin o = context.getMetaData().getOrigin("cookie-config.path");
switch (o)
switch (context.getMetaData().getOrigin("cookie-config.path"))
{
case NotSet:
{
@ -794,8 +778,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String comment = cookieConfig.getString("comment", false, true);
if (comment != null)
{
Origin o = context.getMetaData().getOrigin("cookie-config.comment");
switch (o)
switch (context.getMetaData().getOrigin("cookie-config.comment"))
{
case NotSet:
{
@ -831,8 +814,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (tNode != null)
{
boolean httpOnly = Boolean.parseBoolean(tNode.toString(false,true));
Origin o = context.getMetaData().getOrigin("cookie-config.http-only");
switch (o)
switch (context.getMetaData().getOrigin("cookie-config.http-only"))
{
case NotSet:
{
@ -868,8 +850,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (tNode != null)
{
boolean secure = Boolean.parseBoolean(tNode.toString(false,true));
Origin o = context.getMetaData().getOrigin("cookie-config.secure");
switch (o)
switch (context.getMetaData().getOrigin("cookie-config.secure"))
{
case NotSet:
{
@ -905,8 +886,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (tNode != null)
{
int maxAge = Integer.parseInt(tNode.toString(false,true));
Origin o = context.getMetaData().getOrigin("cookie-config.max-age");
switch (o)
switch (context.getMetaData().getOrigin("cookie-config.max-age"))
{
case NotSet:
{
@ -954,8 +934,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String mimeType = node.getString("mime-type", false, true);
if (extension != null)
{
Origin o = context.getMetaData().getOrigin("extension."+extension);
switch (o)
switch (context.getMetaData().getOrigin("extension."+extension))
{
case NotSet:
{
@ -994,8 +973,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
*/
protected void visitWelcomeFileList(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
Origin o = context.getMetaData().getOrigin("welcome-file-list");
switch (o)
switch (context.getMetaData().getOrigin("welcome-file-list"))
{
case NotSet:
{
@ -1051,8 +1029,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (encoding != null)
{
Origin o = context.getMetaData().getOrigin("locale-encoding."+locale);
switch (o)
switch (context.getMetaData().getOrigin("locale-encoding."+locale))
{
case NotSet:
{
@ -1105,11 +1082,8 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String location = node.getString("location", false, true);
ErrorPageErrorHandler handler = (ErrorPageErrorHandler)context.getErrorHandler();
Origin o = context.getMetaData().getOrigin("error."+error);
switch (o)
switch (context.getMetaData().getOrigin("error."+error))
{
case NotSet:
{
@ -1484,8 +1458,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (method != null)
{
//handle auth-method merge
Origin o = context.getMetaData().getOrigin("auth-method");
switch (o)
switch (context.getMetaData().getOrigin("auth-method"))
{
case NotSet:
{
@ -1518,8 +1491,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//handle realm-name merge
XmlParser.Node name = node.get("realm-name");
String nameStr = (name == null ? "default" : name.toString(false, true));
o = context.getMetaData().getOrigin("realm-name");
switch (o)
switch (context.getMetaData().getOrigin("realm-name"))
{
case NotSet:
{
@ -1564,8 +1536,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
errorPageName = errorPage.toString(false, true);
//handle form-login-page
o = context.getMetaData().getOrigin("form-login-page");
switch (o)
switch (context.getMetaData().getOrigin("form-login-page"))
{
case NotSet:
{
@ -1596,8 +1567,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
//handle form-error-page
o = context.getMetaData().getOrigin("form-error-page");
switch (o)
switch (context.getMetaData().getOrigin("form-error-page"))
{
case NotSet:
{
@ -1670,8 +1640,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
{
((WebDescriptor)descriptor).addClassName(filter_class);
Origin o = context.getMetaData().getOrigin(name+".filter.filter-class");
switch (o)
switch (context.getMetaData().getOrigin(name+".filter.filter-class"))
{
case NotSet:
{
@ -1700,7 +1669,6 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
break;
}
}
}
Iterator<XmlParser.Node> iter = node.iterator("init-param");
@ -1710,8 +1678,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String pname = paramNode.getString("param-name", false, true);
String pvalue = paramNode.getString("param-value", false, true);
Origin origin = context.getMetaData().getOrigin(name+".filter.init-param."+pname);
switch (origin)
switch (context.getMetaData().getOrigin(name+".filter.init-param."+pname))
{
case NotSet:
{
@ -1749,8 +1716,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (async!=null)
{
boolean val = async.length()==0||Boolean.valueOf(async);
Origin o = context.getMetaData().getOrigin(name+".filter.async-supported");
switch (o)
switch (context.getMetaData().getOrigin(name+".filter.async-supported"))
{
case NotSet:
{
@ -1780,7 +1746,6 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
}
}
/**
@ -1794,13 +1759,8 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//filter-mappings are always additive, whether from web xml descriptors (web.xml/web-default.xml/web-override.xml) or web-fragments.
//Maintenance update 3.0a to spec:
// Updated 8.2.3.g.v to say <servlet-mapping> elements are additive across web-fragments.
String filter_name = node.getString("filter-name", false, true);
Origin origin = context.getMetaData().getOrigin(filter_name+".filter.mappings");
switch (origin)
switch (context.getMetaData().getOrigin(filter_name+".filter.mappings"))
{
case NotSet:
{