Example usage for javax.servlet ServletContext getInitParameterNames

List of usage examples for javax.servlet ServletContext getInitParameterNames

Introduction

In this page you can find the example usage for javax.servlet ServletContext getInitParameterNames.

Prototype

public Enumeration<String> getInitParameterNames();

Source Link

Document

Returns the names of the context's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the context has no initialization parameters.

Usage

From source file:WebAppProperties.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    ServletContext context = getServletContext();
    String displayName = context.getServletContextName();
    if (displayName == null) {
        displayName = "(no display-name element defined)";
    }/* w  ww . j ava  2 s  .  c o m*/

    out.println("<html>");
    out.println("<body>");
    out.println("<br>Name: " + displayName);
    out.println("<br>Context: " + req.getContextPath());

    out.println("<h2><center>");
    out.println("Initialization Parameters</center></h2>");
    out.println("<br>");

    out.println("<center><table>");

    Enumeration e = context.getInitParameterNames();

    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println("<tr>");
        out.println("<td>" + name + "</td>");
        out.println("<td>" + context.getInitParameter(name) + "</td>");
        out.println("</tr>");
    }
    out.println("</table></center>");

    out.println("</body>");
    out.println("</html>");
    out.flush();
}

From source file:WebAppProperties.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    ServletContext context = getServletContext();
    String displayName = context.getServletContextName();
    if (displayName == null) {
        displayName = "(no display-name element defined)";
    }/* w  w  w  .j a v a  2s . c o m*/

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Web Application Properties");
    out.println("</title>");
    out.println("</head><body>");
    out.println("<h1>Web Application Properties</h2>");
    out.println("<br>Name: " + displayName);
    out.println("<br>Context: " + req.getContextPath());

    out.println("<h2><center>");
    out.println("Initialization Parameters</center></h2>");
    out.println("<br>");

    out.println("<center><table border width=80%>");

    Enumeration e = context.getInitParameterNames();

    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println("<tr>");
        out.println("<td>" + name + "</td>");
        out.println("<td>" + context.getInitParameter(name) + "</td>");
        out.println("</tr>");
    }
    out.println("</table></center>");

    out.println("</body>");
    out.println("</html>");
    out.flush();
}

From source file:org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfigurationTests.java

@Test
public void onDifferentPortInWebServer() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
    this.applicationContext.register(RootConfig.class, EndpointConfig.class, DifferentPortConfig.class,
            BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    ServletContext servletContext = mock(ServletContext.class);
    given(servletContext.getInitParameterNames()).willReturn(new Vector<String>().elements());
    given(servletContext.getAttributeNames()).willReturn(new Vector<String>().elements());
    this.applicationContext.setServletContext(servletContext);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().management, null);
    assertContent("/endpoint", ports.get().management, null);
}

From source file:org.accada.epcis.repository.RepositoryContextListener.java

/**
 * {@inheritDoc}//from   ww w  . j  a v  a  2s. c om
 * 
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 */
public void contextInitialized(ServletContextEvent event) {
    ServletContext ctx = event.getServletContext();

    /*
     * Note: logging is initialized automatically by reading
     * logging.properties and log4j.properties from the classpath.
     * logging.properties is used to tell commons-logging to use LOG4J as
     * its underlying logging toolkit; log4j.properties is used to configure
     * LOG4J. To initialize LOG4J manually from LOG4J_CONFIG_LOCATION,
     * un-comment the following code (LOG4J_CONFIG_LOCATION =
     * "log4jConfigLocation") ...
     */
    // "log4jConfigLocation";
    // String path = ctx.getRealPath("/");
    // String log4jCfg = ctx.getInitParameter(LOG4J_CONFIG_LOCATION);
    // // initialize Log4j
    // if (log4jCfg != null) {
    // // if no log4j properties file found, then do not try
    // // to load it (the application runs without logging)
    // PropertyConfigurator.configure(path + log4jCfg);
    // }
    // log = LogFactory.getLog(this.getClass());

    // set a system property to configure CXF to use LOG4J
    System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Log4jLogger");

    LOG.info("Starting Accada EPCIS Repository application");

    if (LOG.isDebugEnabled()) {
        LOG.debug("Logging application context init-parameters:");
        Enumeration<?> e = ctx.getInitParameterNames();
        while (e.hasMoreElements()) {
            String param = (String) e.nextElement();
            LOG.debug(param + "=" + ctx.getInitParameter(param));
        }
    }
}

From source file:org.apache.cocoon.servletservice.ServletServiceContext.java

public Enumeration getInitParameterNames() {
    Vector names = new Vector();

    // add all names of the parent servlet context
    Enumeration enumeration = super.getInitParameterNames();
    while (enumeration.hasMoreElements()) {
        names.add(enumeration.nextElement());
    }/* ww  w .j ava2  s.  c o m*/

    // add names of the super servlet
    ServletContext superContext = this.getNamedContext(SUPER);
    if (superContext != null) {
        enumeration = superContext.getInitParameterNames();
        while (enumeration.hasMoreElements()) {
            names.add(enumeration.nextElement());
        }
    }

    // add property names of this servlet
    if (this.properties != null) {
        names.addAll(this.properties.keySet());
    }

    return names.elements();
}

From source file:org.apache.hadoop.fs.webdav.WebdavServlet.java

private static Configuration getConf(ServletContext application) {
    Configuration conf = (Configuration) application.getAttribute("dfs.servlet.conf.key");

    if (conf == null) {
        conf = hadoopConfig;//  ww w . ja  v a 2s.  c  o m
        Enumeration e = application.getInitParameterNames();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            conf.set(name, application.getInitParameter(name));
        }
        application.setAttribute("dfs.servlet.conf.key", conf);
    }

    if (currentUserName != null) {
        WebAppContext webapp = (WebAppContext) application.getAttribute(WebdavServer.WEB_APP_CONTEXT);
        WebdavHashUserRealm userRealm = (WebdavHashUserRealm) webapp.getSecurityHandler().getUserRealm();
        List<String> userRoles = userRealm.getUserRoles(currentUserName);
        currentUserRoles = userRoles;

        UnixUserGroupInformation ugi = new UnixUserGroupInformation(currentUserName,
                userRoles.toArray(new String[0]));
        UnixUserGroupInformation.saveToConf(conf, UnixUserGroupInformation.UGI_PROPERTY_NAME, ugi);
    }
    return conf;
}

From source file:org.apache.isis.core.runtime.runner.opts.OptionHandlerInitParameters.java

private static Map<String, String> asMap(ServletContext servletContext) {
    Enumeration<String> initParameterNames = servletContext.getInitParameterNames();
    final Map<String, String> map = Maps.newTreeMap();
    while (initParameterNames.hasMoreElements()) {
        final String initParameterName = initParameterNames.nextElement();
        final String initParameterValue = servletContext.getInitParameter(initParameterName);
        if (initParameterName.startsWith("isis.")) {
            map.put(initParameterName, initParameterValue);
        }/*  w ww.  j  av a2 s  .  c o m*/
    }
    return map;
}

From source file:org.apache.tapestry.request.RequestContext.java

/**
 * Writes the state of the context to the writer, typically for inclusion
 * in a HTML page returned to the user. This is useful
 * when debugging.  The Inspector uses this as well.
 *
 **///  w  ww .  j a va 2  s.c  o  m

public void write(IMarkupWriter writer) {
    // Create a box around all of this stuff ...

    writer.begin("table");
    writer.attribute("class", "request-context-border");
    writer.begin("tr");
    writer.begin("td");

    // Get the session, if it exists, and display it.

    HttpSession session = getSession();

    if (session != null) {
        object(writer, "Session");
        writer.begin("table");
        writer.attribute("class", "request-context-object");

        section(writer, "Properties");
        header(writer, "Name", "Value");

        pair(writer, "id", session.getId());
        datePair(writer, "creationTime", session.getCreationTime());
        datePair(writer, "lastAccessedTime", session.getLastAccessedTime());
        pair(writer, "maxInactiveInterval", session.getMaxInactiveInterval());
        pair(writer, "new", session.isNew());

        List names = getSorted(session.getAttributeNames());
        int count = names.size();

        for (int i = 0; i < count; i++) {
            if (i == 0) {
                section(writer, "Attributes");
                header(writer, "Name", "Value");
            }

            String name = (String) names.get(i);
            pair(writer, name, session.getAttribute(name));
        }

        writer.end(); // Session

    }

    object(writer, "Request");
    writer.begin("table");
    writer.attribute("class", "request-context-object");

    // Parameters ...

    List parameters = getSorted(_request.getParameterNames());
    int count = parameters.size();

    for (int i = 0; i < count; i++) {

        if (i == 0) {
            section(writer, "Parameters");
            header(writer, "Name", "Value(s)");
        }

        String name = (String) parameters.get(i);
        String[] values = _request.getParameterValues(name);

        writer.begin("tr");
        writer.attribute("class", getRowClass());
        writer.begin("th");
        writer.print(name);
        writer.end();
        writer.begin("td");

        if (values.length > 1)
            writer.begin("ul");

        for (int j = 0; j < values.length; j++) {
            if (values.length > 1)
                writer.beginEmpty("li");

            writer.print(values[j]);

        }

        writer.end("tr");
    }

    section(writer, "Properties");
    header(writer, "Name", "Value");

    pair(writer, "authType", _request.getAuthType());
    pair(writer, "characterEncoding", _request.getCharacterEncoding());
    pair(writer, "contentLength", _request.getContentLength());
    pair(writer, "contentType", _request.getContentType());
    pair(writer, "method", _request.getMethod());
    pair(writer, "pathInfo", _request.getPathInfo());
    pair(writer, "pathTranslated", _request.getPathTranslated());
    pair(writer, "protocol", _request.getProtocol());
    pair(writer, "queryString", _request.getQueryString());
    pair(writer, "remoteAddr", _request.getRemoteAddr());
    pair(writer, "remoteHost", _request.getRemoteHost());
    pair(writer, "remoteUser", _request.getRemoteUser());
    pair(writer, "requestedSessionId", _request.getRequestedSessionId());
    pair(writer, "requestedSessionIdFromCookie", _request.isRequestedSessionIdFromCookie());
    pair(writer, "requestedSessionIdFromURL", _request.isRequestedSessionIdFromURL());
    pair(writer, "requestedSessionIdValid", _request.isRequestedSessionIdValid());
    pair(writer, "requestURI", _request.getRequestURI());
    pair(writer, "scheme", _request.getScheme());
    pair(writer, "serverName", _request.getServerName());
    pair(writer, "serverPort", _request.getServerPort());
    pair(writer, "contextPath", _request.getContextPath());
    pair(writer, "servletPath", _request.getServletPath());

    // Now deal with any headers

    List headers = getSorted(_request.getHeaderNames());
    count = headers.size();

    for (int i = 0; i < count; i++) {
        if (i == 0) {
            section(writer, "Headers");
            header(writer, "Name", "Value");
        }

        String name = (String) headers.get(i);
        String value = _request.getHeader(name);

        pair(writer, name, value);
    }

    // Attributes

    List attributes = getSorted(_request.getAttributeNames());
    count = attributes.size();

    for (int i = 0; i < count; i++) {
        if (i == 0) {
            section(writer, "Attributes");
            header(writer, "Name", "Value");
        }

        String name = (String) attributes.get(i);

        pair(writer, name, _request.getAttribute(name));
    }

    // Cookies ...

    Cookie[] cookies = _request.getCookies();

    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {

            if (i == 0) {
                section(writer, "Cookies");
                header(writer, "Name", "Value");
            }

            Cookie cookie = cookies[i];

            pair(writer, cookie.getName(), cookie.getValue());

        } // Cookies loop
    }

    writer.end(); // Request

    object(writer, "Servlet");
    writer.begin("table");
    writer.attribute("class", "request-context-object");

    section(writer, "Properties");
    header(writer, "Name", "Value");

    pair(writer, "servlet", _servlet);
    pair(writer, "name", _servlet.getServletName());
    pair(writer, "servletInfo", _servlet.getServletInfo());

    ServletConfig config = _servlet.getServletConfig();

    List names = getSorted(config.getInitParameterNames());
    count = names.size();

    for (int i = 0; i < count; i++) {

        if (i == 0) {
            section(writer, "Init Parameters");
            header(writer, "Name", "Value");
        }

        String name = (String) names.get(i);
        ;
        pair(writer, name, config.getInitParameter(name));

    }

    writer.end(); // Servlet

    ServletContext context = config.getServletContext();

    object(writer, "Servlet Context");
    writer.begin("table");
    writer.attribute("class", "request-context-object");

    section(writer, "Properties");
    header(writer, "Name", "Value");

    pair(writer, "majorVersion", context.getMajorVersion());
    pair(writer, "minorVersion", context.getMinorVersion());
    pair(writer, "serverInfo", context.getServerInfo());

    names = getSorted(context.getInitParameterNames());
    count = names.size();
    for (int i = 0; i < count; i++) {
        if (i == 0) {
            section(writer, "Initial Parameters");
            header(writer, "Name", "Value");
        }

        String name = (String) names.get(i);
        pair(writer, name, context.getInitParameter(name));
    }

    names = getSorted(context.getAttributeNames());
    count = names.size();
    for (int i = 0; i < count; i++) {
        if (i == 0) {
            section(writer, "Attributes");
            header(writer, "Name", "Value");
        }

        String name = (String) names.get(i);
        pair(writer, name, context.getAttribute(name));
    }

    writer.end(); // Servlet Context

    writeSystemProperties(writer);

    writer.end("table"); // The enclosing border
}

From source file:org.exoplatform.frameworks.jcr.command.web.GenericWebAppContext.java

public GenericWebAppContext(ServletContext servletContext, HttpServletRequest request,
        HttpServletResponse response, SessionProvider sessionProvider, ManageableRepository repository) {

    initialize(servletContext, request, response);

    this.sessionProvider = sessionProvider;
    this.repository = repository;

    // log.info("WEb context ---------------");
    // initialize context with all props
    Enumeration en = servletContext.getInitParameterNames();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        put(name, servletContext.getInitParameter(name));
        LOG.debug("ServletContext init param: " + name + "=" + servletContext.getInitParameter(name));
    }/*from   www  .  j  av  a  2 s . co  m*/

    en = servletContext.getAttributeNames();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        put(name, servletContext.getAttribute(name));
        LOG.debug("ServletContext: " + name + "=" + servletContext.getAttribute(name));
    }

    HttpSession session = request.getSession(false);
    if (session != null) {
        en = session.getAttributeNames();
        while (en.hasMoreElements()) {
            String name = (String) en.nextElement();
            put(name, session.getAttribute(name));
            LOG.debug("Session: " + name + "=" + session.getAttribute(name));
        }
    }

    en = request.getAttributeNames();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        put(name, request.getAttribute(name));
    }

    en = request.getParameterNames();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        put(name, request.getParameter(name));
        LOG.debug("Request: " + name + "=" + request.getParameter(name));
    }
}

From source file:org.fosstrak.epcis.repository.RepositoryContextListener.java

/**
 * {@inheritDoc}/*w  w  w  .j a  v a  2  s . co  m*/
 * 
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 */
public void contextInitialized(ServletContextEvent event) {
    ServletContext ctx = event.getServletContext();

    /*
     * Note: logging is initialized automatically by reading
     * logging.properties and log4j.properties from the classpath.
     * logging.properties is used to tell commons-logging to use LOG4J as
     * its underlying logging toolkit; log4j.properties is used to configure
     * LOG4J. To initialize LOG4J manually from LOG4J_CONFIG_LOCATION,
     * un-comment the following code (LOG4J_CONFIG_LOCATION =
     * "log4jConfigLocation") ...
     */
    // "log4jConfigLocation";
    // String path = ctx.getRealPath("/");
    // String log4jCfg = ctx.getInitParameter(LOG4J_CONFIG_LOCATION);
    // // initialize Log4j
    // if (log4jCfg != null) {
    // // if no log4j properties file found, then do not try
    // // to load it (the application runs without logging)
    // PropertyConfigurator.configure(path + log4jCfg);
    // }
    // log = LogFactory.getLog(this.getClass());

    // set a system property to configure CXF to use LOG4J
    System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Log4jLogger");

    LOG.info("Starting Fosstrak EPCIS Repository application");

    if (LOG.isDebugEnabled()) {
        LOG.debug("Logging application context init-parameters:");
        Enumeration<?> e = ctx.getInitParameterNames();
        while (e.hasMoreElements()) {
            String param = (String) e.nextElement();
            LOG.debug(param + "=" + ctx.getInitParameter(param));
        }
    }
}