private Resource createResource(URL url) throws Exception { if ("file".equals(url.getProtocol())) { File file = new File(url.toURI()); if (file.isFile()) { return Resource.newResource("jar:" + url + "!/META-INF/resources"); } } return Resource.newResource(url + "META-INF/resources"); }
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); } } }
if (web_app.isAlias()) LOG.debug(web_app + " anti-aliased to " + web_app.getAlias()); web_app = context.newResource(web_app.getAlias()); if (LOG.isDebugEnabled()) LOG.debug("Try webapp=" + web_app + ", exists=" + web_app.exists() + ", directory=" + web_app.isDirectory()+" file="+(web_app.getFile())); if (web_app.exists() && !web_app.isDirectory() && !web_app.toString().startsWith("jar:")) if (jarWebApp.exists() && jarWebApp.isDirectory()) web_app= jarWebApp; if (web_app.exists() && ( (context.isCopyWebDir() && web_app.getFile() != null && web_app.getFile().isDirectory()) || (context.isExtractWAR() && web_app.getFile() != null && !web_app.getFile().isDirectory()) || (context.isExtractWAR() && web_app.getFile() == null) || !web_app.isDirectory()) File warfile=Resource.newResource(war).getFile(); if (warfile!=null && warfile.getName().toLowerCase(Locale.ENGLISH).endsWith(".war")) if (web_app.getFile()!=null && web_app.getFile().isDirectory()) web_app.copyTo(extractedWebAppDir); jar_web_app.copyTo(extractedWebAppDir); extractionLock.delete();
public void init(WebAppContext webAppContext) throws IOException { String railsRootDirName = webAppContext.getInitParameter("rails.root").replaceAll("/WEB-INF/", ""); String assetsDir = webAppContext.getWebInf().addPath(String.format("%s/public/assets/", railsRootDirName)).getName(); handler.setAssetsDir(assetsDir); }
/** * Get <code>WEB-INF/classes</code> dir * * @param context the context to look for the <code>WEB-INF/classes</code> directory * @return the Resource for the <code>WEB-INF/classes</code> directory * @throws Exception if unable to find the <code>WEB-INF/classes</code> directory */ protected Resource findWebInfClassesDir (WebAppContext context) throws Exception { if (context == null) return null; Resource web_inf = context.getWebInf(); // Find WEB-INF/classes if (web_inf != null && web_inf.isDirectory()) { // Look for classes directory Resource classes= web_inf.addPath("classes/"); if (classes.exists()) return classes; } return null; }
protected Resource findWebXml(WebAppContext context) throws IOException, MalformedURLException { String descriptor = context.getDescriptor(); if (descriptor != null) { Resource web = context.newResource(descriptor); if (web.exists() && !web.isDirectory()) return web; } Resource web_inf = context.getWebInf(); if (web_inf != null && web_inf.isDirectory()) { // do web.xml file Resource web = web_inf.addPath("web.xml"); if (web.exists()) return web; if (LOG.isDebugEnabled()) LOG.debug("No WEB-INF/web.xml in " + context.getWar() + ". Serving files and default/dynamic servlets only"); } return null; }
url = new URL(resource); LOG.warn("Bad Resource: "+resource); throw e; return newResource(url, useCaches);
public void parse () throws Exception { ensureParser(); try { //xerces on apple appears to sometimes close the zip file instead //of the inputstream, so try opening the input stream, but if //that doesn't work, fallback to opening a new url _root = _parser.parse(_xml.getInputStream()); } catch (Exception e) { _root = _parser.parse(_xml.getURL().toString()); } if (_root==null) { LOG.warn("No TLD root in {}",_xml); } } }
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; } }
protected void foundWebXml(ResourceScanListener.ScanResource scanResource, WebAppContext context) throws Exception { if (context.getMetaData().getWebXml() == null) { webXml = Resource.newResource(scanResource.getResolvedUrl()); if (log.isDebugEnabled()) { log.debug("webapp.scan: found web.xml {}", webXml.toString()); } context.getMetaData().setWebXml(webXml); } else { log.info("Found extra web.xml, ignoring {}", scanResource.getResolvedUrl().toString()); } }
public boolean check(String path, Resource resource) { if (resource.exists()) return false; String a=resource.getAlias().toString(); String r=resource.getURL().toString(); if (a.length()>r.length()) return a.startsWith(r) && a.length()==r.length()+1 && a.endsWith("/"); else return r.startsWith(a) && r.length()==a.length()+1 && r.endsWith("/"); } }
String base = URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH); resource=_resourceBase.addPath(pathInContext); else if (_contextHandler.getBaseResource() instanceof ResourceCollection) resource=_contextHandler.getBaseResource().addPath(pathInContext);
private void addStaticPath(ServletHolder holder, String basePath, String relativeMarkerPathToResource) throws URISyntaxException { String path = Resource.newClassPathResource(relativeMarkerPathToResource).getURL().toString(); final String fullBasePath = path.substring(0, path.length() - relativeMarkerPathToResource.length()) + basePath; holder.setInitParameter("dirAllowed", "false"); holder.setInitParameter("pathInfoOnly", "true"); holder.setInitParameter("resourceBase", fullBasePath); }
final WebAppContext staticContext = new WebAppContext(); staticContext.setServer( getJetty() ); staticContext.setContextPath( mountPoint ); staticContext.setSessionHandler( sessionHandler ); staticContext.setInitParameter( "org.eclipse.jetty.servlet.Default.dirAllowed", "false" ); if ( resourceLoc != null ) URL url = resourceLoc.toURI().toURL(); final Resource resource = Resource.newResource( url ); staticContext.setBaseResource( resource );
final String classpath = configuration.getClasspath(); WebAppContext ctx = new WebAppContext(); ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); ctx.setContextPath(path); ctx.setBaseResource(newResource(webapp)); ctx.setConfigurations(new Configuration[]{ ctx.getMetaData().addContainerResource(containerResources);
Server server = new Server(); WebAppContext servletContextHandler = new WebAppContext(); servletContextHandler.setContextPath("/"); servletContextHandler.setResourceBase("src/main/resources/" + webFolder); ClassList clist = ClassList.setServerDefault(server); clist.addBefore(JettyWebXmlConfiguration.class.getName(), AnnotationConfiguration.class.getName()); Resource staticResources = Resource.newClassPathResource(webFolder); staticResourceHandler.setBaseResource(staticResources); staticResourceHandler.setWelcomeFiles(new String[]{"html/index.html"});
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; }
if (resourcesDir == EmptyResource.INSTANCE) if (LOG.isDebugEnabled()) LOG.debug(target+" cached as containing no META-INF/resources"); return; if (LOG.isDebugEnabled()) LOG.debug(target+" META-INF/resources found in cache "); if (LOG.isDebugEnabled()) LOG.debug(target+" META-INF/resources checked"); if (target.isDirectory()) resourcesDir = target.addPath("/META-INF/resources"); URI uri = target.getURI(); resourcesDir = Resource.newResource(uriJarPrefix(uri,"!/META-INF/resources")); if (!resourcesDir.exists() || !resourcesDir.isDirectory()) resourcesDir.close(); resourcesDir = EmptyResource.INSTANCE; Set<Resource> dirs = (Set<Resource>)context.getAttribute(METAINF_RESOURCES); if (dirs == null) context.setAttribute(METAINF_RESOURCES, dirs); if (LOG.isDebugEnabled()) LOG.debug(resourcesDir+" added to context");
if (context.isStarted()) LOG.debug("Cannot configure webapp after it is started"); return; LOG.debug("Configuring web-jetty.xml"); Resource web_inf = context.getWebInf(); if(web_inf!=null&&web_inf.isDirectory()) Resource jetty=web_inf.addPath("jetty8-web.xml"); if(!jetty.exists()) jetty=web_inf.addPath(JETTY_WEB_XML); if(!jetty.exists()) jetty=web_inf.addPath("web-jetty.xml"); if(jetty.exists()) if(LOG.isDebugEnabled()) LOG.debug("Configure: "+jetty); Object xml_attr=context.getAttribute(XML_CONFIGURATION); context.removeAttribute(XML_CONFIGURATION); final XmlConfiguration jetty_config = xml_attr instanceof XmlConfiguration?(XmlConfiguration)xml_attr:new XmlConfiguration(jetty.getURI().toURL());