本文整理汇总了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();
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
}
示例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
}
}
}
}
}
示例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));
}
});
}
示例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()));
}
};
}
示例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();
}
示例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);
}
示例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);
});
}
}
示例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);
});
}
示例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();
}
示例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);
}
}
示例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);
}
};
}