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


Java FilterRegistration.Dynamic方法代碼示例

本文整理匯總了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, "/*");

}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:23,代碼來源:SpringWebInitializer.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-gate,代碼行數:26,代碼來源:WebConfigurer.java

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

示例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));
    }
 
開發者ID:eduyayo,項目名稱:gamesboard,代碼行數:33,代碼來源:ExampleApplicationConfig.java

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

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

示例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
}
 
開發者ID:xiaomin0322,項目名稱:marathon-auth-plugin,代碼行數:37,代碼來源:ServletContextHandler.java

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

示例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);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:21,代碼來源:ApplicationContext.java

示例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);
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:25,代碼來源:ApplicationContext.java


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