Search in sources :

Example 1 with DirResourceSet

use of org.apache.catalina.webresources.DirResourceSet in project kontraktor by RuedigerMoeller.

the class TomcatEmbeddedMain method main.

public static void main(String[] args) throws Exception {
    String webappDirLocation = "src/main/webapp/";
    Tomcat tomcat = new Tomcat();
    if (!new File(webappDirLocation + "client/index.html").exists()) {
        System.out.println("Please run with working dir: '[..]examples/servlet");
        System.exit(-1);
    }
    // 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();
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) DirResourceSet(org.apache.catalina.webresources.DirResourceSet) StandardContext(org.apache.catalina.core.StandardContext) StandardRoot(org.apache.catalina.webresources.StandardRoot) File(java.io.File) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 2 with DirResourceSet

use of org.apache.catalina.webresources.DirResourceSet in project tomee by apache.

the class TomEEWebappClassLoader method start.

// embeddeding implementation of sthg (JPA, JSF) can lead to classloading issues if we don't enrich the webapp
// with our integration jars
// typically the class will try to be loaded by the common classloader
// but the interface implemented or the parent class
// will be in the webapp
@Override
public void start() throws LifecycleException {
    // do it first otherwise we can't use this as classloader
    super.start();
    // mainly for tomee-maven-plugin
    initAdditionalRepos();
    if (additionalRepos != null && !additionalRepos.isEmpty()) {
        for (final File f : additionalRepos) {
            final DirResourceSet webResourceSet = new PremptiveDirResourceSet(resources, "/", f.getAbsolutePath(), "/");
            resources.addPreResources(webResourceSet);
        }
        resources.setCachingAllowed(false);
    }
    // add configurer enrichments
    if (configurer != null) {
        // add now we removed all we wanted
        final URL[] enrichment = configurer.additionalURLs();
        for (final URL url : enrichment) {
            super.addURL(url);
        }
    }
    // add internal enrichments
    for (final URL url : SystemInstance.get().getComponent(WebAppEnricher.class).enrichment(this)) {
        super.addURL(url);
    }
    // WEB-INF/jars.xml
    final File war = Contexts.warPath(CONTEXT.get());
    final File jarsXml = new File(war, "WEB-INF/" + QuickJarsTxtParser.FILE_NAME);
    final ClassLoaderConfigurer configurerTxt = QuickJarsTxtParser.parse(jarsXml);
    if (configurerTxt != null) {
        configurer = new CompositeClassLoaderConfigurer(configurer, configurerTxt);
    }
    stopped = false;
}
Also used : DirResourceSet(org.apache.catalina.webresources.DirResourceSet) CompositeClassLoaderConfigurer(org.apache.openejb.classloader.CompositeClassLoaderConfigurer) ClassLoaderConfigurer(org.apache.openejb.classloader.ClassLoaderConfigurer) CompositeClassLoaderConfigurer(org.apache.openejb.classloader.CompositeClassLoaderConfigurer) WebAppEnricher(org.apache.openejb.classloader.WebAppEnricher) File(java.io.File) URL(java.net.URL)

Example 3 with DirResourceSet

use of org.apache.catalina.webresources.DirResourceSet in project joinfaces by joinfaces.

the class JsfTomcatApplicationListenerIT method embeddedJarWithoutAppResources.

@Test
public void embeddedJarWithoutAppResources() throws LifecycleException {
    ContextMock contextMock = new ContextMock();
    File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.jar");
    JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES);
    jarWarResourceSet.init();
    DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(), TEST, TEST, TEST);
    contextMock.init(jarWarResourceSet, dirResourceSet);
    callApplicationEvent(contextMock);
    assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()).isEqualTo(2);
}
Also used : JarWarResourceSet(org.apache.catalina.webresources.JarWarResourceSet) DirResourceSet(org.apache.catalina.webresources.DirResourceSet) File(java.io.File) Test(org.junit.Test)

Example 4 with DirResourceSet

use of org.apache.catalina.webresources.DirResourceSet in project joinfaces by joinfaces.

the class JsfTomcatApplicationListenerIT method embeddedJarWithoutAppResources2.

@Test
public void embeddedJarWithoutAppResources2() throws LifecycleException {
    ContextMock contextMock = new ContextMock();
    File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.jar");
    JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES);
    jarWarResourceSet.init();
    DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(), TEST, TEST, TEST);
    contextMock.init(dirResourceSet, jarWarResourceSet);
    callApplicationEvent(contextMock);
    assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()).isEqualTo(2);
}
Also used : JarWarResourceSet(org.apache.catalina.webresources.JarWarResourceSet) DirResourceSet(org.apache.catalina.webresources.DirResourceSet) File(java.io.File) Test(org.junit.Test)

Example 5 with DirResourceSet

use of org.apache.catalina.webresources.DirResourceSet in project joinfaces by joinfaces.

the class JsfTomcatApplicationListenerIT method embeddedWarWithoutAppResources.

@Test
public void embeddedWarWithoutAppResources() throws LifecycleException {
    ContextMock contextMock = new ContextMock();
    File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.war");
    JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES);
    jarWarResourceSet.init();
    DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(), TEST, TEST, TEST);
    contextMock.init(jarWarResourceSet, dirResourceSet);
    callApplicationEvent(contextMock);
    assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()).isEqualTo(0);
}
Also used : JarWarResourceSet(org.apache.catalina.webresources.JarWarResourceSet) DirResourceSet(org.apache.catalina.webresources.DirResourceSet) File(java.io.File) Test(org.junit.Test)

Aggregations

DirResourceSet (org.apache.catalina.webresources.DirResourceSet)9 File (java.io.File)8 Test (org.junit.Test)5 WebResourceRoot (org.apache.catalina.WebResourceRoot)4 JarWarResourceSet (org.apache.catalina.webresources.JarWarResourceSet)3 StandardRoot (org.apache.catalina.webresources.StandardRoot)3 Tomcat (org.apache.catalina.startup.Tomcat)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 JarFile (java.util.jar.JarFile)1 Context (org.apache.catalina.Context)1 Wrapper (org.apache.catalina.Wrapper)1 StandardContext (org.apache.catalina.core.StandardContext)1 ClassLoaderConfigurer (org.apache.openejb.classloader.ClassLoaderConfigurer)1 CompositeClassLoaderConfigurer (org.apache.openejb.classloader.CompositeClassLoaderConfigurer)1 WebAppEnricher (org.apache.openejb.classloader.WebAppEnricher)1