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:net.firejack.platform.model.config.GatewayLoader.java

/**
 * @param config//from  w  w  w . j a v a 2  s  .  co  m
 * @throws javax.servlet.ServletException
 */
public void init(ServletConfig config) throws ServletException {
    String gateway = config.getInitParameter(CONFIG);
    File resource = FileUtils.getResource(gateway);

    try {
        FileInputStream stream = FileUtils.openInputStream(resource);

        Properties properties = new Properties();
        properties.load(stream);
        IOUtils.closeQuietly(stream);

        this.port = TomcatUtils.getCatalinaPort(config);
        this.lookup = properties.getProperty(LOOKUP);
        OpenFlameSecurityConstants.setPackageLookup(this.lookup);

        String start = properties.getProperty(TIMEOUT);

        OpenFlameConfig.MC_SERVER_URL.setValue(properties.getProperty(OpenFlameConfig.MC_SERVER_URL.getKey()));
        OpenFlameConfig.MC_PORT.setValue(properties.getProperty(OpenFlameConfig.MC_PORT.getKey()));

        if (StringUtils.isNotBlank(start)) {
            this.timeout = Integer.parseInt(start);
        }
        if (StringUtils.isBlank(lookup)) {
            logger.error("Not found servlet parameter 'lookup'");
        }

        init();
    } catch (Exception e) {
        logger.error(e);
    }
}

From source file:org.signserver.web.SignServerHealthCheck.java

@Override
public void init(final ServletConfig config, final EntityManager em) {
    minfreememory = Integer.parseInt(config.getInitParameter("MinimumFreeMemory")) * 1024 * 1024;
    checkDBString = config.getInitParameter("checkDBString");
    maintenanceFile = config.getInitParameter("MaintenanceFile");
    maintenancePropertyName = config.getInitParameter("MaintenancePropertyName");
    this.em = em;
    if (LOG.isDebugEnabled()) {
        final StringBuilder buff = new StringBuilder();
        buff.append("Health check configured with:\n").append("minfreeememory: ").append(minfreememory)
                .append("\n").append("checkDBString: ").append(checkDBString).append("\n")
                .append("maintenancePropertyName: ").append(maintenancePropertyName).append("\n")
                .append("entityManager: ").append(em);
        LOG.debug(buff.append(buff));//from  www.j ava 2 s.co  m
    }
    initMaintenanceFile();
}

From source file:org.apache.camel.component.servlet.CamelHttpTransportServlet.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    servletName = config.getServletName();
    // parser the servlet init parameters
    CAMEL_SERVLET_MAP.put(servletName, this);
    String contextConfigLocation = config.getInitParameter("contextConfigLocation");
    if (contextConfigLocation != null) {
        //Create a spring application context for it
        applicationContext = new ClassPathXmlApplicationContext(contextConfigLocation.split(","));
        LOG.info("Started the application context rightly");
    }// ww w  .  java2s .  c o  m
}

From source file:org.ventiv.webjars.requirejs.servlet.RequireJsConfigServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    if (requireJsConfigBuilder == null) { // Only initialize this if we haven't already (e.g. Not in Spring-Boot)
        webJarRootUrl = getWithDefault(config.getInitParameter("webjars.requirejs.config.rootUrl"),
                webJarRootUrl);//from  w  w  w.j  a  va 2 s  .c  o m
        prettyPrint = getWithDefault(config.getInitParameter("webjars.requirejs.config.prettyPrint"),
                prettyPrint);

        requireJsConfigBuilder = new RequireJsConfigBuilder(webJarRootUrl, null);
    }
}

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

/**
 * {@inheritDoc}/* www.  jav a2  s .  c om*/
 */
@Override
public void init(ServletConfig config) throws ServletException {

    this.idpDestination = config.getInitParameter(IDP_DESTINATION_PARAM);
    this.spDestination = config.getInitParameter(SP_DESTINATION_PARAM);
    this.spDestinationPage = config.getInitParameter(SP_DESTINATION_PAGE_PARAM);
    this.language = config.getInitParameter(LANGUAGE_PARAM);
    this.authenticationRequestServiceLocator = new ServiceLocator<AuthenticationRequestService>(
            AUTHN_REQUEST_SERVICE_PARAM, config);

    // validate necessary configuration params
    if (null == this.idpDestination && !this.authenticationRequestServiceLocator.isConfigured()) {
        throw new ServletException("need to provide either " + IDP_DESTINATION_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");
    }
}

From source file:org.appcelerator.transport.AjaxServiceTransportServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    String validate = config.getInitParameter("validate");
    if (validate != null && !validate.equals("")) {
        performValidation = Boolean.parseBoolean(validate);
    }/*  ww w  .j  av  a  2s  .  c  o m*/

    if (this.embeddedMode) {
        AnnotationHelper.initializeAnnotationDBFromClasspath();
    } else {
        AnnotationHelper.initializeAnnotationDBFromServlet(config.getServletContext());
    }

    ServiceRegistry.intialize(config.getServletContext());
}

From source file:com.vaadin.addon.jpacontainer.demo.servlet.SpringApplicationServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    /*//from w  w  w.java 2  s.c o m
     * Look up the name of the Vaadin application prototype bean.
     */
    applicationBean = servletConfig.getInitParameter("applicationBean");
    if (applicationBean == null) {
        if (logger.isErrorEnabled()) {
            logger.error("ApplicationBean not specified in servlet parameters");
        }
        throw new ServletException("ApplicationBean not specified in servlet parameters");
    }

    if (logger.isInfoEnabled()) {
        logger.info("Found Vaadin ApplicationBean [" + applicationBean + "]");
    }
    /*
     * Fetch the Spring web application context
     */
    applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext());

    if (!applicationContext.isPrototype(applicationBean)) {
        if (logger.isWarnEnabled()) {
            logger.warn("ApplicationBean not configured as a prototype");
        }
    }

    applicationClass = (Class<? extends Application>) applicationContext.getType(applicationBean);
    if (logger.isDebugEnabled()) {
        logger.debug("Vaadin application class is [" + applicationClass + "]");
    }
}

From source file:org.sakaiproject.vm.VelocityServlet.java

/**
 * Called by the VelocityServlet init(). We want to set a set of properties so that templates will be found in the webapp root. This makes this easier to work with as an example, so a new user doesn't have to worry about config issues when first
 * figuring things out//from   w  w  w  . ja  v  a2s.  com
 */
protected ExtendedProperties loadConfiguration(ServletConfig config) throws IOException, FileNotFoundException {
    // This is to support old config property.
    String configPath = config.getInitParameter("properties");
    ExtendedProperties p;
    if (configPath != null && configPath.length() > 0) {
        p = new ExtendedProperties();
        if (!configPath.startsWith("/")) {
            configPath = "/" + configPath;
        }
        p.load(getServletContext().getResourceAsStream(configPath));
    } else {
        // load the properties as configured in the servlet init params
        p = super.loadConfiguration(config);
    }

    /*
     * first, we set the template path for the FileResourceLoader to the root of the webapp. This probably won't work under in a WAR under WebLogic, but should under tomcat :)
     */

    String path = config.getServletContext().getRealPath("/");

    if (path == null) {
        getVelocityEngine().getLog().debug(" VelocityServlet.loadConfiguration() : unable to "
                + "get the current webapp root.  Using '/'. Please fix.");
        path = "/";
    }

    p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);

    /**
     * and the same for the log file
     */
    p.setProperty("runtime.log", path + p.getProperty("runtime.log"));

    return p;
}

From source file:common.web.servlets.StaticFilesServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    if (config != null) {
        String prop_file = config.getInitParameter(PROPERTIES_PATH_NAME);
        if (prop_file == null || prop_file.equals(""))
            throw new ServletException("properties_file not specified");
        //loadFromPropertiesFile( config.getServletContext().getRealPath(prop_file) );
        loadFromPropertiesFile(prop_file);

        config.getServletContext().setAttribute("NewIO", newStat);
        config.getServletContext().setAttribute("OldIO", oldStat);
    }/* w w w.  j av a 2 s .  c o m*/
    if (realPath == null)
        throw new ServletException("path to directory not found");
}

From source file:org.fcrepo.indexer.webapp.FedoraIndexer.java

/**
 * Servlet initialization./*from w  w  w .  j av  a  2  s.  com*/
**/
public void init(final ServletConfig sc) throws ServletException {
    super.init(sc);
    final WebApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    indexer = (IndexerGroup) ctx.getBean(sc.getInitParameter("beanName"));
}