org.eclipse.jetty.webapp.WebAppContext.setTempDirectory()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中org.eclipse.jetty.webapp.WebAppContext.setTempDirectory()方法的一些代码示例,展示了WebAppContext.setTempDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebAppContext.setTempDirectory()方法的具体详情如下:
包路径:org.eclipse.jetty.webapp.WebAppContext
类名称:WebAppContext
方法名:setTempDirectory

WebAppContext.setTempDirectory介绍

[英]Set temporary directory for context. The javax.servlet.context.tempdir attribute is also set.
[中]为上下文设置临时目录。javax。servlet。上下文还设置了tempdir属性。

代码示例

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

/**
 * @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);
}

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

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);
}

代码示例来源:origin: apache/geode

webapp.setTempDirectory(tmpPath);
logger.info("Adding webapp " + webAppContext);
((HandlerCollection) httpServer.getHandler()).addHandler(webapp);

代码示例来源:origin: apache/nifi

webappContext.setTempDirectory(tempDir);

代码示例来源:origin: org.apache.hadoop/hadoop-common

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;
}

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

context.setTempDirectory(tmpDir);
return;

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

@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);
}

代码示例来源:origin: org.springframework.boot/spring-boot

ServletContextInitializer... initializers) {
Assert.notNull(context, "Context must not be null");
context.setTempDirectory(getTempDirectory());
if (this.resourceLoader != null) {
  context.setClassLoader(this.resourceLoader.getClassLoader());

代码示例来源:origin: opensourceBIM/BIMserver

server.addConnector(socketConnector);
context = new WebAppContext(server, "", "/");
context.setTempDirectory(bimServer.getHomeDir().resolve("jettytmp").toFile());

代码示例来源:origin: works.lmz.common/common-runnable-war

protected void createContextTempDirectory() {
  if (context.getTempDirectory() == null) {
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    tmpDir.mkdirs();
    context.setTempDirectory(tmpDir);
  }
}

代码示例来源:origin: cd.connect.common/connect-runnable-war

protected void createContextTempDirectory() {
  if (context.getTempDirectory() == null) {
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    tmpDir.mkdirs();
    context.setTempDirectory(tmpDir);
  }
}

代码示例来源:origin: com.aspectran/aspectran-with-jetty

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);
  }
}

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: mifos/head

@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;
}

代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9

/**
 * @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);
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server

/**
 * @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);
}

代码示例来源:origin: io.snappydata/gemfire-core

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;
}

代码示例来源:origin: org.apache.geode/gemfire-core

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;
}

代码示例来源:origin: org.avaje.glue/jetty-runner

/**
 * 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();
}

代码示例来源:origin: shunyang/thrift-all

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;
}

相关文章

微信公众号

最新文章

更多

WebAppContext类方法