Search in sources :

Example 11 with FilterRegistration

use of javax.servlet.FilterRegistration in project webanno by webanno.

the class WebAnnoWebInitializer method onStartup.

@Override
public void onStartup(ServletContext aServletContext) throws ServletException {
    // 2) Make username accessible to logging framework
    FilterRegistration loggingFilter = aServletContext.addFilter("logging", LoggingFilter.class);
    loggingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
    // 5) Make sure we have one JPA session/transaction per request. Closes session at the
    // end, without this, changed data may not be automatically saved to the DB.
    FilterRegistration openSessionInViewFilter = aServletContext.addFilter("opensessioninview", OpenEntityManagerInViewFilter.class);
    openSessionInViewFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
}
Also used : FilterRegistration(javax.servlet.FilterRegistration)

Example 12 with FilterRegistration

use of javax.servlet.FilterRegistration in project herd by FINRAOS.

the class WarInitializer method initCharacterEncodingFilter.

/**
 * Initializes the character encoding filter which provides UTF-8 encoding.
 *
 * @param servletContext the servlet context.
 */
protected void initCharacterEncodingFilter(ServletContext servletContext) {
    // Add a filter that encodes incoming requests and outgoing responses with UTF-8 encoding.
    FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter());
    filterRegistration.setInitParameter("encoding", StandardCharsets.UTF_8.name());
    filterRegistration.setInitParameter("forceEncoding", "true");
    filterRegistration.addMappingForUrlPatterns(null, true, "/*");
}
Also used : CharacterEncodingFilter(org.springframework.web.filter.CharacterEncodingFilter) FilterRegistration(javax.servlet.FilterRegistration)

Example 13 with FilterRegistration

use of javax.servlet.FilterRegistration in project mica2 by obiba.

the class WebConfiguration method initGzipFilter.

/**
 * Initializes the GZip filter.
 */
private void initGzipFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Registering GZip Filter");
    FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("gzipFilter", new GzipFilter());
    if (filterRegistration == null) {
        filterRegistration = (FilterRegistration.Dynamic) servletContext.getFilterRegistration("gzipFilter");
    }
    filterRegistration.addMappingForUrlPatterns(disps, true, "*.css");
    filterRegistration.addMappingForUrlPatterns(disps, true, "*.json");
    filterRegistration.addMappingForUrlPatterns(disps, true, "*.html");
    filterRegistration.addMappingForUrlPatterns(disps, true, "*.js");
    filterRegistration.addMappingForUrlPatterns(disps, true, "/jvm/*");
    filterRegistration.addMappingForUrlPatterns(disps, true, WS_ROOT + "/*");
    filterRegistration.setAsyncSupported(true);
}
Also used : GzipFilter(org.eclipse.jetty.servlets.GzipFilter) FilterRegistration(javax.servlet.FilterRegistration)

Example 14 with FilterRegistration

use of javax.servlet.FilterRegistration in project tutorials by eugenp.

the class SpringBootWithServletComponentIntegrationTest method givenServletContext_whenCheckHelloFilterMappings_thenCorrect.

@Test
public void givenServletContext_whenCheckHelloFilterMappings_thenCorrect() {
    assertNotNull(servletContext);
    FilterRegistration filterRegistration = servletContext.getFilterRegistration("hello filter");
    assertNotNull(filterRegistration);
    assertTrue(filterRegistration.getServletNameMappings().contains("echo servlet"));
}
Also used : FilterRegistration(javax.servlet.FilterRegistration) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with FilterRegistration

use of javax.servlet.FilterRegistration in project jodd by oblac.

the class JoyContextListener method configureServletContext.

/**
 * Configures servlet context.
 */
private void configureServletContext(final ServletContext servletContext) {
    servletContext.addListener(jodd.servlet.RequestContextListener.class);
    if (decoraEnabled) {
        final FilterRegistration filter = servletContext.addFilter("decora", jodd.decora.DecoraServletFilter.class);
        filter.addMappingForUrlPatterns(null, true, contextPath);
    }
    final FilterRegistration filter = servletContext.addFilter("madvoc", jodd.madvoc.MadvocServletFilter.class);
    filter.addMappingForUrlPatterns(madvocDispatcherTypes, true, contextPath);
}
Also used : FilterRegistration(javax.servlet.FilterRegistration)

Aggregations

FilterRegistration (javax.servlet.FilterRegistration)16 Test (org.junit.Test)5 ServletRegistration (javax.servlet.ServletRegistration)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 URL (java.net.URL)3 URLConnection (java.net.URLConnection)3 SpringWebApplicationFactory (org.apache.wicket.spring.SpringWebApplicationFactory)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 HttpSessionEventPublisher (org.springframework.security.web.session.HttpSessionEventPublisher)2 RequestContextListener (org.springframework.web.context.request.RequestContextListener)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HttpConstraintElement (javax.servlet.HttpConstraintElement)1 ServletContext (javax.servlet.ServletContext)1 ServletSecurityElement (javax.servlet.ServletSecurityElement)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)1