Add more origin info to quickstart-web.xml elements (#5400)
* Issue #5360 Add more origin info to quickstart-web.xml elements Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
parent
210ae6ef5f
commit
5e60837822
|
@ -63,6 +63,7 @@ public class DeclareRolesAnnotationHandler extends AbstractIntrospectableAnnotat
|
|||
for (String r : roles)
|
||||
{
|
||||
((ConstraintSecurityHandler)_context.getSecurityHandler()).addRole(r);
|
||||
_context.getMetaData().setOrigin("security-role." + r, declareRoles, clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public class WebFilterAnnotation extends DiscoveredAnnotation
|
|||
|
||||
FilterMapping mapping = new FilterMapping();
|
||||
mapping.setFilterName(holder.getName());
|
||||
|
||||
metaData.setOrigin(name + ".filter.mapping." + Long.toHexString(mapping.hashCode()), filterAnnotation, clazz);
|
||||
if (urlPatterns.length > 0)
|
||||
{
|
||||
ArrayList<String> paths = new ArrayList<String>();
|
||||
|
@ -179,7 +179,7 @@ public class WebFilterAnnotation extends DiscoveredAnnotation
|
|||
{
|
||||
FilterMapping mapping = new FilterMapping();
|
||||
mapping.setFilterName(holder.getName());
|
||||
|
||||
metaData.setOrigin(holder.getName() + ".filter.mapping." + Long.toHexString(mapping.hashCode()), filterAnnotation, clazz);
|
||||
if (urlPatterns.length > 0)
|
||||
{
|
||||
ArrayList<String> paths = new ArrayList<String>();
|
||||
|
|
|
@ -154,6 +154,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation
|
|||
mapping = new ServletMapping(source);
|
||||
mapping.setServletName(holder.getName());
|
||||
mapping.setPathSpecs(LazyList.toStringArray(urlPatternList));
|
||||
_context.getMetaData().setOrigin(servletName + ".servlet.mapping." + Long.toHexString(mapping.hashCode()), annotation, clazz);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -190,6 +191,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation
|
|||
mapping = new ServletMapping(new Source(Source.Origin.ANNOTATION, clazz.getName()));
|
||||
mapping.setServletName(servletName);
|
||||
mapping.setPathSpecs(LazyList.toStringArray(urlPatternList));
|
||||
_context.getMetaData().setOrigin(servletName + ".servlet.mapping." + Long.toHexString(mapping.hashCode()), annotation, clazz);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,7 +230,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation
|
|||
LOG.debug("Removed path {} from mapping {} from defaults descriptor ", p, existingMapping);
|
||||
}
|
||||
}
|
||||
_context.getMetaData().setOrigin(servletName + ".servlet.mapping." + p, annotation, clazz);
|
||||
_context.getMetaData().setOrigin(servletName + ".servlet.mapping.url" + p, annotation, clazz);
|
||||
}
|
||||
allMappings.add(mapping);
|
||||
_context.getServletHandler().setServletMappings(allMappings.toArray(new ServletMapping[allMappings.size()]));
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.quickstart;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.webapp.Descriptor;
|
||||
import org.eclipse.jetty.webapp.IterativeDescriptorProcessor;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
@ -36,12 +37,11 @@ public class ExtraXmlDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
private static final Logger LOG = LoggerFactory.getLogger(ExtraXmlDescriptorProcessor.class);
|
||||
|
||||
private final StringBuilder _buffer = new StringBuilder();
|
||||
private final boolean _showOrigin;
|
||||
private String _originAttribute;
|
||||
private String _origin;
|
||||
|
||||
public ExtraXmlDescriptorProcessor()
|
||||
{
|
||||
_showOrigin = LOG.isDebugEnabled();
|
||||
try
|
||||
{
|
||||
registerVisitor("env-entry", getClass().getMethod("saveSnippet", __signature));
|
||||
|
@ -60,7 +60,7 @@ public class ExtraXmlDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
public void start(WebAppContext context, Descriptor descriptor)
|
||||
{
|
||||
LOG.debug("process {}", descriptor);
|
||||
_origin = (" <!-- " + descriptor + " -->\n");
|
||||
_origin = (StringUtil.isBlank(_originAttribute) ? null : " <!-- " + descriptor + " -->\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,11 +68,19 @@ public class ExtraXmlDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
}
|
||||
|
||||
public void setOriginAttribute(String name)
|
||||
{
|
||||
_originAttribute = name;
|
||||
}
|
||||
|
||||
public void saveSnippet(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
|
||||
throws Exception
|
||||
{
|
||||
//Note: we have to output the origin as a comment field instead of
|
||||
//as an attribute like the other other elements because
|
||||
//we are copying these elements _verbatim_ from the descriptor
|
||||
LOG.debug("save {}", node.getTag());
|
||||
if (_showOrigin)
|
||||
if (_origin != null)
|
||||
_buffer.append(_origin);
|
||||
_buffer.append(" ").append(node.toString()).append("\n");
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
|
|||
if (f != null && f.getSource() == Source.EMBEDDED)
|
||||
continue;
|
||||
|
||||
out.openTag("filter-mapping");
|
||||
out.openTag("filter-mapping", origin(md, mapping.getFilterName() + ".filter.mapping." + Long.toHexString(mapping.hashCode())));
|
||||
out.tag("filter-name", mapping.getFilterName());
|
||||
if (mapping.getPathSpecs() != null)
|
||||
for (String s : mapping.getPathSpecs())
|
||||
|
@ -289,7 +289,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
|
|||
if (sh != null && sh.getSource() == Source.EMBEDDED)
|
||||
continue;
|
||||
|
||||
out.openTag("servlet-mapping", origin(md, mapping.getServletName() + ".servlet.mappings"));
|
||||
out.openTag("servlet-mapping", origin(md, mapping.getServletName() + ".servlet.mapping." + Long.toHexString(mapping.hashCode())));
|
||||
out.tag("servlet-name", mapping.getServletName());
|
||||
if (mapping.getPathSpecs() != null)
|
||||
for (String s : mapping.getPathSpecs())
|
||||
|
@ -327,7 +327,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
|
|||
ConstraintAware ca = (ConstraintAware)security;
|
||||
for (String r : ca.getRoles())
|
||||
{
|
||||
out.openTag("security-role")
|
||||
out.openTag("security-role", origin(md, "security-role." + r))
|
||||
.tag("role-name", r)
|
||||
.closeTag();
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
|
|||
out.openTag("welcome-file-list");
|
||||
for (String welcomeFile : context.getWelcomeFiles())
|
||||
{
|
||||
out.tag("welcome-file", welcomeFile);
|
||||
out.tag("welcome-file", origin(md, "welcome-file." + welcomeFile), welcomeFile);
|
||||
}
|
||||
out.closeTag();
|
||||
}
|
||||
|
@ -429,6 +429,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
|
|||
if (cookieConfig != null)
|
||||
{
|
||||
out.openTag("cookie-config");
|
||||
|
||||
if (cookieConfig.getName() != null)
|
||||
out.tag("name", origin(md, "cookie-config.name"), cookieConfig.getName());
|
||||
|
||||
|
@ -789,6 +790,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
|
|||
public void preConfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
ExtraXmlDescriptorProcessor extraXmlProcessor = new ExtraXmlDescriptorProcessor();
|
||||
extraXmlProcessor.setOriginAttribute(getOriginAttribute());
|
||||
context.getMetaData().addDescriptorProcessor(extraXmlProcessor);
|
||||
context.setAttribute(ExtraXmlDescriptorProcessor.class.getName(), extraXmlProcessor);
|
||||
super.preConfigure(context);
|
||||
|
|
|
@ -663,6 +663,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
if (TimeUnit.MINUTES.toSeconds(mins) > Integer.MAX_VALUE)
|
||||
throw new IllegalStateException("Max session-timeout in minutes is " + TimeUnit.SECONDS.toMinutes(Integer.MAX_VALUE));
|
||||
context.getServletContext().setSessionTimeout((int)mins);
|
||||
context.getMetaData().setOrigin("session.timeout", descriptor);
|
||||
}
|
||||
|
||||
//Servlet Spec 3.0
|
||||
|
@ -672,7 +673,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
if (iter.hasNext())
|
||||
{
|
||||
Set<SessionTrackingMode> modes = null;
|
||||
Origin o = context.getMetaData().getOrigin("session.tracking-mode");
|
||||
Origin o = context.getMetaData().getOrigin("session.tracking-modes");
|
||||
switch (o)
|
||||
{
|
||||
case NotSet://not previously set, starting fresh
|
||||
|
@ -680,7 +681,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
|
||||
modes = new HashSet<SessionTrackingMode>();
|
||||
context.getMetaData().setOrigin("session.tracking-mode", descriptor);
|
||||
context.getMetaData().setOrigin("session.tracking-modes", descriptor);
|
||||
break;
|
||||
}
|
||||
case WebXml:
|
||||
|
@ -692,7 +693,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
modes = new HashSet<SessionTrackingMode>();
|
||||
else
|
||||
modes = new HashSet<SessionTrackingMode>(context.getSessionHandler().getEffectiveSessionTrackingModes());
|
||||
context.getMetaData().setOrigin("session.tracking-mode", descriptor);
|
||||
context.getMetaData().setOrigin("session.tracking-modes", descriptor);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -703,7 +704,9 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
XmlParser.Node mNode = (XmlParser.Node)iter.next();
|
||||
String trackMode = mNode.toString(false, true);
|
||||
modes.add(SessionTrackingMode.valueOf(trackMode));
|
||||
SessionTrackingMode mode = SessionTrackingMode.valueOf(trackMode);
|
||||
modes.add(mode);
|
||||
context.getMetaData().setOrigin("session.tracking-mode." + mode, descriptor);
|
||||
}
|
||||
context.getSessionHandler().setSessionTrackingModes(modes);
|
||||
}
|
||||
|
@ -1035,13 +1038,13 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
case NotSet:
|
||||
{
|
||||
context.getMetaData().setOrigin("welcome-file-list", descriptor);
|
||||
addWelcomeFiles(context, node);
|
||||
addWelcomeFiles(context, node, descriptor);
|
||||
break;
|
||||
}
|
||||
case WebXml:
|
||||
{
|
||||
//web.xml set the welcome-file-list, all other descriptors then just merge in
|
||||
addWelcomeFiles(context, node);
|
||||
addWelcomeFiles(context, node, descriptor);
|
||||
break;
|
||||
}
|
||||
case WebDefaults:
|
||||
|
@ -1052,19 +1055,19 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
context.setWelcomeFiles(new String[0]);
|
||||
}
|
||||
addWelcomeFiles(context, node);
|
||||
addWelcomeFiles(context, node, descriptor);
|
||||
break;
|
||||
}
|
||||
case WebOverride:
|
||||
{
|
||||
//web-override set the list, all other descriptors just merge in
|
||||
addWelcomeFiles(context, node);
|
||||
addWelcomeFiles(context, node, descriptor);
|
||||
break;
|
||||
}
|
||||
case WebFragment:
|
||||
{
|
||||
//A web-fragment first set the welcome-file-list. Other descriptors just add.
|
||||
addWelcomeFiles(context, node);
|
||||
addWelcomeFiles(context, node, descriptor);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1182,14 +1185,14 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
}
|
||||
}
|
||||
|
||||
public void addWelcomeFiles(WebAppContext context, XmlParser.Node node)
|
||||
public void addWelcomeFiles(WebAppContext context, XmlParser.Node node, Descriptor descriptor)
|
||||
{
|
||||
Iterator<XmlParser.Node> iter = node.iterator("welcome-file");
|
||||
while (iter.hasNext())
|
||||
{
|
||||
XmlParser.Node indexNode = (XmlParser.Node)iter.next();
|
||||
String welcome = indexNode.toString(false, true);
|
||||
|
||||
context.getMetaData().setOrigin("welcome-file." + welcome, descriptor);
|
||||
//Servlet Spec 3.0 p. 74 welcome files are additive
|
||||
if (welcome != null && welcome.trim().length() > 0)
|
||||
context.setWelcomeFiles((String[])ArrayUtil.addToArray(context.getWelcomeFiles(), welcome, String.class));
|
||||
|
@ -1201,7 +1204,8 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
|
||||
mapping.setServletName(servletName);
|
||||
mapping.setFromDefaultDescriptor(descriptor instanceof DefaultsDescriptor);
|
||||
|
||||
context.getMetaData().setOrigin(servletName + ".servlet.mapping." + Long.toHexString(mapping.hashCode()), descriptor);
|
||||
|
||||
List<String> paths = new ArrayList<String>();
|
||||
Iterator<XmlParser.Node> iter = node.iterator("url-pattern");
|
||||
while (iter.hasNext())
|
||||
|
@ -1255,7 +1259,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
}
|
||||
|
||||
paths.add(p);
|
||||
context.getMetaData().setOrigin(servletName + ".servlet.mapping." + p, descriptor);
|
||||
context.getMetaData().setOrigin(servletName + ".servlet.mapping.url" + p, descriptor);
|
||||
}
|
||||
|
||||
mapping.setPathSpecs((String[])paths.toArray(new String[paths.size()]));
|
||||
|
@ -1269,7 +1273,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
{
|
||||
FilterMapping mapping = new FilterMapping();
|
||||
mapping.setFilterName(filterName);
|
||||
|
||||
context.getMetaData().setOrigin(filterName + ".filter.mapping." + Long.toHexString(mapping.hashCode()), descriptor);
|
||||
List<String> paths = new ArrayList<String>();
|
||||
Iterator<XmlParser.Node> iter = node.iterator("url-pattern");
|
||||
while (iter.hasNext())
|
||||
|
@ -1277,7 +1281,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
String p = iter.next().toString(false, true);
|
||||
p = ServletPathSpec.normalize(p);
|
||||
paths.add(p);
|
||||
context.getMetaData().setOrigin(filterName + ".filter.mapping." + p, descriptor);
|
||||
context.getMetaData().setOrigin(filterName + ".filter.mapping.url" + p, descriptor);
|
||||
}
|
||||
mapping.setPathSpecs((String[])paths.toArray(new String[paths.size()]));
|
||||
|
||||
|
@ -1286,6 +1290,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
while (iter.hasNext())
|
||||
{
|
||||
String n = ((XmlParser.Node)iter.next()).toString(false, true);
|
||||
context.getMetaData().setOrigin(filterName + ".filter.mapping.servlet" + n, descriptor);
|
||||
names.add(n);
|
||||
}
|
||||
mapping.setServletNames((String[])names.toArray(new String[names.size()]));
|
||||
|
@ -1741,6 +1746,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
XmlParser.Node roleNode = node.get("role-name");
|
||||
String role = roleNode.toString(false, true);
|
||||
((ConstraintAware)context.getSecurityHandler()).addRole(role);
|
||||
context.getMetaData().setOrigin("security-role." + role, descriptor);
|
||||
}
|
||||
|
||||
public void visitFilter(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
|
||||
|
|
Loading…
Reference in New Issue