List of usage examples for javax.servlet FilterConfig getServletContext
public ServletContext getServletContext();
From source file:co.nubetech.crux.servlet.filter.CruxFilter.java
@Override public void init(FilterConfig filter) { try {//from w w w.ja v a 2s .c o m super.init(filter); ConnectionDAO connectionDAO = new ConnectionDAO(); connectionDAO.session = com.googlecode.s2hibernate.struts2.plugin.util.HibernateSessionFactory .getNewSession(); List<Connection> connectionList = connectionDAO.findAll(); logger.debug("connectionList size is: " + connectionList.size()); KeyedPoolableObjectFactory factory = PoolUtils .synchronizedPoolableFactory(new HBaseConnectionPoolFactory()); HBaseConnectionPool pool = new HBaseConnectionPool(factory); for (Connection connection : connectionList) { logger.debug("Connection is: " + connection); pool.addObject(connection); } filter.getServletContext().setAttribute(CruxConstants.HBASE_POOL, pool); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.teiid.olingo.web.ODataFilter.java
@Override public void init(FilterConfig config) throws ServletException { // handle proxy-uri in the case of cloud environments String proxyURI = config.getInitParameter("proxy-base-uri"); //$NON-NLS-1$ if (proxyURI != null && proxyURI.startsWith("${") && proxyURI.endsWith("}")) { //$NON-NLS-1$ //$NON-NLS-2$ proxyURI = proxyURI.substring(2, proxyURI.length() - 1); proxyURI = System.getProperty(proxyURI); }/*from w w w .j a v a2 s. c o m*/ if (proxyURI != null) { this.proxyBaseURI = proxyURI; } Properties props = new Properties(); Enumeration<String> names = config.getServletContext().getInitParameterNames(); while (names.hasMoreElements()) { String name = names.nextElement(); props.setProperty(name, config.getServletContext().getInitParameter(name)); } names = config.getInitParameterNames(); while (names.hasMoreElements()) { String name = names.nextElement(); props.setProperty(name, config.getInitParameter(name)); } this.initProperties = props; }
From source file:org.apache.atlas.web.filters.AtlasAuthenticationFilter.java
/** * Initialize the filter.//from w w w .jav a2s. c o m * * @param filterConfig filter configuration. * @throws ServletException thrown if the filter could not be initialized. */ @Override public void init(FilterConfig filterConfig) throws ServletException { LOG.info("AtlasAuthenticationFilter initialization started"); final FilterConfig globalConf = filterConfig; final Map<String, String> params = new HashMap<>(); FilterConfig filterConfig1 = new FilterConfig() { @Override public ServletContext getServletContext() { if (globalConf != null) { return globalConf.getServletContext(); } else { return nullContext; } } @SuppressWarnings("unchecked") @Override public Enumeration<String> getInitParameterNames() { return new IteratorEnumeration(params.keySet().iterator()); } @Override public String getInitParameter(String param) { return params.get(param); } @Override public String getFilterName() { return "AtlasAuthenticationFilter"; } }; super.init(filterConfig1); optionsServlet = new HttpServlet() { }; optionsServlet.init(); }
From source file:edu.indiana.d2i.htrc.security.JWTServletFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { // TokenVerifierConfiguration should be HOCON file stored in somewhere in the file system. String filterConfigFile = filterConfig.getInitParameter(PARAM_FILTER_CONFIG); if (filterConfigFile == null) { log.warn(// w ww. j av a 2 s . co m "No configuration was specified for JWTServletFilter. Using default " + DEFAULT_JWTFILTER_CONF); filterConfigFile = DEFAULT_JWTFILTER_CONF; } URL configUrl; try { if (filterConfigFile.contains(":/")) { configUrl = new URL(filterConfigFile); } else if (!filterConfigFile.startsWith("/")) { ServletContext servletContext = filterConfig.getServletContext(); configUrl = servletContext.getResource(filterConfigFile); } else { configUrl = new File(filterConfigFile).toURI().toURL(); } } catch (MalformedURLException e) { throw new ServletException("Could not load JWTFilter configuration from: " + filterConfigFile, e); } JWTServletFilterConfiguration configuration = new JWTServletFilterConfiguration(configUrl); try { this.tokenVerifier = new TokenVerifier(configuration.getTokenVerifierConfiguration()); } catch (InvalidAlgorithmParameterException e) { throw new ServletException("Could not initialize token verifier.", e); } // We map following JWT claims to HTRC specific request headers by default claimToHeaderMappings.put("email", "htrc-user-email"); claimToHeaderMappings.put("sub", "htrc-user-id"); claimToHeaderMappings.put("iss", "htrc-token-issuer"); // Any extra claim mappings are loaded from configuration file claimToHeaderMappings.putAll(configuration.getClaimMappings()); }
From source file:org.apache.struts2.dispatcher.FilterDispatcher.java
/** * Create a default {@link Dispatcher} that subclasses can override * with a custom Dispatcher, if needed.//from w w w .j a v a 2s. co m * * @param filterConfig Our FilterConfig * @return Initialized Dispatcher */ protected Dispatcher createDispatcher(FilterConfig filterConfig) { Map<String, String> params = new HashMap<String, String>(); for (Enumeration e = filterConfig.getInitParameterNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); String value = filterConfig.getInitParameter(name); params.put(name, value); } return new Dispatcher(filterConfig.getServletContext(), params); }
From source file:org.rhq.helpers.rtfilter.filter.RtFilter.java
/** * Read initialization parameters, and determine the context root. * The logfile name will be determined later, as we don't know the vhost yet. * * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) *//*from www.jav a 2 s. c o m*/ public void init(FilterConfig filterConfig) throws ServletException { try { synchronized (lock) { myHostName = InetAddress.getLocalHost().getHostName(); myCHostName = InetAddress.getLocalHost().getCanonicalHostName(); initializeParameters(filterConfig); ServletContext servletContext = filterConfig.getServletContext(); this.contextName = ServletUtility.getContextRoot(servletContext); /* * We don't open the file here, as we have no way to know the vhost this filter instance is for. * Instead we mark ourselves as initialized, and try to open the file in doFilter(). */ this.initialized = true; log.info("Initialized response-time filter for webapp with context root '" + this.contextName + "'."); } } catch (Exception e) { handleFatalError(e); } }
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/*from ww w. j a v a2s . com*/ 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.codeconsole.web.analytics.AnalyticsFilter.java
/** * @see Filter#init(FilterConfig)//www.ja v a 2 s . c o m */ public void init(FilterConfig fConfig) throws ServletException { String springConfigurationParam = fConfig.getInitParameter("spring-context-location"); if (springConfigurationParam != null) { this.springConfiguration = springConfigurationParam; } ApplicationContext context = null; try { context = new ClassPathXmlApplicationContext(springConfiguration); } catch (BeanDefinitionStoreException notfound) { System.out.println("AnalyticsFilter: Could not locate context configuration: " + springConfiguration + ". Attempting to load root Web Application Context."); context = WebApplicationContextUtils.getWebApplicationContext(fConfig.getServletContext()); } System.out.println("AnalyticsFilter: Loading bean definitions."); if (context != null) { if (context.containsBean("analyticsGateway")) { analyticsGateway = context.getBean("analyticsGateway", AnalyticsGateway.class); System.out.println("AnalyticsFilter: Gateway loaded."); } else { System.out.println( "AnalyticsFilter: Could not a bean named 'analyticsGateway'. Analytics will not be sent!"); } if (context.containsBean("userDetailsResolver")) { userDetailsResolver = context.getBean("userDetailsResolver", UserDetailsResolver.class); System.out.println("AnalyticsFilter: UserDetailsResolver loaded."); } if (context.containsBean("sourceRevisionResolver")) { sourceRevisionResolver = context.getBean("sourceRevisionResolver", SourceRevisionResolver.class); System.out.println("AnalyticsFilter: SourceRevisionResolver loaded."); } } else { System.out.println("AnalyticsFilter: Could not load root Web Application Context."); } String historySize = fConfig.getInitParameter("history-size"); if (historySize != null) { this.maxHistorySize = Integer.parseInt(historySize); } String sessionAttribute = fConfig.getInitParameter("session-attribute"); if (sessionAttribute != null) { this.sessionAttributeName = sessionAttribute; } String excluded = fConfig.getInitParameter("exclude-urls"); if (excluded != null) { String[] excludes = excluded.split("[\r\n]+"); for (String exclude : excludes) { exclude = exclude.trim(); if (!exclude.isEmpty()) excludedUrlPatterns.add(Pattern.compile(exclude)); } } String excludedParms = fConfig.getInitParameter("exclude-params"); if (excludedParms != null) { String[] paramExcludes = excludedParms.split("[\r\n]+"); for (String exclude : paramExcludes) { exclude = exclude.trim(); if (!exclude.isEmpty()) excludedParamPatterns.add(Pattern.compile(exclude)); } } }
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 ww w . ja v a 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.wso2.carbon.identity.relyingparty.OpenIDRelyingPartyData.java
/** * {@inheritDoc}/*w w w.ja v a 2s.c o m*/ */ public void loadData(FilterConfig filterConfig) throws ServletException { loadOpenIDHostMapping(filterConfig); opValidationPolicy = filterConfig.getInitParameter(TokenVerifierConstants.OP_VALIDATION_POLICY); if (opValidationPolicy != null && (opValidationPolicy.equals(TokenVerifierConstants.WHITE_LIST) || opValidationPolicy.equals(TokenVerifierConstants.BLACK_LIST))) { String opStoreFilePath = filterConfig.getInitParameter(TokenVerifierConstants.OP_KEY_STORE); String opStorePass = filterConfig.getInitParameter(TokenVerifierConstants.OP_STORE_PASS); String opStoreType = filterConfig.getInitParameter(TokenVerifierConstants.OP_STORE_TYPE); FileInputStream inputStream = null; String realPath = null; try { opKeyStore = KeyStore.getInstance(opStoreType); realPath = filterConfig.getServletContext().getRealPath(opStoreFilePath); inputStream = new FileInputStream(realPath); opKeyStore.load(inputStream, opStorePass.toCharArray()); } catch (Exception e) { throw new ServletException("Cannot load OP key store" + opStoreFilePath + " and " + opStorePass, e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { log.error("Error while closing in inputstream" + realPath, e); } } } } }