Search in sources :

Example 1 with ServletContainerInitializersStarter

use of org.eclipse.jetty.annotations.ServletContainerInitializersStarter in project jetty.project by eclipse.

the class QuickStartConfiguration method configure.

/**
     * @see org.eclipse.jetty.webapp.AbstractConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext)
     */
@Override
public void configure(WebAppContext context) throws Exception {
    LOG.debug("configure {}", this);
    if (context.isStarted()) {
        LOG.warn("Cannot configure webapp after it is started");
        return;
    }
    //Temporary:  set up the classpath here. This should be handled by the QuickStartDescriptorProcessor
    Resource webInf = context.getWebInf();
    if (webInf != null && webInf.isDirectory() && context.getClassLoader() instanceof WebAppClassLoader) {
        // Look for classes directory
        Resource classes = webInf.addPath("classes/");
        if (classes.exists())
            ((WebAppClassLoader) context.getClassLoader()).addClassPath(classes);
        // Look for jars
        Resource lib = webInf.addPath("lib/");
        if (lib.exists() || lib.isDirectory())
            ((WebAppClassLoader) context.getClassLoader()).addJars(lib);
    }
    //add the processor to handle normal web.xml content
    context.getMetaData().addDescriptorProcessor(new StandardDescriptorProcessor());
    //add a processor to handle extended web.xml format
    context.getMetaData().addDescriptorProcessor(new QuickStartDescriptorProcessor());
    //add a decorator that will find introspectable annotations
    //this must be the last Decorator because they are run in reverse order!
    context.getObjectFactory().addDecorator(new AnnotationDecorator(context));
    //add a context bean that will run ServletContainerInitializers as the context starts
    ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter) context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER);
    if (starter != null)
        throw new IllegalStateException("ServletContainerInitializersStarter already exists");
    starter = new ServletContainerInitializersStarter(context);
    context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER, starter);
    context.addBean(starter, true);
    LOG.debug("configured {}", this);
}
Also used : StandardDescriptorProcessor(org.eclipse.jetty.webapp.StandardDescriptorProcessor) ServletContainerInitializersStarter(org.eclipse.jetty.annotations.ServletContainerInitializersStarter) Resource(org.eclipse.jetty.util.resource.Resource) WebAppClassLoader(org.eclipse.jetty.webapp.WebAppClassLoader) AnnotationDecorator(org.eclipse.jetty.annotations.AnnotationDecorator)

Example 2 with ServletContainerInitializersStarter

use of org.eclipse.jetty.annotations.ServletContainerInitializersStarter in project steve by RWTH-i5-IDSG.

the class SteveAppContext method initJSP.

// -------------------------------------------------------------------------
// JSP stuff
// 
// Help by:
// 
// https://github.com/jetty-project/embedded-jetty-jsp
// https://github.com/jasonish/jetty-springmvc-jsp-template
// http://examples.javacodegeeks.com/enterprise-java/jetty/jetty-jsp-example
// -------------------------------------------------------------------------
private void initJSP(WebAppContext ctx) {
    ctx.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
    ctx.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    ctx.addBean(new ServletContainerInitializersStarter(ctx), true);
}
Also used : SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) InstanceManager(org.apache.tomcat.InstanceManager) ServletContainerInitializersStarter(org.eclipse.jetty.annotations.ServletContainerInitializersStarter) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager)

Example 3 with ServletContainerInitializersStarter

use of org.eclipse.jetty.annotations.ServletContainerInitializersStarter in project mysql_perf_analyzer by yahoo.

the class App method createDeployedApplicationInstance.

private WebAppContext createDeployedApplicationInstance(File workDirectory, String deployedApplicationPath) {
    WebAppContext deployedApplication = new WebAppContext();
    deployedApplication.setContextPath(this.getContextPath());
    deployedApplication.setWar(deployedApplicationPath);
    deployedApplication.setAttribute("javax.servlet.context.tempdir", workDirectory.getAbsolutePath());
    deployedApplication.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$");
    deployedApplication.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
    deployedApplication.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    deployedApplication.addBean(new ServletContainerInitializersStarter(deployedApplication), true);
    // webapp.setClassLoader(new URLClassLoader(new
    // URL[0],App.class.getClassLoader()));
    deployedApplication.addServlet(jspServletHolder(), "*.jsp");
    return deployedApplication;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) InstanceManager(org.apache.tomcat.InstanceManager) ServletContainerInitializersStarter(org.eclipse.jetty.annotations.ServletContainerInitializersStarter) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager)

Example 4 with ServletContainerInitializersStarter

use of org.eclipse.jetty.annotations.ServletContainerInitializersStarter in project jetty.project by eclipse.

the class QuickStartDescriptorProcessor method visitContainerInitializer.

public void visitContainerInitializer(WebAppContext context, ContainerInitializer containerInitializer) {
    if (containerInitializer == null)
        return;
    //add the ContainerInitializer to the list of container initializers
    List<ContainerInitializer> containerInitializers = (List<ContainerInitializer>) context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS);
    if (containerInitializers == null) {
        containerInitializers = new ArrayList<ContainerInitializer>();
        context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS, containerInitializers);
    }
    containerInitializers.add(containerInitializer);
    //Ensure a bean is set up on the context that will invoke the ContainerInitializers as the context starts
    ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter) context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER);
    if (starter == null) {
        starter = new ServletContainerInitializersStarter(context);
        context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER, starter);
        context.addBean(starter, true);
    }
}
Also used : ServletContainerInitializersStarter(org.eclipse.jetty.annotations.ServletContainerInitializersStarter) ContainerInitializer(org.eclipse.jetty.plus.annotation.ContainerInitializer) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ServletContainerInitializersStarter

use of org.eclipse.jetty.annotations.ServletContainerInitializersStarter in project opennms by OpenNMS.

the class OpenNMSWebAppProvider method createContextHandler.

@Override
public ContextHandler createContextHandler(final App app) throws Exception {
    final ContextHandler handler = super.createContextHandler(app);
    /*
         * Add an alias check that accepts double slashes in our resource paths.
         */
    handler.addAliasCheck(new ApproveAbsolutePathAliases());
    /*
         * Pulled from: http://bengreen.eu/fancyhtml/quickreference/jettyjsp9error.html
         *
         * Configure the application to support the compilation of JSP files.
         * We need a new class loader and some stuff so that Jetty can call the
         * onStartup() methods as required.
         */
    if (handler instanceof WebAppContext) {
        WebAppContext context = (WebAppContext) handler;
        context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS, jspInitializers());
        context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
        context.addBean(new ServletContainerInitializersStarter(context), true);
    }
    return handler;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) InstanceManager(org.apache.tomcat.InstanceManager) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) ServletContainerInitializersStarter(org.eclipse.jetty.annotations.ServletContainerInitializersStarter) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager)

Aggregations

ServletContainerInitializersStarter (org.eclipse.jetty.annotations.ServletContainerInitializersStarter)6 InstanceManager (org.apache.tomcat.InstanceManager)3 SimpleInstanceManager (org.apache.tomcat.SimpleInstanceManager)3 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)2 File (java.io.File)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AnnotationDecorator (org.eclipse.jetty.annotations.AnnotationDecorator)1 ContainerInitializer (org.eclipse.jetty.plus.annotation.ContainerInitializer)1 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)1 Resource (org.eclipse.jetty.util.resource.Resource)1 StandardDescriptorProcessor (org.eclipse.jetty.webapp.StandardDescriptorProcessor)1 WebAppClassLoader (org.eclipse.jetty.webapp.WebAppClassLoader)1