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.impalaframework.web.integration.BaseLockingProxyFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    ModuleManagementFacade moduleManagementFacade = ImpalaServletUtils
            .getModuleManagementFacade(filterConfig.getServletContext());
    this.frameworkLockHolder = moduleManagementFacade.getFrameworkLockHolder();
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteResponseTest.java

@Test
public void testResolveGatewayParams() throws Exception {

    UrlRewriteProcessor rewriter = EasyMock.createNiceMock(UrlRewriteProcessor.class);

    ServletContext context = EasyMock.createNiceMock(ServletContext.class);
    EasyMock.expect(context.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME))
            .andReturn(rewriter).anyTimes();

    FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
    EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes();

    HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
    EasyMock.expect(request.getScheme()).andReturn("mock-scheme").anyTimes();
    EasyMock.expect(request.getLocalName()).andReturn("mock-host").anyTimes();
    EasyMock.expect(request.getLocalPort()).andReturn(42).anyTimes();
    EasyMock.expect(request.getContextPath()).andReturn("/mock-path").anyTimes();
    HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);

    EasyMock.replay(rewriter, context, config, request, response);

    UrlRewriteResponse rewriteResponse = new UrlRewriteResponse(config, request, response);

    List<String> url = rewriteResponse.resolve("gateway.url");
    assertThat(url, hasItems(new String[] { "mock-scheme://mock-host:42/mock-path" }));

    List<String> scheme = rewriteResponse.resolve("gateway.scheme");
    assertThat(scheme, hasItems(new String[] { "mock-scheme" }));

    List<String> host = rewriteResponse.resolve("gateway.host");
    assertThat(host, hasItems(new String[] { "mock-host" }));

    List<String> port = rewriteResponse.resolve("gateway.port");
    assertThat(port, hasItems(new String[] { "42" }));

    List<String> addr = rewriteResponse.resolve("gateway.addr");
    assertThat(addr, hasItems(new String[] { "mock-host:42" }));

    List<String> address = rewriteResponse.resolve("gateway.addr");
    assertThat(address, hasItems(new String[] { "mock-host:42" }));

    List<String> path = rewriteResponse.resolve("gateway.path");
    assertThat(path, hasItems(new String[] { "/mock-path" }));
}

From source file:org.usergrid.rest.SwaggerServlet.java

@Override
public void init(FilterConfig config) throws ServletException {
    logger.info("init(FilterConfig paramFilterConfig)");
    if (sc == null) {
        sc = config.getServletContext();
    }//from w  w  w. j  a  v  a 2 s  .c  o  m
    properties = (Properties) getSpringBeanFromWeb("properties");
    loadSwagger();
}

From source file:com.wikipy.security.AuthenticationFilter.java

@Override
public void init(FilterConfig config) throws ServletException {
    WebApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(config.getServletContext());
    userService = (BasicUserService) ctx.getBean("userService");
    cacheService = (EhCacheService) ctx.getBean("cacheService");
}

From source file:com.paladin.mvc.URLMappingFilter.java

@Override
public void init(FilterConfig cfg) throws ServletException {
    this.context = cfg.getServletContext();

    // ?  // w w  w  . java 2  s  . c  o m
    this.PATH_PREFIX = cfg.getInitParameter("template-path-prefix");
    if (this.PATH_PREFIX == null)
        this.PATH_PREFIX = "/WEB-INF/templates";
    else if (this.PATH_PREFIX.endsWith("/"))
        this.PATH_PREFIX = this.PATH_PREFIX.substring(0, this.PATH_PREFIX.length() - 1);

    // ? URL ??? /img/***
    String ignores = cfg.getInitParameter("ignore");
    if (ignores != null)
        for (String ig : StringUtils.split(ignores, ','))
            ignoreURIs.add(ig.trim());

    // ? URL ?? ? ? *.jpg
    ignores = cfg.getInitParameter("ignoreExts");
    if (ignores != null)
        for (String ig : StringUtils.split(ignores, ','))
            ignoreExts.add('.' + ig.trim());

    // ?? 
    String tmp = cfg.getInitParameter("domain");
    if (StringUtils.isNotBlank(tmp))
        rootDomain = tmp;

    //  ??   ? ? 
    @SuppressWarnings("unchecked")
    Enumeration<String> names = cfg.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String v = cfg.getInitParameter(name);
        if (v.endsWith("/"))
            v = v.substring(0, v.length() - 1);
        if ("ignore".equalsIgnoreCase(name) || "ignoreExts".equalsIgnoreCase(name))
            continue;
        if ("default".equalsIgnoreCase(name))
            default_base = PATH_PREFIX + v;
        else
            other_base.put(name, PATH_PREFIX + v);
    }
}

From source file:ar.sgt.resolver.filter.ResolverFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    log.debug("Initializing filter");
    this.resolverConfig = (ResolverConfig) filterConfig.getServletContext()
            .getAttribute(ContextLoader.RESOLVER_CONFIG);
    this.appendBackSlash = filterConfig.getInitParameter("append_backslash") != null
            ? Boolean.parseBoolean(filterConfig.getInitParameter("append_backslash"))
            : true;//w  ww.  java 2s . co m
    this.filterConfig = filterConfig;
    if (filterConfig.getInitParameter("exclude-path") != null) {
        this.excludePath = new HashSet<String>(
                Arrays.asList(StringUtils.split(filterConfig.getInitParameter("exclude-path"), ",")));
    } else {
        this.excludePath = null;
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.servlets.filters.AnnualTeachingCreditsDocumentFilter.java

@Override
public void init(FilterConfig arg0) throws ServletException {
    servletContext = arg0.getServletContext();
}

From source file:com.mtgi.analytics.servlet.BehaviorTrackingFilter.java

public void init(FilterConfig config) throws ServletException {
    servletContext = config.getServletContext();
    WebApplicationContext context = getRequiredWebApplicationContext(servletContext);
    String managerName = config.getInitParameter(PARAM_MANAGER_NAME);

    BehaviorTrackingManager manager;//from w ww.ja  va  2s.  c  o  m
    if (managerName == null) {
        //if there is no bean name configured, we assume there
        //must be exactly one such bean in the application context.
        Map<?, ?> managers = context.getBeansOfType(BehaviorTrackingManager.class);
        if (managers.isEmpty())
            throw new ServletException(
                    "Unable to find a bean of class " + BehaviorTrackingManager.class.getName()
                            + " in the Spring application context; perhaps it has not been configured?");
        if (managers.size() > 1)
            throw new ServletException("More than one instance of " + BehaviorTrackingManager.class.getName()
                    + " in Spring application context; you must specify which to use with the filter parameter "
                    + PARAM_MANAGER_NAME);

        manager = (BehaviorTrackingManager) managers.values().iterator().next();
    } else {
        //lookup the specified bean name.
        manager = (BehaviorTrackingManager) context.getBean(managerName, BehaviorTrackingManager.class);
    }

    //see if there is an event type name configured.
    String eventType = config.getInitParameter(PARAM_EVENT_TYPE);

    //parameters included in event data
    String params = config.getInitParameter(PARAM_PARAMETERS_INCLUDE);
    String[] parameters = params == null ? null : LIST_SEPARATOR.split(params);

    //parameters included in event name
    String nameParams = config.getInitParameter(PARAM_PARAMETERS_NAME);
    String[] nameParameters = nameParams == null ? null : LIST_SEPARATOR.split(nameParams);

    delegate = new ServletRequestBehaviorTrackingAdapter(eventType, manager, parameters, nameParameters, null);

    //increment count of tracking filters registered in the servlet context.  the filter
    //and alternative request listener check this attribute to make sure both are not registered at once.
    Integer count = (Integer) servletContext.getAttribute(ATT_FILTER_REGISTERED);
    servletContext.setAttribute(ATT_FILTER_REGISTERED, count == null ? 1 : count + 1);
}

From source file:org.wwarn.cms.authentication.CasAuthenticationFilter.java

public void init(FilterConfig config) throws ServletException {
    this.context = config.getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();

    authComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authService = (AuthenticationService) ctx.getBean("authenticationService");
    personService = (PersonService) ctx.getBean("personService");

    // Get a list of the available locales
    ConfigService configServiceService = (ConfigService) ctx.getBean("webClientConfigService");
    LanguagesConfigElement configElement = (LanguagesConfigElement) configServiceService.getConfig("Languages")
            .getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);

    m_languages = configElement.getLanguages();
}

From source file:com.idega.servlet.filter.CacheFilter.java

/**
 * Initialises blockingCache to use/*from  ww  w  . ja  v a  2  s .  com*/
 *
 * @throws CacheException The most likely cause is that a cache has not been
 *                        configured in ehcache's configuration file ehcache.xml for the filter name
 */
@Override
public void doInit() throws CacheException {
    //overriding from superclass

    int cacheSize = DEFAULT_CACHE_SIZE;
    long cacheTTLSeconds = DEFAULT_CACHE_TIME_SECONDS;
    long cacheTTLIdleSeconds = DEFAULT_CACHE_TIME_IDLE_SECONDS;

    FilterConfig config = this.getFilterConfig();
    ServletContext context = config.getServletContext();
    IWMainApplication iwma = IWMainApplication.getIWMainApplication(context);

    try {
        String propEnabled = iwma.getSettings().getProperty(PROPERTY_CACHE_FILTER_ENABLED);
        defaultEnabled = Boolean.valueOf(propEnabled).booleanValue();
        if (defaultEnabled) {
            log.info("CacheFilter is enabled");
        } else {
            log.info("CacheFilter is disabled");
        }
    } catch (Exception e) {
    }
    try {
        String propCacheSize = iwma.getSettings().getProperty(PROPERTY_CACHE_FILTER_SIZE);
        cacheSize = Integer.parseInt(propCacheSize);
    } catch (Exception e) {
    }
    try {
        String propTTL = iwma.getSettings().getProperty(PROPERTY_CACHE_FILTER_TTL);
        cacheTTLSeconds = Long.parseLong(propTTL);
    } catch (Exception e) {
    }
    try {
        String propIdleTTL = iwma.getSettings().getProperty(PROPERTY_CACHE_FILTER_IDLE_TTL);
        cacheTTLIdleSeconds = Long.parseLong(propIdleTTL);
    } catch (Exception e) {
    }

    final String cacheName = getCacheName();

    CacheManager cm = CacheManager.create();
    cm.removeCache(cacheName);
    Cache cache = new Cache(cacheName, cacheSize, true, false, cacheTTLSeconds, cacheTTLIdleSeconds);
    cm.addCache(cache);

    super.doInit();
    INITALIZED = true;
}