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:org.codelibs.fess.filter.FessEncodingFilter.java

@Override
public void init(final FilterConfig config) throws ServletException {
    super.init(config);
    servletContext = config.getServletContext();

    encoding = config.getInitParameter(ENCODING);
    if (encoding == null) {
        encoding = DEFAULT_ENCODING;/*from   w  w  w. j av  a2  s  .c  o m*/
    }

    // ex. sjis:Shift_JIS,eucjp:EUC-JP
    final String value = config.getInitParameter(ENCODING_MAP);
    if (StringUtil.isNotBlank(value)) {
        final String[] encodingPairs = value.split(",");
        for (final String pair : encodingPairs) {
            final String[] encInfos = pair.trim().split(":");
            if (encInfos.length == 2) {
                encodingMap.put("/" + encInfos[0] + "/", encInfos[1]);
            }
        }
    }
}

From source file:de.mare.mobile.ui.security.AuthFilter.java

/**
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 */// w  w w. ja v a 2s. c om
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    final String responseCodeAsString = filterConfig.getInitParameter("redirectToLoginPage");
    if (StringUtils.isEmpty(responseCodeAsString)) {
        this.redirectToLoginPage = false;
    } else {
        this.redirectToLoginPage = Boolean.valueOf(responseCodeAsString).booleanValue();
    }
    final String loginPageString = filterConfig.getInitParameter("loginPage");
    if (StringUtils.isEmpty(loginPageString)) {
        this.loginPage = "login.xhtml";
    } else {
        this.loginPage = StringUtils.trim(loginPageString);
    }

    final String excludeURI = filterConfig.getInitParameter("excludeURIs");
    if (StringUtils.isNotEmpty(excludeURI)) {
        this.excludeURIs = excludeURI.split(",");
    }
}

From source file:uk.ac.ox.oucs.vle.StreamRequestFilter.java

@Override
public void init(FilterConfig arg0) throws ServletException {
    super.init(arg0);
    timeOn = "true".equals(arg0.getInitParameter("time-requests"));
    m_toolPlacement = false; // disable tool placement handelling on this
    // request/*  w  w w  .j  a  v  a  2 s .  c  om*/
    m_uploadEnabled = false; // disable upload handling on this request
}

From source file:org.eclipse.skalli.view.internal.filter.LoginFilter.java

@Override
public void init(FilterConfig config) throws ServletException {
    this.rejectAnonymousUsers = BooleanUtils.toBoolean(config.getInitParameter("rejectAnonymousUsers")); //$NON-NLS-1$
}

From source file:org.apache.hadoop.gateway.hdfs.dispatch.WebHdfsHaHttpClientDispatchTest.java

@Test
public void testConnectivityFailover() throws Exception {
    String serviceName = "WEBHDFS";
    HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
    descriptor.addServiceConfig(//from w  ww  .j a va  2 s .c  o m
            HaDescriptorFactory.createServiceConfig(serviceName, "true", "1", "1000", "2", "1000"));
    HaProvider provider = new DefaultHaProvider(descriptor);
    URI uri1 = new URI("http://unreachable-host");
    URI uri2 = new URI("http://reachable-host");
    ArrayList<String> urlList = new ArrayList<String>();
    urlList.add(uri1.toString());
    urlList.add(uri2.toString());
    provider.addHaService(serviceName, urlList);
    FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
    ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);

    EasyMock.expect(filterConfig.getInitParameter(WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE))
            .andReturn(serviceName).anyTimes();
    EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
    EasyMock.expect(servletContext.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME))
            .andReturn(provider).anyTimes();

    BasicHttpParams params = new BasicHttpParams();

    HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpRequestBase.class);
    EasyMock.expect(outboundRequest.getMethod()).andReturn("GET").anyTimes();
    EasyMock.expect(outboundRequest.getURI()).andReturn(uri1).anyTimes();
    EasyMock.expect(outboundRequest.getParams()).andReturn(params).anyTimes();

    HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class);
    EasyMock.expect(inboundRequest.getRequestURL()).andReturn(new StringBuffer(uri2.toString())).once();
    EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(0))
            .once();
    EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(1))
            .once();

    HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class);
    EasyMock.expect(outboundResponse.getOutputStream()).andAnswer(new IAnswer<ServletOutputStream>() {
        @Override
        public ServletOutputStream answer() throws Throwable {
            return new ServletOutputStream() {
                @Override
                public void write(int b) throws IOException {
                    throw new IOException("unreachable-host");
                }
            };
        }
    }).once();
    EasyMock.replay(filterConfig, servletContext, outboundRequest, inboundRequest, outboundResponse);
    Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName));
    WebHdfsHaHttpClientDispatch dispatch = new WebHdfsHaHttpClientDispatch();
    dispatch.init(filterConfig);
    long startTime = System.currentTimeMillis();
    try {
        dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse);
    } catch (IOException e) {
        //this is expected after the failover limit is reached
    }
    long elapsedTime = System.currentTimeMillis() - startTime;
    Assert.assertEquals(uri2.toString(), provider.getActiveURL(serviceName));
    //test to make sure the sleep took place
    Assert.assertTrue(elapsedTime > 1000);
}

From source file:com.versatus.jwebshield.filter.SecurityFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    String file = filterConfig.getInitParameter("configFile");
    if (file != null) {

        try {//from w  w  w . ja v a  2 s . c  o m
            XMLConfiguration config = new XMLConfiguration(file);

            useCsrfToken = config.getBoolean(SecurityConstant.USECSRFHEADER_PARAM);
            csrfHeaderName = config.getString(SecurityConstant.CSRFHEADERNAME_PARAM);
            csrfCookieName = config.getString(SecurityConstant.CSRFCOOKIENAME_PARAM);
            methodExclusionList = config.getStringArray("httpMethodExclusions");

            logger.info("init: useCsrfToken=" + useCsrfToken);
            logger.info("init: csrfHeaderName=" + csrfHeaderName);
            logger.info("init: httpMethodExclusions=" + Arrays.asList(methodExclusionList));
        } catch (Exception cex) {
            logger.error("init: unable to load configFile " + file, cex);

        }
    } else {
        logger.error("init: No configFile specified");
    }
}

From source file:opa.filter.BlockProcessing.java

@Override
public void init(FilterConfig fc) throws ServletException {
    /*//from www.  j a v  a 2  s.  com
     * build a regex of the form:
     * ^.+\\.((jsp)|(js)|(sh)|(cmd)|(exe)|(com)|(pl)|(cgi))$
     */
    String[] extensions = fc.getInitParameter("extensions").split(",");

    StringBuffer buf = new StringBuffer();
    buf.append("^.+\\.(");

    for (int i = 0; i != extensions.length; ++i) {
        buf.append("(");
        buf.append(extensions[i]);
        buf.append(")");

        if (i + 1 != extensions.length)
            buf.append("|");
    }

    buf.append(")$");

    String extMatch = buf.toString();

    pattern = Pattern.compile(buf.toString());
    log.info("extensions to be filtered from upload directory: " + extMatch);
}

From source file:org.kuali.rice.krad.web.filter.UifSessionTimeoutFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    String timeoutErrorCode = filterConfig.getInitParameter("sessionTimeoutErrorCode");

    if (timeoutErrorCode != null) {
        sessionTimeoutErrorCode = Integer.parseInt(timeoutErrorCode);
    }//  w  w w .  j ava 2 s  .  c  om
}

From source file:org.infoscoop.web.OpenIDFilter.java

public void init(FilterConfig config) throws ServletException {

    String excludePathStr = config.getInitParameter("excludePath");
    if (excludePathStr != null) {
        String[] pathArray = excludePathStr.split(",");
        for (int i = 0; i < pathArray.length; i++) {
            String path = pathArray[i].trim();
            if (path.endsWith("*")) {
                excludePaths.add(path.substring(0, path.length() - 1));
            } else {
                excludePaths.add(path);//from w  ww . ja va 2s  .c om
            }
        }
    }

    String opIdentifierParam = config.getInitParameter("opIdentifier");
    if (opIdentifierParam != null) {
        if (log.isInfoEnabled())
            log.info("loginUrl is set to " + opIdentifierParam);
        this.opIdentifier = opIdentifierParam;
    }

    int socketTimeout = 30 * 1000;
    String socketTimeoutParam = config.getInitParameter("socketTimeout");
    if (socketTimeoutParam != null) {
        if (log.isInfoEnabled())
            log.info("socketTimeout is set to " + socketTimeoutParam);
        socketTimeout = Integer.parseInt(socketTimeoutParam);
    }

    try {
        ConsumerManager newmgr = (ConsumerManager) config.getServletContext()
                .getAttribute("openid-consumermanager");
        if (newmgr == null) {
            newmgr = new ConsumerManager();
            newmgr.setAssociations(new InMemoryConsumerAssociationStore());
            newmgr.setNonceVerifier(new InMemoryNonceVerifier(5000));
            newmgr.setSocketTimeout(socketTimeout);
            config.getServletContext().setAttribute("openid-consumermanager", newmgr);
        }
        this.consumerMgr = newmgr;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}

From source file:org.dspace.utils.servlet.DSpaceWebappServletFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    // ensure the kernel is running, if not then we have to die here
    try {// w w w.  ja  v  a2 s .c  o m
        getKernel();
        String param = filterConfig.getInitParameter("paths-to-be-ignored");
        pathsToBeIgnored = new ArrayList<String>();
        if (null != StringUtils.trimToNull(param)) {
            String[] items = StringUtils.split(param, ';');
            for (String item : items) {
                pathsToBeIgnored.add(item);
            }
        }

    } catch (IllegalStateException e) {
        // no kernel so we die
        String message = "Could not start up DSpaceWebappServletFilter because the DSpace Kernel is unavailable or not running: "
                + e.getMessage();
        System.err.println(message);
        throw new ServletException(message, e);
    }
}