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:com.netscape.cms.servlet.cert.ReasonToRevoke.java

/**
 * initialize the servlet. This servlet uses the template file
 * 'reasonToRevoke.template' to render the response
 *
 * @param sc servlet configuration, read from the web.xml file
 *//*from   w  ww. j a v a 2  s.co  m*/
public void init(ServletConfig sc) throws ServletException {
    super.init(sc);
    mFormPath = "/" + mAuthority.getId() + "/" + TPL_FILE;
    if (mAuthority instanceof ICertificateAuthority) {
        mCA = (ICertificateAuthority) mAuthority;
        mCertDB = ((ICertificateAuthority) mAuthority).getCertificateRepository();
    }

    if (mCA != null && mCA.noncesEnabled()) {

        JssSubsystem jssSubsystem = (JssSubsystem) CMS.getSubsystem(JssSubsystem.ID);
        mRandom = jssSubsystem.getRandomNumberGenerator();
    }

    mTemplates.remove(ICMSRequest.SUCCESS);
    if (mOutputTemplatePath != null)
        mFormPath = mOutputTemplatePath;

    /* Server-Side time limit */
    try {
        mTimeLimits = Integer.parseInt(sc.getInitParameter("timeLimits"));
    } catch (Exception e) {
        /* do nothing, just use the default if integer parsing failed */
    }
}

From source file:com.konakart.server.KKGWTServiceImpl.java

public void init(ServletConfig config) throws ServletException {
    // very important to call super.init() here
    super.init(config);

    if (config != null) {
        String startOwnEnginesParam = config.getInitParameter("startOwnEngines");
        if (log.isDebugEnabled()) {
            log.debug("startOwnEngines parameter = " + startOwnEnginesParam);
        }//from   w ww  .j ava 2s . c  om

        if (startOwnEnginesParam != null && startOwnEnginesParam.equalsIgnoreCase("FALSE")) {
            setStartOwnEngines(false);
        }
    } else {
        if (log.isInfoEnabled()) {
            log.info("Servlet config was null");
        }
    }

    if (isStartOwnEngines() == false) {
        if (log.isDebugEnabled()) {
            log.debug("No engines created in KKGWTServiceImpl()");
        }
        return;
    }

    if (log.isInfoEnabled()) {
        log.info("startOwnEngines undefined so we now create some engines...");
    }

    /*
     * This should only be used when debugging from Eclipse. Otherwise we use the instance of
     * the engine which is attached to the session.
     */
    synchronized (mutex) {
        if (kkConfig == null) {
            try {
                String configFile;
                /*
                 * Find the properties file which is guaranteed to return the full path name of
                 * the properties file or throw an exception. It can't send out an error message
                 * since Log4j hasn't been initialised yet. In this case the properties file
                 * should be called konakart_gwt.properties
                 */
                configFile = PropertyFileFinder.findProperties(propertiesFileName);
                Configuration conf = new PropertiesConfiguration(configFile);
                if (conf.isEmpty()) {
                    log.error("KKGWTServiceImpl() " + propertiesFileName + " contains no keys");
                    throw new KKException(
                            "The configuration file: " + propertiesFileName + " contains no keys");
                }

                // Look for properties that are in the "konakart.app" namespace.
                Configuration subConf = conf.subset("konakart.gwt");
                if (subConf == null || subConf.isEmpty()) {
                    log.error("The konakart.gwt section in the properties file is missing. "
                            + "You must add at least one property to resolve this problem. "
                            + "e.g. konakart.gwt.engineclass=com.konakart.app.KKEng");
                    return;
                }
                kkConfig = subConf;
            } catch (Exception e) {
                log.warn("KonakartGWTServer() an error has occured");
                // e.printStackTrace();
                throw new ServletException(getExceptionMessage(e));
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("kkConfig not null");
            }
        }

        // Instantiate the engine
        try {
            if (kkConfig == null) {
                throw new KKException("No properties have been found for the application. "
                        + "Please ensure that the properties file " + propertiesFileName + " exists");
            }
            String engineClassName = kkConfig.getString("engineclass");
            System.out.println("KonakartGWTServer() Engine to be used by application is " + engineClassName);

            EngineConfigIf engConf = new EngineConfig();
            engConf.setStoreId("store1");
            engConf.setAppPropertiesFileName(konakart_app_propertiesFileName);
            engConf.setPropertiesFileName(konakart_eng_propertiesFileName);
            engConf.setMode(EngineConfig.MODE_SINGLE_STORE);

            if (log.isInfoEnabled()) {
                log.info("Kick off an engine as if by Struts");
            }
            getAppEngByName(engineClassName, engConf);

            debugAppEng = getAppEngByName(engineClassName);

            // while (debugAppEng.getOrderMgr().isMgrReady() == false)
            // {
            // if (log.isInfoEnabled())
            // {
            // log.info("Mgr is not ready");
            // }
            // Thread.sleep(1000);
            // }

            debugAppEng.getOrderMgr().setHostAndPort("localhost:8080");

            // debugAppEng.getCustomerMgr().login("root@localhost", "password");
            if (log.isInfoEnabled()) {
                log.info("KonakartGWTServer() Engine created successfully");
            }

        } catch (Exception e) {
            // e.printStackTrace();
            throw new ServletException(getExceptionMessage(e));
        }
    }
}

From source file:org.sakaiproject.util.Web.java

public static String snoop(PrintWriter out, boolean html, ServletConfig config, HttpServletRequest req) {
    // if no out, send to system out
    ByteArrayOutputStream ostream = null;
    if (out == null) {
        ostream = new ByteArrayOutputStream();
        out = new PrintWriter(ostream);
        html = false;//from   w w  w  .j  ava 2  s . c o m
    }

    String h1 = "";
    String h1x = "";
    String pre = "";
    String prex = "";
    String b = "";
    String bx = "";
    String p = "";
    if (html) {
        h1 = "<h1>";
        h1x = "</h1>";
        pre = "<pre>";
        prex = "</pre>";
        b = "<b>";
        bx = "</b>";
        p = "<p>";
    }

    Enumeration<?> e = null;

    out.println(h1 + "Snoop for request" + h1x);
    out.println(req.toString());

    if (config != null) {
        e = config.getInitParameterNames();
        if (e != null) {
            boolean first = true;
            while (e.hasMoreElements()) {
                if (first) {
                    out.println(h1 + "Init Parameters" + h1x);
                    out.println(pre);
                    first = false;
                }
                String param = (String) e.nextElement();
                out.println(" " + param + ": " + config.getInitParameter(param));
            }
            out.println(prex);
        }
    }

    out.println(h1 + "Request information:" + h1x);
    out.println(pre);

    print(out, "Request method", req.getMethod());
    String requestUri = req.getRequestURI();
    print(out, "Request URI", requestUri);
    displayStringChars(out, requestUri);
    print(out, "Request protocol", req.getProtocol());
    String servletPath = req.getServletPath();
    print(out, "Servlet path", servletPath);
    displayStringChars(out, servletPath);
    String contextPath = req.getContextPath();
    print(out, "Context path", contextPath);
    displayStringChars(out, contextPath);
    String pathInfo = req.getPathInfo();
    print(out, "Path info", pathInfo);
    displayStringChars(out, pathInfo);
    print(out, "Path translated", req.getPathTranslated());
    print(out, "Query string", req.getQueryString());
    print(out, "Content length", req.getContentLength());
    print(out, "Content type", req.getContentType());
    print(out, "Server name", req.getServerName());
    print(out, "Server port", req.getServerPort());
    print(out, "Remote user", req.getRemoteUser());
    print(out, "Remote address", req.getRemoteAddr());
    // print(out, "Remote host", req.getRemoteHost());
    print(out, "Authorization scheme", req.getAuthType());

    out.println(prex);

    e = req.getHeaderNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Request headers:" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            out.println(" " + name + ": " + req.getHeader(name));
        }
        out.println(prex);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Servlet parameters (Single Value style):" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            out.println(" " + name + " = " + req.getParameter(name));
        }
        out.println(prex);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Servlet parameters (Multiple Value style):" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            String vals[] = (String[]) req.getParameterValues(name);
            if (vals != null) {
                out.print(b + " " + name + " = " + bx);
                out.println(vals[0]);
                for (int i = 1; i < vals.length; i++)
                    out.println("           " + vals[i]);
            }
            out.println(p);
        }
        out.println(prex);
    }

    e = req.getAttributeNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Request attributes:" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            out.println(" " + name + ": " + req.getAttribute(name));
        }
        out.println(prex);
    }

    if (ostream != null) {
        out.flush();
        return ostream.toString();
    }

    return "";
}

From source file:com.w20e.socrates.servlet.WebsurveyServlet.java

/**
 * The 'init' method creates an instance of the Socrates class, and allocates
 * initial resources. This includes compiling of XSL style sheets and
 * allocation of the database connections.
 * //from  w w  w.j ava 2 s  .c o m
 * @param c
 *            Servlet configuration
 * @throws ServletException
 *             when the servlet fails.
 */
public final void init(final ServletConfig c) throws ServletException {

    super.init(c);

    LOGGER.info("Initializing the Websurvey servlet");

    this.sessionMgr = new SessionManager();

    // Adding sessionmanager to servlet context, so individual sessions can
    // reach their manager.
    //
    getServletContext().setAttribute("socrates.sessionmanager", this.sessionMgr);

    if (System.getProperty("socrates.cfg.root") != null) {
        this.rootDir = System.getProperty("socrates.cfg.root");
    } else if (c.getInitParameter("socrates.cfg.root") != null) {
        this.rootDir = c.getInitParameter("socrates.cfg.root");
    } else {
        this.rootDir = ".";
    }

    LOGGER.info("Setting config root to " + this.rootDir);

    this.runnerFactory = new RunnerFactoryImpl(this.rootDir);

    // Register handlers
    HandlerManager.getInstance().register("file", new XMLFileSubmissionHandler());
    HandlerManager.getInstance().register("none", new NoneSubmissionHandler());
}

From source file:org.jpublish.servlet.JPublishServlet.java

/**
 * Initialize the servlet./* w w w.ja v  a  2  s. co  m*/
 *
 * @param servletConfig The Servlet configuration
 * @throws ServletException
 */

public void init(ServletConfig servletConfig) throws ServletException {

    super.init(servletConfig);

    log.info("Initializing JPublish servlet; " + SiteContext.JPUBLISH_VERSION);

    ServletContext servletContext = getServletContext();

    String configLocation = servletConfig.getInitParameter("config");
    if (log.isDebugEnabled())
        log.debug("Config location: " + configLocation);

    // find the WEB-INF root
    String rootDir = servletContext.getRealPath("/");
    File contextRoot = new File(rootDir);
    File webInfPath = new File(contextRoot, "WEB-INF");

    // create the site context
    try {
        siteContext = new SiteContext(contextRoot, configLocation);
        servletContext.setAttribute(SiteContext.NAME, siteContext);
        siteContext.setWebInfPath(webInfPath);
        siteContext.setServletContext(servletContext);
        siteContext.setServletConfig(servletConfig);
        siteContext.setJPublishServlet(this);
        siteContext.init();
        formatParameterSupported = siteContext.getFormatChangeParameterName() != null
                && siteContext.getFormatChangeParameterName().trim().length() > 0;
    } catch (Exception e) {
        log.error("Error creating SiteContext: " + e.getMessage());
        throw new ServletException(e);
    }

    // set the ActionManager classpath
    ActionManager actionManager = siteContext.getActionManager();

    // configure BSF
    configureBSF();

    // construct the classpath for scripting support
    String classPath = constructClasspath(webInfPath);

    // configure classpath
    configureClasspath(classPath);

    // execute startup actions
    try {
        actionManager.executeStartupActions();
    } catch (Exception e) {
        log.error("Error executing startup actions: " + e.getMessage());
        throw new ServletException(e);
    }

    log.info("JPublish servlet initialized.");
}

From source file:org.apache.beehive.netui.pageflow.AutoRegisterActionServlet.java

private void writeObject(ObjectOutputStream stream) throws IOException {
    if (_log.isInfoEnabled()) {
        _log.info("serializing ActionServlet " + this);
    }/*from ww w. j a  va  2s .co  m*/

    if (_configParams != null) {
        stream.writeObject(_configParams);
    } else {
        ServletConfig servletConfig = getServletConfig();
        assert servletConfig != null;
        HashMap params = new HashMap();

        for (Enumeration e = servletConfig.getInitParameterNames(); e.hasMoreElements();) {
            String name = (String) e.nextElement();
            params.put(name, servletConfig.getInitParameter(name));
        }

        stream.writeObject(params);
    }
}

From source file:fi.hoski.web.forms.RaceEntryServlet.java

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

    repositoryBundle = ResourceBundle.getBundle("fi/hoski/datastore/repository/fields");
    datastore = DatastoreServiceFactory.getDatastoreService();
    entities = new DSUtilsImpl(datastore);
    mailService = new MailServiceImpl();
    LogWrapper log = new ServletLog(this);
    races = new RacesImpl(log, datastore, entities, mailService);
    boatInfoFactory = new BoatInfoFactory(log, new DatastorePersistence(datastore));
    boatInfoFactory.setURL("LYS", msg(Messages.LYSINFOURL), msg(Messages.LYSCLASSINFOURL));
    boatInfoFactory.setURL("IRC", msg(Messages.IRCINFOURL), null);
    boatInfoFactory.setURL("ORC", msg(Messages.ORCINFOURL), null);
    String uc = config.getInitParameter("use-cookies");
    useCookies = Boolean.parseBoolean(uc);
    log("useCookies=" + useCookies + " // " + uc);
}

From source file:org.kuali.rice.ksb.messaging.servlet.KSBDispatcherServlet.java

/**
 * This is a workaround after upgrading to CXF 2.7.0 whereby we could no longer just call "setHideServiceList" on
 * the ServletController. Instead, it is now reading this information from the ServletConfig, so wrapping the base
 * ServletContext to return true or false for hide service list depending on whether or not we are in dev mode.
 *//* w  w w.j av a2  s  .co m*/
protected ServletConfig getCXFServletConfig(final ServletConfig baseServletConfig) {
    // disable handling of URLs ending in /services which display CXF generated service lists if we are not in dev mode
    final String shouldHide = Boolean
            .toString(!ConfigContext.getCurrentContextConfig().getDevMode().booleanValue());
    return new ServletConfig() {
        private static final String HIDE_SERVICE_LIST_PAGE_PARAM = "hide-service-list-page";

        @Override
        public String getServletName() {
            return baseServletConfig.getServletName();
        }

        @Override
        public ServletContext getServletContext() {
            return baseServletConfig.getServletContext();
        }

        @Override
        public String getInitParameter(String parameter) {
            if (HIDE_SERVICE_LIST_PAGE_PARAM.equals(parameter)) {
                return shouldHide;
            }
            return baseServletConfig.getInitParameter(parameter);
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            List<String> initParameterNames = EnumerationUtils
                    .toList(baseServletConfig.getInitParameterNames());
            initParameterNames.add(HIDE_SERVICE_LIST_PAGE_PARAM);
            return new Vector<String>(initParameterNames).elements();
        }
    };
}

From source file:org.aludratest.cloud.selenium.impl.SeleniumHttpProxy.java

@Override
protected HttpClient createHttpClient(ServletConfig config) throws Exception {
    synchronized (SeleniumHttpProxy.class) {
        if (httpClient != null) {
            httpClientReferences.incrementAndGet();
            return httpClient;
        }/* ww w.  j ava  2s.c  o m*/
    }

    HttpClient client = createHttpClientInstance();
    client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);

    client.setThreadPool(new NamedQueuedThreadPool(250));

    client.setMaxConnectionsPerAddress(100);
    client.setConnectTimeout((int) timeout);
    // 30 minutes IDLE timeout
    client.setIdleTimeout(30 * 60 * 1000l);

    String t = config.getInitParameter("requestHeaderSize");

    if (t != null) {
        client.setRequestHeaderSize(Integer.parseInt(t));
    }

    t = config.getInitParameter("requestBufferSize");

    if (t != null) {
        client.setRequestBufferSize(Integer.parseInt(t));
    }

    t = config.getInitParameter("responseHeaderSize");

    if (t != null) {
        client.setResponseHeaderSize(Integer.parseInt(t));
    }

    t = config.getInitParameter("responseBufferSize");

    if (t != null) {
        client.setResponseBufferSize(Integer.parseInt(t));
    }

    synchronized (SeleniumHttpProxy.class) {
        if (httpClient == null) {
            client.start();
            httpClient = client;

            updateProxyConfig();
        }
        httpClientReferences.incrementAndGet();
        return httpClient;
    }
}

From source file:org.wings.session.Session.java

/**
 * Copy the init parameters./*from   w ww  . j a  v  a 2 s  .c o  m*/
 */
protected void initProps(ServletConfig servletConfig) {
    Enumeration params = servletConfig.getInitParameterNames();
    while (params.hasMoreElements()) {
        String name = (String) params.nextElement();
        props.put(name, servletConfig.getInitParameter(name));
    }
}