/** * 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 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)); } }
@Override public URL getResource(String path) throws MalformedURLException { Resource resource=WebAppContext.this.getResource(path); if (resource==null || !resource.exists()) return null; // Should we go to the original war? if (resource.isDirectory() && resource instanceof ResourceCollection && !WebAppContext.this.isExtractWAR()) { Resource[] resources = ((ResourceCollection)resource).getResources(); for (int i=resources.length;i-->0;) { if (resources[i].getName().startsWith("jar:file")) return resources[i].getURI().toURL(); } } return resource.getURI().toURL(); }
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)); } }
for (Resource r: jars) uris.add(r.getURI());
URI uri = jar.getURI(); tlds.addAll(getTlds(uri));
static WebAppContext newWebAppContext() throws MalformedURLException { final WebAppContext handler = new WebAppContext(); handler.setContextPath("/"); handler.setBaseResource(Resource.newResource(webAppRoot())); handler.setClassLoader(new URLClassLoader( new URL[] { Resource.newResource(new File(webAppRoot(), "WEB-INF" + File.separatorChar + "lib" + File.separatorChar + "hello.jar")).getURI().toURL() }, JettyService.class.getClassLoader())); handler.addBean(new ServletContainerInitializersStarter(handler), true); handler.setAttribute( "org.eclipse.jetty.containerInitializers", Collections.singletonList(new ContainerInitializer(new JettyJasperInitializer(), null))); return handler; }
URI uri = target.getURI(); resourcesDir = Resource.newResource(uriJarPrefix(uri,"!/META-INF/resources"));
URI uri = jar.getURI(); webFrag = Resource.newResource(uriJarPrefix(uri,"!/META-INF/web-fragment.xml"));
final XmlConfiguration jetty_config = xml_attr instanceof XmlConfiguration?(XmlConfiguration)xml_attr:new XmlConfiguration(jetty.getURI().toURL());
/** * Check if this jar:file: resource is contained in the * named resource. Eg <code>jar:file:///a/b/c/foo.jar!/x.html</code> isContainedIn <code>file:///a/b/c/foo.jar</code> * @param resource the resource to test for * @return true if resource is contained in the named resource * @throws MalformedURLException if unable to process is contained due to invalid URL format */ @Override public boolean isContainedIn (Resource resource) throws MalformedURLException { String string = _urlString; int index = string.lastIndexOf("!/"); if (index > 0) string = string.substring(0,index); if (string.startsWith("jar:")) string = string.substring(4); URL url = new URL(string); return url.sameFile(resource.getURI().toURL()); } }
@Override public boolean check(String path, Resource resource) { if (resource.exists()) return false; String a=resource.getAlias().toString(); String r=resource.getURI().toString(); if (a.length()>r.length()) return a.startsWith(r) && a.length()==r.length()+1 && a.endsWith("/"); if (a.length()<r.length()) return r.startsWith(a) && r.length()==a.length()+1 && r.endsWith("/"); return a.equals(r); } }
@Override public boolean check(String path, Resource resource) { if (resource.exists()) return false; String a = resource.getAlias().toString(); String r = resource.getURI().toString(); if (a.length() > r.length()) return a.startsWith(r) && a.length() == r.length() + 1 && a.endsWith("/"); if (a.length() < r.length()) return r.startsWith(a) && r.length() == a.length() + 1 && r.endsWith("/"); return a.equals(r); } }
/** * 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()); } }
private Resource extractJarResource (Resource r) { if (r == null) return null; try { String url = r.getURI().toURL().toString(); int idx = url.lastIndexOf("!/"); if (idx >= 0) url = url.substring(0, idx); if (url.startsWith("jar:")) url = url.substring(4); return Resource.newResource(url); } catch (IOException e) { LOG.warn(e); return null; } }
private Resource extractJarResource (Resource r) { if (r == null) return null; try { String url = r.getURI().toURL().toString(); int idx = url.lastIndexOf("!/"); if (idx >= 0) url = url.substring(0, idx); if (url.startsWith("jar:")) url = url.substring(4); return Resource.newResource(url); } catch (IOException e) { LOG.warn(e); return null; } }
@Override public URL getResource(String path) throws MalformedURLException { Resource resource = ContextHandler.this.getResource(path); if (resource != null && resource.exists()) return resource.getURI().toURL(); return null; }
@Override public URL getResource(String path) throws MalformedURLException { Resource resource = ContextHandler.this.getResource(path); if (resource != null && resource.exists()) return resource.getURI().toURL(); return null; }
@Override public URL getResource(String path) throws MalformedURLException { Resource resource=WebAppContext.this.getResource(path); if (resource==null || !resource.exists()) return null; // Should we go to the original war? if (resource.isDirectory() && resource instanceof ResourceCollection && !WebAppContext.this.isExtractWAR()) { Resource[] resources = ((ResourceCollection)resource).getResources(); for (int i=resources.length;i-->0;) { if (resources[i].getName().startsWith("jar:file")) return resources[i].getURI().toURL(); } } return resource.getURI().toURL(); }