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


Java FilterConfig.getServletContext方法代碼示例

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


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

示例1: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
	this.cfg = filterConfig;
	this.ctx = filterConfig.getServletContext();
	final TreeMap<String, Limit> limits = new TreeMap<String, Limit>();
	final Enumeration<String> e = filterConfig.getInitParameterNames();
	final int ipMaxSize = getIntConfigParam("ipMaxSize", DEFAULT_IPMAXSIZE);
	while (e.hasMoreElements()) {
		final String key = e.nextElement();
		if (!key.isEmpty() && (key.charAt(0) == '/')) {
			final String uri = key;
			final String value = filterConfig.getInitParameter(key);
			final String[] conf = value.split(":"); // 0=concurrent-limit, 1=ip-time-limit-millis
			final int concurrent = (conf.length > 0 ? Integer.parseInt(conf[0]) : 0);
			final long timeByIP = (conf.length > 1 ? Long.parseLong(conf[1]) : 0);
			final Limit limit = new Limit(timeByIP, ipMaxSize, concurrent);
			filterConfig.getServletContext().log("uri=" + uri + " limit=[" + limit + "]");
			limits.put(uri, limit);
		}
	}
	this.limits = limits;
}
 
開發者ID:ggrandes,項目名稱:concurrentlimit-servlet-filter,代碼行數:23,代碼來源:ConcurrentLimitFilter.java

示例2: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    ServletContext servletContext = filterConfig.getServletContext();

    // use decorators from context attributes
    Object contextAttribute = servletContext.getAttribute(SPAN_DECORATORS);
    if (contextAttribute instanceof Collection) {
        List<ServletFilterSpanDecorator> decorators = new ArrayList<>();
        for (Object decorator: (Collection)contextAttribute) {
            if (decorator instanceof ServletFilterSpanDecorator) {
                decorators.add((ServletFilterSpanDecorator) decorator);
            } else {
                log.severe(decorator + " is not an instance of " + ServletFilterSpanDecorator.class);
            }
        }
        this.spanDecorators = decorators.size() > 0 ? decorators : this.spanDecorators;
    }

    contextAttribute = servletContext.getAttribute(SKIP_PATTERN);
    if (contextAttribute instanceof Pattern) {
        skipPattern = (Pattern) contextAttribute;
    }
}
 
開發者ID:opentracing-contrib,項目名稱:java-web-servlet-filter,代碼行數:25,代碼來源:TracingFilter.java

示例3: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
public void init(FilterConfig cfg) throws ServletException {
	iContext = cfg.getServletContext();
	try {
		Document config = (new SAXReader()).read(cfg.getServletContext().getResource(cfg.getInitParameter("config")));
		for (Iterator i=config.getRootElement().element("action-mappings").elementIterator("action"); i.hasNext();) {
			Element action = (Element)i.next();
			String path = action.attributeValue("path");
			String input = action.attributeValue("input");
			if (path!=null && input!=null) {
				iPath2Tile.put(path+".do", input);
			}
		}
	} catch (Exception e) {
		sLog.error("Unable to read config "+cfg.getInitParameter("config")+", reason: "+e.getMessage());
	}
	if (cfg.getInitParameter("debug-time")!=null) {
		debugTime = Long.parseLong(cfg.getInitParameter("debug-time"));
	}
	if (cfg.getInitParameter("dump-time")!=null) {
		dumpTime = Long.parseLong(cfg.getInitParameter("dump-time"));
	}
	if (cfg.getInitParameter("session-attributes")!=null) {
		dumpSessionAttribues = Boolean.parseBoolean(cfg.getInitParameter("session-attributes"));
	}
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:26,代碼來源:PageAccessFilter.java

示例4: loadUrlRewriter

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
@Override
protected void loadUrlRewriter(FilterConfig filterConfig) throws ServletException {
    try {
        Conf conf = new Conf(filterConfig.getServletContext(), resource.getInputStream(), resource.getFilename(), "");
    checkConf(conf);
    } catch (IOException ex) {
        throw new ServletException("Unable to load URL-rewrite configuration file from " + CONFIG_LOCATION, ex);
    }
}
 
開發者ID:Angular2Guy,項目名稱:AngularAndSpring,代碼行數:10,代碼來源:MyUrlRewriteFilter.java

示例5: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
public void init(FilterConfig config) throws ServletException {
    if (enable) {
        ProxyFilterConfig proxyFilterConfig = new ProxyFilterConfig(
                config.getServletContext());
        proxyFilterConfig.setFilterName(name);
        proxyFilterConfig.setMap(map);
        filter.init(proxyFilterConfig);
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:10,代碼來源:ProxyFilter.java

示例6: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
public void init(FilterConfig filterConfig) throws ServletException
{
  // potentially wrap the FilterConfig to catch Serialization changes
  filterConfig = CheckSerializationConfigurator.getFilterConfig(filterConfig);
  
  _servletContext = filterConfig.getServletContext();
          
  //There is some functionality that still might require servlet-only filter services.
  _filters = ClassLoaderUtils.getServices(TrinidadFilterImpl.class.getName());

  ExternalContext externalContext = new ServletExternalContext(
                                      _servletContext, null, null);

  PseudoFacesContext facesContext = new PseudoFacesContext(externalContext);
  facesContext.setAsCurrentInstance();

  try
  {
    for(Filter f:_filters)
    {
      f.init(filterConfig);
    }
  }
  finally
  {
    facesContext.release();
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:29,代碼來源:TrinidadFilterImpl.java

示例7: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
/**
 * Standard way of initializing this filter.
 * Map config parameters onto bean properties of this filter, and
 * invoke subclass initialization.
 * @param filterConfig the configuration for this filter
 * @throws ServletException if bean properties are invalid (or required
 * properties are missing), or if subclass initialization fails.
 * @see #initFilterBean
 */
@Override
public final void init(FilterConfig filterConfig) throws ServletException {
	Assert.notNull(filterConfig, "FilterConfig must not be null");
	if (logger.isDebugEnabled()) {
		logger.debug("Initializing filter '" + filterConfig.getFilterName() + "'");
	}

	this.filterConfig = filterConfig;

	// Set bean properties from init parameters.
	try {
		PropertyValues pvs = new FilterConfigPropertyValues(filterConfig, this.requiredProperties);
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
		ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext());
		bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.environment));
		initBeanWrapper(bw);
		bw.setPropertyValues(pvs, true);
	}
	catch (BeansException ex) {
		String msg = "Failed to set bean properties on filter '" +
			filterConfig.getFilterName() + "': " + ex.getMessage();
		logger.error(msg, ex);
		throw new NestedServletException(msg, ex);
	}

	// Let subclasses do whatever initialization they like.
	initFilterBean();

	if (logger.isDebugEnabled()) {
		logger.debug("Filter '" + filterConfig.getFilterName() + "' configured successfully");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:42,代碼來源:GenericFilterBean.java

示例8: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
@Override
public synchronized void init(FilterConfig filterConfig) throws ServletException {
    checkArgument(servletContext == null, "servlet context is already initialized");
    servletContext = filterConfig.getServletContext();
    Object prevAttribute = servletContext.getAttribute(SERVLET_CONTEXT_ATTRIBUTE_KEY);
    checkArgument(prevAttribute == null, "servlet context attribute is already initialized");
    servletContext.setAttribute(SERVLET_CONTEXT_ATTRIBUTE_KEY, this);
    LOGGER.trace("initialized");
}
 
開發者ID:vy,項目名稱:hrrs,代碼行數:10,代碼來源:HrrsFilter.java

示例9: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
/**
 * Initialize the filter
 * 
 * @param config
 *            FitlerConfig
 * @exception ServletException
 */
public void init(FilterConfig config) throws ServletException
{
    // Save the context

    m_context = config.getServletContext();

    // Setup the authentication context

    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(m_context);

    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    setNodeService(serviceRegistry.getNodeService());
    setAuthenticationService(serviceRegistry.getAuthenticationService());
    setTransactionService(serviceRegistry.getTransactionService());
    setPersonService((PersonService) ctx.getBean("PersonService")); // transactional and permission-checked
    m_authComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    httpServletRequestAuthHeaderName = config.getInitParameter("httpServletRequestAuthHeaderName");
    if(httpServletRequestAuthHeaderName == null)
    {
        httpServletRequestAuthHeaderName = "x-user";
    }
    this.m_authPatternString = config.getInitParameter("authPatternString");
    if (this.m_authPatternString != null)
    {
        try
        {
            m_authPattern = Pattern.compile(this.m_authPatternString);
        }
        catch (PatternSyntaxException e)
        {
            logger.warn("Invalid pattern: " + this.m_authPatternString, e);
            m_authPattern = null;
        }
    }
    
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:45,代碼來源:HTTPRequestAuthenticationFilter.java

示例10: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    logger.debug("init...");
    long start = System.currentTimeMillis();

    // 獲取配置類
    String configClass = filterConfig.getInitParameter("configClass");
    createDispatcherConfig(configClass);

    ServletContext servletContext = filterConfig.getServletContext();
    String realPath = servletContext.getRealPath("/");
    logger.info("webRootPath:{}", realPath);
    Constants.me().setWebRootPath(new File(realPath));

    config();

    BeanFactory.getInject().injectMembers(ViewManager.me());
    ViewManager.me().init(servletContext);

    String contextPath = servletContext.getContextPath();
    logger.info("contextPath:{}", contextPath);
    contextPathLength = (contextPath == null || "/".equals(contextPath) ? 0 : contextPath.length());

    actionHandler = BeanFactory.getBean(ActionHandler.class);
    actionHandler.init(contextPath);
    actionConfig.afterStart();

    long end = System.currentTimeMillis();
    logger.info("init {} ms", (end - start));
}
 
開發者ID:Xlongshu,項目名稱:EasyController,代碼行數:31,代碼來源:ActionDispatcherFilter.java

示例11: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
public void init(FilterConfig config) throws ServletException
{
    servletContext = config.getServletContext();
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:5,代碼來源:FacesExtensionFilter.java

示例12: init

import javax.servlet.FilterConfig; //導入方法依賴的package包/類
/**
 * Initialize the filter.
 * 
 * @param args
 *            FilterConfig
 * @throws ServletException
 *             the servlet exception
 * @exception ServletException
 */
public void init(FilterConfig args) throws ServletException
{
    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(args.getServletContext());
    this.filter = (DependencyInjectedFilter)ctx.getBean(args.getInitParameter(INIT_PARAM_BEAN_NAME));
    this.context = args.getServletContext();
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:16,代碼來源:BeanProxyFilter.java


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