javax.servlet.Filter.init()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(245)

本文整理了Java中javax.servlet.Filter.init()方法的一些代码示例,展示了Filter.init()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Filter.init()方法的具体详情如下:
包路径:javax.servlet.Filter
类名称:Filter
方法名:init

Filter.init介绍

[英]Called by the web container to indicate to a filter that it is being placed into service.

The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.

The web container cannot place the filter into service if the init method either

  1. Throws a ServletException
  2. Does not return within a time period defined by the web container
    [中]由web容器调用,以向筛选器指示它正在投入服务。
    servlet容器在实例化过滤器后只调用init方法一次。在要求筛选器执行任何筛选工作之前,init方法必须成功完成。
    如果init方法
    1.抛出ServletException
    1.在web容器定义的时间段内不返回

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Initialize all the filters, calling each one's init method in turn in the order supplied.
 * @see Filter#init(FilterConfig)
 */
@Override
public void init(FilterConfig config) throws ServletException {
  for (Filter filter : this.filters) {
    filter.init(config);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void init(FilterConfig filterConfig) throws ServletException {
  this.delegate.init(filterConfig);
}

代码示例来源:origin: apache/incubator-druid

@Override
public void init(FilterConfig filterConfig) throws ServletException
{
 delegate.init(filterConfig);
}

代码示例来源:origin: org.springframework/spring-web

/**
 * Initialize all the filters, calling each one's init method in turn in the order supplied.
 * @see Filter#init(FilterConfig)
 */
@Override
public void init(FilterConfig config) throws ServletException {
  for (Filter filter : this.filters) {
    filter.init(config);
  }
}

代码示例来源:origin: jenkinsci/jenkins

public void init(FilterConfig filterConfig) throws ServletException {
  if (LOGGER.isLoggable(Level.FINEST))
    for (Filter f : filters)
      LOGGER.finest("ChainedServletFilter contains: " + f);
  for (Filter f : filters)
    f.init(filterConfig);
}

代码示例来源:origin: jenkinsci/jenkins

public void init(FilterConfig config) throws ServletException {
  this.config = config;
  synchronized (LEGACY) {
    list.addAll(LEGACY);
    LEGACY.clear();
  }
  for (Filter f : list) {
    f.init(config);
  }
  config.getServletContext().setAttribute(KEY,this);
}

代码示例来源:origin: jenkinsci/jenkins

public static void addFilter(Filter filter) throws ServletException {
  Jenkins j = Jenkins.getInstanceOrNull();
  
  PluginServletFilter container = null;
  if(j != null) {
    container = getInstance(j.servletContext);
}
  // https://marvelution.atlassian.net/browse/JJI-188
  if (j==null || container == null) {
    // report who is doing legacy registration
    LOGGER.log(Level.WARNING, "Filter instance is registered too early: "+filter, new Exception());
    LEGACY.add(filter);
  } else {
    filter.init(container.config);
    container.list.add(filter);
  }
}

代码示例来源:origin: jersey/jersey

@Override
public void init(final FilterConfig filterConfig) throws ServletException {
  wrappedFilter.init(new FilterConfigWrapper(filterConfig));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Initialize the Filter delegate, defined as bean the given Spring
 * application context.
 * <p>The default implementation fetches the bean from the application context
 * and calls the standard {@code Filter.init} method on it, passing
 * in the FilterConfig of this Filter proxy.
 * @param wac the root application context
 * @return the initialized delegate Filter
 * @throws ServletException if thrown by the Filter
 * @see #getTargetBeanName()
 * @see #isTargetFilterLifecycle()
 * @see #getFilterConfig()
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 */
protected Filter initDelegate(WebApplicationContext wac) throws ServletException {
  String targetBeanName = getTargetBeanName();
  Assert.state(targetBeanName != null, "No target bean name set");
  Filter delegate = wac.getBean(targetBeanName, Filter.class);
  if (isTargetFilterLifecycle()) {
    delegate.init(getFilterConfig());
  }
  return delegate;
}

代码示例来源:origin: Atmosphere/atmosphere

/**
 * Initialize the {@link Filter}
 *
 * @throws javax.servlet.ServletException
 */
public void init() throws ServletException {
  for (FilterConfigImpl f : filters) {
    if (f != null) {
      f.getFilter().init(f);
    }
  }
  if (servlet != null) {
    servlet.init(configImpl);
  }
}

代码示例来源:origin: apache/shiro

/**
 * Initializes the filter by calling <code>filter.init( {@link #getFilterConfig() getFilterConfig()} );</code>.
 *
 * @param filter the filter to initialize with the {@code FilterConfig}.
 */
protected void initFilter(Filter filter) {
  FilterConfig filterConfig = getFilterConfig();
  if (filterConfig == null) {
    throw new IllegalStateException("FilterConfig attribute has not been set.  This must occur before filter " +
        "initialization can occur.");
  }
  try {
    filter.init(filterConfig);
  } catch (ServletException e) {
    throw new ConfigurationException(e);
  }
}

代码示例来源:origin: apache/shiro

public static Map<String, Filter> createInstanceMap(FilterConfig config) {
    Map<String, Filter> filters = new LinkedHashMap<String, Filter>(values().length);
    for (DefaultFilter defaultFilter : values()) {
      Filter filter = defaultFilter.newInstance();
      if (config != null) {
        try {
          filter.init(config);
        } catch (ServletException e) {
          String msg = "Unable to correctly init default filter instance of type " +
              filter.getClass().getName();
          throw new IllegalStateException(msg, e);
        }
      }
      filters.put(defaultFilter.name(), filter);
    }
    return filters;
  }
}

代码示例来源:origin: nutzam/nutz

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  if (proxy == null) {
    synchronized (lock) {
      if (proxy == null) {
        Ioc ioc = Mvcs.ctx().getDefaultIoc();
        Filter proxy = ioc.get(null, beanName);
        proxy.init(filterConfig);
        this.proxy = proxy;
      }
    }
  }
  proxy.doFilter(request, response, chain);
}

代码示例来源:origin: org.springframework/spring-web

/**
 * Initialize the Filter delegate, defined as bean the given Spring
 * application context.
 * <p>The default implementation fetches the bean from the application context
 * and calls the standard {@code Filter.init} method on it, passing
 * in the FilterConfig of this Filter proxy.
 * @param wac the root application context
 * @return the initialized delegate Filter
 * @throws ServletException if thrown by the Filter
 * @see #getTargetBeanName()
 * @see #isTargetFilterLifecycle()
 * @see #getFilterConfig()
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 */
protected Filter initDelegate(WebApplicationContext wac) throws ServletException {
  String targetBeanName = getTargetBeanName();
  Assert.state(targetBeanName != null, "No target bean name set");
  Filter delegate = wac.getBean(targetBeanName, Filter.class);
  if (isTargetFilterLifecycle()) {
    delegate.init(getFilterConfig());
  }
  return delegate;
}

代码示例来源:origin: igniterealtime/Openfire

( (Filter) instance ).init( new FilterConfig()

代码示例来源:origin: jenkinsci/jenkins

/**
 * Reset the proxies and filter for a change in {@link SecurityRealm}.
 */
public void reset(SecurityRealm securityRealm) throws ServletException {
  if (securityRealm != null) {
    SecurityRealm.SecurityComponents sc = securityRealm.getSecurityComponents();
    AUTHENTICATION_MANAGER.setDelegate(sc.manager);
    USER_DETAILS_SERVICE_PROXY.setDelegate(sc.userDetails);
    REMEMBER_ME_SERVICES_PROXY.setDelegate(sc.rememberMe);
    // make sure this.filter is always a valid filter.
    Filter oldf = this.filter;
    Filter newf = securityRealm.createFilter(this.filterConfig);
    newf.init(this.filterConfig);
    this.filter = newf;
    if(oldf!=null)
      oldf.destroy();
  } else {
    // no security related filter needed.
    AUTHENTICATION_MANAGER.setDelegate(null);
    USER_DETAILS_SERVICE_PROXY.setDelegate(null);
    REMEMBER_ME_SERVICES_PROXY.setDelegate(null);
    filter = null;
  }
}

代码示例来源:origin: awslabs/aws-serverless-java-container

/**
 * Initializes the wrapped filter and sets the <code>isFilterInitialized</code> property to true. This should be called
 * before invoking a filter if the result of the <code>isFilterInitialized()</code> method is false.
 * @throws ServletException Propagates any servlet exception thrown by the filter initialization
 */
public void init() throws ServletException {
  this.getFilter().init(filterConfig);
  this.filterInitialized = true;
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected void setupFilter() throws ServletException {
 MockFilterConfig config = new MockFilterConfig();
 config.addInitParameter(ProcessEngineAuthenticationFilter.AUTHENTICATION_PROVIDER_PARAM, HttpBasicAuthenticationProvider.class.getName());
 authenticationFilter = new ProcessEngineAuthenticationFilter();
 authenticationFilter.init(config);
}

代码示例来源:origin: haraldk/TwelveMonkeys

@Test
public void testLifeCycle() throws ServletException {
  Filter filter = makeFilter();
  try {
    filter.init(makeFilterConfig());
  }
  finally {
    filter.destroy();
  }
}

代码示例来源:origin: haraldk/TwelveMonkeys

@Test
public void testFilterBasic() throws ServletException, IOException {
  Filter filter = makeFilter();
  try {
    filter.init(makeFilterConfig());
    filter.doFilter(makeRequest(), makeResponse(), makeFilterChain());
  }
  finally {
    filter.destroy();
  }
}

相关文章

微信公众号

最新文章

更多