private static void mapFilterToServlet( FilterRegistration filterRegistration, ServletRegistration servletRegistration ) { EnumSet<DispatcherType> dispatcherType = EnumSet.of( DispatcherType.REQUEST ); String servletName = servletRegistration.getName(); filterRegistration.addMappingForServletNames( dispatcherType, false, servletName ); }
ServletContext sc = event.getServletContext(); // dynamically register servlet ServletRegistration.Dynamic reg = sc.addServlet("MyServlet", MyServlet.class); reg.addMapping("/MyUrl/*"); // register new servlet with an existing filter FilterRegistration fr = sc.getFilterRegistration("MyExistingFilterInWebXML"); EnumSet<DispatcherType> all = EnumSet.allOf(DispatcherType.class); fr.addMappingForServletNames(all, false, "MyServlet");
public static void loadProviderAndRegisterFilter(ServletContext context) { // Check for a user configured custom cache provider, or get default one CacheProvider cacheProvider = getCacheProvider(context); // Build a map of settings for either the custom- or the default cache provider and set them. cacheProvider.setParameters(getCacheSetting(context)); // Installs a filter that on demands buffers the response from the Faces Servlet, in order to grab child content // from the buffer. if (parseBoolean(context.getInitParameter(CACHE_INSTALL_BUFFER_FILTER))) { ServletRegistration facesServletRegistration = getFacesServletRegistration(context); FilterRegistration bufferFilterRegistration = context.addFilter(OnDemandResponseBufferFilter.class.getName(), OnDemandResponseBufferFilter.class); bufferFilterRegistration.addMappingForServletNames(null, true, facesServletRegistration.getName()); } }
Set<ServletSecurity> securitySet = ArgFactory.enumerateAnnotation(servletClass, ServletSecurity.class, HttpServlet.class); if(securitySet.size() > 0) { filter.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), false, e.getKey()); logger.debug("adding security to servlet " + e.getKey());
public static void loadProviderAndRegisterFilter(ServletContext context) { // Check for a user configured custom cache provider, or get default one CacheProvider cacheProvider = getCacheProvider(context); // Build a map of settings for either the custom- or the default cache provider and set them. cacheProvider.setParameters(getCacheSetting(context)); // Installs a filter that on demands buffers the response from the Faces Servlet, in order to grab child content // from the buffer. if (parseBoolean(context.getInitParameter(CACHE_INSTALL_BUFFER_FILTER))) { ServletRegistration facesServletRegistration = getFacesServletRegistration(context); FilterRegistration bufferFilterRegistration = context.addFilter(OnDemandResponseBufferFilter.class.getName(), OnDemandResponseBufferFilter.class); bufferFilterRegistration.addMappingForServletNames(null, true, facesServletRegistration.getName()); } }
String[] urlPatterns = element.elements("url-pattern").stream().map(Element::getTextTrim).toArray(String[]::new); if (servletNames.length > 0) { fReg.addMappingForServletNames(dispatcherTypes, true, servletNames);