Merge fixes from jetty-8: 330188, 330208

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2504 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Jan Bartel 2010-11-15 06:47:58 +00:00
parent 62726cc4e2
commit 35c063fb95
5 changed files with 302 additions and 56 deletions

View File

@ -1,3 +1,7 @@
jetty-7.2.2-SNAPSHOT
+ 330188 Reject web-fragment.xml with same <name> as another already loaded one
+ 330208 Support new wording on servlet-mapping and filter-mapping merging from servlet3.0a
jetty-7.2.1.v20101111 11 November 2010
+ 324679 Fixed dedection of write before static content
+ 328199 Ensure blocking connectors always close socket

View File

@ -316,9 +316,11 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
//ServletSpec p.75. No declaration of resource-ref in web xml, but different in multiple web-fragments. Error.
if (!type.equals(otherType) || !auth.equals(otherAuth) || !shared.equals(otherShared))
throw new IllegalStateException("Conflicting resource-ref "+jndiName+" in "+descriptor.getResource());
//TODO get clarification from jsr315 if injection-targets should be merged
//same in multiple web-fragments, merge the injections
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
}
else
throw new IllegalStateException("resource-ref."+jndiName+" not found in declaring descriptor "+otherFragment);
}
}
@ -416,8 +418,11 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
if (!type.equals(otherType))
throw new IllegalStateException("Conflicting resource-env-ref "+jndiName+" in "+descriptor.getResource());
//TODO get clarification from jsr315 if injection-targets should be merged
//same in multiple web-fragments, merge the injections
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
}
else
throw new IllegalStateException("resource-env-ref."+jndiName+" not found in declaring descriptor "+otherFragment);
}
}
}
@ -506,8 +511,11 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
if (!type.equals(otherType) || !usage.equalsIgnoreCase(otherUsage))
throw new IllegalStateException("Conflicting message-destination-ref "+jndiName+" in "+descriptor.getResource());
//TODO get clarification from jsr315 if injection-targets should be merged
//same in multiple web-fragments, merge the injections
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
}
else
throw new IllegalStateException("message-destination-ref."+jndiName+" not found in declaring descriptor "+otherFragment);
}
}

View File

@ -52,9 +52,12 @@ public class MetaData
protected final List<Resource> _orderedWebInfJars = new ArrayList<Resource>();
protected final List<Resource> _orderedContainerJars = new ArrayList<Resource>();
protected Ordering _ordering;//can be set to RelativeOrdering by web-default.xml, web.xml, web-override.xml
protected boolean allowDuplicateFragmentNames = false;
public static class OriginInfo
{
protected String name;
@ -211,7 +214,15 @@ public class MetaData
descriptor.parse();
if (descriptor.getName() != null)
_webFragmentNameMap.put(descriptor.getName(), descriptor);
{
Descriptor existing = _webFragmentNameMap.get(descriptor.getName());
if (existing != null && !isAllowDuplicateFragmentNames())
{
throw new IllegalStateException("Duplicate fragment name: "+descriptor.getName()+" for "+existing.getResource()+" and "+descriptor.getResource());
}
else
_webFragmentNameMap.put(descriptor.getName(), descriptor);
}
//If web.xml has specified an absolute ordering, ignore any relative ordering in the fragment
if (_ordering != null && _ordering.isAbsolute())
@ -472,4 +483,13 @@ public class MetaData
{
_orderedContainerJars.add(jar);
}
public boolean isAllowDuplicateFragmentNames()
{
return allowDuplicateFragmentNames;
}
public void setAllowDuplicateFragmentNames(boolean allowDuplicateFragmentNames)
{
this.allowDuplicateFragmentNames = allowDuplicateFragmentNames;
}
}

View File

@ -35,6 +35,7 @@ import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.FilterMapping;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletMapping;
import org.eclipse.jetty.util.LazyList;
@ -47,7 +48,7 @@ import org.eclipse.jetty.xml.XmlParser;
/**
* StandardDescriptorProcessor
*
*
* Process a web.xml, web-defaults.xml, web-overrides.xml, web-fragment.xml.
*/
public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
{
@ -103,6 +104,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
{
}
/**
* @param context
* @param descriptor
* @param node
*/
public void visitContextParam (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
String name = node.getString("param-name", false, true);
@ -146,6 +152,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
/* ------------------------------------------------------------ */
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitDisplayName(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
//Servlet Spec 3.0 p. 74 Ignore from web-fragments
@ -156,6 +167,12 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitServlet(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
String id = node.getAttribute("id");
@ -447,31 +464,61 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitServletMapping(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
//Servlet Spec 3.0, p74
//servlet-mappings are always additive, whether from web xml descriptors (web.xml/web-default.xml/web-override.xml) or web-fragments.
String servlet_name = node.getString("servlet-name", false, true);
ServletMapping mapping = new ServletMapping();
mapping.setServletName(servlet_name);
//Maintenance update 3.0a to spec:
// Updated 8.2.3.g.v to say <servlet-mapping> elements are additive across web-fragments.
// <servlet-mapping> declared in web.xml overrides the mapping for the servlet specified in the web-fragment.xml
if (context.getMetaData().getOrigin(servlet_name+".servlet.mappings") == Origin.NotSet)
context.getMetaData().setOrigin(servlet_name+".servlet.mappings", descriptor);
String servlet_name = node.getString("servlet-name", false, true);
Origin origin = context.getMetaData().getOrigin(servlet_name+".servlet.mappings");
List<String> paths = new ArrayList<String>();
Iterator<XmlParser.Node> iter = node.iterator("url-pattern");
while (iter.hasNext())
switch (origin)
{
String p = iter.next().toString(false, true);
p = normalizePattern(p);
paths.add(p);
}
mapping.setPathSpecs((String[]) paths.toArray(new String[paths.size()]));
context.getServletHandler().addServletMapping(mapping);
case NotSet:
{
//no servlet mappings
context.getMetaData().setOrigin(servlet_name+".servlet.mappings", descriptor);
addServletMapping(servlet_name, node, context);
break;
}
case WebXml:
case WebDefaults:
case WebOverride:
{
//previously set by a web xml descriptor, if we're parsing another web xml descriptor allow override
//otherwise just ignore it
if (!(descriptor instanceof FragmentDescriptor))
{
addServletMapping(servlet_name, node, context);
}
break;
}
case WebFragment:
{
//mappings previously set by another web-fragment, so merge in this web-fragment's mappings
addServletMapping(servlet_name, node, context);
break;
}
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitSessionConfig(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
XmlParser.Node tNode = node.get("session-timeout");
@ -482,6 +529,13 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitMimeMapping(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
String extension = node.getString("extension", false, true);
@ -523,6 +577,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitWelcomeFileList(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
Origin o = context.getMetaData().getOrigin("welcome-file-list");
@ -566,6 +625,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitLocaleEncodingList(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
Iterator<XmlParser.Node> iter = node.iterator("locale-encoding-mapping");
@ -611,6 +675,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitErrorPage(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
String error = node.getString("error-code", false, true);
@ -664,6 +733,10 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
/**
* @param context
* @param node
*/
protected void addWelcomeFiles(WebAppContext context, XmlParser.Node node)
{
Iterator<XmlParser.Node> iter = node.iterator("welcome-file");
@ -677,6 +750,79 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param servletName
* @param node
* @param context
*/
protected void addServletMapping (String servletName, XmlParser.Node node, WebAppContext context)
{
ServletMapping mapping = new ServletMapping();
mapping.setServletName(servletName);
List<String> paths = new ArrayList<String>();
Iterator<XmlParser.Node> iter = node.iterator("url-pattern");
while (iter.hasNext())
{
String p = iter.next().toString(false, true);
p = normalizePattern(p);
paths.add(p);
}
mapping.setPathSpecs((String[]) paths.toArray(new String[paths.size()]));
context.getServletHandler().addServletMapping(mapping);
}
/**
* @param filterName
* @param node
* @param context
*/
protected void addFilterMapping (String filterName, XmlParser.Node node, WebAppContext context)
{
FilterMapping mapping = new FilterMapping();
mapping.setFilterName(filterName);
List<String> paths = new ArrayList<String>();
Iterator<XmlParser.Node> iter = node.iterator("url-pattern");
while (iter.hasNext())
{
String p = iter.next().toString(false, true);
p = normalizePattern(p);
paths.add(p);
}
mapping.setPathSpecs((String[]) paths.toArray(new String[paths.size()]));
List<String> names = new ArrayList<String>();
iter = node.iterator("servlet-name");
while (iter.hasNext())
{
String n = ((XmlParser.Node) iter.next()).toString(false, true);
names.add(n);
}
mapping.setServletNames((String[]) names.toArray(new String[names.size()]));
List<DispatcherType> dispatches = new ArrayList<DispatcherType>();
iter=node.iterator("dispatcher");
while(iter.hasNext())
{
String d=((XmlParser.Node)iter.next()).toString(false,true);
dispatches.add(FilterMapping.dispatch(d));
}
if (dispatches.size()>0)
mapping.setDispatcherTypes(EnumSet.copyOf(dispatches));
context.getServletHandler().addFilterMapping(mapping);
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitTagLib(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
//Additive across web.xml and web-fragment.xml
@ -686,6 +832,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
context.setResourceAlias(uri, location);
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitJspConfig(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
for (int i = 0; i < node.size(); i++)
@ -731,6 +882,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitSecurityConstraint(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
Constraint scBase = new Constraint();
@ -816,6 +972,12 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param context
* @param descriptor
* @param node
* @throws Exception
*/
protected void visitLoginConfig(WebAppContext context, Descriptor descriptor, XmlParser.Node node) throws Exception
{
//ServletSpec 3.0 p74 says elements present 0/1 time if specified in web.xml take
@ -976,6 +1138,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitSecurityRole(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
//ServletSpec 3.0, p74 elements with multiplicity >1 are additive when merged
@ -985,6 +1152,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitFilter(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
String name = node.getString("filter-name", false, true);
@ -1114,52 +1286,58 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitFilterMapping(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
//Servlet Spec 3.0, p74
//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);
FilterMapping mapping = new FilterMapping();
mapping.setFilterName(filter_name);
List<String> paths = new ArrayList<String>();
Iterator<XmlParser.Node> iter = node.iterator("url-pattern");
while (iter.hasNext())
{
String p = iter.next().toString(false, true);
p = normalizePattern(p);
paths.add(p);
}
mapping.setPathSpecs((String[]) paths.toArray(new String[paths.size()]));
List<String> names = new ArrayList<String>();
iter = node.iterator("servlet-name");
while (iter.hasNext())
{
String n = ((XmlParser.Node) iter.next()).toString(false, true);
names.add(n);
}
mapping.setServletNames((String[]) names.toArray(new String[names.size()]));
List<DispatcherType> dispatches = new ArrayList<DispatcherType>();
iter=node.iterator("dispatcher");
while(iter.hasNext())
{
String d=((XmlParser.Node)iter.next()).toString(false,true);
dispatches.add(FilterMapping.dispatch(d));
}
Origin origin = context.getMetaData().getOrigin(filter_name+".filter.mappings");
if (dispatches.size()>0)
mapping.setDispatcherTypes(EnumSet.copyOf(dispatches));
context.getServletHandler().addFilterMapping(mapping);
switch (origin)
{
case NotSet:
{
//no filtermappings for this filter yet defined
context.getMetaData().setOrigin(filter_name+".filter.mappings", descriptor);
addFilterMapping(filter_name, node, context);
break;
}
case WebDefaults:
case WebOverride:
case WebXml:
{
//filter mappings defined in a web xml file. If we're processing a fragment, we ignore filter mappings.
if (!(descriptor instanceof FragmentDescriptor))
{
addFilterMapping(filter_name, node, context);
}
break;
}
case WebFragment:
{
//filter mappings first defined in a web-fragment, allow other fragments to add
addFilterMapping(filter_name, node, context);
break;
}
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitListener(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
String className = node.getString("listener-class", false, true);
@ -1201,6 +1379,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param context
* @param descriptor
* @param node
*/
protected void visitDistributable(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
// the element has no content, so its simple presence
@ -1209,6 +1392,14 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
((WebDescriptor)descriptor).setDistributable(true);
}
/**
* @param context
* @param clazz
* @return
* @throws ServletException
* @throws InstantiationException
* @throws IllegalAccessException
*/
protected EventListener newListenerInstance(WebAppContext context,Class<? extends EventListener> clazz) throws ServletException, InstantiationException, IllegalAccessException
{
try
@ -1226,6 +1417,10 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
}
}
/**
* @param p
* @return
*/
protected String normalizePattern(String p)
{
if (p != null && p.length() > 0 && !p.startsWith("/") && !p.startsWith("*")) return "/" + p;

View File

@ -139,7 +139,9 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
private boolean _configurationDiscovered=true;
private boolean _configurationClassesSet=false;
private boolean _configurationsSet=false;
private boolean _allowDuplicateFragmentNames = false;
private MetaData _metadata;
public static WebAppContext getCurrentWebAppContext()
@ -245,7 +247,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
_configurations = new Configuration[]{new CloneConfiguration(template)};
// TODO we need some better way to work out what attributes should be copied at this stage.
setAllowDuplicateFragmentNames(template.isAllowDuplicateFragmentNames());
setAliases(template.isAliases());
setBaseResource(template.getBaseResource());
setClassLoader(template.getClassLoader());
@ -488,6 +490,8 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
{
try
{
if (_metadata != null)
_metadata.setAllowDuplicateFragmentNames(isAllowDuplicateFragmentNames());
preConfigure();
super.doStart();
postConfigure();
@ -1146,6 +1150,21 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
setConfigurationClasses(serverConfigs);
}
}
/* ------------------------------------------------------------ */
public boolean isAllowDuplicateFragmentNames()
{
return _allowDuplicateFragmentNames;
}
/* ------------------------------------------------------------ */
public void setAllowDuplicateFragmentNames(boolean allowDuplicateFragmentNames)
{
_allowDuplicateFragmentNames = allowDuplicateFragmentNames;
}
/* ------------------------------------------------------------ */
@Override