org.apache.catalina.Context.setResources()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(145)

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

Context.setResources介绍

[英]Set the Resources object with which this Context is associated.
[中]设置与此上下文关联的资源对象。

代码示例

代码示例来源:origin: line/armeria

ctx.setResources(new ArmeriaWebResourceRoot(ctx, config));

代码示例来源:origin: com.sitewhere/sitewhere-web

protected void postProcessContext(Context context) {
  final int cacheSize = 100 * 1024 * 1024;
  StandardRoot standardRoot = new StandardRoot(context);
  standardRoot.setCacheMaxSize(cacheSize);
  standardRoot.setCacheObjectMaxSize(Integer.MAX_VALUE / 1024);
  context.setResources(standardRoot);
  }
};

代码示例来源:origin: justlive1/oxygen

@Override
 public void lifecycleEvent(LifecycleEvent event) {
  if (event.getType().equals(Lifecycle.BEFORE_START_EVENT)) {
   Context context = (Context) event.getLifecycle();
   WebResourceRoot resources = context.getResources();
   if (resources == null) {
    resources = new StandardRoot(context);
    context.setResources(resources);
   }

   // 使用embedded tomcat时 WEB-INF放在了classpath下
   URL resource = context.getParentClassLoader().getResource(Constants.WEB_INF);
   if (resource != null) {
    String webXmlUrlString = resource.toString();
    try {
     URL root = new URL(
       webXmlUrlString.substring(0, webXmlUrlString.length() - Constants.WEB_INF.length()));
     resources.createWebResourceSet(ResourceSetType.RESOURCE_JAR, Constants.WEB_INF_PATH, root,
       Constants.WEB_INF_PATH);
    } catch (MalformedURLException e) {
     // ignore
    }
   }
  }
 }
}

代码示例来源:origin: hengyunabc/executable-embeded-tomcat-sample

@Override
public void lifecycleEvent(LifecycleEvent event) {
  if (event.getType().equals(Lifecycle.BEFORE_START_EVENT)) {
    Context context = (Context) event.getLifecycle();
    WebResourceRoot resources = context.getResources();
    if (resources == null) {
      resources = new StandardRoot(context);
      context.setResources(resources);
    }
    /**
     * <pre>
     * when run as embeded tomcat, context.getParentClassLoader() is AppClassLoader,
     * so it can load "WEB-INF/web.xml" from app classpath.
     * </pre>
     */
    URL resource = context.getParentClassLoader().getResource("WEB-INF/web.xml");
    if (resource != null) {
      String webXmlUrlString = resource.toString();
      URL root;
      try {
        root = new URL(webXmlUrlString.substring(0, webXmlUrlString.length() - "WEB-INF/web.xml".length()));
        resources.createWebResourceSet(ResourceSetType.RESOURCE_JAR, "/WEB-INF", root, "/WEB-INF");
      } catch (MalformedURLException e) {
        // ignore
      }
    }
  }
}

代码示例来源:origin: org.talend.sdk.component/component-server

@Override
public void run() {
  try {
    try (final Meecrowave meecrowave = new Meecrowave(create(args)) {
      @Override
      protected Connector createConnector() {
        return new Connector(CustomPefixHttp11NioProtocol.class.getName());
      }
    }) {
      this.instance = meecrowave;
      meecrowave.start();
      meecrowave.deployClasspath(new Meecrowave.DeploymentMeta("", null, stdCtx -> {
        stdCtx.setResources(new StandardRoot() {
          @Override
          protected void registerURLStreamHandlerFactory() {
            // no-op: not supported into OSGi since there is already one and it must set a
            // single time
          }
        });
      }));
      doWait(meecrowave, null);
    }
  } catch (final Exception e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: org.talend.sdk.component/component-tools

try (final Meecrowave meecrowave = new Meecrowave(Cli.create(buildArgs()))) {
  meecrowave.start().deployClasspath(new Meecrowave.DeploymentMeta("", null, stdCtx -> {
    stdCtx.setResources(new StandardRoot() {

代码示例来源:origin: com.github.mjeanroy/junit-servers-tomcat

);
context.setResources(root);

代码示例来源:origin: apache/tomcat-maven-plugin

context.setResources(
  new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath() ) );

代码示例来源:origin: apache/tomcat-maven-plugin

context.setResources(
  new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath(), //

代码示例来源:origin: Red5/red5-plugins

/**
 * @see #addWebapp(String, String)
 */
public Context addWebapp(Host host, String contextPath, String docBase, ContextConfig config) {
  Context ctx = createContext(host, contextPath);
  ctx.setPath(contextPath);
  ctx.setDocBase(docBase);
  ctx.addLifecycleListener(new DefaultWebXmlListener());
  ctx.setConfigFile(getWebappConfigFile(docBase, contextPath));
  ctx.addLifecycleListener(config);
  // prevent it from looking ( if it finds one - it'll have dup error )
  config.setDefaultWebXml(noDefaultWebXmlPath());
  // get the host first, creates a new std host if not already set
  getHost();
  // reset ParentClassLoader 
  if (!host.getParentClassLoader().equals(Thread.currentThread().getContextClassLoader())) {
    host.setParentClassLoader(Thread.currentThread().getContextClassLoader());
  }
  StandardRoot standardRoot = new StandardRoot(ctx);
  standardRoot.setCacheMaxSize(cacheMaxSize);
  ctx.setResources(standardRoot);
  // add the context
  host.addChild(ctx);
  return ctx;
}

代码示例来源:origin: apache/tomcat-maven-plugin

context.setResources(
  new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath(), //

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

MultipleDirContext dirContext = new MultipleDirContext();
dirContext.setVirtualDocBase(resources);
context.setResources(dirContext);

代码示例来源:origin: com.github.bordertech.lde/lde-tomcat

/**
 * @param context the context to configure
 * @throws IOException an IO Exception
 * @throws ServletException a Servlet Exception
 */
protected void configWebApp(final Context context) throws IOException, ServletException {
  final String libDir = getLibDir();
  final String classesDir = getClassesDir();
  configJarScanner(context);
  WebResourceRoot resources = new StandardRoot(context);
  context.setResources(resources);
  // Declare an alternative location for the "WEB-INF/lib" dir
  if (libDir != null && !libDir.isEmpty()) {
    resources.addPreResources(new DirResourceSet(resources, Constants.WEB_INF_LIB, libDir, "/"));
  }
  // Declare an alternative location for the "WEB-INF/classes" dir
  if (classesDir != null && !classesDir.isEmpty()) {
    resources.addPreResources(new DirResourceSet(resources, Constants.WEB_INF_CLASSES, classesDir, "/"));
  }
  // Stop persistent sessions
  StandardManager mgr = new StandardManager();
  mgr.setPathname(null);
  context.setManager(mgr);
  // Delay for requets to stop processing in milliseconds
  ((StandardContext) context).setUnloadDelay(10000);
}

代码示例来源:origin: org.jboss.jbossas/jboss-as-tomcat

context.setResources((javax.naming.directory.DirContext)TomcatService.getInstance(contextMetaData.getResources(),
   "org.apache.naming.resources.FileDirContext"));

代码示例来源:origin: org.visallo/visallo-tomcat-server

webRoot.setCacheMaxSize(100000);
webRoot.setCachingAllowed(true);
context.setResources(webRoot);

代码示例来源:origin: ch.rasc/embeddedtc

"/WEB-INF/classes", "./target/classes", "/");
resourceRoot.addPreResources(dirResource);
ctx.setResources(resourceRoot);

相关文章

微信公众号

最新文章

更多

Context类方法