Example usage for javax.servlet FilterConfig getInitParameter

List of usage examples for javax.servlet FilterConfig getInitParameter

Introduction

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

Prototype

public String getInitParameter(String name);

Source Link

Document

Returns a String containing the value of the named initialization parameter, or null if the initialization parameter does not exist.

Usage

From source file:com.github.woonsan.katharsis.servlet.AbstractKatharsisFilter.java

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

From source file:org.energyos.espi.thirdparty.web.filter.CORSFilter.java

public void init(FilterConfig cfg) throws ServletException {

    // Process origin parameters
    String regex = cfg.getInitParameter("allow.origin.regex");
    if (regex != null) {
        allowOriginRegex = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    } else {//  w  w w .java 2 s. c  om
        allowOrigin = cfg.getInitParameter("allow.origin");
        if (allowOrigin != null) {
            optionsHeaders.put("Access-Control-Allow-Origin", allowOrigin);
        }
    }

    // Process optional header parameters
    for (Enumeration<String> i = cfg.getInitParameterNames(); i.hasMoreElements();) {
        String name = i.nextElement();
        if (name.startsWith("header:")) {
            optionsHeaders.put(name.substring(7), cfg.getInitParameter(name));
        }
    }

    // Process Credential support parameter
    allowCredentials = cfg.getInitParameter("allow.credentials");

    // Process Expose header parameter
    exposeHeaders = cfg.getInitParameter("expose.headers");

    // Initialize default header values
    optionsHeaders.put("Access-Control-Allow-Headers", "Origin, Authorization, Accept, Content-Type");
    optionsHeaders.put("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    optionsHeaders.put("Access-Control-Max-Age", "1800");

}

From source file:ar.com.zauber.commons.web.filter.JSONPRequestFilter.java

/** @see javax.servlet.Filter#init(javax.servlet.FilterConfig) */
public final void init(final FilterConfig filterConfig) throws ServletException {
    final String suppliedCallbackParameterName = filterConfig.getInitParameter("callbackParameterName");

    if (StringUtils.isNotBlank(suppliedCallbackParameterName)) {
        setCallbackParameterName(suppliedCallbackParameterName);
    }/*from w w w . java 2s  .c o m*/

    final String suppliedResponseContentType = filterConfig.getInitParameter("responseContentType");

    if (StringUtils.isNotBlank(suppliedResponseContentType)) {
        setResponseContentType(suppliedResponseContentType);
    }
}

From source file:cn.vlabs.duckling.vwb.VWBFilter.java

public void init(FilterConfig config) throws ServletException {
    encoding = config.getInitParameter("charset");
    if (encoding == null)
        encoding = "UTF-8";
    String ignore = config.getInitParameter("ignore");
    if (ignore != null) {
        ignoreList = ignore.split(";");
    }/*from  w  w w  . jav a2 s .  co m*/
}

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

@Test
public void testResolve() throws Exception {

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

    ServletContext context = EasyMock.createNiceMock(ServletContext.class);
    EasyMock.expect(context.getServletContextName()).andReturn("test-cluster-name").anyTimes();
    EasyMock.expect(context.getInitParameter("test-init-param-name")).andReturn("test-init-param-value")
            .anyTimes();/*from   ww  w  .j  a  v a 2  s. c  o m*/
    EasyMock.expect(context.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME))
            .andReturn(rewriter).anyTimes();

    FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
    EasyMock.expect(config.getInitParameter("test-filter-init-param-name"))
            .andReturn("test-filter-init-param-value").anyTimes();
    EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes();

    HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
    HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);

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

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

    List<String> names = rewriteResponse.resolve("test-filter-init-param-name");
    assertThat(names.size(), is(1));
    assertThat(names.get(0), is("test-filter-init-param-value"));
}

From source file:de.rgielen.struts1.filter.ParamWrapperFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    final String toCompile;
    final String initParameter = filterConfig.getInitParameter(INIT_PARAM_NAME);
    if (initParameter != null && initParameter.trim().length() > 0) {
        toCompile = initParameter;//w ww .jav  a  2 s.c o m
    } else {
        toCompile = DEFAULT_BLACKLIST_PATTERN;
    }
    this.pattern = Pattern.compile(toCompile, Pattern.DOTALL);
}

From source file:org.energyos.espi.datacustodian.web.filter.CORSFilter.java

@SuppressWarnings("unchecked")
// TODO: fix the class problem
public void init(FilterConfig cfg) throws ServletException {

    // Process origin parameters
    String regex = cfg.getInitParameter("allow.origin.regex");
    if (regex != null) {
        allowOriginRegex = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    } else {/*from w  w w  .j  a  v  a  2 s. c  om*/
        allowOrigin = cfg.getInitParameter("allow.origin");
        if (allowOrigin != null) {
            optionsHeaders.put("Access-Control-Allow-Origin", allowOrigin);
        }
    }

    // Process optional header parameters
    for (Enumeration<String> i = cfg.getInitParameterNames(); i.hasMoreElements();) {
        String name = i.nextElement();
        if (name.startsWith("header:")) {
            optionsHeaders.put(name.substring(7), cfg.getInitParameter(name));
        }
    }

    // Process Credential support parameter
    allowCredentials = cfg.getInitParameter("allow.credentials");

    // Process Expose header parameter
    exposeHeaders = cfg.getInitParameter("expose.headers");

    // Initialize default header values
    optionsHeaders.put("Access-Control-Allow-Headers", "Origin, Authorization, Accept, Content-Type");
    optionsHeaders.put("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    optionsHeaders.put("Access-Control-Max-Age", "1800");

}

From source file:AIR.Common.Web.Session.CaseInsensitiveFileNameFilter.java

private void setUpExtensionMapping(FilterConfig filterConfig) {
    String extensionsMappingConfig = filterConfig.getInitParameter("extensionsMapping");
    if (StringUtils.isEmpty(extensionsMappingConfig)) {
        _logger.warn(//from   w  ww .jav a 2 s  .  c om
                "No extensions mapping provided. Please fill out the extensionsMapping init-param for CaseInsensitiveFileNameFilter. Extensions mapping tuples are pipe (|) seperated e.g. a=b|c=d.... This will changes paths with extensions \"a\" to a path with extension \"b\" and so on.");
    } else {
        String[] extensionsMapStrings = StringUtils.split(extensionsMappingConfig, "|");
        for (String extensionMapString : extensionsMapStrings) {
            String[] pairs = StringUtils.split(extensionMapString, "=");
            if (pairs.length != 2) {
                _logger.warn(String.format(
                        "In extensionsMapping filter configuration, %s does not resolve to a key value pair. Skipping.",
                        extensionMapString));
            } else {
                this._extensionsMap.put(pairs[0], pairs[1]);
            }
        }
    }
}

From source file:org.wings.session.SmartURLsFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    if (filterConfig.getInitParameter("wings.servlet.smarturls.parameterSeparator") != null)
        parameterSeparator = filterConfig.getInitParameter("wings.servlet.smarturls.parameterSeparator");

    if (filterConfig.getInitParameter("wings.servlet.smarturls.nameValueSeparator") != null)
        nameValueSeparator = filterConfig.getInitParameter("wings.servlet.smarturls.nameValueSeparator");

    log.info("wings.servlet.smarturls.parameterSeparator " + parameterSeparator);
    log.info("wings.servlet.smarturls.nameValueSeparator " + nameValueSeparator);

    encodePattern = Pattern/*from ww  w  .  ja  v  a  2 s.  c  om*/
            .compile("(" + "\\?|&" + ")([a-zA-Z0-9%+.-[*]_]*)" + "(" + "=" + ")([a-zA-Z0-9%+.-[*]_=/:]*)");
    decodePattern = Pattern.compile("(" + parameterSeparator + ")([a-zA-Z0-9%+.-[*]_]*)" + "("
            + nameValueSeparator + ")([a-zA-Z0-9%+.-[*]_=/:]*)");
}

From source file:org.wso2.carbon.identity.relyingparty.OpenIDRelyingPartyData.java

/**
 * {@inheritDoc}/* w ww  .ja  v  a2 s  .com*/
 */
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);
                }
            }
        }
    }
}