Example usage for javax.servlet ServletContext getFilterRegistration

List of usage examples for javax.servlet ServletContext getFilterRegistration

Introduction

In this page you can find the example usage for javax.servlet ServletContext getFilterRegistration.

Prototype

public FilterRegistration getFilterRegistration(String filterName);

Source Link

Document

Gets the FilterRegistration corresponding to the filter with the given filterName.

Usage

From source file:net.bull.javamelody.JavaMelodyAutoConfiguration.java

/**
 * Registers the JavaMelody {@link SessionListener}.
 * @param servletContext ServletContext/*from   w w w .j a v  a  2 s . co  m*/
 * @return ServletListenerRegistrationBean
 */
@Bean
public ServletListenerRegistrationBean<EventListener> monitoringSessionListener(ServletContext servletContext) {
    final ServletListenerRegistrationBean<EventListener> servletListenerRegistrationBean = new ServletListenerRegistrationBean<EventListener>(
            new SessionListener());
    if (servletContext.getFilterRegistration("javamelody") != null) {
        // if webapp deployed as war in a container with MonitoringFilter and SessionListener already added by web-fragment.xml,
        // do not add again
        servletListenerRegistrationBean.setEnabled(false);
    }
    return servletListenerRegistrationBean;
}

From source file:org.obiba.mica.config.WebConfiguration.java

/**
 * Initializes the GZip filter./*from  ww  w . j a v a  2 s . c  o  m*/
 */
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);
}

From source file:net.bull.javamelody.JavaMelodyAutoConfiguration.java

/**
 * Registers the JavaMelody {@link MonitoringFilter}. The filter can be overridden completely by creating a custom
 * {@link FilterRegistrationBean} with the name "javamelody-registration" in the application context.
 * @param properties JavaMelodyConfigurationProperties
 * @param servletContext ServletContext/* ww  w  .  j  a  v  a2s  .c o  m*/
 * @return FilterRegistrationBean
 */
@Bean(name = REGISTRATION_BEAN_NAME)
@ConditionalOnMissingBean(name = REGISTRATION_BEAN_NAME)
public FilterRegistrationBean monitoringFilter(JavaMelodyConfigurationProperties properties,
        ServletContext servletContext) {
    final FilterRegistrationBean registrationBean = new FilterRegistrationBean();

    // Create the monitoring filter and set its configuration parameters.
    final MonitoringFilter filter = new MonitoringFilter();
    filter.setApplicationType("Spring Boot");

    // Wrap the monitoring filter in the registration bean.
    registrationBean.setFilter(filter);
    registrationBean.setAsyncSupported(true);
    registrationBean.setName("javamelody");
    registrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);

    // Set the initialization parameter for the monitoring filter.
    for (final Entry<String, String> parameter : properties.getInitParameters().entrySet()) {
        registrationBean.addInitParameter(parameter.getKey(), parameter.getValue());
    }

    // Set the URL patterns to activate the monitoring filter for.
    registrationBean.addUrlPatterns("/*");

    final FilterRegistration filterRegistration = servletContext.getFilterRegistration("javamelody");
    if (filterRegistration != null) {
        // if webapp deployed as war in a container with MonitoringFilter already added by web-fragment.xml,
        // do not try to add it again
        registrationBean.setEnabled(false);
        for (final Map.Entry<String, String> entry : registrationBean.getInitParameters().entrySet()) {
            filterRegistration.setInitParameter(entry.getKey(), entry.getValue());
        }
    }
    return registrationBean;
}

From source file:org.openmrs.module.uiframework.UrlMappingsRegistrar.java

@Override
public void setServletContext(ServletContext servletContext) {
    log.debug("Registering URL mappings");

    //Dynamic servlet registration can only be done once i.e. at application startup
    //In theory it means this module can only be installed at application startup
    if (!skipAddMappings) {
        servletContext.getServletRegistration("openmrs").addMapping("*.page", "*.action");
        servletContext.getFilterRegistration("compressionFilter").addMappingForUrlPatterns(null, true, "*.page",
                "*.action");
        skipAddMappings = true;/*from  ww  w  .  j  a  va  2s . c o m*/
    }
}