本文整理汇总了Java中org.apache.catalina.WebResourceRoot类的典型用法代码示例。如果您正苦于以下问题:Java WebResourceRoot类的具体用法?Java WebResourceRoot怎么用?Java WebResourceRoot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebResourceRoot类属于org.apache.catalina包,在下文中一共展示了WebResourceRoot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.catalina.WebResourceRoot; //导入依赖的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: getTomcatRuntime
import org.apache.catalina.WebResourceRoot; //导入依赖的package包/类
/**
* Inform tomcat runtime setup. UNPACKAGED_WAR not covered yet.
* @param resources of the tomcat
* @return tomcat runtime
*/
TomcatRuntime getTomcatRuntime(WebResourceRoot resources) {
TomcatRuntime result = null;
if (isUberJar(resources)) {
result = TomcatRuntime.UBER_JAR;
}
else if (isUberWar(resources)) {
result = TomcatRuntime.UBER_WAR;
}
else if (isTesting(resources)) {
result = TomcatRuntime.TEST;
}
else if (isUnpackagedJar(resources)) {
result = TomcatRuntime.UNPACKAGED_JAR;
}
return result;
}
示例3: jarResourcesNull
import org.apache.catalina.WebResourceRoot; //导入依赖的package包/类
@Test
public void jarResourcesNull() throws LifecycleException {
Context standardContext = mock(Context.class);
WebResourceRoot webResourceRoot = mock(WebResourceRoot.class);
Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);
Mockito.when(webResourceRoot.getJarResources()).thenReturn(null);
JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
jsfTomcatContextCustomizer.customize(standardContext);
JsfTomcatApplicationListener jsfTomcatApplicationListener = JsfTomcatApplicationListener
.builder().context(jsfTomcatContextCustomizer.getContext()).build();
jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));
assertThat(jsfTomcatApplicationListener)
.isNotNull();
}
示例4: RAFSResource
import org.apache.catalina.WebResourceRoot; //导入依赖的package包/类
public RAFSResource(WebResourceRoot root, Path path, RAFS rafs) {
super(root, path);
m_RAFS = rafs;
m_Cache = null;
try {
if(Files.exists(path) && !Files.isDirectory(path) && isInRAF()) {
Version v = rafs.getVersionDataForFile(path, null);
if(v != null) {
m_Cache = v.dataSource.read();
}
}
} catch(IOException e) {
m_Cache = null;
}
}
示例5: setUpClass
import org.apache.catalina.WebResourceRoot; //导入依赖的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();
}
示例6: servletContainer
import org.apache.catalina.WebResourceRoot; //导入依赖的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;
}
示例7: main
import org.apache.catalina.WebResourceRoot; //导入依赖的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);
}
}
示例8: setResources
import org.apache.catalina.WebResourceRoot; //导入依赖的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
}
}
}
}
}
示例9: destroy
import org.apache.catalina.WebResourceRoot; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void destroy(final StandardContext standardContext) {
final Loader standardContextLoader = standardContext.getLoader();
if (LazyStopLoader.class.isInstance(standardContextLoader)) {
final Loader delegate = LazyStopLoader.class.cast(standardContextLoader).getDelegateLoader();
if (TomEEWebappLoader.class.isInstance(delegate)) {
final TomEEWebappLoader webappLoader = TomEEWebappLoader.class.cast(delegate);
final ClassLoader loader = webappLoader.internalLoader();
webappLoader.clearLoader();
if (TomEEWebappClassLoader.class.isInstance(loader)) {
TomEEWebappClassLoader.class.cast(loader).internalDestroy();
}
}
}
final WebResourceRoot root = standardContext.getResources();
if (LazyStopStandardRoot.class.isInstance(root)) {
try {
LazyStopStandardRoot.class.cast(root).internalDestroy();
} catch (final LifecycleException e) {
throw new IllegalStateException(e);
}
}
}
示例10: getFirstJarWarResourceSetAtJarResources
import org.apache.catalina.WebResourceRoot; //导入依赖的package包/类
private JarWarResourceSet getFirstJarWarResourceSetAtJarResources(WebResourceRoot resources) {
JarWarResourceSet result = null;
for (WebResourceSet resourceSet :resources.getJarResources()) {
if (resourceSet instanceof JarWarResourceSet) {
result = (JarWarResourceSet) resourceSet;
break;
}
}
return result;
}
示例11: mainFile
import org.apache.catalina.WebResourceRoot; //导入依赖的package包/类
private URL mainFile(WebResourceRoot resources) {
URL result = null;
for (WebResourceSet resourceSet :resources.getJarResources()) {
if (resourceSet instanceof JarWarResourceSet) {
result = resourceSet.getBaseUrl();
break;
}
}
return result;
}
示例12: addMainJarResourceSet
import org.apache.catalina.WebResourceRoot; //导入依赖的package包/类
private void addMainJarResourceSet(WebResourceRoot resources) throws URISyntaxException {
String webAppMount = "/";
String archivePath = null;
String internalPath = "/META-INF/resources";
resources.createWebResourceSet(WebResourceRoot.ResourceSetType.POST,
webAppMount, base(mainFile(resources)), archivePath, internalPath);
}
示例13: addClasspathResourceSets
import org.apache.catalina.WebResourceRoot; //导入依赖的package包/类
private void addClasspathResourceSets(WebResourceRoot resources) throws URISyntaxException {
String webAppMount = "/";
String archivePath = null;
String internalPath = "/META-INF/resources";
for (URL url : ClasspathHelper.forResource("META-INF/resources/", this.getClass().getClassLoader())) {
resources.createWebResourceSet(WebResourceRoot.ResourceSetType.POST,
webAppMount, base(url), archivePath, internalPath);
}
}
示例14: JarSubsetResourceSet
import org.apache.catalina.WebResourceRoot; //导入依赖的package包/类
JarSubsetResourceSet(WebResourceRoot root, String webAppMount, String base, String internalPath,
String jarRoot) {
super(root, webAppMount, base, internalPath);
// Should be normalized by TomcatServiceBuilder.
assert !"/".equals(jarRoot) : "JarResourceSet should be used instead.";
assert jarRoot.startsWith("/") : "jarRoot must be absolute.";
assert !jarRoot.endsWith("/") : "jarRoot must not end with '/'.";
prefix = jarRoot.substring(1) + '/';
}
示例15: main
import org.apache.catalina.WebResourceRoot; //导入依赖的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();
}