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"); }
public Resource getResource(String pathInContext) { // Take only last slice of the URL as a filename, so we can adjust path. // This also prevents mischief like '../../foo.css' String[] parts = pathInContext.split("/"); String filename = parts[parts.length - 1]; URL resource = getClass().getClassLoader().getResource( "org/apache/avro/ipc/stats/static/" + filename); if (resource == null) { return null; } return Resource.newResource(resource); } }
/** * @see org.eclipse.jetty.util.PatternMatcher#matched(java.net.URI) */ @Override public void matched(URI uri) throws Exception { _context.getMetaData().addContainerResource(Resource.newResource(uri)); } }
/** * @see org.eclipse.jetty.util.PatternMatcher#matched(java.net.URI) */ @Override public void matched(URI uri) throws Exception { _context.getMetaData().addWebInfJar(Resource.newResource(uri)); }
@Override public void matched (URI uri) throws Exception { LOG.debug("Search of {}",uri); if (uri.toString().toLowerCase(Locale.ENGLISH).endsWith(".jar")) { InputStream in = Resource.newResource(uri).getInputStream(); if (in==null) return; JarInputStream jar_in = new JarInputStream(in); try { JarEntry entry = jar_in.getNextJarEntry(); while (entry!=null) { processEntry(uri, entry); entry = jar_in.getNextJarEntry(); } } finally { jar_in.close(); } } } }
context.setBaseResource(Resource.newResource(STATIC_RESOURCE_DIRECTORY_PATH)); } catch (IOException e) { throw new RuntimeException("Can't locate static resource directory " + STATIC_RESOURCE_DIRECTORY_PATH);
protected LocationEntry(String name, boolean inclusive) { super(name, inclusive); if (!getName().startsWith("file:")) throw new IllegalArgumentException(name); try { _file = Resource.newResource(getName()).getFile(); } catch(IOException e) { throw new RuntimeIOException(e); } }
private void configureDocumentRoot(WebAppContext handler) { File root = getValidDocumentRoot(); File docBase = (root != null) ? root : createTempDir("jetty-docbase"); try { List<Resource> resources = new ArrayList<>(); Resource rootResource = (docBase.isDirectory() ? Resource.newResource(docBase.getCanonicalFile()) : JarResource.newJarResource(Resource.newResource(docBase))); resources.add((root != null) ? new LoaderHidingResource(rootResource) : rootResource); for (URL resourceJarUrl : this.getUrlsOfJarsWithMetaInfResources()) { Resource resource = createResource(resourceJarUrl); if (resource.exists() && resource.isDirectory()) { resources.add(resource); } } handler.setBaseResource( new ResourceCollection(resources.toArray(new Resource[0]))); } catch (Exception ex) { throw new IllegalStateException(ex); } }
@Before public void setUp() throws Exception { initMocks(this); when(systemEnvironment.getWebappContextPath()).thenReturn("/go"); when(webAppContext.getInitParameter("rails.root")).thenReturn("/rails.root"); when(webAppContext.getWebInf()).thenReturn(Resource.newResource("WEB-INF")); handler = new AssetsContextHandler(systemEnvironment); handler.init(webAppContext); }
ServerConfiguration.get(PropertyKey.WEB_RESOURCES) + "/master/build/"; File resourceDir = new File(resourceDirPathString); mServletContextHandler.setBaseResource(Resource.newResource(resourceDir.getAbsolutePath())); mServletContextHandler.setWelcomeFiles(new String[] {"index.html"}); mServletContextHandler.setResourceBase(resourceDir.getAbsolutePath());
ServerConfiguration.get(PropertyKey.WEB_RESOURCES) + "/worker/build/"; File resourceDir = new File(resourceDirPathString); mServletContextHandler.setBaseResource(Resource.newResource(resourceDir.getAbsolutePath())); mServletContextHandler.setWelcomeFiles(new String[] {"index.html"}); mServletContextHandler.setResourceBase(resourceDir.getAbsolutePath());
final Resource resource = Resource.newResource( url ); staticContext.setBaseResource( resource );
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); } } }
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 (jar.isDirectory()) webFrag = Resource.newResource( new File (jar.getFile(),"/META-INF/web-fragment.xml")); webFrag = Resource.newResource(uriJarPrefix(uri,"!/META-INF/web-fragment.xml"));
File warfile=Resource.newResource(war).getFile(); if (warfile!=null && warfile.getName().toLowerCase(Locale.ENGLISH).endsWith(".war")) web_app = Resource.newResource(extractedWebAppDir.getCanonicalPath()); web_inf=Resource.newResource(extractedWebInfDir.getCanonicalPath());
ctx.setBaseResource(newResource(webapp));
resourcesDir = Resource.newResource(uriJarPrefix(uri,"!/META-INF/resources"));
private void configureSslKeyStore(SslContextFactory factory, Ssl ssl) { try { URL url = ResourceUtils.getURL(ssl.getKeyStore()); factory.setKeyStoreResource(Resource.newResource(url)); } catch (IOException ex) { throw new WebServerException( "Could not find key store '" + ssl.getKeyStore() + "'", ex); } if (ssl.getKeyStoreType() != null) { factory.setKeyStoreType(ssl.getKeyStoreType()); } if (ssl.getKeyStoreProvider() != null) { factory.setKeyStoreProvider(ssl.getKeyStoreProvider()); } }
private void configureSslTrustStore(SslContextFactory factory, Ssl ssl) { if (ssl.getTrustStorePassword() != null) { factory.setTrustStorePassword(ssl.getTrustStorePassword()); } if (ssl.getTrustStore() != null) { try { URL url = ResourceUtils.getURL(ssl.getTrustStore()); factory.setTrustStoreResource(Resource.newResource(url)); } catch (IOException ex) { throw new WebServerException( "Could not find trust store '" + ssl.getTrustStore() + "'", ex); } } if (ssl.getTrustStoreType() != null) { factory.setTrustStoreType(ssl.getTrustStoreType()); } if (ssl.getTrustStoreProvider() != null) { factory.setTrustStoreProvider(ssl.getTrustStoreProvider()); } }