当前位置: 首页>>代码示例>>Java>>正文


Java StandardRoot类代码示例

本文整理汇总了Java中org.apache.catalina.webresources.StandardRoot的典型用法代码示例。如果您正苦于以下问题:Java StandardRoot类的具体用法?Java StandardRoot怎么用?Java StandardRoot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StandardRoot类属于org.apache.catalina.webresources包,在下文中一共展示了StandardRoot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
    String userDir = System.getProperty("user.dir") + File.separator + "server.tomcat";
    String webappDirLocation = userDir + File.separator +"src/main/webapp/";
    Tomcat tomcat = new Tomcat();

    String webPort = System.getenv("PORT");
    if (webPort == null || webPort.isEmpty())
    {
        webPort = "8080";
    }

    tomcat.setPort(Integer.valueOf(webPort));

    System.out.println("configuring app with basedir: " + new File(webappDirLocation).getAbsolutePath());

    StandardContext standardContext = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
    File additionWebInfClasses = new File(userDir + File.separator + "build/classes");
    WebResourceRoot resourceRoot = new StandardRoot(standardContext);
    resourceRoot.addPreResources(new DirResourceSet(resourceRoot, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
    standardContext.setResources(resourceRoot);

    tomcat.start();
    tomcat.getServer().await();
}
 
开发者ID:geekflow,项目名称:light,代码行数:26,代码来源:TomcatMain.java

示例2: customize

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
@Test
public void customize() throws LifecycleException {
	Context standardContext = mock(Context.class);
	StandardRoot webResourceRoot = new StandardRoot(standardContext);
	Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
	Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);

	JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
	jsfTomcatContextCustomizer.customize(standardContext);

	JsfTomcatApplicationListener jsfTomcatApplicationListener = JsfTomcatApplicationListener
		.builder().context(jsfTomcatContextCustomizer.getContext()).build();
	jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));
	assertThat(webResourceRoot.getPostResources().length)
		.isEqualTo(9);
}
 
开发者ID:joinfaces,项目名称:joinfaces,代码行数:17,代码来源:JsfTomcatApplicationListenerIT.java

示例3: setUpClass

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
/**
 * Sets up the test environment, generates data to upload, starts a
 * Tomcat instance which will receive the client requests.
 * @throws Exception If an error occurred with the servlets
 */
@BeforeClass
public static void setUpClass() throws Exception {
    server = new Tomcat();

    Path base = Paths.get("build/tomcat");
    Files.createDirectories(base);

    server.setPort(8100);
    server.setBaseDir("build/tomcat");
    server.getHost().setAppBase("build/tomcat");
    server.getHost().setAutoDeploy(true);
    server.getHost().setDeployOnStartup(true);

    StandardContext context = (StandardContext) server.addWebapp("/", base.toAbsolutePath().toString());

    Path additionWebInfClasses = Paths.get("build/classes");
    WebResourceRoot resources = new StandardRoot(context);
    resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
            additionWebInfClasses.toAbsolutePath().toString(), "/"));
    context.setResources(resources);
    context.getJarScanner().setJarScanFilter((jarScanType, jarName) -> false);

    server.start();
}
 
开发者ID:Elopteryx,项目名称:upload-parser,代码行数:30,代码来源:TomcatIntegrationTest.java

示例4: servletContainer

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    final TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();

    if(useReverseProxy) {
        tomcat.addAdditionalTomcatConnectors(createAjpConnector());
    }

    // Set the web resources cache size (this defaults to 10MB but that is too small for Find)
    tomcat.addContextCustomizers(context -> {
        final WebResourceRoot resources = new StandardRoot(context);
        resources.setCacheMaxSize(webResourcesCacheSize);
        context.setResources(resources);
    });

    tomcat.addConnectorCustomizers(connector -> {
        connector.setMaxPostSize(connectorMaxPostSize);
    });

    return tomcat;
}
 
开发者ID:hpe-idol,项目名称:find,代码行数:22,代码来源:TomcatConfig.java

示例5: main

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
public static void main(String[] args) {
	Connector connector = new Connector();
	connector.setPort(80);
	Tomcat tomcat = new Tomcat();
	tomcat.setPort(80);
	tomcat.getService().addConnector(connector);
	tomcat.setConnector(connector);
	try {
		Context ctx = tomcat.addWebapp("", Conf.getAbsolutePath("../src/main/webapp"));
		WebResourceRoot resources = new StandardRoot(ctx);
		resources.addPreResources(new DirResourceSet(resources,
				"/WEB-INF/classes", Conf.getAbsolutePath("classes"), "/"));
		ctx.setResources(resources);

		Server server = tomcat.getServer();
		server.start();
		server.setPort(8005);
		server.await();
		server.stop();
	} catch (ServletException | LifecycleException e) {
		Log.e(e);
	}
}
 
开发者ID:xqbase,项目名称:metric,代码行数:24,代码来源:Startup.java

示例6: setResources

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
@Override
public void setResources(final WebResourceRoot resources) {
    this.resources = resources;
    if (StandardRoot.class.isInstance(resources)) {
        final List<WebResourceSet> jars = (List<WebResourceSet>) Reflections.get(resources, "jarResources");
        if (jars != null && !jars.isEmpty()) {
            final Iterator<WebResourceSet> jarIt = jars.iterator();
            while (jarIt.hasNext()) {
                final WebResourceSet set = jarIt.next();
                if (set.getBaseUrl() == null) {
                    continue;
                }
                final File file = URLs.toFile(set.getBaseUrl());
                try {
                    if (file.exists() && (!TomEEClassLoaderEnricher.validateJarFile(file) || !jarIsAccepted(file))) {
                        // need to remove this resource
                        LOGGER.warning("Removing " + file.getAbsolutePath() + " since it is offending");
                        jarIt.remove();
                    }
                } catch (final IOException e) {
                    // ignore
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:27,代码来源:TomEEWebappClassLoader.java

示例7: configure

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
public static void configure(TomcatEmbeddedServletContainerFactory tomcatFactory) {

            tomcatFactory.addContextCustomizers((TomcatContextCustomizer) context -> {

                boolean development = (System.getProperty("airsonic.development") != null);

                // Increase the size and time before eviction of the Tomcat
                // cache so that resources aren't uncompressed too often.
                // See https://github.com/jhipster/generator-jhipster/issues/3995

                StandardRoot resources = new StandardRoot();
                if (development) {
                    resources.setCachingAllowed(false);
                } else {
                    resources.setCacheMaxSize(100000);
                    resources.setCacheObjectMaxSize(4000);
                    resources.setCacheTtl(24 * 3600 * 1000);  // 1 day, in milliseconds
                }
                context.setResources(resources);

                // Put Jasper in production mode so that JSP aren't recompiled
                // on each request.
                // See http://stackoverflow.com/questions/29653326/spring-boot-application-slow-because-of-jsp-compilation
                Container jsp = context.findChild("jsp");
                if (jsp instanceof Wrapper) {
                    ((Wrapper) jsp).addInitParameter("development", Boolean.toString(development));
                }
            });
    }
 
开发者ID:airsonic,项目名称:airsonic,代码行数:30,代码来源:TomcatApplication.java

示例8: servletContainer

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
/**
 * Servlet container embedded servlet container factory.
 *
 * @return the embedded servlet container factory
 * @source http://stackoverflow.com/questions/39146476/how-does-spring-boot-control-tomcat-cache
 */
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    return new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            final int cacheSize = 256 * 1024;
            final StandardRoot standardRoot = new StandardRoot(context);
            standardRoot.setCacheMaxSize(cacheSize);
            context.setResources(standardRoot);

            logger.info(String.format("New cache size (KB): %d", context.getResources().getCacheMaxSize()));
        }
    };
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:21,代码来源:SpringConfig.java

示例9: start

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
public static void start() throws Exception {
	Tomcat tomcat = new Tomcat();
	tomcat.setHostname("localhost");
	tomcat.setPort(80);
	// tomcat.setBaseDir("D:\\work\\zhongcao\\zhongcao\\zhongcao-web");
	// tomcat.addWebapp("WebRoot", "D:\\work\\zhongcao\\zhongcao\\zhongcao-web\\target\\zhongcao-web");
	StandardContext ctx = (StandardContext) tomcat.addWebapp("/", "D:\\work\\zhongcao\\zhongcao\\zhongcao-web\\target\\zhongcao-web");
	StandardRoot resources = new StandardRoot(ctx);
	resources.setCachingAllowed(false);
	ctx.setResources(resources);
	tomcat.start();
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:13,代码来源:TomcatServer.java

示例10: customizeTargetTestClasses

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
@Test
public void customizeTargetTestClasses() throws LifecycleException {
	Context standardContext = mock(Context.class);
	StandardRoot webResourceRoot = new StandardRoot(standardContext);
	Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
	Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);

	String absolutePath = new File("").getAbsolutePath();
	String internalPath = METAINF_RESOURCES;

	String targetTestClassesBase = absolutePath + "/" + "target/test-classes";
	File testClassesResources = new File(targetTestClassesBase + internalPath);
	if (!testClassesResources.mkdirs()) {
		throw new RuntimeException("Could not create dir: " + testClassesResources.toString());
	}

	JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
	jsfTomcatContextCustomizer.customize(standardContext);

	JsfTomcatApplicationListener jsfTomcatApplicationListener = JsfTomcatApplicationListener
		.builder().context(jsfTomcatContextCustomizer.getContext()).build();

	jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));
	if (!testClassesResources.delete()) {
		throw new RuntimeException("Could not delete dir: " + testClassesResources.toString());
	}
	assertThat(webResourceRoot.getPostResources().length)
		.isEqualTo(10);
}
 
开发者ID:joinfaces,项目名称:joinfaces,代码行数:30,代码来源:JsfTomcatApplicationListenerIT.java

示例11: customizeTomcat

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
/**
 * Customize Tomcat configuration.
 */
private void customizeTomcat(ConfigurableEmbeddedServletContainer container) {
    if (container instanceof TomcatEmbeddedServletContainerFactory) {
        TomcatEmbeddedServletContainerFactory tomcatFactory = (TomcatEmbeddedServletContainerFactory) container;
        tomcatFactory.addContextCustomizers((TomcatContextCustomizer) context -> {
            // See https://github.com/jhipster/generator-jhipster/issues/3995
            StandardRoot resources = new StandardRoot();
            resources.setCacheMaxSize(40960);
            resources.setCacheObjectMaxSize(2048);
            context.setResources(resources);
        });
    }
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:16,代码来源:WebConfigurer.java

示例12: configure

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
@Override
public void configure(TomcatEmbeddedServletContainerFactory tomcat, int cacheSize,
        int tomcatCacheSize) {
    tomcat.addContextCustomizers((context) -> {
        StandardRoot standardRoot = new StandardRoot(context);
        standardRoot.setCachingAllowed(true);
        standardRoot.setCacheMaxSize(cacheSize);
        standardRoot.setCacheTtl(tomcatCacheSize);
        context.setResources(standardRoot);
    });
}
 
开发者ID:epam,项目名称:NGB,代码行数:12,代码来源:TomcatConfigurerImpl.java

示例13: main

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        String webappDirLocation = "src/main/webapp/";
        Tomcat tomcat = new Tomcat();

        //The port that we should run on can be set into an environment variable
        //Look for that variable and default to 8080 if it isn't there.
        String webPort = System.getenv("PORT");
        if(webPort == null || webPort.isEmpty()) {
            webPort = "8080";
        }

        tomcat.setPort(Integer.valueOf(webPort));

        StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
        System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());

        // Declare an alternative location for your "WEB-INF/classes" dir
        // Servlet 3.0 annotation will work
        File additionWebInfClasses = new File("target/classes");
        WebResourceRoot resources = new StandardRoot(ctx);
        resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
                additionWebInfClasses.getAbsolutePath(), "/"));
        ctx.setResources(resources);

        tomcat.start();
        tomcat.getServer().await();
    }
 
开发者ID:salesforceidentity,项目名称:heroku-identity-java,代码行数:29,代码来源:Main.java

示例14: main

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
public static void main(String[] args) {
	Connector connector = new Connector();
	connector.setPort(80);
	Tomcat tomcat = new Tomcat();
	tomcat.setPort(80);
	tomcat.getService().addConnector(connector);
	tomcat.setConnector(connector);
	try {
		Context ctx = tomcat.addWebapp("", Conf.getAbsolutePath("../src/main/webapp"));
		// Ensure to Load All Classes in the Same Class Loader
		ctx.setLoader(new WebappLoader(Startup.class.getClassLoader()) {
			@Override
			public ClassLoader getClassLoader() {
				return Startup.class.getClassLoader();
			}
		});
		WebResourceRoot resources = new StandardRoot(ctx);
		resources.addPreResources(new DirResourceSet(resources,
				"/WEB-INF/classes", Conf.getAbsolutePath("classes"), "/"));
		ctx.setResources(resources);

		Server server = tomcat.getServer();
		server.start();
		server.setPort(8005);
		server.await();
		server.stop();
	} catch (ServletException | LifecycleException e) {
		Log.e(e);
	}
}
 
开发者ID:xqbase,项目名称:metric,代码行数:31,代码来源:Startup.java

示例15: servletContainer

import org.apache.catalina.webresources.StandardRoot; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    return new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context ctx) {
            final int sizeInKB = 32 * 1024;  // default is 10MiB, increase to 32
            WebResourceRoot resourceRoot = new StandardRoot(ctx);
            resourceRoot.setCacheMaxSize(sizeInKB);
            ctx.setResources(resourceRoot);
        }
    };
}
 
开发者ID:cims-bioko,项目名称:cims-server,代码行数:13,代码来源:WebConfig.java


注:本文中的org.apache.catalina.webresources.StandardRoot类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。