Search in sources :

Example 56 with ServletContext

use of javax.servlet.ServletContext in project lucene-solr by apache.

the class KerberosPlugin method getInitFilterConfig.

@VisibleForTesting
protected FilterConfig getInitFilterConfig(Map<String, Object> pluginConfig, boolean skipKerberosChecking) {
    Map<String, String> params = new HashMap();
    params.put("type", "kerberos");
    putParam(params, "kerberos.name.rules", NAME_RULES_PARAM, "DEFAULT");
    putParam(params, "token.valid", TOKEN_VALID_PARAM, "30");
    putParam(params, "cookie.path", COOKIE_PATH_PARAM, "/");
    if (!skipKerberosChecking) {
        putParam(params, "kerberos.principal", PRINCIPAL_PARAM, null);
        putParam(params, "kerberos.keytab", KEYTAB_PARAM, null);
    } else {
        putParamOptional(params, "kerberos.principal", PRINCIPAL_PARAM);
        putParamOptional(params, "kerberos.keytab", KEYTAB_PARAM);
    }
    String delegationTokenStr = System.getProperty(DELEGATION_TOKEN_ENABLED, null);
    boolean delegationTokenEnabled = (delegationTokenStr == null) ? false : Boolean.parseBoolean(delegationTokenStr);
    ZkController controller = coreContainer.getZkController();
    if (delegationTokenEnabled) {
        putParam(params, "delegation-token.token-kind", DELEGATION_TOKEN_KIND, DELEGATION_TOKEN_TYPE_DEFAULT);
        if (coreContainer.isZooKeeperAware()) {
            putParam(params, "signer.secret.provider", DELEGATION_TOKEN_SECRET_PROVIDER, "zookeeper");
            if ("zookeeper".equals(params.get("signer.secret.provider"))) {
                String zkHost = controller.getZkServerAddress();
                putParam(params, "token.validity", DELEGATION_TOKEN_VALIDITY, "36000");
                params.put("zk-dt-secret-manager.enable", "true");
                String chrootPath = zkHost.contains("/") ? zkHost.substring(zkHost.indexOf("/")) : "";
                String znodeWorkingPath = chrootPath + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH + "/zkdtsm";
                // Note - Curator complains if the znodeWorkingPath starts with /
                znodeWorkingPath = znodeWorkingPath.startsWith("/") ? znodeWorkingPath.substring(1) : znodeWorkingPath;
                putParam(params, "zk-dt-secret-manager.znodeWorkingPath", DELEGATION_TOKEN_SECRET_MANAGER_ZNODE_WORKING_PATH, znodeWorkingPath);
                putParam(params, "signer.secret.provider.zookeeper.path", DELEGATION_TOKEN_SECRET_PROVIDER_ZK_PATH, "/token");
                // ensure krb5 is setup properly before running curator
                getHttpClientBuilder(SolrHttpClientBuilder.create());
            }
        } else {
            log.info("CoreContainer is not ZooKeeperAware, not setting ZK-related delegation token properties");
        }
    }
    // Special handling for the "cookie.domain" based on whether port should be
    // appended to the domain. Useful for situations where multiple solr nodes are
    // on the same host.
    String usePortStr = System.getProperty(COOKIE_PORT_AWARE_PARAM, null);
    boolean needPortAwareCookies = (usePortStr == null) ? false : Boolean.parseBoolean(usePortStr);
    if (!needPortAwareCookies || !coreContainer.isZooKeeperAware()) {
        putParam(params, "cookie.domain", COOKIE_DOMAIN_PARAM, null);
    } else {
        // we need port aware cookies and we are in SolrCloud mode.
        String host = System.getProperty(COOKIE_DOMAIN_PARAM, null);
        if (host == null) {
            throw new SolrException(ErrorCode.SERVER_ERROR, "Missing required parameter '" + COOKIE_DOMAIN_PARAM + "'.");
        }
        int port = controller.getHostPort();
        params.put("cookie.domain", host + ":" + port);
    }
    // check impersonator config
    for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements(); ) {
        String key = e.nextElement().toString();
        if (key.startsWith(IMPERSONATOR_PREFIX)) {
            if (!delegationTokenEnabled) {
                throw new SolrException(ErrorCode.SERVER_ERROR, "Impersonator configuration requires delegation tokens to be enabled: " + key);
            }
            params.put(key, System.getProperty(key));
        }
    }
    final ServletContext servletContext = new AttributeOnlyServletContext();
    if (controller != null) {
        servletContext.setAttribute(DELEGATION_TOKEN_ZK_CLIENT, controller.getZkClient());
    }
    if (delegationTokenEnabled) {
        kerberosFilter = new DelegationTokenKerberosFilter();
    // pass an attribute-enabled context in order to pass the zkClient
    // and because the filter may pass a curator instance.
    } else {
        kerberosFilter = new KerberosFilter();
    }
    log.info("Params: " + params);
    FilterConfig conf = new FilterConfig() {

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return new IteratorEnumeration(params.keySet().iterator());
        }

        @Override
        public String getInitParameter(String param) {
            return params.get(param);
        }

        @Override
        public String getFilterName() {
            return "KerberosFilter";
        }
    };
    return conf;
}
Also used : Enumeration(java.util.Enumeration) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) HashMap(java.util.HashMap) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) ZkController(org.apache.solr.cloud.ZkController) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) SolrException(org.apache.solr.common.SolrException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 57 with ServletContext

use of javax.servlet.ServletContext in project adempiere by adempiere.

the class WebEnv method getServletInfo.

//  getFooter
/**
	 *	Get Information and put it in a HTML table
	 *  @param request request
	 *  @param response response
	 *  @param servlet servlet
	 *  @return Table
	 */
private static table getServletInfo(HttpServletRequest request, HttpServletResponse response, HttpServlet servlet) {
    table table = new table();
    table.setID("DEBUG");
    Enumeration e;
    tr space = new tr().addElement(new td().addElement("."));
    //	Request Info
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Request Info"))));
    table.addElement(new tr().addElement(new td().addElement("Method")).addElement(new td().addElement(request.getMethod())));
    table.addElement(new tr().addElement(new td().addElement("Protocol")).addElement(new td().addElement(request.getProtocol())));
    table.addElement(new tr().addElement(new td().addElement("URI")).addElement(new td().addElement(request.getRequestURI())));
    table.addElement(new tr().addElement(new td().addElement("Context Path")).addElement(new td().addElement(request.getContextPath())));
    table.addElement(new tr().addElement(new td().addElement("Servlet Path")).addElement(new td().addElement(request.getServletPath())));
    table.addElement(new tr().addElement(new td().addElement("Path Info")).addElement(new td().addElement(request.getPathInfo())));
    table.addElement(new tr().addElement(new td().addElement("Path Translated")).addElement(new td().addElement(request.getPathTranslated())));
    table.addElement(new tr().addElement(new td().addElement("Query String")).addElement(new td().addElement(request.getQueryString())));
    table.addElement(new tr().addElement(new td().addElement("Content Length")).addElement(new td().addElement("" + request.getContentLength())));
    table.addElement(new tr().addElement(new td().addElement("Content Type")).addElement(new td().addElement(request.getContentType())));
    table.addElement(new tr().addElement(new td().addElement("Character Encoding")).addElement(new td().addElement(request.getCharacterEncoding())));
    table.addElement(new tr().addElement(new td().addElement("Locale")).addElement(new td().addElement(request.getLocale().toString())));
    table.addElement(new tr().addElement(new td().addElement("Schema")).addElement(new td().addElement(request.getScheme())));
    table.addElement(new tr().addElement(new td().addElement("Server Name")).addElement(new td().addElement(request.getServerName())));
    table.addElement(new tr().addElement(new td().addElement("Server Port")).addElement(new td().addElement("" + request.getServerPort())));
    table.addElement(new tr().addElement(new td().addElement("Remote User")).addElement(new td().addElement(request.getRemoteUser())));
    table.addElement(new tr().addElement(new td().addElement("Remote Address")).addElement(new td().addElement(request.getRemoteAddr())));
    table.addElement(new tr().addElement(new td().addElement("Remote Host")).addElement(new td().addElement(request.getRemoteHost())));
    table.addElement(new tr().addElement(new td().addElement("Authorization Type")).addElement(new td().addElement(request.getAuthType())));
    table.addElement(new tr().addElement(new td().addElement("User Principal")).addElement(new td().addElement(request.getUserPrincipal() == null ? "" : request.getUserPrincipal().toString())));
    table.addElement(new tr().addElement(new td().addElement("IsSecure")).addElement(new td().addElement(request.isSecure() ? "true" : "false")));
    //	Request Attributes
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Request Attributes"))));
    e = request.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = e.nextElement().toString();
        String attrib = request.getAttribute(name).toString();
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(attrib)));
    }
    //	Request Parameter
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Req Parameters"))));
    try {
        String enc = request.getCharacterEncoding();
        if (enc == null)
            request.setCharacterEncoding(WebEnv.ENCODING);
    } catch (Exception ee) {
        log.log(Level.SEVERE, "Set CharacterEncoding=" + WebEnv.ENCODING, ee);
    }
    e = request.getParameterNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String para = WebUtil.getParameter(request, name);
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(para)));
    }
    //	Request Header
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Req Header"))));
    e = request.getHeaderNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        if (!name.equals("Cockie")) {
            String hdr = request.getHeader(name);
            table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(hdr)));
        }
    }
    //  Request Cookies
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Req Cookies"))));
    Cookie[] cc = request.getCookies();
    if (cc != null) {
        for (int i = 0; i < cc.length; i++) {
            //	Name and Comment
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName())).addElement(new td().addElement(cc[i].getValue())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Comment")).addElement(new td().addElement(cc[i].getComment())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Domain")).addElement(new td().addElement(cc[i].getDomain())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Max Age")).addElement(new td().addElement("" + cc[i].getMaxAge())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Path")).addElement(new td().addElement(cc[i].getPath())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Is Secure")).addElement(new td().addElement(cc[i].getSecure() ? "true" : "false")));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Version")).addElement(new td().addElement("" + cc[i].getVersion())));
        }
    }
    //	Cookies
    //  Request Session Info
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Req Session"))));
    HttpSession session = request.getSession(true);
    table.addElement(new tr().addElement(new td().addElement("Session ID")).addElement(new td().addElement(session.getId())));
    Timestamp ts = new Timestamp(session.getCreationTime());
    table.addElement(new tr().addElement(new td().addElement("Created")).addElement(new td().addElement(ts.toString())));
    ts = new Timestamp(session.getLastAccessedTime());
    table.addElement(new tr().addElement(new td().addElement("Accessed")).addElement(new td().addElement(ts.toString())));
    table.addElement(new tr().addElement(new td().addElement("Request Session ID")).addElement(new td().addElement(request.getRequestedSessionId())));
    table.addElement(new tr().addElement(new td().addElement(".. via Cookie")).addElement(new td().addElement("" + request.isRequestedSessionIdFromCookie())));
    table.addElement(new tr().addElement(new td().addElement(".. via URL")).addElement(new td().addElement("" + request.isRequestedSessionIdFromURL())));
    table.addElement(new tr().addElement(new td().addElement("Valid")).addElement(new td().addElement("" + request.isRequestedSessionIdValid())));
    //	Request Session Attributes
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Session Attributes"))));
    e = session.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String attrib = session.getAttribute(name).toString();
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(attrib)));
    }
    //	Response Info
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Response"))));
    table.addElement(new tr().addElement(new td().addElement("Buffer Size")).addElement(new td().addElement(String.valueOf(response.getBufferSize()))));
    table.addElement(new tr().addElement(new td().addElement("Character Encoding")).addElement(new td().addElement(response.getCharacterEncoding())));
    table.addElement(new tr().addElement(new td().addElement("Locale")).addElement(new td().addElement(response.getLocale() == null ? "null" : response.getLocale().toString())));
    //  Servlet
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Servlet"))));
    table.addElement(new tr().addElement(new td().addElement("Name")).addElement(new td().addElement(servlet.getServletName())));
    table.addElement(new tr().addElement(new td().addElement("Info")).addElement(new td().addElement(servlet.getServletInfo())));
    //  Servlet Init
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Servlet Init Parameter"))));
    e = servlet.getInitParameterNames();
    //  same as:  servlet.getServletConfig().getInitParameterNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String para = servlet.getInitParameter(name);
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(para)));
    }
    //  Servlet Context
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Servlet Context"))));
    ServletContext servCtx = servlet.getServletContext();
    e = servCtx.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String attrib = servCtx.getAttribute(name).toString();
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(attrib)));
    }
    //  Servlet Context
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Servlet Context Init Parameter"))));
    e = servCtx.getInitParameterNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String attrib = servCtx.getInitParameter(name).toString();
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(attrib)));
    }
    /*	*/
    return table;
}
Also used : Cookie(javax.servlet.http.Cookie) Enumeration(java.util.Enumeration) HttpSession(javax.servlet.http.HttpSession) org.apache.ecs.xhtml.h3(org.apache.ecs.xhtml.h3) Timestamp(java.sql.Timestamp) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) ServletContext(javax.servlet.ServletContext) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr)

Example 58 with ServletContext

use of javax.servlet.ServletContext in project adempiere by adempiere.

the class MobileEnv method getServletInfo.

//  getFooter
/**
	 *	Get Information and put it in a HTML table
	 *  @param request request
	 *  @param response response
	 *  @param servlet servlet
	 *  @return Table
	 */
private static table getServletInfo(HttpServletRequest request, HttpServletResponse response, HttpServlet servlet) {
    table table = new table();
    table.setID("DEBUG");
    Enumeration e;
    tr space = new tr().addElement(new td().addElement("."));
    //	Request Info
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Request Info"))));
    table.addElement(new tr().addElement(new td().addElement("Method")).addElement(new td().addElement(request.getMethod())));
    table.addElement(new tr().addElement(new td().addElement("Protocol")).addElement(new td().addElement(request.getProtocol())));
    table.addElement(new tr().addElement(new td().addElement("URI")).addElement(new td().addElement(request.getRequestURI())));
    table.addElement(new tr().addElement(new td().addElement("Context Path")).addElement(new td().addElement(request.getContextPath())));
    table.addElement(new tr().addElement(new td().addElement("Servlet Path")).addElement(new td().addElement(request.getServletPath())));
    table.addElement(new tr().addElement(new td().addElement("Path Info")).addElement(new td().addElement(request.getPathInfo())));
    table.addElement(new tr().addElement(new td().addElement("Path Translated")).addElement(new td().addElement(request.getPathTranslated())));
    table.addElement(new tr().addElement(new td().addElement("Query String")).addElement(new td().addElement(request.getQueryString())));
    table.addElement(new tr().addElement(new td().addElement("Content Length")).addElement(new td().addElement("" + request.getContentLength())));
    table.addElement(new tr().addElement(new td().addElement("Content Type")).addElement(new td().addElement(request.getContentType())));
    table.addElement(new tr().addElement(new td().addElement("Character Encoding")).addElement(new td().addElement(request.getCharacterEncoding())));
    table.addElement(new tr().addElement(new td().addElement("Locale")).addElement(new td().addElement(request.getLocale().toString())));
    table.addElement(new tr().addElement(new td().addElement("Schema")).addElement(new td().addElement(request.getScheme())));
    table.addElement(new tr().addElement(new td().addElement("Server Name")).addElement(new td().addElement(request.getServerName())));
    table.addElement(new tr().addElement(new td().addElement("Server Port")).addElement(new td().addElement("" + request.getServerPort())));
    table.addElement(new tr().addElement(new td().addElement("Remote User")).addElement(new td().addElement(request.getRemoteUser())));
    table.addElement(new tr().addElement(new td().addElement("Remote Address")).addElement(new td().addElement(request.getRemoteAddr())));
    table.addElement(new tr().addElement(new td().addElement("Remote Host")).addElement(new td().addElement(request.getRemoteHost())));
    table.addElement(new tr().addElement(new td().addElement("Authorization Type")).addElement(new td().addElement(request.getAuthType())));
    table.addElement(new tr().addElement(new td().addElement("User Principal")).addElement(new td().addElement(request.getUserPrincipal() == null ? "" : request.getUserPrincipal().toString())));
    table.addElement(new tr().addElement(new td().addElement("IsSecure")).addElement(new td().addElement(request.isSecure() ? "true" : "false")));
    //	Request Attributes
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Request Attributes"))));
    e = request.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = e.nextElement().toString();
        String attrib = request.getAttribute(name).toString();
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(attrib)));
    }
    //	Request Parameter
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Req Parameters"))));
    try {
        String enc = request.getCharacterEncoding();
        if (enc == null)
            request.setCharacterEncoding(MobileEnv.ENCODING);
    } catch (Exception ee) {
        log.log(Level.SEVERE, "Set CharacterEncoding=" + MobileEnv.ENCODING, ee);
    }
    e = request.getParameterNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String para = MobileUtil.getParameter(request, name);
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(para)));
    }
    //	Request Header
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Req Header"))));
    e = request.getHeaderNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        if (!name.equals("Cockie")) {
            String hdr = request.getHeader(name);
            table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(hdr)));
        }
    }
    //  Request Cookies
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Req Cookies"))));
    Cookie[] cc = request.getCookies();
    if (cc != null) {
        for (int i = 0; i < cc.length; i++) {
            //	Name and Comment
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName())).addElement(new td().addElement(cc[i].getValue())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Comment")).addElement(new td().addElement(cc[i].getComment())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Domain")).addElement(new td().addElement(cc[i].getDomain())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Max Age")).addElement(new td().addElement("" + cc[i].getMaxAge())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Path")).addElement(new td().addElement(cc[i].getPath())));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Is Secure")).addElement(new td().addElement(cc[i].getSecure() ? "true" : "false")));
            table.addElement(new tr().addElement(new td().addElement(cc[i].getName() + ": Version")).addElement(new td().addElement("" + cc[i].getVersion())));
        }
    }
    //	Cookies
    //  Request Session Info
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Req Session"))));
    HttpSession session = request.getSession(true);
    table.addElement(new tr().addElement(new td().addElement("Session ID")).addElement(new td().addElement(session.getId())));
    Timestamp ts = new Timestamp(session.getCreationTime());
    table.addElement(new tr().addElement(new td().addElement("Created")).addElement(new td().addElement(ts.toString())));
    ts = new Timestamp(session.getLastAccessedTime());
    table.addElement(new tr().addElement(new td().addElement("Accessed")).addElement(new td().addElement(ts.toString())));
    table.addElement(new tr().addElement(new td().addElement("Request Session ID")).addElement(new td().addElement(request.getRequestedSessionId())));
    table.addElement(new tr().addElement(new td().addElement(".. via Cookie")).addElement(new td().addElement("" + request.isRequestedSessionIdFromCookie())));
    table.addElement(new tr().addElement(new td().addElement(".. via URL")).addElement(new td().addElement("" + request.isRequestedSessionIdFromURL())));
    table.addElement(new tr().addElement(new td().addElement("Valid")).addElement(new td().addElement("" + request.isRequestedSessionIdValid())));
    //	Request Session Attributes
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Session Attributes"))));
    e = session.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String attrib = session.getAttribute(name).toString();
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(attrib)));
    }
    //	Response Info
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Response"))));
    table.addElement(new tr().addElement(new td().addElement("Buffer Size")).addElement(new td().addElement(String.valueOf(response.getBufferSize()))));
    table.addElement(new tr().addElement(new td().addElement("Character Encoding")).addElement(new td().addElement(response.getCharacterEncoding())));
    table.addElement(new tr().addElement(new td().addElement("Locale")).addElement(new td().addElement(response.getLocale() == null ? "null" : response.getLocale().toString())));
    //  Servlet
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Servlet"))));
    table.addElement(new tr().addElement(new td().addElement("Name")).addElement(new td().addElement(servlet.getServletName())));
    table.addElement(new tr().addElement(new td().addElement("Info")).addElement(new td().addElement(servlet.getServletInfo())));
    //  Servlet Init
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Servlet Init Parameter"))));
    e = servlet.getInitParameterNames();
    //  same as:  servlet.getServletConfig().getInitParameterNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String para = servlet.getInitParameter(name);
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(para)));
    }
    //  Servlet Context
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Servlet Context"))));
    ServletContext servCtx = servlet.getServletContext();
    e = servCtx.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String attrib = servCtx.getAttribute(name).toString();
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(attrib)));
    }
    //  Servlet Context
    table.addElement(space);
    table.addElement(new tr().addElement(new td().addElement(new h3("Servlet Context Init Parameter"))));
    e = servCtx.getInitParameterNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String attrib = servCtx.getInitParameter(name).toString();
        table.addElement(new tr().addElement(new td().addElement(name)).addElement(new td().addElement(attrib)));
    }
    /*	*/
    return table;
}
Also used : Cookie(javax.servlet.http.Cookie) Enumeration(java.util.Enumeration) HttpSession(javax.servlet.http.HttpSession) org.apache.ecs.xhtml.h3(org.apache.ecs.xhtml.h3) Timestamp(java.sql.Timestamp) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) ServletContext(javax.servlet.ServletContext) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr)

Example 59 with ServletContext

use of javax.servlet.ServletContext in project jena by apache.

the class DumpServlet method dumpServletContext.

public String dumpServletContext() {
    StringWriter sw = new StringWriter();
    try (PrintWriter pw = new PrintWriter(sw)) {
        ServletContext sc = getServletContext();
        pw.println("majorVersion: '" + sc.getMajorVersion() + "'");
        pw.println("minorVersion: '" + sc.getMinorVersion() + "'");
        pw.println("contextName:  '" + sc.getServletContextName() + "'");
        pw.println("servletInfo:  '" + getServletInfo() + "'");
        pw.println("serverInfo:  '" + sc.getServerInfo() + "'");
        {
            Enumeration<String> en = sc.getInitParameterNames();
            if (en != null) {
                pw.println("initParameters: ");
                while (en.hasMoreElements()) {
                    String key = en.nextElement();
                    pw.println(key + ": '" + sc.getInitParameter(key) + "'");
                }
            }
        }
        {
            Enumeration<String> en = sc.getAttributeNames();
            if (en != null) {
                pw.println("attributes: ");
                while (en.hasMoreElements()) {
                    String key = en.nextElement();
                    pw.println(key + ": '" + sc.getAttribute(key) + "'");
                }
            }
        }
        pw.println();
        pw.close();
    }
    return sw.toString();
}
Also used : Enumeration(java.util.Enumeration) StringWriter(java.io.StringWriter) ServletContext(javax.servlet.ServletContext) PrintWriter(java.io.PrintWriter)

Example 60 with ServletContext

use of javax.servlet.ServletContext in project jena by apache.

the class FusekiServerListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    String x = servletContext.getContextPath();
    if (!x.isEmpty())
        Fuseki.configLog.info("Context path = " + x);
    serverInitialization(servletContext);
}
Also used : ServletContext(javax.servlet.ServletContext)

Aggregations

ServletContext (javax.servlet.ServletContext)1059 Test (org.junit.Test)231 HttpServletRequest (javax.servlet.http.HttpServletRequest)171 IOException (java.io.IOException)138 HttpServletResponse (javax.servlet.http.HttpServletResponse)127 ServletException (javax.servlet.ServletException)95 File (java.io.File)75 ServletConfig (javax.servlet.ServletConfig)68 FilterConfig (javax.servlet.FilterConfig)65 HashMap (java.util.HashMap)63 Enumeration (java.util.Enumeration)52 InputStream (java.io.InputStream)51 ArrayList (java.util.ArrayList)49 URL (java.net.URL)47 HttpSession (javax.servlet.http.HttpSession)43 Map (java.util.Map)38 PrintWriter (java.io.PrintWriter)32 List (java.util.List)32 RequestDispatcher (javax.servlet.RequestDispatcher)30 WebApplicationContext (org.springframework.web.context.WebApplicationContext)28