List of usage examples for javax.servlet FilterConfig getInitParameter
public String getInitParameter(String name);
String
containing the value of the named initialization parameter, or null
if the initialization parameter does not exist. From source file:optional.BasicFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; filterConfig.getServletContext();/*from ww w . ja v a 2 s .c o m*/ String packagepath = filterConfig.getInitParameter(""); packagepath = ""; // configs // actions String path = filterConfig.getServletContext().getRealPath("/WEB-INF/classes" + packagepath); // Klassen finden ArrayList list = ActionPlugin.getClasses(path, packagepath); System.out.println("## looking for direct actions ##"); for (Iterator iterator = list.iterator(); iterator.hasNext();) { try { Class clazz = Class.forName((String) iterator.next()); if (!isInterfaceImplementer(clazz, DirectInterface.class)) { continue; } // store Actionclass and its configuration ConfigWrapper wrapper = new ConfigWrapper(); wrapper.setConfig((ActionConfig) clazz.getField("struts").get(clazz)); wrapper.setActionclass(clazz); wrapper.getConfig().setPath(getPathFromClassName(clazz.getName(), "Action")); System.out.println(wrapper.getConfig().getPath() + "\n" + clazz); actions.put(wrapper.getConfig().getPath(), wrapper); } catch (Exception e) { continue; } } System.out.println("## looking for direct actions DONE ##"); // request.setCharacterEncoding(encoding); // CharsetFilter // response.setCharacterEncoding(encoding); }
From source file:org.apache.tiles.web.util.TilesDecorationFilter.java
/** {@inheritDoc} */ public void init(FilterConfig config) throws ServletException { filterConfig = config;/* w w w . j a v a2s.com*/ containerKey = filterConfig.getInitParameter(CONTAINER_KEY_INIT_PARAMETER); String temp = config.getInitParameter("attribute-name"); if (temp != null) { definitionAttributeName = temp; } temp = config.getInitParameter("definition"); if (temp != null) { definitionName = temp; } temp = config.getInitParameter("prevent-token"); preventDecorationToken = "org.apache.tiles.decoration.PREVENT:" + (temp == null ? definitionName : temp); alternateDefinitions = parseAlternateDefinitions(); temp = config.getInitParameter("mutator"); if (temp != null) { try { mutator = (AttributeContextMutator) Class.forName(temp).newInstance(); } catch (Exception e) { throw new ServletException("Unable to instantiate specified context mutator.", e); } } else { mutator = new DefaultMutator(); } }
From source file:ORG.oclc.os.ipUseThrottleFilter.ipUseThrottleFilter.java
@Override public void init(FilterConfig fc) throws ServletException { Calendar c = new GregorianCalendar(); nextReportingHour = c.get(Calendar.HOUR_OF_DAY) + 1; String t = fc.getInitParameter("maxTotalSimultaneousRequests"); if (t != null) try {//from w ww . j av a2 s .c om maxTotalSimultaneousRequests = Integer.parseInt(t); } catch (NumberFormatException e) { log.error("Bad value for parameter 'maxTotalSimultaneousRequests': '" + t + "'"); log.error("Using the default value of 10 instead"); } // t=fc.getInitParameter("maxSimultaneousRequests"); // if(t!=null) // try { // maxSimultaneousRequests=Integer.parseInt(t); // } // catch(Exception e) { // log.error("Bad value for parameter 'maxSimultaneousRequests': '"+t+"'"); // log.error("Using the default value of 3 instead"); // } contactInfo = fc.getInitParameter("contactInfo"); if (log.isDebugEnabled()) log.debug("contactInfo=" + contactInfo); addressInHeader = fc.getInitParameter("addressInHeader"); if (log.isDebugEnabled()) log.debug("addressInHeader=" + addressInHeader); String eA = fc.getInitParameter("equivalentAddresses"); if (eA != null) { // comma/blank/tab separated list of shortAddr=shortAddr // e.g. 157.55.33=157.55.32, 157.55.34=157.55.32, 157.55.35=157.55.32, 157.55.36=157.55.32, 157.55.37=157.55.32 // or 157.55.*=157.55.0 // or 69.171.224-255=69.171.224 String first, pair, second; StringTokenizer findPairs = new StringTokenizer(eA, ",\t "); StringTokenizer findValues; while (findPairs.hasMoreTokens()) { pair = findPairs.nextToken(); findValues = new StringTokenizer(pair, "="); first = findValues.nextToken(); second = findValues.nextToken(); if (first.endsWith(".*")) { first = first.substring(0, first.indexOf(".*")); for (int i = 0; i < 256; i++) equivalentAddresses.put(first + "." + i, second); } else if (first.contains("-")) { int offset = first.lastIndexOf('.'); String base = first.substring(0, offset); String rest = first.substring(offset + 1); StringTokenizer range = new StringTokenizer(rest, "-"); int start = Integer.parseInt(range.nextToken()); int end = Integer.parseInt(range.nextToken()); for (int i = start; i < end; i++) { System.out.println("adding " + base + "." + i + "=" + second + " to the equivalence table"); equivalentAddresses.put(base + "." + i, second); } } else equivalentAddresses.put(first, second); } } String iA = fc.getInitParameter("ignorableAddresses"); if (iA != null) { StringTokenizer st = new StringTokenizer(iA, ", "); while (st.hasMoreTokens()) ignorableAddresses.add(st.nextToken()); } }
From source file:org.vulpe.controller.filter.VulpeFilterDispatcher.java
/** * Initiate URL Rewrite Filter.//from w w w.ja v a 2s .com * * @param filterConfig * @throws ServletException */ private void initURLRewrite(final FilterConfig filterConfig) throws ServletException { URL_REWRITE_FILTER.init(filterConfig); final ServletContext context = filterConfig.getServletContext(); String confPath = filterConfig.getInitParameter("confPath"); if (StringUtils.isEmpty(confPath)) { confPath = UrlRewriteFilter.DEFAULT_WEB_CONF_PATH; } URL confUrl = null; try { confUrl = context.getResource(confPath); } catch (MalformedURLException e) { LOG.debug(e.getMessage()); } String confUrlStr = null; if (confUrl != null) { confUrlStr = confUrl.toString(); } final InputStream inputStream = context.getResourceAsStream(confPath); final Conf conf = new Conf(context, inputStream, confPath, confUrlStr, false); URL_REWRITER = new UrlRewriter(conf); }
From source file:com.alfaariss.oa.util.web.SharedSecretFilter.java
/** * Initializes the <code>RemoteAddrFilter</code>. * /*from w w w . j av a 2 s . c o m*/ * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) */ public void init(FilterConfig oFilterConfig) throws ServletException { try { //Get filter name _sFilterName = oFilterConfig.getFilterName(); if (_sFilterName == null) _sFilterName = SharedSecretFilter.class.getSimpleName(); //Read shared secret parameter _sharedSecret = oFilterConfig.getInitParameter("shared_secret"); if (_sharedSecret == null || _sharedSecret.length() <= 0) { _logger.error("No 'shared_secret' init parameter found in filter configuration"); throw new OAException(SystemErrors.ERROR_INIT); } _logger.info(_sFilterName + " started."); } catch (OAException e) { _logger.fatal(_sFilterName + " start failed", e); throw new ServletException(); } catch (Exception e) { _logger.fatal(_sFilterName + " start failed due to internal error", e); throw new ServletException(); } }
From source file:com.jaspersoft.jasperserver.war.StaticFilesCacheControlFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { Enumeration<String> paramNames = filterConfig.getInitParameterNames(); while (paramNames != null && paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); String value = filterConfig.getInitParameter(paramName); if (URL_ENDS_WITH.equals(paramName)) { if (value != null && value.length() > 0) { String[] types = value.split(" "); for (int i = 0; i < types.length; i++) { if (types[i].length() > 0) { urlSuffixes.add(types[i].toLowerCase()); log.debug("URL suffix added : " + types[i]); }/*from w w w . j a va 2s . com*/ } } } else if (URL_STARTS_WITH.equals(paramName)) { if (value != null && value.length() > 0) { String[] types = value.split(" "); for (int i = 0; i < types.length; i++) { if (types[i].length() > 0) { urlPrefixes.add(types[i].toLowerCase()); log.debug("URL prefix added : " + types[i]); } } } } else if (EXCLUDE_PAGE_FROM_CACHE_REGEX.equals(paramName)) { if (value == null) continue; String[] regexStrs = value.split(" "); exclusionRegexSet.addAll(Arrays.asList(regexStrs)); log.debug("Added " + exclusionRegexSet.size() + " cache exclusion regex."); } else if (EXPIRES_AFTER_ACCESS_IN_SECS.equals(paramName)) { try { expiresInSecs = Integer.parseInt(value); log.debug("Expires in seconds set : " + expiresInSecs); } catch (Exception ex) { log.error(EXPIRES_AFTER_ACCESS_IN_SECS + " should be a non-negative integer", ex); } } else { log.warn("Unknown parameter, ignoring : " + paramName); } } }
From source file:io.milton.servlet.SpringMiltonFilter.java
@Override public void init(FilterConfig fc) throws ServletException { log.info("init"); initSpringApplicationContext(fc);//from w ww . ja v a 2s .com servletContext = fc.getServletContext(); String sExcludePaths = fc.getInitParameter(EXCLUDE_PATHS_SYSPROP); if (sExcludePaths != null) { log.info("init: exclude paths: " + sExcludePaths); excludeMiltonPaths = sExcludePaths.split(","); } else { log.info("init: exclude paths property has not been set in filter init param " + EXCLUDE_PATHS_SYSPROP); } Object milton = context.getBean("milton.http.manager"); if (milton instanceof HttpManager) { this.httpManager = (HttpManager) milton; } else if (milton instanceof HttpManagerBuilder) { HttpManagerBuilder builder = (HttpManagerBuilder) milton; ResourceFactory rf = builder.getMainResourceFactory(); if (rf instanceof AnnotationResourceFactory) { AnnotationResourceFactory arf = (AnnotationResourceFactory) rf; if (arf.getViewResolver() == null) { ViewResolver viewResolver = new JspViewResolver(servletContext); arf.setViewResolver(viewResolver); } } this.httpManager = builder.buildHttpManager(); } // init mail server if (context.containsBean("milton.mail.server")) { log.info("init mailserver..."); Object oMailServer = context.getBean("milton.mail.server"); if (oMailServer instanceof MailServer) { mailServer = (MailServer) oMailServer; } else if (oMailServer instanceof MailServerBuilder) { MailServerBuilder builder = (MailServerBuilder) oMailServer; mailServer = builder.build(); } else { throw new RuntimeException("Unsupported type: " + oMailServer.getClass() + " expected " + MailServer.class + " or " + MailServerBuilder.class); } log.info("starting mailserver"); mailServer.start(); } log.info("Finished init"); }
From source file:org.apache.hadoop.gateway.dispatch.HttpClientDispatch.java
protected void init(FilterConfig filterConfig, AppCookieManager cookieManager) throws ServletException { super.init(filterConfig); appCookieManager = cookieManager;/* ww w . j a v a2 s . co m*/ String replayBufferSizeString = filterConfig.getInitParameter(REPLAY_BUFFER_SIZE_PARAM); if (replayBufferSizeString != null) { setReplayBufferSize(Integer.valueOf(replayBufferSizeString)); } }
From source file:net.big_oh.common.web.filters.ipaddress.IPAddressFilter.java
@SuppressWarnings(value = "unchecked") private void initIPAddressFilteringRules(FilterConfig filterConfig) { Enumeration<String> filterInitParamNames = filterConfig.getInitParameterNames(); while (filterInitParamNames.hasMoreElements()) { String initParamName = filterInitParamNames.nextElement(); String initParamValue = filterConfig.getInitParameter(initParamName); if (initParamName.indexOf(".") != -1) { IPAddressFilterRule newFilterRuleFromFilterConfigParam = instantiateIPAddressFilterRule( initParamName, initParamValue); if (newFilterRuleFromFilterConfigParam != null) { registerFilterRuleWithFilter(newFilterRuleFromFilterConfigParam); }/*from w w w.j a va 2 s .co m*/ } else { logger.warn("Ignoring filter init parameter '" + initParamName + "' because it doesn't seem to be the name of a Class."); } } }
From source file:com.avlesh.web.filter.responseheaderfilter.ResponseHeaderFilter.java
public void init(FilterConfig filterConfig) throws ServletException, RuntimeException { //if specified in web.xml, take that value as the config file if (StringUtils.isNotEmpty(filterConfig.getInitParameter("configFile"))) { configFileName = filterConfig.getInitParameter("configFile"); }// w w w . j a v a 2 s . c om String fullConfigFilePath = filterConfig.getServletContext().getRealPath(configFileName); configFile = new File(fullConfigFilePath); if (!configFile.exists() || !configFile.canRead()) { //not expecting this, the config file should exist and be readable throw new RuntimeException("Cannot initialize ResponseHeaderFilter, error reading " + configFileName); } //object to hold preferences related to conf reloading confReloadInfo = new ConfReloadInfo(); String reloadCheckIntervalStr = filterConfig.getInitParameter("reloadCheckInterval"); //if web.xml filter definition has no "reloadCheckInterval" applied, default values in ConfReloadInfo are used if (StringUtils.isNotEmpty(reloadCheckIntervalStr)) { Integer reloadCheckInterval = Integer.valueOf(reloadCheckIntervalStr); if (reloadCheckInterval > 0) { confReloadInfo.reloadEnabled = true; confReloadInfo.reloadCheckInterval = reloadCheckInterval; } else { //zero or negative values means don't ever reload confReloadInfo.reloadEnabled = false; confReloadInfo.reloadCheckInterval = 0; } } //parse all the mappings into Rules ConfigProcessor configProcessor = new ConfigProcessor(configFile); Map<Pattern, Mapping> allRules = configProcessor.getRuleMap(); urlPatterns.addAll(allRules.keySet()); rules.putAll(allRules); }