Example usage for javax.servlet ServletConfig getInitParameter

List of usage examples for javax.servlet ServletConfig getInitParameter

Introduction

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

Prototype

public String getInitParameter(String name);

Source Link

Document

Gets the value of the initialization parameter with the given name.

Usage

From source file:br.bireme.mlts.MoreLikeThatServlet.java

@Override
public void init(final ServletConfig servletConfig) throws ServletException {
    final String sdir = servletConfig.getInitParameter("INDEX_DIR");
    if (sdir == null) {
        throw new ServletException("missing index directory (INDEX_DIR) " + "parameter.");
    }/*ww w  .jav a2  s  .com*/
    final Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
    try {
        mlt = new MoreLikeThat(new File(sdir), analyzer);
    } catch (IOException ex) {
        throw new ServletException(ex);
    }

    final String maxHits = servletConfig.getInitParameter("MAX_HITS");
    if (maxHits != null) {
        mlt.setMaxHits(Integer.parseInt(maxHits));
    }
    final String minTermFreq = servletConfig.getInitParameter("MIN_TERM_FREQ");
    if (minTermFreq != null) {
        mlt.setMinTermFreq(Integer.parseInt(minTermFreq));
    }
    final String minDocFreq = servletConfig.getInitParameter("MIN_DOC_FREQ");
    if (minDocFreq != null) {
        mlt.setMinDocFreq(Integer.parseInt(minDocFreq));
    }
    final String maxDocFreq = servletConfig.getInitParameter("MAX_DOC_FREQ");
    if (maxDocFreq != null) {
        mlt.setMaxDocFreq(Integer.parseInt(maxDocFreq));
    }
    final String minWordLen = servletConfig.getInitParameter("MIN_WORD_LENGTH");
    if (minWordLen != null) {
        mlt.setMinWordLen(Integer.parseInt(minWordLen));
    }
    final String maxWordLen = servletConfig.getInitParameter("MAX_WORD_LENGTH");
    if (maxWordLen != null) {
        mlt.setMaxWordLen(Integer.parseInt(maxWordLen));
    }
    final String maxQueryTerms = servletConfig.getInitParameter("MAX_QUERY_TERMS");
    if (maxQueryTerms != null) {
        mlt.setMaxQueryTerms(Integer.parseInt(maxQueryTerms));
    }
    final String maxNumTokensParsed = servletConfig.getInitParameter("MAX_NUM_TOKENS_PARSED");
    if (maxNumTokensParsed != null) {
        mlt.setMaxNumTokensParsed(Integer.parseInt(maxNumTokensParsed));
    }
    final String minScore = servletConfig.getInitParameter("MIN_SCORE");
    if (minScore != null) {
        mlt.setMinScore(Float.parseFloat(minScore));
    }
}

From source file:be.fedict.eid.idp.sp.protocol.openid.AuthenticationRequestServlet.java

/**
 * {@inheritDoc}//  ww  w .j  a v a  2 s .c  om
 */
@Override
public void init(ServletConfig config) throws ServletException {

    this.userIdentifier = config.getInitParameter(USER_IDENTIFIER_PARAM);
    this.spDestination = config.getInitParameter(SP_DESTINATION_PARAM);
    this.spDestinationPage = config.getInitParameter(SP_DESTINATION_PAGE_PARAM);
    this.languages = config.getInitParameter(LANGUAGES_PARAM);
    this.authenticationRequestServiceLocator = new ServiceLocator<AuthenticationRequestService>(
            AUTHN_REQUEST_SERVICE_PARAM, config);

    // validate necessary configuration params
    if (null == this.userIdentifier && !this.authenticationRequestServiceLocator.isConfigured()) {
        throw new ServletException("need to provide either " + USER_IDENTIFIER_PARAM + " or "
                + AUTHN_REQUEST_SERVICE_PARAM + "(Class) init-params");
    }

    if (null == this.spDestination && null == this.spDestinationPage
            && !this.authenticationRequestServiceLocator.isConfigured()) {
        throw new ServletException("need to provide either " + SP_DESTINATION_PARAM + " or "
                + SP_DESTINATION_PAGE_PARAM + " or " + AUTHN_REQUEST_SERVICE_PARAM + "(Class) init-param");
    }

    // SSL configuration
    String trustServer = config.getInitParameter(TRUST_SERVER_PARAM);
    if (null != trustServer) {
        this.trustServer = Boolean.parseBoolean(trustServer);
    }
    X509Certificate serverCertificate = null;
    if (this.authenticationRequestServiceLocator.isConfigured()) {
        AuthenticationRequestService service = this.authenticationRequestServiceLocator.locateService();
        serverCertificate = service.getServerCertificate();
    }

    if (this.trustServer) {

        LOG.warn("Trusting all SSL server certificates!");
        try {
            OpenIDSSLSocketFactory.installAllTrusted();
        } catch (Exception e) {
            throw new ServletException("could not install OpenID SSL Socket Factory: " + e.getMessage(), e);
        }
    } else if (null != serverCertificate) {

        LOG.info("Trusting specified SSL certificate: " + serverCertificate);
        try {
            OpenIDSSLSocketFactory.install(serverCertificate);
        } catch (Exception e) {
            throw new ServletException("could not install OpenID SSL Socket Factory: " + e.getMessage(), e);
        }
    }

    ServletContext servletContext = config.getServletContext();
    this.consumerManager = (ConsumerManager) servletContext.getAttribute(CONSUMER_MANAGER_ATTRIBUTE);

    if (null == this.consumerManager) {
        try {
            if (this.trustServer || null != serverCertificate) {

                TrustManager trustManager;
                if (this.trustServer) {
                    trustManager = new OpenIDTrustManager();
                } else {
                    trustManager = new OpenIDTrustManager(serverCertificate);
                }

                SSLContext sslContext = SSLContext.getInstance("SSL");
                TrustManager[] trustManagers = { trustManager };
                sslContext.init(null, trustManagers, null);
                HttpFetcherFactory httpFetcherFactory = new HttpFetcherFactory(sslContext,
                        SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                YadisResolver yadisResolver = new YadisResolver(httpFetcherFactory);
                RealmVerifierFactory realmFactory = new RealmVerifierFactory(yadisResolver);
                HtmlResolver htmlResolver = new HtmlResolver(httpFetcherFactory);
                XriResolver xriResolver = Discovery.getXriResolver();
                Discovery discovery = new Discovery(htmlResolver, yadisResolver, xriResolver);
                this.consumerManager = new ConsumerManager(realmFactory, discovery, httpFetcherFactory);

            } else {
                this.consumerManager = new ConsumerManager();
            }
        } catch (Exception e) {
            throw new ServletException("could not init OpenID ConsumerManager");
        }
        servletContext.setAttribute(CONSUMER_MANAGER_ATTRIBUTE, this.consumerManager);
    }
}

From source file:org.codehaus.mojo.mrm.servlet.FileSystemServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    String repositoryDir = config.getInitParameter("repository.dir");
    File repo = new File(repositoryDir);
    if (repo.exists() == false) {
        throw new RuntimeException("The repository " + repo + " does not exist!");
    }/*from   w  w  w.ja  v  a2  s  . co  m*/

    System.out.println("<< Repository dir is: " + repo.getAbsolutePath() + " >>");

    this.fileSystem = new DiskFileSystem(repo, false);
}

From source file:org.codice.ddf.catalog.ui.SparkServlet.java

private synchronized void populateWrapperSupplier(ServletConfig config) {
    // Do not override an injected supplier through initialization
    if (requestSupplier != null) {
        return;/*from  w  w  w .  ja  v a  2s .  co m*/
    }

    String wrapperSupplierName = config.getInitParameter(WRAPPER_SUPPLIER_PARAM_NAME);

    if (StringUtils.isNotBlank(wrapperSupplierName)) {
        try {
            Class<?> wrapperClass = Class.forName(wrapperSupplierName);
            if (BiFunction.class.isAssignableFrom(wrapperClass)) {
                requestSupplier = (BiFunction<HttpServletRequest, String, HttpServletRequestWrapper>) wrapperClass
                        .newInstance();
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            LOGGER.debug(
                    "Error converting {} to BiFunction<HttpServletRequest, String, HttpServletRequestWrapper>; "
                            + "falling back to default",
                    wrapperSupplierName, e);
        }
    }

    if (requestSupplier == null) {
        requestSupplier = DEFAULT_REQ_FUNC;
    }
}

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

/**
 * Initialization of the servlet. <br>
 * /*from  ww w  .  jav a2  s  . c  om*/
 * @throws ServletException
 *             if an error occure
 */
public void init(ServletConfig config) throws ServletException {
    try {
        int to = Integer.parseInt(config.getInitParameter("timeout"));
        DEFAULT_TIMEOUT = to;
    } catch (Throwable t) {
        // just ignore.
    }
}

From source file:zutil.jee.upload.AjaxFileUpload.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {/*w w  w .  j av a  2  s.c o m*/
        // Read the javascript file to memory
        String path = JAVASCRIPT_FILE;
        if (config.getInitParameter("JAVASCRIPT_FILE") != null)
            path = config.getInitParameter("JAVASCRIPT_FILE");
        JAVASCRIPT = FileUtil.getContent(FileUtil.findURL(path));

        // Read temp dir
        if (config.getInitParameter("TEMP_PATH") != null) {
            if (config.getInitParameter("TEMP_PATH").equalsIgnoreCase("SYSTEM"))
                TEMPFILE_PATH = new File(System.getProperty("java.io.tmpdir"));
            else if (config.getInitParameter("TEMP_PATH").equalsIgnoreCase("SERVLET"))
                TEMPFILE_PATH = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir");
            else
                TEMPFILE_PATH = new File(config.getInitParameter("TEMP_PATH"));
        }

        // Read allowed file types
        if (config.getInitParameter("ALLOWED_EXTENSIONS") != null) {
            String[] tmp = config.getInitParameter("ALLOWED_EXTENSIONS").split(",");
            StringBuilder ext_log = new StringBuilder("Allowed extensions: ");
            for (String ext : tmp) {
                ALLOWED_EXTENSIONS.add(ext.trim().toLowerCase());
                ext_log.append(ext).append(", ");
            }
            logger.info(ext_log.toString());
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.funambol.server.sendlog.LogServlet.java

/**
 * Initializes the servlet//from w  w  w  . j av a  2  s .c  o m
 * @throws javax.servlet.ServletException
 */
@Override
public void init() throws ServletException {
    String msg1 = "================================================================================";
    String sp = "\n";
    String msg2 = "Funambol Send log started.";

    Configuration configuration = Configuration.getConfiguration();
    try {
        configuration.configureLogging();
    } catch (Exception e) {
        //
        //
        System.out.println(msg1);
        System.out.println(sp);
        System.out.println(msg2);
        System.out.println(sp);
        System.out.println(msg1);
    }

    if (log.isInfoEnabled()) {
        log.info(msg1 + sp);
        log.info(msg2 + sp);
        log.info(msg1);
    }

    ServletConfig config = getServletConfig();

    String value = config.getInitParameter(CLIENTS_LOG_BASEDIR);
    if (StringUtils.isEmpty(value)) {
        String msg = "The servlet configuration parameter '" + CLIENTS_LOG_BASEDIR + "' cannot be empty ("
                + value + ")";
        log(msg);
        throw new ServletException(msg);
    }
    clientsLogBaseDir = value;
    if (log.isTraceEnabled()) {
        log.trace("Read value '" + value + "' for key '" + CLIENTS_LOG_BASEDIR + "'.");
    }

    value = config.getInitParameter(CLIENTS_LOG_MAX_SIZE);
    if (StringUtils.isEmpty(value)) {
        String msg = "The servlet configuration parameter '" + CLIENTS_LOG_MAX_SIZE + "' cannot be empty ("
                + value + ")";
        log(msg);
        throw new ServletException(msg);
    }
    try {
        clientsLogMaxSize = StringTools.converterStringSizeInBytes(value);
    } catch (NumberFormatException e) {
        String msg = "Unable to parse value '" + value + "' for '" + CLIENTS_LOG_MAX_SIZE + "'";
        log(msg);
        throw new ServletException(msg);
    }
    if (log.isTraceEnabled()) {
        log.trace("Read value '" + clientsLogMaxSize + "' for key '" + CLIENTS_LOG_MAX_SIZE + "'.");
    }
}

From source file:org.webguitoolkit.ui.controls.form.fileupload.FileUploadServlet.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    String maxFileSizeString = config.getInitParameter(MAX_FILE_SIZE);
    if (StringUtils.isNumeric(maxFileSizeString))
        maxFileSize = Integer.parseInt(maxFileSizeString);
}

From source file:com.jaspersoft.jasperserver.war.themes.ThemeResolverServlet.java

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

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
    themeCache = (ThemeCache) ctx.getBean("themeCache");

    String value = config.getInitParameter(EXPIRES_AFTER_ACCESS_IN_SECS);
    try {//from  w w w  .j  a  v  a 2s.  c o m
        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);
    }

}

From source file:org.codice.proxy.http.HttpProxyCamelHttpTransportServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    String ignore = config.getInitParameter("ignoreDuplicateServletName");
    Boolean bool = ObjectConverter.toBoolean(ignore);
    if (bool != null) {
        ignoreDuplicateServletName = bool;
    } else {//ww w.j  av a  2 s .c  om
        // always log so people can see it easier
        String msg = "Invalid parameter value for init-parameter ignoreDuplicateServletName with value: "
                + ignore;
        LOG.error(msg);
        throw new ServletException(msg);
    }

    String name = config.getServletName();
    String contextPath = config.getServletContext().getContextPath();

    if (httpRegistry == null) {
        httpRegistry = DefaultHttpRegistry.getHttpRegistry(name);
        CamelServlet existing = httpRegistry.getCamelServlet(name);
        if (existing != null) {
            String msg = "Duplicate ServetName detected: " + name + ". Existing: " + existing + " This: "
                    + this.toString() + ". Its advised to use unique ServletName per Camel application.";
            // always log so people can see it easier
            if (isIgnoreDuplicateServletName()) {
                LOG.warn(msg);
            } else {
                LOG.error(msg);
                throw new ServletException(msg);
            }
        }
        httpRegistry.register(this);
    }

    LOG.info("Initialized CamelHttpTransportServlet[name={}, contextPath={}]", getServletName(), contextPath);
}