Search in sources :

Example 1 with JasperInitializer

use of org.apache.jasper.servlet.JasperInitializer in project tomcat by apache.

the class TestGenerator method doTestTrimSpacesExtended.

private void doTestTrimSpacesExtended(boolean removeBlankLines) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp");
    Context ctxt = tomcat.addContext("", appDir.getAbsolutePath());
    ctxt.addServletContainerInitializer(new JasperInitializer(), null);
    Tomcat.initWebappDefaults(ctxt);
    Wrapper w = (Wrapper) ctxt.findChild("jsp");
    if (removeBlankLines) {
        w.addInitParameter("trimSpaces", "extended");
    }
    tomcat.start();
    ByteChunk res = getUrl("http://localhost:" + getPort() + "/jsp/trim-spaces-extended.jsp");
    String result = res.toString();
    Scanner scanner = new Scanner(result);
    int blankLineCount = 0;
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        if (line.length() == 0) {
            blankLineCount++;
        }
    }
    if (!removeBlankLines && blankLineCount == 0) {
        Assert.fail("TrimSpaceOptions.EXTENDED not configured but balnk lines have been removed");
    } else if (removeBlankLines && blankLineCount > 0) {
        Assert.fail("TrimSpaceOptions.EXTENDED does not allow the line to be just a new line character");
    }
    scanner.close();
}
Also used : Context(org.apache.catalina.Context) PageContext(jakarta.servlet.jsp.PageContext) Wrapper(org.apache.catalina.Wrapper) Scanner(java.util.Scanner) Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) File(java.io.File) JasperInitializer(org.apache.jasper.servlet.JasperInitializer)

Example 2 with JasperInitializer

use of org.apache.jasper.servlet.JasperInitializer in project tomcat by apache.

the class TestDefaultInstanceManager method doClassUnloadingPrep.

private DefaultInstanceManager doClassUnloadingPrep() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // Create the context (don't use addWebapp as we want to modify the
    // JSP Servlet settings).
    File appDir = new File("test/webapp");
    StandardContext ctxt = (StandardContext) tomcat.addContext(null, "/test", appDir.getAbsolutePath());
    ctxt.addServletContainerInitializer(new JasperInitializer(), null);
    // Configure the defaults and then tweak the JSP servlet settings
    // Note: Min value for maxLoadedJsps is 2
    Tomcat.initWebappDefaults(ctxt);
    Wrapper w = (Wrapper) ctxt.findChild("jsp");
    w.addInitParameter("maxLoadedJsps", "2");
    tomcat.start();
    return (DefaultInstanceManager) ctxt.getInstanceManager();
}
Also used : Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) File(java.io.File) JasperInitializer(org.apache.jasper.servlet.JasperInitializer)

Example 3 with JasperInitializer

use of org.apache.jasper.servlet.JasperInitializer in project Openfire by igniterealtime.

the class AdminConsolePlugin method createWebAppContext.

private void createWebAppContext() {
    contexts = new ContextHandlerCollection();
    WebAppContext context = new WebAppContext(contexts, pluginDir.getAbsoluteFile() + File.separator + "webapp", "/");
    // Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
    final List<ContainerInitializer> initializers = new ArrayList<>();
    initializers.add(new ContainerInitializer(new JasperInitializer(), null));
    context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
    context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    context.setConfigurations(new Configuration[] { new AnnotationConfiguration(), new WebInfConfiguration(), new WebXmlConfiguration(), new MetaInfConfiguration(), new FragmentConfiguration(), new EnvConfiguration(), new PlusConfiguration(), new JettyWebXmlConfiguration() });
    final URL classes = getClass().getProtectionDomain().getCodeSource().getLocation();
    context.getMetaData().setWebInfClassesDirs(Collections.singletonList(Resource.newResource(classes)));
    // The index.html includes a redirect to the index.jsp and doesn't bypass
    // the context security when in development mode
    context.setWelcomeFiles(new String[] { "index.html" });
}
Also used : WebXmlConfiguration(org.eclipse.jetty.webapp.WebXmlConfiguration) JettyWebXmlConfiguration(org.eclipse.jetty.webapp.JettyWebXmlConfiguration) WebInfConfiguration(org.eclipse.jetty.webapp.WebInfConfiguration) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) InstanceManager(org.apache.tomcat.InstanceManager) PlusConfiguration(org.eclipse.jetty.plus.webapp.PlusConfiguration) ArrayList(java.util.ArrayList) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) JettyWebXmlConfiguration(org.eclipse.jetty.webapp.JettyWebXmlConfiguration) URL(java.net.URL) EnvConfiguration(org.eclipse.jetty.plus.webapp.EnvConfiguration) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) MetaInfConfiguration(org.eclipse.jetty.webapp.MetaInfConfiguration) ContainerInitializer(org.eclipse.jetty.plus.annotation.ContainerInitializer) FragmentConfiguration(org.eclipse.jetty.webapp.FragmentConfiguration) AnnotationConfiguration(org.eclipse.jetty.annotations.AnnotationConfiguration) JasperInitializer(org.apache.jasper.servlet.JasperInitializer)

Example 4 with JasperInitializer

use of org.apache.jasper.servlet.JasperInitializer in project Openfire by igniterealtime.

the class HttpBindManager method createBoshHandler.

private void createBoshHandler(ContextHandlerCollection contexts, String boshPath) {
    ServletContextHandler context = new ServletContextHandler(contexts, boshPath, ServletContextHandler.SESSIONS);
    // Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
    final List<ContainerInitializer> initializers = new ArrayList<>();
    initializers.add(new ContainerInitializer(new JasperInitializer(), null));
    context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
    context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    context.setAllowNullPathInfo(true);
    context.addServlet(new ServletHolder(new HttpBindServlet()), "/*");
    if (isHttpCompressionEnabled()) {
        Filter gzipFilter = new AsyncGzipFilter() {

            @Override
            public void init(FilterConfig config) throws ServletException {
                super.init(config);
                _methods.add(HttpMethod.POST.asString());
                Log.info("Installed response compression filter");
            }
        };
        FilterHolder filterHolder = new FilterHolder();
        filterHolder.setFilter(gzipFilter);
        context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) AsyncGzipFilter(org.eclipse.jetty.servlets.AsyncGzipFilter) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) InstanceManager(org.apache.tomcat.InstanceManager) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) Filter(javax.servlet.Filter) AsyncGzipFilter(org.eclipse.jetty.servlets.AsyncGzipFilter) ContainerInitializer(org.eclipse.jetty.plus.annotation.ContainerInitializer) FilterConfig(javax.servlet.FilterConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) JasperInitializer(org.apache.jasper.servlet.JasperInitializer)

Example 5 with JasperInitializer

use of org.apache.jasper.servlet.JasperInitializer in project Openfire by igniterealtime.

the class HttpBindManager method createCrossDomainHandler.

private void createCrossDomainHandler(ContextHandlerCollection contexts, String crossPath) {
    ServletContextHandler context = new ServletContextHandler(contexts, crossPath, ServletContextHandler.SESSIONS);
    // Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
    final List<ContainerInitializer> initializers = new ArrayList<>();
    initializers.add(new ContainerInitializer(new JasperInitializer(), null));
    context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
    context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    context.setAllowNullPathInfo(true);
    context.addServlet(new ServletHolder(new FlashCrossDomainServlet()), "");
}
Also used : SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) InstanceManager(org.apache.tomcat.InstanceManager) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ContainerInitializer(org.eclipse.jetty.plus.annotation.ContainerInitializer) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) JasperInitializer(org.apache.jasper.servlet.JasperInitializer) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager)

Aggregations

JasperInitializer (org.apache.jasper.servlet.JasperInitializer)9 InstanceManager (org.apache.tomcat.InstanceManager)5 SimpleInstanceManager (org.apache.tomcat.SimpleInstanceManager)5 ContainerInitializer (org.eclipse.jetty.plus.annotation.ContainerInitializer)5 File (java.io.File)4 Tomcat (org.apache.catalina.startup.Tomcat)4 Wrapper (org.apache.catalina.Wrapper)3 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 Context (org.apache.catalina.Context)2 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)2 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)2 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)2 EmailScheduler (com.ifsoft.jmxweb.plugin.EmailScheduler)1 CoreThreadPool (com.javamonitor.openfire.mbeans.CoreThreadPool)1 DatabasePool (com.javamonitor.openfire.mbeans.DatabasePool)1 Openfire (com.javamonitor.openfire.mbeans.Openfire)1 PacketCounter (com.javamonitor.openfire.mbeans.PacketCounter)1 ServletContext (jakarta.servlet.ServletContext)1 PageContext (jakarta.servlet.jsp.PageContext)1