Search in sources :

Example 6 with Dynamic

use of javax.servlet.FilterRegistration.Dynamic in project alf.io by alfio-event.

the class Initializer method onStartup.

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    super.onStartup(servletContext);
    Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
    configureSessionCookie(servletContext);
    CharacterEncodingFilter cef = new CharacterEncodingFilter();
    cef.setEncoding("UTF-8");
    cef.setForceEncoding(true);
    Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter", cef);
    characterEncodingFilter.setAsyncSupported(true);
    characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");
    // force log initialization, then disable it
    XRLog.setLevel(XRLog.EXCEPTION, Level.WARNING);
    XRLog.setLoggingEnabled(false);
}
Also used : Dynamic(javax.servlet.FilterRegistration.Dynamic) CharacterEncodingFilter(org.springframework.web.filter.CharacterEncodingFilter) DefaultExceptionHandler(alfio.util.DefaultExceptionHandler)

Example 7 with Dynamic

use of javax.servlet.FilterRegistration.Dynamic in project spring-session by spring-projects.

the class Initializer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    this.instance = createHazelcastInstance();
    Map<String, Session> sessions = this.instance.getMap(SESSION_MAP_NAME);
    MapSessionRepository sessionRepository = new MapSessionRepository(sessions);
    SessionRepositoryFilter<? extends Session> filter = new SessionRepositoryFilter<>(sessionRepository);
    Dynamic fr = sce.getServletContext().addFilter("springSessionFilter", filter);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}
Also used : Dynamic(javax.servlet.FilterRegistration.Dynamic) MapSessionRepository(org.springframework.session.MapSessionRepository) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) SessionRepositoryFilter(org.springframework.session.web.http.SessionRepositoryFilter)

Example 8 with Dynamic

use of javax.servlet.FilterRegistration.Dynamic in project spring-session by spring-projects.

the class AbstractHttpSessionApplicationInitializer method registerFilter.

/**
 * Registers the provided filter using the {@link #isAsyncSessionSupported()} and
 * {@link #getSessionDispatcherTypes()}.
 *
 * @param servletContext the servlet context
 * @param insertBeforeOtherFilters should this Filter be inserted before or after
 * other {@link Filter}
 * @param filterName the filter name
 * @param filter the filter
 */
private void registerFilter(ServletContext servletContext, boolean insertBeforeOtherFilters, String filterName, Filter filter) {
    Dynamic registration = servletContext.addFilter(filterName, filter);
    if (registration == null) {
        throw new IllegalStateException("Duplicate Filter registration for '" + filterName + "'. Check to ensure the Filter is only configured once.");
    }
    registration.setAsyncSupported(isAsyncSessionSupported());
    EnumSet<DispatcherType> dispatcherTypes = getSessionDispatcherTypes();
    registration.addMappingForUrlPatterns(dispatcherTypes, !insertBeforeOtherFilters, "/*");
}
Also used : Dynamic(javax.servlet.FilterRegistration.Dynamic) DispatcherType(javax.servlet.DispatcherType)

Example 9 with Dynamic

use of javax.servlet.FilterRegistration.Dynamic in project newts by OpenNMS.

the class NewtsService method configureCors.

// Copy-pasta from http://jitterted.com/tidbits/2014/09/12/cors-for-dropwizard-0-7-x/
private void configureCors(Environment environment) {
    Dynamic filter = environment.servlets().addFilter("CORS", CrossOriginFilter.class);
    filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,DELETE,OPTIONS");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
    filter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
    filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin");
    filter.setInitParameter("allowCredentials", "true");
}
Also used : Dynamic(javax.servlet.FilterRegistration.Dynamic) DispatcherType(javax.servlet.DispatcherType)

Example 10 with Dynamic

use of javax.servlet.FilterRegistration.Dynamic in project brave by openzipkin.

the class ITSpanCustomizingApplicationEventListener method init.

@Override
public void init(ServletContextHandler handler) {
    ResourceConfig config = new ResourceConfig();
    config.register(new TestResource(httpTracing));
    config.register(SpanCustomizingApplicationEventListener.create());
    handler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
    // add the underlying servlet tracing filter which the event listener decorates with more tags
    Dynamic filterRegistration = handler.getServletContext().addFilter("tracingFilter", TracingFilter.create(httpTracing));
    filterRegistration.setAsyncSupported(true);
    // isMatchAfter=true is required for async tests to pass!
    filterRegistration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}
Also used : Dynamic(javax.servlet.FilterRegistration.Dynamic) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ITServletContainer(brave.test.http.ITServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) DispatcherType(javax.servlet.DispatcherType)

Aggregations

Dynamic (javax.servlet.FilterRegistration.Dynamic)10 DispatcherType (javax.servlet.DispatcherType)5 ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)3 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)3 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 DefaultExceptionHandler (alfio.util.DefaultExceptionHandler)1 ITServletContainer (brave.test.http.ITServletContainer)1 Tracer (io.opentracing.Tracer)1 TracingFilter (io.opentracing.contrib.web.servlet.filter.TracingFilter)1 GlobalTracer (io.opentracing.util.GlobalTracer)1 ServletContext (javax.servlet.ServletContext)1 ServletRegistration (javax.servlet.ServletRegistration)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 MapSession (org.springframework.session.MapSession)1 MapSessionRepository (org.springframework.session.MapSessionRepository)1 Session (org.springframework.session.Session)1 SessionRepositoryFilter (org.springframework.session.web.http.SessionRepositoryFilter)1