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:org.localmatters.lesscss4j.servlet.LessCssServlet.java

protected Boolean getInitParameterBoolean(ServletConfig config, String name) {
    String value = config.getInitParameter(name);
    if (value != null) {
        return value.equals("true");
    }/*from w w  w.  j  a  v  a2  s  . co m*/
    return null;
}

From source file:org.apache.chemistry.opencmis.server.impl.webservices.CmisWebServicesServlet.java

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

    // get CMIS version
    String cmisVersionStr = config.getInitParameter(PARAM_CMIS_VERSION);
    if (cmisVersionStr != null) {
        try {//from   w ww. ja  va2  s .co m
            cmisVersion = CmisVersion.fromValue(cmisVersionStr);
        } catch (IllegalArgumentException e) {
            LOG.warn("CMIS version is invalid! Setting it to CMIS 1.0.");
            cmisVersion = CmisVersion.CMIS_1_0;
        }
    } else {
        LOG.warn("CMIS version is not defined! Setting it to CMIS 1.0.");
        cmisVersion = CmisVersion.CMIS_1_0;
    }

    // set up WSDL and XSD documents
    docs = new HashMap<String, String>();

    String path = (cmisVersion == CmisVersion.CMIS_1_0 ? CMIS10_PATH : CMIS11_PATH);

    docs.put("wsdl", readFile(config, path + "CMISWS-Service.wsdl.template"));
    docs.put("core", readFile(config, path + "CMIS-Core.xsd.template"));
    docs.put("msg", readFile(config, path + "CMIS-Messaging.xsd.template"));

    // set up CSRF manager
    csrfManager = new CsrfManager(config);

    super.init(config);
}

From source file:talend.ext.images.server.ImageUploadServlet.java

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

    String types = config.getInitParameter("image-file-types"); //$NON-NLS-1$
    String[] typeArray = types.split("\\|"); //$NON-NLS-1$
    okFileTypes = Arrays.asList(typeArray);
    defaultFilefieldName = config.getInitParameter("default-file-field-name"); //$NON-NLS-1$
    defaultFileNamefieldName = config.getInitParameter("default-filename-field-name"); //$NON-NLS-1$
    defaultCatalogfieldName = config.getInitParameter("default-catalog-field-name"); //$NON-NLS-1$
    outputFormat = config.getInitParameter("output-format"); //$NON-NLS-1$
}

From source file:z.tool.web.servlet.AbstractServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    String maxConcurrent = config.getInitParameter("maxConcurrent");
    if (null != maxConcurrent) {
        int intMaxConcurrent = StringUtil.stringToInt(maxConcurrent);
        if (intMaxConcurrent > 0) {
            this.maxConcurrent = intMaxConcurrent;
        }// w w  w. j a v a 2s.  com
    }

    if (LOG_INFO) {
        LOG.info(new ToStringBuilder().add("method", "init").add("clazz", getRealClassName())
                .add("maxConcurrent", this.maxConcurrent).plain());
    }
}

From source file:net.unicon.academus.apps.blogger.access.CompositeAuthorizationProvider.java

public void init(ServletConfig servletConfig, BlojsomConfiguration blojsomConfiguration)
        throws BlojsomConfigurationException {
    if (!bootstrapped) {
        synchronized (this) {
            if (!bootstrapped) {
                String authorizationConfiguration = servletConfig.getInitParameter(BLOG_COMPOSITEAUTH_IP);
                if (BlojsomUtils.checkNullOrBlank(authorizationConfiguration)) {
                    _logger.error("No authorization configuration file specified: Attempted to load: "
                            + authorizationConfiguration + " with key: " + BLOG_COMPOSITEAUTH_IP);
                    throw new BlojsomConfigurationException("No authorization configuration file specified");
                }/*from   www .  jav  a  2s  .  co  m*/

                Properties authorizationProperties;
                InputStream is = servletConfig.getServletContext()
                        .getResourceAsStream(authorizationConfiguration);
                authorizationProperties = new BlojsomProperties();
                try {
                    authorizationProperties.load(is);
                    is.close();
                    Map authorizationMap = BlojsomUtils.propertiesToMap(authorizationProperties);

                    if (!authorizationMap.containsKey(AUTHENTICATION_KEY)
                            || !authorizationMap.containsKey(AUTHORIZATION_KEY)) {
                        _logger.error("Both authentication and authorization keys must be specified.");
                        throw new BlojsomConfigurationException(
                                "Both authentication and authorization keys must be specified.");
                    }

                    authorization = loadClass((String) authorizationMap.get(AUTHORIZATION_KEY));
                    authentication = loadClass((String) authorizationMap.get(AUTHENTICATION_KEY));
                } catch (IOException e) {
                    _logger.error(e);
                    throw new BlojsomConfigurationException(e);
                }

                this.bootstrapped = true;
            }
        }
    }

    authorization.init(servletConfig, blojsomConfiguration);
    authentication.init(servletConfig, blojsomConfiguration);
}

From source file:org.keysupport.shibboleth.idp.x509.X509AuthServlet.java

/** {@inheritDoc} */
@Override//  w  ww. j  av  a2s.  co  m
public void init(final ServletConfig config) throws ServletException {
    super.init(config);

    final WebApplicationContext springContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());

    final String param = config.getInitParameter(TRUST_ENGINE_PARAM);
    if (param != null) {
        log.debug("Looking up TrustEngine bean: {}", param);
        final Object bean = springContext.getBean(param);
        if (bean instanceof TrustEngine) {
            trustEngine = (TrustEngine) bean;
        } else {
            throw new ServletException("Bean " + param + " was missing, or not a TrustManager");
        }
    }
}

From source file:org.openremote.foxycart.resources.FoxyCartResource.java

@POST()
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)/* w w  w . j  a  va  2 s. co  m*/
public Response setCustomer(@FormDataParam("FoxyData") FormDataBodyPart foxyCartBody,
        @Context ServletConfig servletConfig) {
    String key = servletConfig.getInitParameter(INIT_PARAM_NAME_FOXYCART_KEY);
    String password = servletConfig.getInitParameter(INIT_PARAM_NAME_PASSWORD);

    String foxyDataString = null;
    foxyDataString = new String(decrypt(decode(foxyCartBody.getValue()), key), StandardCharsets.UTF_8);

    Document doc = parseXML(foxyDataString);

    String firstName = evaluateXPath(doc, "/foxydata/transactions/transaction/customer_first_name/text()");
    String lastName = evaluateXPath(doc, "/foxydata/transactions/transaction/customer_last_name/text()");
    String eMail = evaluateXPath(doc, "/foxydata/transactions/transaction/customer_email/text()");

    if (firstName == null) {
        String msg = "Could not find XML element 'customer_first_name'.";
        log.error(msg);
        Response resp = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("ERROR : " + msg).build();
        throw new WebApplicationException(resp);
    }

    if (lastName == null) {
        String msg = "Could not find XML element 'customer_last_name'.";
        log.error(msg);
        Response resp = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("ERROR : " + msg).build();
        throw new WebApplicationException(resp);
    }

    if (eMail == null) {
        String msg = "Could not find XML element 'customer_email'.";
        log.error(msg);
        Response resp = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
        throw new WebApplicationException(resp);
    }

    int count = 1;
    while (!createAccount(password, createUniqueUserName(firstName, lastName, count), eMail)) {
        ++count;

        if (count > MAX_NUM_OF_UNIQUE_USER_NAMES) {
            String msg = "Did not create user '" + createUniqueUserName(firstName, lastName, count)
                    + "' because reached max number ('" + MAX_NUM_OF_UNIQUE_USER_NAMES + "') of unique users.";
            log.error(msg);
            Response resp = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("ERROR : " + msg)
                    .build();
            throw new WebApplicationException(resp);
        }
    }

    return Response.status(Response.Status.OK).entity("foxy").build();
}

From source file:com.netspective.sparx.navigate.NavigationControllerServletOptions.java

public NavigationControllerServletOptions(ServletConfig servletConfig) {
    initOptions();/*from w w w . ja  va  2 s  .co  m*/
    try {
        String optionsParamValue = servletConfig.getInitParameter(INITPARAMNAME_SERVLET_OPTIONS);
        log.debug("Using servlet init param " + INITPARAMNAME_SERVLET_OPTIONS + ":\n  " + optionsParamValue);
        commandLine = parser.parse(servletOptions,
                optionsParamValue != null ? TextUtils.getInstance().split(optionsParamValue, " ", false)
                        : new String[0]);
    } catch (ParseException pe) {
        log.error("Unable to parse servlet options using CLI", pe);

        printHelp();
        try {
            commandLine = parser.parse(servletOptions, new String[0]);
        } catch (ParseException pe2) {
            throw new RuntimeException("This should never happen!");
        }
    }
    log.debug(this);
}

From source file:org.apache.jackrabbit.j2ee.AbstractConfig.java

public void init(ServletConfig ctx) throws ServletException {
    Enumeration names = ctx.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String mapName = toMapName(name, '-');
        try {/*from   www .ja v a  2 s.  co m*/
            if (map.containsKey(mapName)) {
                map.put(mapName, ctx.getInitParameter(name));
            }
        } catch (Exception e) {
            throw new ServletExceptionWithCause("Invalid servlet configuration option: " + name, e);
        }
    }
}

From source file:net.unit8.longadeseo.servlet.AbstractConfig.java

public void init(ServletConfig ctx) throws ServletException {
    Enumeration<String> names = ctx.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String mapName = toMapName(name, '-');
        try {//from w ww  . java2  s  .co m
            if (map.containsKey(mapName)) {
                map.put(mapName, ctx.getInitParameter(name));
            }
        } catch (Exception e) {
            throw new ServletExceptionWithCause("Invalid servlet configuration option: " + name, e);
        }
    }
}