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.efaps.ui.filter.BasicAuthenticationFilter.java

/**
 *
 * Called by the web container to indicate to a filter that it is being
 * placed into service. The servlet container calls the init method exactly
 * once after instantiating the filter. The init method must complete
 * successfully before the filter is asked to do any filtering work.
 *
 * The web container cannot place the filter into service if the init method
 * either 1.Throws a ServletException 2.Does not return within a time period
 * defined by the web container//from   www . j  a v a  2s .  c  o  m
 *
 * @param _filterConfig filter configuration instance
 * @see #INIT_PARAM_TITLE
 * @see #title
 * @see #INIT_PARAM_APPLICATION
 * @see #loginhandler
 * @throws ServletException on error
 *
 */
@Override
public void init(final FilterConfig _filterConfig) throws ServletException {
    super.init(_filterConfig);
    // sets the title
    final String titleTmp = _filterConfig.getInitParameter(BasicAuthenticationFilter.INIT_PARAM_TITLE);
    if (titleTmp != null) {
        this.title = titleTmp;
    }
}

From source file:wicket.protocol.http.servlet.WicketSessionFilter.java

/**
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 *//*w w  w  . java2s.c  o  m*/
public void init(FilterConfig filterConfig) throws ServletException {
    servletPath = filterConfig.getInitParameter("servletPath");

    if (servletPath == null) {
        throw new ServletException(
                "you must provide init parameter servlet-path if you want to use " + getClass().getName());
    }

    if (servletPath.charAt(0) != '/') {
        servletPath = '/' + servletPath;
    }

    if (log.isDebugEnabled()) {
        log.debug("servlet path set to " + servletPath);
    }

    sessionKey = "wicket:" + servletPath + ":" + Session.SESSION_ATTRIBUTE_NAME;

    if (log.isDebugEnabled()) {
        log.debug("will use " + sessionKey + " as the session key to get the Wicket session");
    }
}

From source file:org.springside.modules.security.jcaptcha.JCaptchaFilter.java

/**
 * ?web.xmlfilter init-param./*w w  w .  j  a v a  2 s.c  o  m*/
 */
protected void initParameters(final FilterConfig fConfig) {
    if (StringUtils.isBlank(fConfig.getInitParameter(PARAM_FAILURE_URL))) {
        throw new IllegalArgumentException("CaptchaFilterfailureUrl?");
    }

    failureUrl = fConfig.getInitParameter(PARAM_FAILURE_URL);

    if (StringUtils.isNotBlank(fConfig.getInitParameter(PARAM_FILTER_PROCESSES_URL))) {
        filterProcessesUrl = fConfig.getInitParameter(PARAM_FILTER_PROCESSES_URL);
    }

    if (StringUtils.isNotBlank(fConfig.getInitParameter(PARAM_CAPTCHA_SERVICE_ID))) {
        captchaServiceId = fConfig.getInitParameter(PARAM_CAPTCHA_SERVICE_ID);
    }

    if (StringUtils.isNotBlank(fConfig.getInitParameter(PARAM_CAPTCHA_PARAMTER_NAME))) {
        captchaParamterName = fConfig.getInitParameter(PARAM_CAPTCHA_PARAMTER_NAME);
    }

    if (StringUtils.isNotBlank(fConfig.getInitParameter(PARAM_AUTO_PASS_VALUE))) {
        autoPassValue = fConfig.getInitParameter(PARAM_AUTO_PASS_VALUE);
    }
}

From source file:org.apache.hadoop.security.http.CrossOriginFilter.java

private void initializeMaxAge(FilterConfig filterConfig) {
    maxAge = filterConfig.getInitParameter(MAX_AGE);
    if (maxAge == null) {
        maxAge = MAX_AGE_DEFAULT;//from  w ww  .  ja v a  2  s . c  o  m
    }
    LOG.info("Max Age: " + maxAge);
}

From source file:org.sonar.server.platform.ProfilingFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    contextRoot = filterConfig.getServletContext().getContextPath();

    String staticResourcesConfig = filterConfig.getInitParameter("staticDirs");
    if (StringUtils.isNotBlank(staticResourcesConfig)) {
        staticResourceDirs = ImmutableSet.copyOf(staticResourcesConfig.split(CONFIG_SEPARATOR));
    } else {//from w w  w .ja  v a2  s.com
        staticResourceDirs = ImmutableSet.of();
    }
}

From source file:com.datatorrent.stram.security.StramWSFilter.java

@Override
public void init(FilterConfig conf) throws ServletException {
    proxyHost = conf.getInitParameter(PROXY_HOST);
    tokenManager = new StramDelegationTokenManager(DELEGATION_KEY_UPDATE_INTERVAL,
            DELEGATION_TOKEN_MAX_LIFETIME, DELEGATION_TOKEN_RENEW_INTERVAL,
            DELEGATION_TOKEN_REMOVER_SCAN_INTERVAL);
    sequenceNumber = new AtomicInteger(0);
    try {/*from  w w  w .  j a  va 2s.  c o m*/
        UserGroupInformation ugi = UserGroupInformation.getLoginUser();
        if (ugi != null) {
            loginUser = ugi.getUserName();
        }
        tokenManager.startThreads();
    } catch (IOException e) {
        throw new ServletException(e);
    }
}

From source file:com.netspective.sparx.fileupload.FileUploadFilter.java

/**
 * This method is called by the server before the filter goes into service,
 * and here it determines the file upload directory.
 *
 * @param <b>config</b> The filter config passed by the servlet engine
 *///  ww  w  .j  a  va 2 s  . c o  m
public void init(FilterConfig config) throws ServletException {
    String tryDirectoryNames = config.getInitParameter(FILTERPARAM_UPLOAD_DIRS); // comma-separated list of directories to try
    if (tryDirectoryNames != null) {
        // find the first available directory either as a resource or a physical directory
        String[] tryDirectories = TextUtils.getInstance().split(tryDirectoryNames, ",", true);
        for (int i = 0; i < tryDirectories.length; i++) {
            String tryDirectory = tryDirectories[i];
            try {
                // first try the directory as a servlet resource
                java.net.URL uploadDirURL = config.getServletContext().getResource(tryDirectory);
                if (uploadDirURL != null && uploadDirURL.getFile() != null) {
                    uploadDir = uploadDirURL.getFile();
                    break;
                }

                File f = new File(tryDirectory);
                if (f.exists()) {
                    uploadDir = f.getAbsolutePath();
                    break;
                }

            } catch (java.net.MalformedURLException ex) {
                throw new ServletException(ex.getMessage());
            }
        }
    }

    // If upload directory parameter is null, assign a temp directory
    if (uploadDir == null) {
        File tempdir = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir");
        if (tempdir != null) {
            uploadDir = tempdir.toString();
        } else {
            throw new ServletException("Error in FileUploadFilter : No upload "
                    + "directory found: set an uploadDir init " + "parameter or ensure the "
                    + "javax.servlet.context.tempdir directory " + "is valid");
        }
    }

    uploadPrefix = config.getInitParameter(FILTERPARAM_UPLOADED_FILES_PREFIX);
    if (uploadPrefix == null)
        uploadPrefix = FILTERPARAMVALUE_DEFAULT_UPLOADED_FILES_PREFIX;
    log.info("uploadPrefix is: " + uploadPrefix);

    uploadFileArg = config.getInitParameter(FILTERPARAM_UPLOADED_FILES_REQUEST_ATTR_NAME);
    if (uploadFileArg == null)
        uploadFileArg = FILTERPARAMVALUE_DEFAULT_UPLOADED_FILES_REQUEST_ATTR_NAME;
    log.info("uploadFileArg is: " + uploadFileArg);

}

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

@Test
public void testStreamResponse() throws IOException, MimeTypeParseException {
    UrlRewriteProcessor rewriter = EasyMock.createNiceMock(UrlRewriteProcessor.class);
    EasyMock.expect(rewriter.getConfig()).andReturn(null).anyTimes();

    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.getInitParameter(UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM))
            .andReturn("test-filter").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);

    String content = "content to test gzip streaming";
    testStreamResponseGzip(content, rewriteResponse, false);
    testStreamResponseGzip(content, rewriteResponse, true);
}

From source file:org.squashtest.tm.web.internal.filter.UserConcurrentRequestLockFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    this.excludePatterns = filterConfig.getInitParameter("excludePatterns");
}

From source file:net.ymate.platform.mvc.web.support.DispatchHelper.java

/**
 * //from w w w .  j  a  v a  2  s  .  c o m
 *
 * @param config
 */
public DispatchHelper(FilterConfig config) {
    prefix = StringUtils.defaultIfEmpty(config.getInitParameter("prefix"), "");
    methodParam = StringUtils.defaultIfEmpty(config.getInitParameter("methodParam"), DEFAULT_METHOD_PARAM);
    baseViewFilePath = RuntimeUtils.getRootPath()
            + StringUtils.substringAfter(TemplateHelper.getRootViewPath(), "/WEB-INF/");
}