當前位置: 首頁>>代碼示例>>Java>>正文


Java FilterRegistration類代碼示例

本文整理匯總了Java中javax.servlet.FilterRegistration的典型用法代碼示例。如果您正苦於以下問題:Java FilterRegistration類的具體用法?Java FilterRegistration怎麽用?Java FilterRegistration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FilterRegistration類屬於javax.servlet包,在下文中一共展示了FilterRegistration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onStartup

import javax.servlet.FilterRegistration; //導入依賴的package包/類
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	//register config classes
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.register(WebMvcConfig.class);
	rootContext.register(JPAConfig.class);
	rootContext.register(WebSecurityConfig.class);
	rootContext.register(ServiceConfig.class);
	//set session timeout
	servletContext.addListener(new SessionListener(maxInactiveInterval));
	//set dispatcher servlet and mapping
	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
			new DispatcherServlet(rootContext));
	dispatcher.addMapping("/");
	dispatcher.setLoadOnStartup(1);
	
	//register filters
	FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("endcodingFilter", new CharacterEncodingFilter());
	filterRegistration.setInitParameter("encoding", "UTF-8");
	filterRegistration.setInitParameter("forceEncoding", "true");
	//make sure encodingFilter is matched first
	filterRegistration.addMappingForUrlPatterns(null, false, "/*");
	//disable appending jsessionid to the URL
	filterRegistration = servletContext.addFilter("disableUrlSessionFilter", new DisableUrlSessionFilter());
	filterRegistration.addMappingForUrlPatterns(null, true, "/*");
}
 
開發者ID:Azanx,項目名稱:Smart-Shopping,代碼行數:27,代碼來源:WebMvcInitialiser.java

示例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);
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:26,代碼來源:WebConfigurer.java

示例3: contextInitialized

import javax.servlet.FilterRegistration; //導入依賴的package包/類
@Override
public void contextInitialized(ServletContextEvent sce) {

    ServletContext ctx = sce.getServletContext();

    ServletRegistration.Dynamic sd = ctx.addServlet("DynamicServlet",
            "com.creditease.monitorframework.fat.DynamicServlet");

    sd.addMapping("/DynamicServlet");
    sd.setInitParameter("test", "test");
    sd.setLoadOnStartup(1);
    sd.setAsyncSupported(false);

    FilterRegistration.Dynamic fd = ctx.addFilter("DynamicFilter",
            "com.creditease.monitorframework.fat.filters.DynamicFilter");

    fd.addMappingForUrlPatterns(null, true, "/DynamicServlet");
    fd.setInitParameter("test2", "test2");
    fd.setAsyncSupported(false);

    ctx.addListener("com.creditease.monitorframework.fat.listeners.TestServletInitListener");
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:23,代碼來源:DynamicServletInit.java

示例4: collectDynInfo

import javax.servlet.FilterRegistration; //導入依賴的package包/類
public void collectDynInfo(String methodName, Object res, Object[] args) {

        if (methodName.equals("addServlet")) {

            servlets.add((ServletRegistration.Dynamic) res);
        }
        else if (methodName.equals("addFilter")) {

            filters.add((FilterRegistration.Dynamic) res);
        }
        else if (methodName.equals("addListener")) {

            String listenerClassName;
            if (args[0].getClass().isAssignableFrom(String.class)) {
                listenerClassName = args[0].toString();
            }
            else if (args[0].getClass().isAssignableFrom(Class.class)) {
                listenerClassName = ((Class<?>) args[0]).getName();
            }
            else {
                listenerClassName = args[0].getClass().getName();
            }

            listeners.add(listenerClassName);
        }
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:27,代碼來源:DynamicServletContextProcessor.java

示例5: 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, "/*");

}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:23,代碼來源:SpringWebInitializer.java

示例6: onStartup

import javax.servlet.FilterRegistration; //導入依賴的package包/類
/**
 * Configure the given {@link ServletContext} with any servlets, filters, listeners
 * context-params and attributes necessary for initializing this web application. See examples
 * {@linkplain WebApplicationInitializer above}.
 *
 * @param servletContext the {@code ServletContext} to initialize
 * @throws ServletException if any call against the given {@code ServletContext} throws a {@code ServletException}
 */
public void onStartup(ServletContext servletContext) throws ServletException {
	// Spring Context Bootstrapping
	AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
	rootAppContext.register(AutoPivotConfig.class);
	servletContext.addListener(new ContextLoaderListener(rootAppContext));

	// Set the session cookie name. Must be done when there are several servers (AP,
	// Content server, ActiveMonitor) with the same URL but running on different ports.
	// Cookies ignore the port (See RFC 6265).
	CookieUtil.configure(servletContext.getSessionCookieConfig(), CookieUtil.COOKIE_NAME);

	// The main servlet/the central dispatcher
	final DispatcherServlet servlet = new DispatcherServlet(rootAppContext);
	servlet.setDispatchOptionsRequest(true);
	Dynamic dispatcher = servletContext.addServlet("springDispatcherServlet", servlet);
	dispatcher.addMapping("/*");
	dispatcher.setLoadOnStartup(1);

	// Spring Security Filter
	final FilterRegistration.Dynamic springSecurity = servletContext.addFilter(SPRING_SECURITY_FILTER_CHAIN, new DelegatingFilterProxy());
	springSecurity.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

}
 
開發者ID:activeviam,項目名稱:autopivot,代碼行數:32,代碼來源:AutoPivotWebAppInitializer.java

示例7: 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);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:ServletContextImpl.java

示例8: run

import javax.servlet.FilterRegistration; //導入依賴的package包/類
@Override
public void run(@Nonnull final GraphiakConfiguration configuration,
        @Nonnull final Environment environment) throws Exception {

    // Enable CORS
    final FilterRegistration.Dynamic cors = environment.servlets()
            .addFilter("cors", CrossOriginFilter.class);
    cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true,
            "/*");

    // get Riak client
    final RiakClient client = configuration.getRiak().build();

    final MetricStore store = new MetricStore(client);
    environment.lifecycle().manage(new MetricStoreManager(store));

    // Configure the Netty TCP server
    configuration.getNetty().build(environment, store);

    // Resources
    environment.jersey().register(new DashboardResource());
    environment.jersey().register(new MetricsResource(store));
    environment.jersey().register(new EventsResource());
    environment.jersey().register(new PingResource());
    environment.jersey().register(new VersionResource());
}
 
開發者ID:smoketurner,項目名稱:graphiak,代碼行數:27,代碼來源:GraphiakApplication.java

示例9: getFilterRegistrations

import javax.servlet.FilterRegistration; //導入依賴的package包/類
@Override
public Map<String, ? extends FilterRegistration> getFilterRegistrations()
{
    if (!_enabled)
        throw new UnsupportedOperationException();

    HashMap<String, FilterRegistration> registrations = new HashMap<String, FilterRegistration>();
    ServletHandler handler=ServletContextHandler.this.getServletHandler();
    FilterHolder[] holders=handler.getFilters();
    if (holders!=null)
    {
        for (FilterHolder holder : holders)
            registrations.put(holder.getName(),holder.getRegistration());
    }
    return registrations;
}
 
開發者ID:xiaomin0322,項目名稱:marathon-auth-plugin,代碼行數:17,代碼來源:ServletContextHandler.java

示例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");
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:10,代碼來源:MinebdApplication.java

示例11: 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()));
}
 
開發者ID:PaperCutSoftware,項目名稱:dust-api,代碼行數:36,代碼來源:DeviceUsageTrackerApp.java

示例12: 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:liaokailin,項目名稱:tomcat7,代碼行數:11,代碼來源:ApplicationContextFacade.java

示例13: getFilterRegistration

import javax.servlet.FilterRegistration; //導入依賴的package包/類
@Override
public FilterRegistration getFilterRegistration(String filterName) {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (FilterRegistration) doPrivileged(
                "getFilterRegistration", new Object[]{filterName});
    } else {
        return context.getFilterRegistration(filterName);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:10,代碼來源:ApplicationContextFacade.java

示例14: doPrivileged

import javax.servlet.FilterRegistration; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (Map<String, ? extends FilterRegistration>) doPrivileged(
                "getFilterRegistrations", null);
    } else {
        return context.getFilterRegistrations();
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:11,代碼來源:ApplicationContextFacade.java

示例15: getFilterRegistration

import javax.servlet.FilterRegistration; //導入依賴的package包/類
@Override
public FilterRegistration getFilterRegistration(String filterName) {
    FilterDef filterDef = context.findFilterDef(filterName);
    if (filterDef == null) {
        return null;
    }
    return new ApplicationFilterRegistration(filterDef, context);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:9,代碼來源:ApplicationContext.java


注:本文中的javax.servlet.FilterRegistration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。