protected void visit (WebAppContext context, Descriptor descriptor, XmlParser.Node node) throws Exception { String name = node.getTag(); Method m = _visitors.get(name); if (m != null) m.invoke(this, new Object[]{context, descriptor, node}); } }
@Override protected InputSource resolveEntity(String pid, String sid) { if (!mapped) { mapResources(); mapped=true; } InputSource is = super.resolveEntity(pid,sid); return is; }
private void performCustomConfiguration() throws Exception { File jettyConfig = systemEnvironment.getJettyConfigFile(); if (jettyConfig.exists()) { replaceJettyXmlIfItBelongsToADifferentVersion(jettyConfig); LOG.info("Configuring Jetty using {}", jettyConfig.getAbsolutePath()); FileInputStream serverConfiguration = new FileInputStream(jettyConfig); XmlConfiguration configuration = new XmlConfiguration(serverConfiguration); configuration.configure(server); } else { String message = String.format( "No custom jetty configuration (%s) found, using defaults.", jettyConfig.getAbsolutePath()); LOG.info(message); } }
public void processOrdering () { //Process the web.xml's optional <absolute-ordering> element XmlParser.Node ordering = _root.get("absolute-ordering"); if (ordering == null) return; _isOrdered = true; //If an absolute-ordering was already set, then ignore it in favor of this new one // _processor.setOrdering(new AbsoluteOrdering()); Iterator<Object> iter = ordering.iterator(); XmlParser.Node node = null; while (iter.hasNext()) { Object o = iter.next(); if (!(o instanceof XmlParser.Node)) continue; node = (XmlParser.Node) o; if (node.getTag().equalsIgnoreCase("others")) //((AbsoluteOrdering)_processor.getOrdering()).addOthers(); _ordering.add("others"); else if (node.getTag().equalsIgnoreCase("name")) //((AbsoluteOrdering)_processor.getOrdering()).add(node.toString(false,true)); _ordering.add(node.toString(false,true)); } }
/** * Configures some well-known properties before the XmlConfiguration reads * the configuration. * @param jetty_config The configuration object. * @param web_inf the WEB-INF location */ private void setupXmlConfiguration(WebAppContext context, XmlConfiguration jetty_config, Resource web_inf) throws IOException { jetty_config.setJettyStandardIdsAndProperties(context.getServer(),null); Map<String,String> props = jetty_config.getProperties(); props.put(PROPERTY_THIS_WEB_INF_URL, web_inf.getURI().toString()); props.put(PROPERTY_WEB_INF_URI, XmlConfiguration.normalizeURI(web_inf.getURI().toString())); props.put(PROPERTY_WEB_INF, web_inf.toString()); } }
public void addWelcomeFiles(WebAppContext context, XmlParser.Node node) { Iterator<XmlParser.Node> iter = node.iterator("welcome-file"); while (iter.hasNext()) { XmlParser.Node indexNode = (XmlParser.Node) iter.next(); String welcome = indexNode.toString(false, true); //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)); } }
public void visitTagLib(WebAppContext context, Descriptor descriptor, XmlParser.Node node) { //Additive across web.xml and web-fragment.xml String uri = node.getString("taglib-uri", false, true); String location = node.getString("taglib-location", false, true); context.setResourceAlias(uri, location); JspConfig config = (JspConfig)context.getServletContext().getJspConfigDescriptor(); if (config == null) { config = new JspConfig(); context.getServletContext().setJspConfigDescriptor(config); } TagLib tl = new TagLib(); tl.setTaglibLocation(location); tl.setTaglibURI(uri); config.addTaglibDescriptor(tl); }
public void visitDisplayName(WebAppContext context, Descriptor descriptor, XmlParser.Node node) { //Servlet Spec 3.0 p. 74 Ignore from web-fragments if (!(descriptor instanceof FragmentDescriptor)) { context.setDisplayName(node.toString(false, true)); context.getMetaData().setOrigin("display-name", descriptor); } }
public void processVersion () String version = _root.getAttribute("version", "DTD"); if ("DTD".equals(version)) String s = (String)_root.getAttribute("metadata-complete"); if (s == null) _metaDataComplete = MetaDataComplete.NotSet;
@Override public void processOrdering () { //Process a fragment jar's web-fragment.xml<ordering> elements XmlParser.Node root = getRoot(); XmlParser.Node ordering = root.get("ordering"); if (ordering == null) return; //No ordering for this fragment _isOrdered = true; processBefores(ordering); processAfters(ordering); }
/** * {@inheritDoc} */ @Override public void process(WebAppContext context, Descriptor descriptor) throws Exception { if (descriptor == null) return; start(context,descriptor); XmlParser.Node root = descriptor.getRoot(); Iterator<?> iter = root.iterator(); XmlParser.Node node = null; while (iter.hasNext()) { Object o = iter.next(); if (!(o instanceof XmlParser.Node)) continue; node = (XmlParser.Node) o; visit(context, descriptor, node); } end(context,descriptor); }
private Server buildServerOrApplyConfiguration(String jettyConfiguration, Server server) throws Exception { // try local file first Resource jettyConfigurationFile = Resource.newResource(jettyConfiguration); if (jettyConfigurationFile == null || !jettyConfigurationFile.exists()) { // fallback to classpath jettyConfigurationFile = Resource.newClassPathResource(jettyConfiguration); if (jettyConfigurationFile == null || !jettyConfigurationFile.exists()) { throw new FileNotFoundException("Unable to find jetty configuration file either locally or on classpath '" + jettyConfiguration + "'"); } } logger.info("Applying jetty configuration '{}'", jettyConfigurationFile); try (InputStream is = jettyConfigurationFile.getInputStream()) { XmlConfiguration configuration = new XmlConfiguration(is); // create or apply to existing if (server == null) { return (Server)configuration.configure(); } else { return (Server)configuration.configure(server); } } }
public void processBefores (XmlParser.Node ordering) { //Process the <before> elements, looking for an <others/> clause and all of the <name> clauses XmlParser.Node before = ordering.get("before"); if (before == null) return; Iterator<?> iter = before.iterator(); XmlParser.Node node = null; while (iter.hasNext()) { Object o = iter.next(); if (!(o instanceof XmlParser.Node)) continue; node = (XmlParser.Node) o; if (node.getTag().equalsIgnoreCase("others")) { if (_otherType != OtherType.None) throw new IllegalStateException("Duplicate <other> clause detected in "+_xml.getURI()); _otherType = OtherType.Before; } else if (node.getTag().equalsIgnoreCase("name")) _befores.add(node.toString(false,true)); } }
public void visitSecurityRole(WebAppContext context, Descriptor descriptor, XmlParser.Node node) { if (context.getSecurityHandler() == null) { LOG.warn("security-role declared but SecurityHandler==null"); return; } //ServletSpec 3.0, p74 elements with multiplicity >1 are additive when merged XmlParser.Node roleNode = node.get("role-name"); String role = roleNode.toString(false, true); ((ConstraintAware)context.getSecurityHandler()).addRole(role); }
String filter_name = node.getString("filter-name", false, true); switch (context.getMetaData().getOrigin(filter_name+".filter.mappings"))
final XmlConfiguration jetty_config = xml_attr instanceof XmlConfiguration?(XmlConfiguration)xml_attr:new XmlConfiguration(jetty.getURI().toURL()); WebAppClassLoader.runWithServerClassAccess(()->{jetty_config.configure(context);return null;});
public void processAfters (XmlParser.Node ordering) { //Process the <after> elements, look for an <others/> clause and all of the <name/> clauses XmlParser.Node after = ordering.get("after"); if (after == null) return; Iterator<?> iter = after.iterator(); XmlParser.Node node = null; while (iter.hasNext()) { Object o = iter.next(); if (!(o instanceof XmlParser.Node)) continue; node = (XmlParser.Node) o; if (node.getTag().equalsIgnoreCase("others")) { if (_otherType != OtherType.None) throw new IllegalStateException("Duplicate <other> clause detected in "+_xml.getURI()); _otherType = OtherType.After; } else if (node.getTag().equalsIgnoreCase("name")) _afters.add(node.toString(false,true)); } }
String servlet_name = node.getString("servlet-name", false, true); switch (context.getMetaData().getOrigin(servlet_name+".servlet.mappings"))