Example usage for javax.servlet FilterConfig getServletContext

List of usage examples for javax.servlet FilterConfig getServletContext

Introduction

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

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns a reference to the ServletContext in which the caller is executing.

Usage

From source file:org.eurekastreams.server.service.filters.FilterInitializer.java

/**
 * /*from   www .j  ava2 s .c o  m*/
 * @param theFilter
 *            - the filter to configure
 * @param filterConfig
 *            - filter config params
 */
public static void initializeFilter(final Filter theFilter, final FilterConfig filterConfig) {
    ApplicationContext context = (ApplicationContext) WebApplicationContextUtils
            .getWebApplicationContext(filterConfig.getServletContext());

    if (theFilter instanceof RootOrgCheckFilter) {
        RootOrgCheckFilter rootOrgFilter = (RootOrgCheckFilter) theFilter;

        GetRootOrganizationIdAndShortName getRootOrgIdMapper = (GetRootOrganizationIdAndShortName) context
                .getBean("getRootOrganizationIdAndShortNameMapper");

        rootOrgFilter.setGetRootOrganizationIdMapper(getRootOrgIdMapper);
    }
}

From source file:com.belajar_filter.config.FilterBeanConfig.java

public static Filter myFilter() {
    Filter filter = new Filter() {

        private ServletContext context;

        @Override//www  .ja va  2 s .  com
        public void init(FilterConfig filterConfig) throws ServletException {
            log.debug("initiate general filter config");
            this.context = filterConfig.getServletContext();
            this.context.log("AuthenticationFilter initialized");
        }

        @Override
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc)
                throws IOException, ServletException {
            log.debug("execute do filter ... ");
            HttpServletResponse response = (HttpServletResponse) res;
            HttpServletRequest request = (HttpServletRequest) req;

            String getParam = request.getParameter("name");
            String urlRequest = request.getRequestURI();
            log.debug("intercept url request : " + urlRequest);
            log.debug("intercept param : " + getParam);

            if ("aji".equals(getParam)) {
                log.debug("is aji");
                fc.doFilter(req, res);
            } else {
                log.debug("is not aji");
                response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
            }

        }

        @Override
        public void destroy() {

        }
    };

    return filter;
}

From source file:org.apache.hadoop.gateway.dispatch.DefaultHttpClientFactory.java

private static int getConnectionTimeout(FilterConfig filterConfig) {
    int timeout = -1;
    GatewayConfig globalConfig = (GatewayConfig) filterConfig.getServletContext()
            .getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
    if (globalConfig != null) {
        timeout = globalConfig.getHttpClientConnectionTimeout();
    }/*from w ww. ja v a  2s .c o m*/
    String str = filterConfig.getInitParameter("httpclient.connectionTimeout");
    if (str != null) {
        try {
            timeout = (int) parseTimeout(str);
        } catch (Exception e) {
            // Ignore it and use the default.
        }
    }
    return timeout;
}

From source file:org.apache.hadoop.gateway.dispatch.DefaultHttpClientFactory.java

private static int getSocketTimeout(FilterConfig filterConfig) {
    int timeout = -1;
    GatewayConfig globalConfig = (GatewayConfig) filterConfig.getServletContext()
            .getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
    if (globalConfig != null) {
        timeout = globalConfig.getHttpClientSocketTimeout();
    }//from  w  ww .j a va 2  s.  c  om
    String str = filterConfig.getInitParameter("httpclient.socketTimeout");
    if (str != null) {
        try {
            timeout = (int) parseTimeout(str);
        } catch (Exception e) {
            // Ignore it and use the default.
        }
    }
    return timeout;
}

From source file:org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter.java

/**
 * Get the parameter value from the given servlet filter configuration.
 *
 * @param filterConfig  the servlet configuration
 * @param parameterName the parameter name
 * @param defaultValue  the default value
 * @return the parameter value or the default value if not set
 *///ww  w  .j av  a  2  s.  c o m
private static String getParameterValue(FilterConfig filterConfig, String parameterName, String defaultValue) {

    String value = filterConfig.getInitParameter(parameterName);
    if (value == null || value.length() == 0) {
        value = filterConfig.getServletContext().getInitParameter(parameterName);
    }
    return value == null || value.length() == 0 ? defaultValue : value;
}

From source file:gov.loc.ndmso.proxyfilter.Log.java

/**
 * Will setup Log based on the filter config.  Uses init paramater "logLevel" to get the log level.
 * Defaults to "INFO".//from   ww  w.j  av a2s .co m
 *
 * @param filterConfig the filter config to use
 */
public static void setConfiguration(final FilterConfig filterConfig) {
    resetAll();

    if (filterConfig == null) {
        localLog.error("no filter config passed");
        return;
    }
    Log.context = filterConfig.getServletContext();

    String logLevelConf = filterConfig.getInitParameter("logLevel");

    if (logLevelConf != null) {
        logLevelConf = trimStr(logLevelConf);
    }

    setLevel(logLevelConf);
    localLog.debug("logLevel set to " + logLevelConf);
}

From source file:org.tuckey.web.filters.urlrewrite.utils.Log.java

/**
 * Will setup Log based on the filter config.  Uses init paramater "logLevel" to get the log level.
 * Defaults to "INFO".//  ww w  . j  a v a 2  s  .  c om
 *
 * @param filterConfig the filter config to use
 */
public static void setConfiguration(final FilterConfig filterConfig) {
    resetAll();

    if (filterConfig == null) {
        localLog.error("no filter config passed");
        return;
    }
    Log.context = filterConfig.getServletContext();

    String logLevelConf = filterConfig.getInitParameter("logLevel");

    if (logLevelConf != null) {
        logLevelConf = StringUtils.trim(logLevelConf);
    }

    setLevel(logLevelConf);
    localLog.debug("logLevel set to " + logLevelConf);
}

From source file:org.dmb.trueprice.utils.internal.InitContextListener.java

public static FilterConfig getFilterConfig(FilterConfig config) {
    String filterName = config.getFilterName();
    log.warn("\n\t >>> \t Filter [" + filterName + "] request for config \n");
    switch (filterName) {
    case "":
        log.warn("Can't determine wich filter wants config > " + filterName);
        break;// www  .  j  a v  a2 s .co  m
    case "RestrictionFilter":
        log.info(filterName + " filter ask config");
        log.info("Add init param [" + RestrictionFilter.URL_ACCES_ADMIN + "]");
        config.getServletContext().setInitParameter(RestrictionFilter.URL_ACCES_ADMIN,
                getEnvEntryValue(RestrictionFilter.URL_ACCES_ADMIN));
        break;
    default:
        log.error("Could not match any filter. Who wants config ? > " + filterName);
        break;
    }
    ;
    return config;
}

From source file:gov.nih.nci.cabig.ctms.web.filters.ContextRetainingFilterAdapter.java

public void init(FilterConfig filterConfig) throws ServletException {
    servletContext = filterConfig.getServletContext();
}

From source file:org.openmrs.module.owa.filter.OwaFilter.java

@Override
public void init(FilterConfig fc) throws ServletException {
    openmrsPath = fc.getServletContext().getContextPath();
}