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();
}
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();
}
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" });
}
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));
}
}
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()), "");
}
Aggregations