/** * @see org.eclipse.jetty.webapp.AbstractConfiguration#cloneConfigure(org.eclipse.jetty.webapp.WebAppContext, org.eclipse.jetty.webapp.WebAppContext) */ @Override public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception { File tmpDir=File.createTempFile(WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context),"",template.getTempDirectory().getParentFile()); if (tmpDir.exists()) { IO.delete(tmpDir); } tmpDir.mkdir(); tmpDir.deleteOnExit(); context.setTempDirectory(tmpDir); }
public void makeTempDirectory (File parent, WebAppContext context) throws Exception { if (parent == null || !parent.exists() || !parent.canWrite() || !parent.isDirectory()) throw new IllegalStateException("Parent for temp dir not configured correctly: "+(parent==null?"null":"writeable="+parent.canWrite())); //Create a name for the webapp String temp = getCanonicalNameForWebAppTmpDir(context); File tmpDir = null; if (context.isPersistTempDirectory()) { //if it is to be persisted, make sure it will be the same name //by not using File.createTempFile, which appends random digits tmpDir = new File (parent, temp); } else { //ensure file will always be unique by appending random digits tmpDir = File.createTempFile(temp, ".dir", parent); //delete the file that was created tmpDir.delete(); //and make a directory of the same name tmpDir.mkdirs(); } configureTempDirectory(tmpDir, context); if(LOG.isDebugEnabled()) LOG.debug("Set temp dir "+tmpDir); context.setTempDirectory(tmpDir); }
webapp.setTempDirectory(tmpPath); logger.info("Adding webapp " + webAppContext); ((HandlerCollection) httpServer.getHandler()).addHandler(webapp);
webappContext.setTempDirectory(tempDir);
private static WebAppContext createWebAppContext(Builder b, AccessControlList adminsAcl, final String appDir) { WebAppContext ctx = new WebAppContext(); ctx.setDefaultsDescriptor(null); ServletHolder holder = new ServletHolder(new DefaultServlet()); Map<String, String> params = ImmutableMap. <String, String> builder() .put("acceptRanges", "true") .put("dirAllowed", "false") .put("gzip", "true") .put("useFileMappedBuffer", "true") .build(); holder.setInitParameters(params); ctx.setWelcomeFiles(new String[] {"index.html"}); ctx.addServlet(holder, "/"); ctx.setDisplayName(b.name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + b.name); String tempDirectory = b.conf.get(HTTP_TEMP_DIR_KEY); if (tempDirectory != null && !tempDirectory.isEmpty()) { ctx.setTempDirectory(new File(tempDirectory)); ctx.setAttribute("javax.servlet.context.tempdir", tempDirectory); } ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, b.conf); ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); addNoCacheFilter(ctx); return ctx; }
context.setTempDirectory(tmpDir); return;
@Override public void deconfigure(WebAppContext context) throws Exception { //if we're not persisting the temp dir contents delete it if (!context.isPersistTempDirectory()) { IO.delete(context.getTempDirectory()); } //if it wasn't explicitly configured by the user, then unset it Boolean tmpdirConfigured = (Boolean)context.getAttribute(TEMPDIR_CONFIGURED); if (tmpdirConfigured != null && !tmpdirConfigured) context.setTempDirectory(null); //reset the base resource back to what it was before we did any unpacking of resources if (context.getBaseResource() != null) context.getBaseResource().close(); context.setBaseResource(_preUnpackBaseResource); }
ServletContextInitializer... initializers) { Assert.notNull(context, "Context must not be null"); context.setTempDirectory(getTempDirectory()); if (this.resourceLoader != null) { context.setClassLoader(this.resourceLoader.getClassLoader());
server.addConnector(socketConnector); context = new WebAppContext(server, "", "/"); context.setTempDirectory(bimServer.getHomeDir().resolve("jettytmp").toFile());
protected void createContextTempDirectory() { if (context.getTempDirectory() == null) { File tmpDir = new File(System.getProperty("java.io.tmpdir")); tmpDir.mkdirs(); context.setTempDirectory(tmpDir); } }
protected void createContextTempDirectory() { if (context.getTempDirectory() == null) { File tmpDir = new File(System.getProperty("java.io.tmpdir")); tmpDir.mkdirs(); context.setTempDirectory(tmpDir); } }
public void setTempDirectory(String tempDirectory) { File tempDir = null; try { tempDir = new File(tempDirectory); if (!tempDir.exists()) { if (!tempDir.mkdirs()) { throw new IOException("Unable to create scratch directory: " + tempDir); } } super.setTempDirectory(tempDir); } catch (Exception e) { log.error("Failed to establish Scratch directory: " + tempDir, e); } }
int port = 8080; String context_path = "/"; File tmp_directory = "C:\\some-custom-path\\"; String war_path = "C:\\path-to-a\\file.war"; WebAppContext app = new WebAppContext(); app.setContextPath( context_path ); app.setWar( war_path ); app.setTempDirectory( tmp_directory ); Server server = new Server( port ); server.setHandler( app ); server.start(); server.join();
@Override protected WebAppContext createWebAppContext() throws Exception { WebAppContext warCtx = new WebAppContext(warFile.toURI().toString(), "/" + getContext()); // http://mifosforge.jira.com/browse/MIFOS-4765 File warCtxTmpDir = new File(warFile.getParentFile(), warFile.getName() + "_tmp"); IO.delete(warCtxTmpDir); warCtx.setTempDirectory(warCtxTmpDir); warCtxTmpDir.deleteOnExit(); warCtx.setExtractWAR(true); return warCtx; }
/** * @see org.eclipse.jetty.webapp.AbstractConfiguration#cloneConfigure(org.eclipse.jetty.webapp.WebAppContext, org.eclipse.jetty.webapp.WebAppContext) */ @Override public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception { File tmpDir=File.createTempFile(WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context),"",template.getTempDirectory().getParentFile()); if (tmpDir.exists()) { IO.delete(tmpDir); } tmpDir.mkdir(); tmpDir.deleteOnExit(); context.setTempDirectory(tmpDir); }
/** * @see org.eclipse.jetty.webapp.AbstractConfiguration#cloneConfigure(org.eclipse.jetty.webapp.WebAppContext, org.eclipse.jetty.webapp.WebAppContext) */ @Override public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception { File tmpDir=File.createTempFile(WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context),"",template.getTempDirectory().getParentFile()); if (tmpDir.exists()) { IO.delete(tmpDir); } tmpDir.mkdir(); tmpDir.deleteOnExit(); context.setTempDirectory(tmpDir); }
public static Server addWebApplication(final Server jetty, final String webAppContext, final String warFilePath) throws IOException { WebAppContext webapp = new WebAppContext(); webapp.setContextPath(webAppContext); webapp.setWar(warFilePath); webapp.setParentLoaderPriority(false); File tmpPath = new File(getWebAppBaseDirectory(webAppContext)); Files.createDirectories(tmpPath.toPath()); webapp.setTempDirectory(tmpPath); ((HandlerCollection) jetty.getHandler()).addHandler(webapp); return jetty; }
public static Server addWebApplication(final Server jetty, final String webAppContext, final String warFilePath) { WebAppContext webapp = new WebAppContext(); webapp.setContextPath(webAppContext); webapp.setWar(warFilePath); webapp.setParentLoaderPriority(false); webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); File tmpPath = new File(getWebAppBaseDirectory(webAppContext)); tmpPath.mkdirs(); webapp.setTempDirectory(tmpPath); ((HandlerCollection) jetty.getHandler()).addHandler(webapp); return jetty; }
/** * Create the WebAppContext with basic configurations set like context path etc. */ void createWebAppContext() { webapp.setServerClasses(getServerClasses()); webapp.setContextPath(contextPath); webapp.setTempDirectory(createTempDir("jetty-app-")); webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); setSecureCookies(); }
private HandlerCollection createHandlers() { WebAppContext context = new WebAppContext(); context.setContextPath(contextPath); context.setWar(webDir); context.setTempDirectory(new File(tempDir)); ErrorPageErrorHandler errorPage = new ErrorPageErrorHandler(); errorPage.addErrorPage(404,"/404"); context.setErrorHandler(errorPage); RequestLogHandler logHandler = new RequestLogHandler(); logHandler.setRequestLog(createRequestLog()); HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.setHandlers(new Handler[]{context, logHandler}); return handlerCollection; }