本文整理匯總了Java中javax.servlet.FilterRegistration.Dynamic方法的典型用法代碼示例。如果您正苦於以下問題:Java FilterRegistration.Dynamic方法的具體用法?Java FilterRegistration.Dynamic怎麽用?Java FilterRegistration.Dynamic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.FilterRegistration
的用法示例。
在下文中一共展示了FilterRegistration.Dynamic方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addDispatcherContext
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
private void addDispatcherContext(ServletContext container) {
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(SpringDispatcherConfig.class);
// Declare <servlet> and <servlet-mapping> for the DispatcherServlet
ServletRegistration.Dynamic dispatcher = container.addServlet("ch03-servlet",
new DispatcherServlet(dispatcherContext));
dispatcher.addMapping("*.html");
dispatcher.setLoadOnStartup(1);
FilterRegistration.Dynamic corsFilter = container.addFilter("corsFilter", new CorsFilter());
corsFilter.setInitParameter("cors.allowed.methods", "GET, POST, HEAD, OPTIONS, PUT, DELETE");
corsFilter.addMappingForUrlPatterns(null, true, "/*");
FilterRegistration.Dynamic filter = container.addFilter("hiddenmethodfilter", new HiddenHttpMethodFilter());
filter.addMappingForServletNames(null, true, "/*");
FilterRegistration.Dynamic multipartFilter = container.addFilter("multipartFilter", new MultipartFilter());
multipartFilter.addMappingForUrlPatterns(null, true, "/*");
}
示例2: initMetrics
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
/**
* Initializes Metrics.
*/
private void initMetrics(ServletContext servletContext, EnumSet<DispatcherType> disps) {
log.debug("Initializing Metrics registries");
servletContext.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE,
metricRegistry);
servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY,
metricRegistry);
log.debug("Registering Metrics Filter");
FilterRegistration.Dynamic metricsFilter = servletContext.addFilter("webappMetricsFilter",
new InstrumentedFilter());
metricsFilter.addMappingForUrlPatterns(disps, true, "/*");
metricsFilter.setAsyncSupported(true);
log.debug("Registering Metrics Servlet");
ServletRegistration.Dynamic metricsAdminServlet =
servletContext.addServlet("metricsServlet", new MetricsServlet());
metricsAdminServlet.addMapping("/management/metrics/*");
metricsAdminServlet.setAsyncSupported(true);
metricsAdminServlet.setLoadOnStartup(2);
}
示例3: addFilter
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
@Override
public FilterRegistration.Dynamic addFilter(final String filterName, final String className) {
ensureNotProgramaticListener();
ensureNotInitialized();
if (deploymentInfo.getFilters().containsKey(filterName)) {
return null;
}
try {
FilterInfo filter = new FilterInfo(filterName, (Class<? extends Filter>) deploymentInfo.getClassLoader().loadClass(className));
deploymentInfo.addFilter(filter);
deployment.getFilters().addFilter(filter);
return new FilterRegistrationImpl(filter, deployment, this);
} catch (ClassNotFoundException e) {
throw UndertowServletMessages.MESSAGES.cannotLoadClass(className, e);
}
}
示例4: onStartup
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
//If you want to use the XML configuration, comment the following two lines out.
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(ApplicationContext.class);
// rootContext.scan("com.pigdroid.social.config");
//If you want to use the XML configuration, uncomment the following lines.
//XmlWebApplicationContext rootContext = new XmlWebApplicationContext();
//rootContext.setConfigLocation("classpath:exampleApplicationContext.xml");
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);
EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter);
characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");
FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
security.addMappingForUrlPatterns(dispatcherTypes, true, "/*");
FilterRegistration.Dynamic sitemesh = servletContext.addFilter("sitemesh", new ConfigurableSiteMeshFilter());
sitemesh.addMappingForUrlPatterns(dispatcherTypes, true, "*.jsp");
servletContext.addListener(new ContextLoaderListener(rootContext));
}
示例5: run
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
@Override
public void run(final DeviceUsageTrackerConfig configuration, final Environment environment) {
ConfigurationHolder.set(configuration);
environment.jersey().register(DeviceResource.class);
environment.jersey().register(UserResource.class);
environment.jersey().register(ProfileResource.class);
environment.jersey().register(ClaimResource.class);
environment.jersey().register(DeviceSlackResource.class);
environment.jersey().register(DeviceClaimResource.class);
// JSON property naming
environment.getObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
environment.jersey().register(new CustomExceptionMapper());
// Enable CORS headers
final FilterRegistration.Dynamic cors = environment.servlets()
.addFilter("CORS", CrossOriginFilter.class);
// Configure CORS parameters
cors.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM,
"*");
cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM,
"X-Requested-With,Content-Type,Accept,Origin,Authorization");
cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM,
"OPTIONS,GET,PUT,POST,DELETE,HEAD");
// Add URL mapping
cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
// Auth
environment.jersey().register(
new AuthenticatorFeature(environment.metrics(), configuration.getAuthConfig()));
}
示例6: addFilter
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
@Override
public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass) {
if (SecurityUtil.isPackageProtectionEnabled()) {
return (FilterRegistration.Dynamic) doPrivileged("addFilter", new Class[] { String.class, Class.class },
new Object[] { filterName, filterClass });
} else {
return context.addFilter(filterName, filterClass);
}
}
示例7: addFilter
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
@Override
public FilterRegistration.Dynamic addFilter(String filterName,
String className) {
if (SecurityUtil.isPackageProtectionEnabled()) {
return (FilterRegistration.Dynamic) doPrivileged(
"addFilter", new Object[]{filterName, className});
} else {
return context.addFilter(filterName, className);
}
}
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:11,代碼來源:ApplicationContextFacade.java
示例8: addFilter
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
/**
* @since servlet-api-3.0
*/
@Override
public FilterRegistration.Dynamic addFilter(String filterName, Filter filter)
{
if (isStarted())
throw new IllegalStateException();
if (filterName == null || "".equals(filterName.trim()))
throw new IllegalStateException("Missing filter name");
if (!_enabled)
throw new UnsupportedOperationException();
final ServletHandler handler = ServletContextHandler.this.getServletHandler();
FilterHolder holder = handler.getFilter(filterName);
if (holder == null)
{
//new filter
holder = handler.newFilterHolder(Source.JAVAX_API);
holder.setName(filterName);
holder.setFilter(filter);
handler.addFilter(holder);
return holder.getRegistration();
}
if (holder.getClassName()==null && holder.getHeldClass()==null)
{
//preliminary filter registration completion
holder.setFilter(filter);
return holder.getRegistration();
}
else
return null; //existing filter
}
示例9: contextInitialized
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
@Override
public void contextInitialized(ServletContextEvent sce) {
FilterRegistration.Dynamic filterRegistration = sce.getServletContext()
.addFilter("BraveServletFilter", new TracingFilter(tracer));
// Explicit mapping to avoid trace on readiness probe
filterRegistration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/order");
}
示例10: installCorsFilter
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
private void installCorsFilter(Environment environment) {
FilterRegistration.Dynamic filter = environment.servlets().addFilter("CORSFilter", CrossOriginFilter.class);
filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, environment.getApplicationContext().getContextPath() + "*");
filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,OPTIONS");
filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
filter.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "Origin, Content-Type, Accept, Authorization");
filter.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, "true");
}
示例11: addFilter
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
/**
* Add filter to context.
* @param filterName Name of filter to add
* @param filterClass Name of filter class
* @return <code>null</code> if the filter has already been fully defined,
* else a {@link javax.servlet.FilterRegistration.Dynamic} object
* that can be used to further configure the filter
* @throws IllegalStateException if the context has already been initialised
* @throws UnsupportedOperationException - if this context was passed to the
* {@link ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)}
* method of a {@link ServletContextListener} that was not declared
* in web.xml, a web-fragment or annotated with
* {@link javax.servlet.annotation.WebListener}.
*/
@Override
public FilterRegistration.Dynamic addFilter(String filterName,
String filterClass) throws IllegalStateException {
return addFilter(filterName, filterClass, null);
}
示例12: addFilter
import javax.servlet.FilterRegistration; //導入方法依賴的package包/類
/**
* Add filter to context.
*
* @param filterName
* Name of filter to add
* @param filter
* Filter to add
* @return <code>null</code> if the filter has already been fully defined,
* else a {@link javax.servlet.FilterRegistration.Dynamic} object
* that can be used to further configure the filter
* @throws IllegalStateException
* if the context has already been initialised
* @throws UnsupportedOperationException
* - if this context was passed to the
* {@link ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)}
* method of a {@link ServletContextListener} that was not
* declared in web.xml, a web-fragment or annotated with
* {@link javax.servlet.annotation.WebListener}.
*/
@Override
public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) throws IllegalStateException {
return addFilter(filterName, null, filter);
}