@Bean public EmbeddedServletContainerCustomizer cookieProcessorCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) container; factory.addContextCustomizers(new TomcatContextCustomizer() { @Override public void customize(Context context) { context.setCookieProcessor(new LegacyCookieProcessor()); } }); } } }; }
@Test public void redirectContextRootCanBeConfigured() throws Exception { Map<String, String> map = new HashMap<String, String>(); map.put("server.tomcat.redirect-context-root", "false"); bindProperties(map); ServerProperties.Tomcat tomcat = this.properties.getTomcat(); assertThat(tomcat.getRedirectContextRoot()).isEqualTo(false); TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); this.properties.customize(container); Context context = mock(Context.class); for (TomcatContextCustomizer customizer : container .getTomcatContextCustomizers()) { customizer.customize(context); } verify(context).setMapperContextRootRedirectEnabled(false); }
@Bean public EmbeddedServletContainerCustomizer customizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container; TomcatContextCustomizer contextCustomizer = new TomcatContextCustomizer() { @Override public void customize(Context context) { context.setCookieProcessor(new LegacyCookieProcessor()); } }; tomcat.addContextCustomizers(contextCustomizer); } }; }
@Bean public EmbeddedServletContainerFactory servletContainer() { TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); MockService config = MockService.getInstance(); factory.setPort(config.getPort()); factory.setSessionTimeout(10, TimeUnit.MINUTES); factory.addContextCustomizers(new TomcatContextCustomizer() { @Override public void customize(Context context) { JarScanner jarScanner = new JarScanner() { @Override public void scan(ServletContext arg0, ClassLoader arg1, JarScannerCallback arg2, Set<String> arg3) { } }; context.setJarScanner(jarScanner); } }); return factory; }
@Bean public EmbeddedServletContainerCustomizer containerCustomizer() { if (highAvailability) { logger.info("Setting up high availability configuration"); return factory -> { logger.info("Customizing Tomcat container"); TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) factory; TomcatContextCustomizer tomcatContextCustomizer = context -> { context.setSessionTimeout(30); context.setManager(new MemcachedBackupSessionManager() {{ setMemcachedNodes(nodes); setFailoverNodes(failover); setRequestUriIgnorePattern(".*\\.(ico|png|gif|jpg|css|js)$"); }}); }; containerFactory.setTomcatContextCustomizers(Collections.singletonList(tomcatContextCustomizer)); setMimeMappings(factory); }; } else { logger.info("Skipping HA configuration"); return this::setMimeMappings; } }
public static void configure(TomcatEmbeddedServletContainerFactory tomcatFactory) { tomcatFactory.addContextCustomizers((TomcatContextCustomizer) context -> { boolean development = (System.getProperty("airsonic.development") != null); // Increase the size and time before eviction of the Tomcat // cache so that resources aren't uncompressed too often. // See https://github.com/jhipster/generator-jhipster/issues/3995 StandardRoot resources = new StandardRoot(); if (development) { resources.setCachingAllowed(false); } else { resources.setCacheMaxSize(100000); resources.setCacheObjectMaxSize(4000); resources.setCacheTtl(24 * 3600 * 1000); // 1 day, in milliseconds } context.setResources(resources); // Put Jasper in production mode so that JSP aren't recompiled // on each request. // See http://stackoverflow.com/questions/29653326/spring-boot-application-slow-because-of-jsp-compilation Container jsp = context.findChild("jsp"); if (jsp instanceof Wrapper) { ((Wrapper) jsp).addInitParameter("development", Boolean.toString(development)); } }); }
private void customizeBackgroundProcessorDelay( TomcatEmbeddedServletContainerFactory factory) { factory.addContextCustomizers(new TomcatContextCustomizer() { @Override public void customize(Context context) { context.setBackgroundProcessorDelay( Tomcat.this.backgroundProcessorDelay); } }); }
private void customizeRedirectContextRoot( TomcatEmbeddedServletContainerFactory factory, final boolean redirectContextRoot) { factory.addContextCustomizers(new TomcatContextCustomizer() { @Override public void customize(Context context) { context.setMapperContextRootRedirectEnabled(redirectContextRoot); } }); }
@Override public void doCustomize(TomcatEmbeddedServletContainerFactory tomcatContainer) { tomcatContainer.addContextCustomizers(new TomcatContextCustomizer() { @Override public void customize(Context context) { addListener(context, findListenerType()); } }); }
@Bean public TomcatContextCustomizer tomcatContextCustomizer() { return new TomcatContextCustomizer() { @Override public void customize(Context context) { context.addApplicationListener("org.apache.tomcat.websocket.server.WsContextListener"); } }; }
@Bean public TomcatEmbeddedServletContainerFactory factory() { TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory(); tomcatEmbeddedServletContainerFactory.addContextCustomizers((TomcatContextCustomizer) (Context context) -> { context.addServletContainerInitializer(new JasperInitializer(), Collections.<Class<?>> emptySet()); }); return tomcatEmbeddedServletContainerFactory; }
@Bean public EmbeddedServletContainerCustomizer servletContainerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { customizeTomcat((TomcatEmbeddedServletContainerFactory)container); } } private void customizeTomcat(TomcatEmbeddedServletContainerFactory tomcatFactory) { tomcatFactory.addContextCustomizers(new TomcatContextCustomizer() { @Override public void customize(Context context) { Container jsp = context.findChild("jsp"); if (jsp instanceof Wrapper) { ((Wrapper)jsp).addInitParameter("development", "false"); } } }); } }; }
@Bean public TomcatEmbeddedServletContainerFactory tomcatContainerFactory() { TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); factory.setTomcatContextCustomizers( Arrays.asList(new TomcatContextCustomizer[] { tomcatContextCustomizer() })); return factory; }
@Bean public TomcatContextCustomizer tomcatContextCustomizer() { return new TomcatContextCustomizer() { @Override public void customize(Context context) { context.addServletContainerInitializer(new WsSci(), null); } }; }