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


Java Filter.init方法代碼示例

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


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

示例1: testMissingHostname

import javax.servlet.Filter; //導入方法依賴的package包/類
@Test
public void testMissingHostname() throws Exception {
  ServletRequest request = Mockito.mock(ServletRequest.class);
  Mockito.when(request.getRemoteAddr()).thenReturn(null);

  ServletResponse response = Mockito.mock(ServletResponse.class);

  final AtomicBoolean invoked = new AtomicBoolean();

  FilterChain chain = new FilterChain() {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
      throws IOException, ServletException {
      assertTrue(HostnameFilter.get().contains("???"));
      invoked.set(true);
    }
  };

  Filter filter = new HostnameFilter();
  filter.init(null);
  assertNull(HostnameFilter.get());
  filter.doFilter(request, response, chain);
  assertTrue(invoked.get());
  assertNull(HostnameFilter.get());
  filter.destroy();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:TestHostnameFilter.java

示例2: init

import javax.servlet.Filter; //導入方法依賴的package包/類
public void init(FilterConfig filterConfig) throws ServletException {
		String casServerLoginUrl = "http://sso.jadyer.com:8080/cas-server-web/login";
		String casServerUrlPrefix = "http://sso.jadyer.com:8080/cas-server-web";
		String casClientServerName = "http://boss.jadyer.com:8080";
		AuthenticationFilter casAuthenticationFilter = new AuthenticationFilter();
		casAuthenticationFilter.setCasServerLoginUrl(casServerLoginUrl);
		casAuthenticationFilter.setServerName(casClientServerName);
		Cas20ProxyReceivingTicketValidationFilter casTicketValidationFilter = new Cas20ProxyReceivingTicketValidationFilter();
		casTicketValidationFilter.setServerName(casClientServerName);
		casTicketValidationFilter.setTicketValidator(new Cas20ServiceTicketValidator(casServerUrlPrefix));
		filters[0] = new SingleSignOutFilter();
//		filters[1] = new AuthenticationFilter();
//		filters[2] = new Cas20ProxyReceivingTicketValidationFilter();
		filters[1] = casAuthenticationFilter;
		filters[2] = casTicketValidationFilter;
		filters[3] = new HttpServletRequestWrapperFilter();
		filters[4] = new AssertionThreadLocalFilter();
		for(Filter obj : filters){
			System.out.println("[複合Filter]-->Initializing Filter defined in ApplicationContext: '" + obj.toString() + "'");
			obj.init(filterConfig);
		}
	}
 
開發者ID:v5java,項目名稱:demo-cas-client,代碼行數:23,代碼來源:MSCompositeFilter.java

示例3: init

import javax.servlet.Filter; //導入方法依賴的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

示例4: init

import javax.servlet.Filter; //導入方法依賴的package包/類
public void init(
  FilterConfig filterConfig) throws ServletException
{
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  if (loader == null)
    _LOG.severe("CANNOT_FIND_CONTEXT_CLASS_LOADER");
  else
  {
    try
    {
      Class<?> proxiedClass = loader.loadClass(
                    "org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl");
      _proxied = (Filter) proxiedClass.newInstance();
      _proxied.init(filterConfig);
    }
    catch (ClassNotFoundException cnfe)
    {
      _LOG.severe(cnfe);
    }
    catch (IllegalAccessException iae)
    {
      _LOG.severe(iae);
    }
    catch (InstantiationException ie)
    {
      _LOG.severe(ie);
    }
    catch (RuntimeException e)
    {
      // OC4J was not reporting these errors properly:
      _LOG.severe(e);
      throw e;
    }
  }


}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:38,代碼來源:TrinidadFilter.java

示例5: init

import javax.servlet.Filter; //導入方法依賴的package包/類
/**
 * 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 : filters) {
		filter.init(config);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:CompositeFilter.java

示例6: hostname

import javax.servlet.Filter; //導入方法依賴的package包/類
@Test
public void hostname() throws Exception {
  ServletRequest request = Mockito.mock(ServletRequest.class);
  Mockito.when(request.getRemoteAddr()).thenReturn("localhost");

  ServletResponse response = Mockito.mock(ServletResponse.class);

  final AtomicBoolean invoked = new AtomicBoolean();

  FilterChain chain = new FilterChain() {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
      throws IOException, ServletException {
      // Hostname was set to "localhost", but may get resolved automatically to
      // "127.0.0.1" depending on OS.
      assertTrue(HostnameFilter.get().contains("localhost") ||
        HostnameFilter.get().contains("127.0.0.1"));
      invoked.set(true);
    }
  };

  Filter filter = new HostnameFilter();
  filter.init(null);
  assertNull(HostnameFilter.get());
  filter.doFilter(request, response, chain);
  assertTrue(invoked.get());
  assertNull(HostnameFilter.get());
  filter.destroy();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:30,代碼來源:TestHostnameFilter.java

示例7: init

import javax.servlet.Filter; //導入方法依賴的package包/類
public void init(FilterConfig config) throws ServletException {
    for (Filter filter : filters) {
        filter.init(config);
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:6,代碼來源:BeforeInvocationFilter.java

示例8: initDelegate

import javax.servlet.Filter; //導入方法依賴的package包/類
/**
 * 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 {
	Filter delegate = wac.getBean(getTargetBeanName(), Filter.class);
	if (isTargetFilterLifecycle()) {
		delegate.init(getFilterConfig());
	}
	return delegate;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:DelegatingFilterProxy.java


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