Java Code Examples for org.apache.catalina.core.StandardContext#addApplicationListener()

The following examples show how to use org.apache.catalina.core.StandardContext#addApplicationListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TomcatTest.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Override
protected int createServer() throws Exception
{
    String baseDir = "target/webapp-runner";
    tomcat = new Tomcat();
    int port = super.getPort();
    tomcat.setPort(port);
    File base = new File(baseDir);
    if (!base.exists())
    {
        base.mkdirs();
    }
    tomcat.setBaseDir(baseDir);
    Context ctx = tomcat.addContext("/",base.getAbsolutePath());
    StandardContext standardContext = (StandardContext)ctx;
    standardContext.addApplicationListener(CdiServletContextListener.class.getName());

    Wrapper wrapper = Tomcat.addServlet(ctx,"RequestServlet",RequestServlet.class.getName());
    wrapper.addMapping("/*");
    tomcat.start();
    return port;
}
 
Example 2
Source File: StatsServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    // Register and map the dispatcher servlet
    final File base = new File(System.getProperty("java.io.tmpdir"));

    final Tomcat server = new Tomcat();
    server.setPort(8686);
    server.setBaseDir(base.getAbsolutePath());

    final StandardContext context = (StandardContext)server.addWebapp("/", base.getAbsolutePath());
    context.setConfigFile(StatsServer.class.getResource("/META-INF/context.xml"));
    context.addApplicationListener(ContextLoaderListener.class.getName());
    context.setAddWebinfClassesResources(true);
    context.setResources(resourcesFrom(context, "target/classes"));
    context.setParentClassLoader(Thread.currentThread().getContextClassLoader());

    final Wrapper cxfServlet = Tomcat.addServlet(context, "cxfServlet", new CXFServlet());
    cxfServlet.setAsyncSupported(true);
    context.addServletMappingDecoded("/rest/*", "cxfServlet");

    final Context staticContext = server.addWebapp("/static", base.getAbsolutePath());
    Tomcat.addServlet(staticContext, "cxfStaticServlet", new DefaultServlet());
    staticContext.addServletMappingDecoded("/static/*", "cxfStaticServlet");
    staticContext.setResources(resourcesFrom(staticContext, "target/classes/web-ui"));
    staticContext.setParentClassLoader(Thread.currentThread().getContextClassLoader());

    server.start();
    server.getServer().await();
}