Example usage for javax.servlet.http HttpServletRequest getProtocol

List of usage examples for javax.servlet.http HttpServletRequest getProtocol

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getProtocol.

Prototype

public String getProtocol();

Source Link

Document

Returns the name and version of the protocol the request uses in the form <i>protocol/majorVersion.minorVersion</i>, for example, HTTP/1.1.

Usage

From source file:org.sakaiproject.portal.util.ErrorReporter.java

@SuppressWarnings("rawtypes")
private String requestDisplay(HttpServletRequest request) {
    ResourceBundle rb = rbDefault;
    StringBuilder sb = new StringBuilder();
    try {//w w  w .  j  a va2 s.com
        sb.append(rb.getString("bugreport.request")).append("\n");
        sb.append(rb.getString("bugreport.request.authtype")).append(request.getAuthType()).append("\n");
        sb.append(rb.getString("bugreport.request.charencoding")).append(request.getCharacterEncoding())
                .append("\n");
        sb.append(rb.getString("bugreport.request.contentlength")).append(request.getContentLength())
                .append("\n");
        sb.append(rb.getString("bugreport.request.contenttype")).append(request.getContentType()).append("\n");
        sb.append(rb.getString("bugreport.request.contextpath")).append(request.getContextPath()).append("\n");
        sb.append(rb.getString("bugreport.request.localaddr")).append(request.getLocalAddr()).append("\n");
        sb.append(rb.getString("bugreport.request.localname")).append(request.getLocalName()).append("\n");
        sb.append(rb.getString("bugreport.request.localport")).append(request.getLocalPort()).append("\n");
        sb.append(rb.getString("bugreport.request.method")).append(request.getMethod()).append("\n");
        sb.append(rb.getString("bugreport.request.pathinfo")).append(request.getPathInfo()).append("\n");
        sb.append(rb.getString("bugreport.request.protocol")).append(request.getProtocol()).append("\n");
        sb.append(rb.getString("bugreport.request.querystring")).append(request.getQueryString()).append("\n");
        sb.append(rb.getString("bugreport.request.remoteaddr")).append(request.getRemoteAddr()).append("\n");
        sb.append(rb.getString("bugreport.request.remotehost")).append(request.getRemoteHost()).append("\n");
        sb.append(rb.getString("bugreport.request.remoteport")).append(request.getRemotePort()).append("\n");
        sb.append(rb.getString("bugreport.request.requesturl")).append(request.getRequestURL()).append("\n");
        sb.append(rb.getString("bugreport.request.scheme")).append(request.getScheme()).append("\n");
        sb.append(rb.getString("bugreport.request.servername")).append(request.getServerName()).append("\n");
        sb.append(rb.getString("bugreport.request.headers")).append("\n");
        for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) {
            String headerName = (String) e.nextElement();
            boolean censor = (censoredHeaders.get(headerName) != null);
            for (Enumeration he = request.getHeaders(headerName); he.hasMoreElements();) {
                String headerValue = (String) he.nextElement();
                sb.append(rb.getString("bugreport.request.header")).append(headerName).append(":")
                        .append(censor ? "---censored---" : headerValue).append("\n");
            }
        }
        sb.append(rb.getString("bugreport.request.parameters")).append("\n");
        for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {

            String parameterName = (String) e.nextElement();
            boolean censor = (censoredParameters.get(parameterName) != null);
            String[] paramvalues = request.getParameterValues(parameterName);
            for (int i = 0; i < paramvalues.length; i++) {
                sb.append(rb.getString("bugreport.request.parameter")).append(parameterName).append(":")
                        .append(i).append(":").append(censor ? "----censored----" : paramvalues[i])
                        .append("\n");
            }
        }
        sb.append(rb.getString("bugreport.request.attributes")).append("\n");
        for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) {
            String attributeName = (String) e.nextElement();
            Object attribute = request.getAttribute(attributeName);
            boolean censor = (censoredAttributes.get(attributeName) != null);
            sb.append(rb.getString("bugreport.request.attribute")).append(attributeName).append(":")
                    .append(censor ? "----censored----" : attribute).append("\n");
        }
        HttpSession session = request.getSession(false);
        if (session != null) {
            DateFormat serverLocaleDateFormat = DateFormat.getDateInstance(DateFormat.FULL,
                    Locale.getDefault());
            sb.append(rb.getString("bugreport.session")).append("\n");
            sb.append(rb.getString("bugreport.session.creation")).append(session.getCreationTime())
                    .append("\n");
            sb.append(rb.getString("bugreport.session.lastaccess")).append(session.getLastAccessedTime())
                    .append("\n");
            sb.append(rb.getString("bugreport.session.creationdatetime"))
                    .append(serverLocaleDateFormat.format(session.getCreationTime())).append("\n");
            sb.append(rb.getString("bugreport.session.lastaccessdatetime"))
                    .append(serverLocaleDateFormat.format(session.getLastAccessedTime())).append("\n");
            sb.append(rb.getString("bugreport.session.maxinactive")).append(session.getMaxInactiveInterval())
                    .append("\n");
            sb.append(rb.getString("bugreport.session.attributes")).append("\n");
            for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();) {
                String attributeName = (String) e.nextElement();
                Object attribute = session.getAttribute(attributeName);
                boolean censor = (censoredAttributes.get(attributeName) != null);
                sb.append(rb.getString("bugreport.session.attribute")).append(attributeName).append(":")
                        .append(censor ? "----censored----" : attribute).append("\n");
            }

        }
    } catch (Exception ex) {
        M_log.error("Failed to generate request display", ex);
        sb.append("Error " + ex.getMessage());
    }

    return sb.toString();
}

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;/*w w  w  .  ja v  a 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:oscar.util.Doc2PDF.java

public static String AddAbsoluteTag(HttpServletRequest request, String docText, String uri) {

    String absolutePath = "";

    docText = docText.replaceAll("src='/", "src='");
    docText = docText.replaceAll("src=\"/", "src=\"");
    docText = docText.replaceAll("src=/", "src=");

    if (request.getProtocol().toString().equals("HTTP/1.1")) {
        absolutePath = "http://";
    } else {/*from   w ww  . jav  a  2 s  .  c o m*/
        absolutePath = "https://";
    }

    absolutePath += request.getRemoteHost() + ":" + request.getServerPort() + "" + request.getContextPath()
            + "/";

    docText = docText.replaceAll("src='", "src='" + absolutePath);
    docText = docText.replaceAll("src=\"", "src=\"" + absolutePath);

    return docText;
}

From source file:pt.webdetails.cdf.dd.api.RenderApi.java

@GET
@Path("/cde-embed.js")
@Produces(JAVASCRIPT)/*from w  w w. ja  va2s  . c  om*/
public String getCdeEmbeddedContext(@Context HttpServletRequest servletRequest,
        @Context HttpServletResponse servletResponse) throws Exception {
    return InterPluginBroker.getCdfEmbed(servletRequest.getProtocol(), servletRequest.getServerName(),
            servletRequest.getServerPort(), servletRequest.getSession().getMaxInactiveInterval(),
            servletRequest.getParameter("locale"), getParameterProvider(servletRequest.getParameterMap()));
}

From source file:pt.webdetails.cdf.dd.CdeApi.java

protected String buildFullServerUrl(HttpServletRequest servletRequest) {
    if (!StringUtils.isEmpty(servletRequest.getProtocol())) {
        return servletRequest.getProtocol().split("/")[0].toLowerCase() + "://" + servletRequest.getServerName()
                + ":" + servletRequest.getServerPort()
                + PentahoRequestContextHolder.getRequestContext().getContextPath();
    }/*from   w  w  w .java2  s  . c  om*/
    return "http://" + servletRequest.getServerName() + ":" + servletRequest.getServerPort()
            + PentahoRequestContextHolder.getRequestContext().getContextPath();
}

From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.XSLTEntityHandler.java

/**
 * {@inheritDoc}//from   w w  w .  j av a  2  s  .c om
 */
public void outputContent(final Entity entity, final Entity sideBar, final HttpServletRequest request,
        final HttpServletResponse res) {
    if (!isAvailable())
        return;
    if (!(entity instanceof RWikiEntity))
        return;

    try {
        String skin = ServerConfigurationService.getString("skin.default"); //$NON-NLS-1$
        String skinRepo = ServerConfigurationService.getString("skin.repo"); //$NON-NLS-1$
        request.setAttribute("sakai.skin.repo", skinRepo); //$NON-NLS-1$
        request.setAttribute("sakai.skin", skin); //$NON-NLS-1$

        HttpSession s = request.getSession();
        PageVisits pageVisits = (PageVisits) s
                .getAttribute(XSLTEntityHandler.class.getName() + this.getMinorType() + "_visits");

        boolean withBreadcrumbs = !"0".equals(request.getParameter(breadCrumbParameter));
        if (pageVisits == null) {
            pageVisits = new PageVisits();
            s.setAttribute(XSLTEntityHandler.class.getName() + this.getMinorType() + "_visits", pageVisits);
        }
        RWikiEntity rwe = (RWikiEntity) entity;
        if (!rwe.isContainer()) {
            RWikiObject rwo = rwe.getRWikiObject();
            pageVisits.addPage(rwo.getName());
        }

        setCurrentRequest(request);

        if (responseHeaders != null) {
            for (Iterator i = responseHeaders.keySet().iterator(); i.hasNext();) {
                String name = (String) i.next();
                String value = (String) responseHeaders.get(name);
                res.setHeader(name, value);

            }

        }

        OutputStream out = res.getOutputStream();

        ContentHandler opch = getOutputHandler(out);
        ContentHandler ch = null;
        if (false) {
            ch = new DebugContentHandler(opch);
        } else {
            ch = opch;
        }

        Attributes dummyAttributes = new AttributesImpl();

        ch.startDocument();
        ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ENTITYSERVICE, SchemaNames.EL_NSENTITYSERVICE,
                dummyAttributes);

        AttributesImpl propA = new AttributesImpl();
        propA.addAttribute("", SchemaNames.ATTR_REQUEST_PATH_INFO, //$NON-NLS-1$
                SchemaNames.ATTR_REQUEST_PATH_INFO, "string", request //$NON-NLS-1$
                        .getPathInfo());
        propA.addAttribute("", SchemaNames.ATTR_REQUEST_USER, //$NON-NLS-1$
                SchemaNames.ATTR_REQUEST_USER, "string", request //$NON-NLS-1$
                        .getRemoteUser());
        propA.addAttribute("", SchemaNames.ATTR_REQUEST_PROTOCOL, //$NON-NLS-1$
                SchemaNames.ATTR_REQUEST_PROTOCOL, "string", request //$NON-NLS-1$
                        .getProtocol());
        propA.addAttribute("", SchemaNames.ATTR_REQUEST_SERVER_NAME, //$NON-NLS-1$
                SchemaNames.ATTR_REQUEST_SERVER_NAME, "string", request //$NON-NLS-1$
                        .getServerName());
        propA.addAttribute("", SchemaNames.ATTR_REQUEST_SERVER_PORT, //$NON-NLS-1$
                SchemaNames.ATTR_REQUEST_SERVER_PORT, "string", String //$NON-NLS-1$
                        .valueOf(request.getServerPort()));
        propA.addAttribute("", SchemaNames.ATTR_REQUEST_REQUEST_URL, //$NON-NLS-1$
                SchemaNames.ATTR_REQUEST_REQUEST_URL, "string", String //$NON-NLS-1$
                        .valueOf(request.getRequestURL()));

        ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_REQUEST_PROPERTIES,
                SchemaNames.EL_NSREQUEST_PROPERTIES, propA);
        addRequestAttributes(ch, request);
        addRequestParameters(ch, request);

        ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_REQUEST_PROPERTIES,
                SchemaNames.EL_NSREQUEST_PROPERTIES);

        if (withBreadcrumbs) {
            ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_PAGEVISITS, SchemaNames.EL_NSPAGEVISITS,
                    dummyAttributes);

            List<String[]> pv = pageVisits.getPageNames(this.getMinorType());

            for (Iterator<String[]> i = pv.iterator(); i.hasNext();) {
                String[] visit = i.next();
                propA = new AttributesImpl();
                propA.addAttribute("", SchemaNames.ATTR_URL, SchemaNames.ATTR_URL, "string", visit[0]);
                addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_PAGEVISIT, SchemaNames.EL_NSPAGEVISIT,
                        propA, visit[1]);
            }
            ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_PAGEVISITS, SchemaNames.EL_NSPAGEVISITS);
        }

        ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ENTITY, SchemaNames.EL_NSENTITY,
                dummyAttributes);
        ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTIES, SchemaNames.EL_NSXMLPROPERTIES,
                dummyAttributes);
        ResourceProperties rp = entity.getProperties();

        for (Iterator i = rp.getPropertyNames(); i.hasNext();) {
            Object key = i.next();
            String name = String.valueOf(key);
            String value = String.valueOf(rp.getProperty(name));
            propA = new AttributesImpl();
            propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$
                    SchemaNames.ATTR_NAME, "string", name); //$NON-NLS-1$
            addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY,
                    propA, value);
        }
        propA = new AttributesImpl();
        propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$
                SchemaNames.ATTR_NAME, "string", "_handler"); //$NON-NLS-1$ //$NON-NLS-2$
        addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY,
                propA, " XSLTEntity Handler"); //$NON-NLS-1$

        if (!rwe.isContainer()) {
            RWikiObject rwo = rwe.getRWikiObject();
            propA = new AttributesImpl();
            propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$
                    SchemaNames.ATTR_NAME, "string", "_title"); //$NON-NLS-1$ //$NON-NLS-2$
            addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY,
                    propA, NameHelper.localizeName(rwo.getName(), rwo.getRealm()));

        } else {
            propA = new AttributesImpl();
            propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$
                    SchemaNames.ATTR_NAME, "string", "_title"); //$NON-NLS-1$ //$NON-NLS-2$
            addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY,
                    propA, entity.getReference());

        }
        ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTIES, SchemaNames.EL_NSXMLPROPERTIES);

        /* http://jira.sakaiproject.org/browse/SAK-13281
         * escapeXML is controlled via config settings
         */

        if (!rwe.isContainer()) {
            RWikiObject rwo = rwe.getRWikiObject();
            ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RENDEREDCONTENT,
                    SchemaNames.EL_NSRENDEREDCONTENT, dummyAttributes);

            renderToXML(rwo, ch, withBreadcrumbs, this.escaped);
            ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RENDEREDCONTENT,
                    SchemaNames.EL_NSRENDEREDCONTENT);
        }
        ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ENTITY, SchemaNames.EL_NSENTITY);

        if (sideBar != null && sideBar instanceof RWikiEntity) {

            RWikiEntity sbrwe = (RWikiEntity) sideBar;
            RWikiObject sbrwo = sbrwe.getRWikiObject();
            ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_SIDEBAR, SchemaNames.EL_NSSIDEBAR,
                    dummyAttributes);

            ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTIES,
                    SchemaNames.EL_NSXMLPROPERTIES, dummyAttributes);
            propA = new AttributesImpl();
            propA.addAttribute("", SchemaNames.ATTR_NAME, //$NON-NLS-1$
                    SchemaNames.ATTR_NAME, "string", "_title"); //$NON-NLS-1$ //$NON-NLS-2$
            addElement(ch, SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTY, SchemaNames.EL_NSXMLPROPERTY,
                    propA, NameHelper.localizeName(sbrwo.getName(), sbrwo.getRealm()));
            ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_XMLPROPERTIES,
                    SchemaNames.EL_NSXMLPROPERTIES);

            ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RENDEREDCONTENT,
                    SchemaNames.EL_NSRENDEREDCONTENT, dummyAttributes);
            renderToXML(sbrwo, ch, withBreadcrumbs, this.escaped);
            ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RENDEREDCONTENT,
                    SchemaNames.EL_NSRENDEREDCONTENT);

            ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_SIDEBAR, SchemaNames.EL_NSSIDEBAR);

        }

        ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ENTITYSERVICE, SchemaNames.EL_NSENTITYSERVICE);

        ch.endDocument();

    } catch (Throwable ex) {
        log.info("Failed to serialize " + ex.getMessage()); //$NON-NLS-1$
        ex.printStackTrace();
        throw new RuntimeException(Messages.getString("XSLTEntityHandler.68") //$NON-NLS-1$
                + ex.getLocalizedMessage(), ex);
    } finally {
        setCurrentRequest(null);
    }
}

From source file:unUtils.ActionError.java

@Override
public Object doAction(WikittyPublicationContext context) {
    error.printStackTrace();/*from  w w  w . ja v  a 2  s  .  c o m*/

    HttpServletRequest req = context.getRequest();
    String result = "<html><body>Error: " + "<br>context: " + context + "<br>" + "<br>getContextPath: "
            + req.getContextPath() + "<br>getMethod: " + req.getMethod() + "<br>getPathInfo: "
            + req.getPathInfo() + "<br>getPathTranslated: " + req.getPathTranslated() + "<br>getQueryString: "
            + req.getQueryString() + "<br>getRemoteUser: " + req.getRemoteUser() + "<br>getRequestURI: "
            + req.getRequestURI() + "<br>getRequestURI: " + req.getRequestURI() + "<br>getRequestedSessionId: "
            + req.getRequestedSessionId() + "<br>getServletPath: " + req.getServletPath()
            + "<br>getCharacterEncoding: " + req.getCharacterEncoding() + "<br>getContentType: "
            + req.getContentType() + "<br>getLocalAddr: " + req.getLocalAddr() + "<br>getLocalName: "
            + req.getLocalName() + "<br>getProtocol: " + req.getProtocol() + "<br>getRemoteAddr: "
            + req.getRemoteAddr() + "<br>getRemoteHost: " + req.getRemoteHost() + "<br>getScheme: "
            + req.getScheme() + "<br>getServerName: " + req.getServerName() + "<br>" + "<br>error:<pre>"
            + StringEscapeUtils.escapeHtml(ExceptionUtil.stackTrace(error)) + "</pre>" + "</body></html>";
    return result;
}