Example usage for javax.servlet FilterConfig getFilterName

List of usage examples for javax.servlet FilterConfig getFilterName

Introduction

In this page you can find the example usage for javax.servlet FilterConfig getFilterName.

Prototype

public String getFilterName();

Source Link

Document

Returns the filter-name of this filter as defined in the deployment descriptor.

Usage

From source file:org.springframework.web.filter.GenericFilterBean.java

/**
 * Standard way of initializing this filter.
 * Map config parameters onto bean properties of this filter, and
 * invoke subclass initialization.//from   w w  w.j ava 2  s  . co  m
 * @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.
    PropertyValues pvs = new FilterConfigPropertyValues(filterConfig, this.requiredProperties);
    if (!pvs.isEmpty()) {
        try {
            BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
            ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext());
            Environment env = this.environment;
            if (env == null) {
                env = new StandardServletEnvironment();
            }
            bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, env));
            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");
    }
}

From source file:org.ajax4jsf.webapp.BaseFilter.java

/**
 * Initialize the filter./*from   w  w w  .  ja va 2s.c o  m*/
 */
public void init(FilterConfig config) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Init ajax4jsf filter with nane: " + config.getFilterName());
        Enumeration<String> parameterNames = config.getInitParameterNames();
        StringBuffer parameters = new StringBuffer("Init parameters :\n");
        while (parameterNames.hasMoreElements()) {
            String name = parameterNames.nextElement();
            parameters.append(name).append(" : '").append(config.getInitParameter(name)).append('\n');
        }
        log.debug(parameters);
        // log.debug("Stack Trace", new Exception());
    }
    // Save config
    filterConfig = config;
    setFunction((String) nz(filterConfig.getInitParameter(FUNCTION_NAME_PARAMETER), getFunction()));
    setAttributesNames(filterConfig.getInitParameter(ABSOLUTE_TAGS_PARAMETER));
    xmlFilter.init(config);
    if ("true".equalsIgnoreCase(filterConfig.getInitParameter(REWRITEID_PARAMETER))) {
        this.setRewriteid(true);
    }
    resourceService = new InternetResourceService();
    // Caching initialization.
    resourceService.init(filterConfig);
    eventsManager = new PollEventsManager();
    eventsManager.init(filterConfig.getServletContext());

    String param = filterConfig.getInitParameter("createTempFiles");
    if (param != null) {
        this.createTempFiles = Boolean.parseBoolean(param);
    } else {
        this.createTempFiles = true;
    }
    param = filterConfig.getInitParameter("maxRequestSize");
    if (param != null) {
        this.maxRequestSize = Integer.parseInt(param);
    }
}

From source file:org.openrepose.filters.custom.extractdeviceid.ExtractDeviceIdFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    configurationFile = new FilterConfigHelper(filterConfig).getFilterConfig(DEFAULT_CONFIG);
    LOG.info("Initializing filter using config {}", configurationFile);
    // Must match the .xsd file created in step 18.
    URL xsdURL = getClass().getResource("/META-INF/schema/config/extract-device-id.xsd");
    configurationService.subscribeTo(filterConfig.getFilterName(), configurationFile, xsdURL, this,
            ExtractDeviceIdConfig.class);
}

From source file:org.withinsea.izayoi.adapter.springmvc.SpringIzayoiDispatcherFilter.java

@Override
public void init(final FilterConfig filterConfig) throws ServletException {

    cloister = new Cloister();
    glowworm = new Glowworm();
    cortile = new Cortile();
    izayoiInterceptor = new SpringGlowwormInterceptor(glowworm);
    izayoiViewResolver = new SpringCloisterCortileViewResolver(cortile, cloister);

    super.init(new ServletConfig() {

        @Override// ww  w  .j  a v a  2  s  . c  o m
        public String getInitParameter(String s) {
            return filterConfig.getInitParameter(s);
        }

        @Override
        public String getServletName() {
            return filterConfig.getFilterName();
        }

        @Override
        public ServletContext getServletContext() {
            return filterConfig.getServletContext();
        }

        @Override
        @SuppressWarnings("unchecked")
        public Enumeration<String> getInitParameterNames() {
            return filterConfig.getInitParameterNames();
        }
    });

    ApplicationContext appctx = getWebApplicationContext();
    ServletContext servletContext = filterConfig.getServletContext();
    Map<String, String> overriddenProperties = ServletFilterUtils.getParamsMap(filterConfig);

    IzayoiContainer container = new IzayoiContainerFactory().addBeanSource(new SpringBeanSource(appctx))
            .addModule("org.withinsea.izayoi.core").addModule("org.withinsea.izayoi.cloister")
            .addModule("org.withinsea.izayoi.glowworm").addModule("org.withinsea.izayoi.cortile")
            .addModule("org.withinsea.izayoi.adapter.springmvc").create(servletContext, overriddenProperties);

    cloister.init(container);
    glowworm.init(container);
    cortile.init(container);
}

From source file:org.openrepose.filters.translation.TranslationFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    config = new FilterConfigHelper(filterConfig).getFilterConfig(DEFAULT_CONFIG);
    LOG.info("Initializing filter using config " + config);
    requestProcessorPools = new ArrayList<>();
    responseProcessorPools = new ArrayList<>();
    xslListener = new XslUpdateListener(this, configurationService, configurationRoot);
    URL xsdURL = getClass().getResource("/META-INF/schema/config/translation-configuration.xsd");
    configurationService.subscribeTo(filterConfig.getFilterName(), config, xsdURL, this,
            TranslationConfig.class);
}

From source file:wicket.protocol.http.WicketFilter.java

/**
 * //from w  ww.  j a  v  a  2s  .  c  o m
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 */
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;

    IWebApplicationFactory factory = getApplicationFactory();

    // Construct WebApplication subclass
    this.webApplication = factory.createApplication(this);

    // Set this WicketServlet as the servlet for the web application
    this.webApplication.setWicketFilter(this);

    // Store instance of this application object in servlet context to make
    // integration with outside world easier
    String contextKey = "wicket:" + filterConfig.getFilterName();
    filterConfig.getServletContext().setAttribute(contextKey, this.webApplication);

    filterPath = filterConfig.getInitParameter(FILTER_PATH_PARAM);

    try {
        Application.set(webApplication);

        // Call internal init method of web application for default
        // initialisation
        this.webApplication.internalInit();

        // Call init method of web application
        this.webApplication.init();

        // We initialize components here rather than in the constructor or
        // in the internal init, because in the init method class aliases
        // can be added, that would be used in installing resources in the
        // component.
        this.webApplication.initializeComponents();

        // Finished
        log.info("Wicket application " + this.webApplication.getName() + " started [factory="
                + factory.getClass().getName() + "]");
    } finally {
        Application.unset();
    }
}

From source file:net.bull.javamelody.TestMonitoringFilter.java

/**
 * Initialisation./*from w  w  w  .  j  a va2s .com*/
 * @throws ServletException e
 */
@Before
public void setUp() throws ServletException {
    try {
        final Field field = MonitoringFilter.class.getDeclaredField("instanceCreated");
        field.setAccessible(true);
        field.set(null, false);
    } catch (final IllegalAccessException e) {
        throw new IllegalStateException(e);
    } catch (final NoSuchFieldException e) {
        throw new IllegalStateException(e);
    }
    final FilterConfig config = createNiceMock(FilterConfig.class);
    final ServletContext context = createNiceMock(ServletContext.class);
    expect(config.getServletContext()).andReturn(context).anyTimes();
    expect(config.getFilterName()).andReturn(FILTER_NAME).anyTimes();
    // anyTimes sur getInitParameter car TestJdbcDriver a pu fixer la proprit systme  false
    expect(context.getInitParameter(Parameters.PARAMETER_SYSTEM_PREFIX + Parameter.DISABLED.getCode()))
            .andReturn(null).anyTimes();
    expect(config.getInitParameter(Parameter.DISABLED.getCode())).andReturn(null).anyTimes();
    expect(context.getMajorVersion()).andReturn(2).anyTimes();
    expect(context.getMinorVersion()).andReturn(5).anyTimes();
    expect(context.getServletContextName()).andReturn("test webapp").anyTimes();
    // mockJetty pour avoir un applicationServerIconName dans JavaInformations
    expect(context.getServerInfo()).andReturn("mockJetty").anyTimes();
    // dependencies pour avoir des dpendances dans JavaInformations
    final Set<String> dependencies = new LinkedHashSet<String>(
            Arrays.asList("/WEB-INF/lib/jrobin.jar", "/WEB-INF/lib/javamelody.jar"));
    // et flags pour considrer que les ressources pom.xml et web.xml existent
    JavaInformations.setWebXmlExistsAndPomXmlExists(true, true);
    expect(context.getResourcePaths("/WEB-INF/lib/")).andReturn(dependencies).anyTimes();
    expect(context.getContextPath()).andReturn(CONTEXT_PATH).anyTimes();
    monitoringFilter = new MonitoringFilter();
    monitoringFilter.setApplicationType("Test");
    replay(config);
    replay(context);
    monitoringFilter.init(config);
    verify(config);
    verify(context);
}

From source file:org.beanfuse.security.monitor.SecurityFilter.java

public void init(FilterConfig cfg) throws ServletException {
    Enumeration en = cfg.getInitParameterNames();
    while (en.hasMoreElements()) {
        String property = (String) en.nextElement();
        Object value = cfg.getInitParameter(property);
        try {/*from  w  w  w. j a  v a  2 s .  c om*/
            PropertyUtils.setProperty(this, property, value);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }
    // ????
    if (StringUtils.isEmpty(resourceExtractorClassName)) {
        resourceExtractorClassName = SimpleResourceExtractor.class.getName();
    }
    try {
        resourceExtractor = (ResourceExtractor) Class.forName(resourceExtractorClassName).newInstance();
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }

    if (StringUtils.isEmpty(expiredPath)) {
        expiredPath = loginFailPath;
    }
    freeResources.add(resourceExtractor.extract(loginFailPath));
    freeResources.add(resourceExtractor.extract(expiredPath));
    freeResources.add(resourceExtractor.extract(noAuthorityPath));

    logger.info("Filter {} configured successfully with free resources {}", cfg.getFilterName(), freeResources);
}

From source file:nl.b3p.commons.security.aselect.ASelectAuthorizationFilter.java

/**
 * Deze functie initialiseert het filter en controleert de init parameters.
 * Indien deze parameters ongeldig zijn wordt dit gelogd en wordt in de
 * doFilter() methode een exception gethrowd en niet de filter chain
 * voortgezet.//  w  w  w. j a  v  a  2 s  .c o m
 */
public void init(FilterConfig filterConfig) {
    if (log.isInfoEnabled()) {
        log.info("init");
    }

    configOK = false;

    try {
        this.filterConfig = filterConfig;

        String apiString = filterConfig.getInitParameter("api");
        if (apiString != null) {
            apiString = apiString.toLowerCase();
        }

        /* voorlopig is alleen de agent API geimplementeerd. */

        if (apiString.equals("agent")) {
            api = ASELECT_API_AGENT;
            client = new ASelectAgentClient(filterConfigToProperties(filterConfig));
        } else {
            throw new IllegalArgumentException("invalid \"api\" init parameter");
        }

        appId = filterConfig.getInitParameter("app_id");
        if (appId == null) {
            throw new IllegalArgumentException("\"app_id\" init parameter required");
        }

        avoidURLParamsInRedirect = "true".equals(filterConfig.getInitParameter("avoid_url_params_in_redirect"));

        configOK = true;
    } catch (IllegalArgumentException e) {
        log.error("error initializing filter " + filterConfig.getFilterName(), e);
    }

    if (!configOK) {
        log.error("bad config; disallowing access to application");
    }
}

From source file:com.logiclander.jaasmine.authentication.http.JaasLoginFilter.java

/**
 * {@inheritDoc}// www.  java2s  . c o  m
 *
 * Checks the given FilterConfig for the init-params named appName and
 * loginServletName.  If these values are not in the FilterConfig, then
 * the default values are used.
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {

    appName = filterConfig.getInitParameter("appName");
    if (appName == null || appName.isEmpty()) {
        appName = AuthenticationService.DEFAULT_JAASMINE_LOGIN_CONFIG;
    }

    loginPath = filterConfig.getInitParameter("loginPath");
    if (loginPath == null || loginPath.isEmpty()) {
        loginPath = EMPTY_STRING;
    }

    loginRedirect = filterConfig.getInitParameter("loginRedirect");
    if (loginRedirect == null || loginRedirect.isEmpty()) {
        loginRedirect = EMPTY_STRING;
    }

    loginServletName = filterConfig.getInitParameter("loginServletName");
    if (loginServletName == null || loginServletName.isEmpty()) {
        loginServletName = DEFAULT_NAMED_LOGIN_DISPATCHER;
    }

    String setRemoteUserOnLoginParam = filterConfig.getInitParameter("setRemoteUserOnLogin");
    if (setRemoteUserOnLoginParam == null || setRemoteUserOnLoginParam.isEmpty()) {
        setRemoteUserOnLoginParam = DEFAULT_SET_REMOTE_USER_ON_LOGIN;
    }

    setRemoteUserOnLogin = Boolean.parseBoolean(setRemoteUserOnLoginParam);

    filterName = filterConfig.getFilterName();

    isUsingBasicAuthentication = Boolean.valueOf(filterConfig.getInitParameter("setBasicAuth"));

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("%s initialized", toString()));
        logger.debug(String.format("loginPath = %s", loginPath == EMPTY_STRING ? "Not set" : loginPath));
        logger.debug(
                String.format("loginRedirect = %s", loginRedirect == EMPTY_STRING ? "Not set" : loginRedirect));
        logger.debug(String.format("loginServletName = %s", loginServletName));
        logger.debug(String.format("setRemoteUserOnLogin = %s", Boolean.toString(setRemoteUserOnLogin)));
    }
}