Java Code Examples for javax.servlet.FilterRegistration#addMappingForUrlPatterns()

The following examples show how to use javax.servlet.FilterRegistration#addMappingForUrlPatterns() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InceptionWebInitializer.java    From inception with Apache License 2.0 6 votes vote down vote up
@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,
            "/*");
    
    aServletContext.addListener(HttpSessionEventPublisher.class);
}
 
Example 2
Source File: CamundaBpmRestInitializer.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
private FilterRegistration registerFilter(final String filterName, final Class<? extends Filter> filterClass, final Map<String, String> initParameters,
                                          final String... urlPatterns) {
  FilterRegistration filterRegistration = servletContext.getFilterRegistration(filterName);

  if (filterRegistration == null) {
    filterRegistration = servletContext.addFilter(filterName, filterClass);
    filterRegistration.addMappingForUrlPatterns(DISPATCHER_TYPES, true, urlPatterns);

    if (initParameters != null) {
      filterRegistration.setInitParameters(initParameters);
    }

    log.debug("Filter {} for URL {} registered.", filterName, urlPatterns);
  }

  return filterRegistration;
}
 
Example 3
Source File: CamundaBpmWebappInitializer.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
private FilterRegistration registerFilter(final String filterName, final Class<? extends Filter> filterClass, final Map<String, String> initParameters,
                                          final String... urlPatterns) {
  FilterRegistration filterRegistration = servletContext.getFilterRegistration(filterName);

  if (filterRegistration == null) {
    filterRegistration = servletContext.addFilter(filterName, filterClass);
    filterRegistration.addMappingForUrlPatterns(DISPATCHER_TYPES, true, urlPatterns);

    if (initParameters != null) {
      filterRegistration.setInitParameters(initParameters);
    }

    log.debug("Filter {} for URL {} registered.", filterName, urlPatterns);
  }

  return filterRegistration;
}
 
Example 4
Source File: WebAnnoWebInitializer.java    From webanno with Apache License 2.0 6 votes vote down vote up
@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,
            "/*");
    
    aServletContext.addListener(HttpSessionEventPublisher.class);
}
 
Example 5
Source File: WebAppConfiguration.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setServletContext(servletContext);
    rootContext.register(ThymeleafConfig.class);

    servletContext.addListener(new ToolListener());
    servletContext.addListener(new SakaiContextLoaderListener(rootContext));
    
    FilterRegistration requestFilterRegistration = servletContext.addFilter("sakai.request", RequestFilter.class);
    requestFilterRegistration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), true, "/*");
    requestFilterRegistration.setInitParameter(RequestFilter.CONFIG_UPLOAD_ENABLED, "true");       

    Dynamic servlet = servletContext.addServlet("sakai-site-group-manager", new DispatcherServlet(rootContext));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
 
Example 6
Source File: WebAppConfiguration.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setServletContext(servletContext);
    rootContext.register(ThymeleafConfig.class);

    servletContext.addListener(new ToolListener());
    servletContext.addListener(new SakaiContextLoaderListener(rootContext));
    
    FilterRegistration requestFilterRegistration = servletContext.addFilter("sakai.request", RequestFilter.class);
    requestFilterRegistration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), true, "/*");
    requestFilterRegistration.setInitParameter(RequestFilter.CONFIG_UPLOAD_ENABLED, "true");       

    Dynamic servlet = servletContext.addServlet("sakai-site-group-manager", new DispatcherServlet(rootContext));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
 
Example 7
Source File: CamundaBpmRestInitializer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private FilterRegistration registerFilter(final String filterName, final Class<? extends Filter> filterClass, final Map<String, String> initParameters,
                                          final String... urlPatterns) {
  FilterRegistration filterRegistration = servletContext.getFilterRegistration(filterName);

  if (filterRegistration == null) {
    filterRegistration = servletContext.addFilter(filterName, filterClass);
    filterRegistration.addMappingForUrlPatterns(DISPATCHER_TYPES, true, urlPatterns);

    if (initParameters != null) {
      filterRegistration.setInitParameters(initParameters);
    }

    log.debug("Filter {} for URL {} registered.", filterName, urlPatterns);
  }

  return filterRegistration;
}
 
Example 8
Source File: CamundaBpmWebappInitializer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private FilterRegistration registerFilter(final String filterName, final Class<? extends Filter> filterClass, final Map<String, String> initParameters,
                                          final String... urlPatterns) {
  FilterRegistration filterRegistration = servletContext.getFilterRegistration(filterName);

  if (filterRegistration == null) {
    filterRegistration = servletContext.addFilter(filterName, filterClass);
    filterRegistration.addMappingForUrlPatterns(DISPATCHER_TYPES, true, urlPatterns);

    if (initParameters != null) {
      filterRegistration.setInitParameters(initParameters);
    }

    log.debug("Filter {} for URL {} registered.", filterName, urlPatterns);
  }

  return filterRegistration;
}
 
Example 9
Source File: WicketWebInitializer.java    From wicket-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	
	String[] beanNamesForType = applicationContext.getBeanNamesForType(WicketBootWebApplication.class);
	if(beanNamesForType.length != 1){
		throw new IllegalStateException("Could not find exactly one bean for type WicketBootWebApplication " + beanNamesForType.length);
	}
	
	FilterRegistration filter = servletContext.addFilter(WICKET_FILTERNAME, wicketWebInitializerConfig.filterClass());

	// Spring configuration
	filter.setInitParameter(WicketFilter.APP_FACT_PARAM, SpringWebApplicationFactory.class.getName());
	filter.setInitParameter("applicationBean", beanNamesForType[0]);

	filter.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, props.getFilterMappingParam());
	filter.addMappingForUrlPatterns(EnumSet.copyOf( props.getDispatcherTypes() ), false, props.getFilterMappingParam());

	Map<String, String> initParameters = props.getInitParameters();
	for (Entry<String, String> initParam : initParameters.entrySet()) {
		filter.setInitParameter(initParam.getKey(), initParam.getValue());
	}
	
	
	wicketEndpointRepository.add(new WicketAutoConfig.Builder(this.getClass())
			.withDetail("wicketFilterName", WICKET_FILTERNAME)
			.withDetail("wicketFilterClass", wicketWebInitializerConfig.filterClass())
			.withDetail("properties", props)
			.build());
	
	
}
 
Example 10
Source File: WebInitializer.java    From spring-boot-example-wicket with Apache License 2.0 5 votes vote down vote up
@Override
  public void onStartup(ServletContext sc) throws ServletException {
      FilterRegistration filter = sc.addFilter("wicket-filter",
              WicketFilter.class);
      filter.setInitParameter(WicketFilter.APP_FACT_PARAM,
              SpringWebApplicationFactory.class.getName());
      filter.setInitParameter(PARAM_APP_BEAN, "wicketWebApplication");
// This line is the only surprise when comparing to the equivalent
      // web.xml. Without some initialization seems to be missing.
      filter.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
      filter.addMappingForUrlPatterns(null, false, "/*");
  }