Example usage for javax.servlet.http HttpServletRequest getHeaderNames

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

Introduction

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

Prototype

public Enumeration<String> getHeaderNames();

Source Link

Document

Returns an enumeration of all the header names this request contains.

Usage

From source file:com.idega.core.cache.filter.Filter.java

/**
 * Logs the request headers, if debug is enabled.
 *
 * @param request/*from w ww  .j a va2 s.c  om*/
 */
protected void logRequestHeaders(final HttpServletRequest request) {
    if (LOG.isDebugEnabled()) {
        Map headers = new HashMap();
        Enumeration enumeration = request.getHeaderNames();
        StringBuffer logLine = new StringBuffer();
        logLine.append("Request Headers");
        while (enumeration.hasMoreElements()) {
            String name = (String) enumeration.nextElement();
            String headerValue = request.getHeader(name);
            headers.put(name, headerValue);
            logLine.append(": ").append(name).append(" -> ").append(headerValue);
        }
        LOG.debug(logLine);
    }
}

From source file:org.wso2.carbon.identity.oauth.endpoint.revoke.OAuthRevocationEndpoint.java

private void logAccessTokenRevocationRequest(HttpServletRequest request) {
    log.debug("Received a access token revocation request : " + request.getRequestURI());
    // log the headers.
    log.debug("----------logging request headers.----------");
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        Enumeration headers = request.getHeaders(headerName);
        while (headers.hasMoreElements()) {
            log.debug(headerName + " : " + headers.nextElement());
        }/* w  w w  .  j a va  2 s.  co  m*/
    }
    // log the parameters.
    log.debug("----------logging request parameters.----------");
    log.debug("token - " + request.getParameter("token"));
}

From source file:com.eviware.soapui.impl.wsdl.monitor.JProxyServletWsdlMonitorMessageExchange.java

@SuppressWarnings("unchecked")
public void setRequestHeader(HttpServletRequest httpRequest) {
    Enumeration<String> headerNames = httpRequest.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String name = headerNames.nextElement();
        Enumeration<String> header = httpRequest.getHeaders(name);
        while (header.hasMoreElements()) {
            String value = header.nextElement();
            if (value != null) {
                requestHeaders.put(name, value);
            }/*w  ww  .j a  va2 s .c  o  m*/
        }
    }
}

From source file:freeciv.servlet.ProxyServlet.java

/**
 * Retreives all of the headers from the servlet request and sets them on
 * the proxy request/*from ww  w.  jav a  2  s.  c  om*/
 * 
 * @param httpServletRequest The request object representing the client's
 *                            request to the servlet engine
 * @param httpMethodProxyRequest The request that we are about to send to
 *                                the proxy host
 */
@SuppressWarnings("unchecked")
private void setProxyRequestHeaders(HttpServletRequest httpServletRequest, HttpMethod httpMethodProxyRequest) {
    // Get an Enumeration of all of the header names sent by the client
    Enumeration enumerationOfHeaderNames = httpServletRequest.getHeaderNames();
    while (enumerationOfHeaderNames.hasMoreElements()) {
        String stringHeaderName = (String) enumerationOfHeaderNames.nextElement();
        if (stringHeaderName.equalsIgnoreCase(STRING_CONTENT_LENGTH_HEADER_NAME))
            continue;
        // As per the Java Servlet API 2.5 documentation:
        //      Some headers, such as Accept-Language can be sent by clients
        //      as several headers each with a different value rather than
        //      sending the header as a comma separated list.
        // Thus, we get an Enumeration of the header values sent by the client
        Enumeration enumerationOfHeaderValues = httpServletRequest.getHeaders(stringHeaderName);
        while (enumerationOfHeaderValues.hasMoreElements()) {
            String stringHeaderValue = (String) enumerationOfHeaderValues.nextElement();
            // In case the proxy host is running multiple virtual servers,
            // rewrite the Host header to ensure that we get content from
            // the correct virtual server
            if (stringHeaderName.equalsIgnoreCase(STRING_HOST_HEADER_NAME)) {
                stringHeaderValue = getProxyHostAndPort();
            }
            Header header = new Header(stringHeaderName, stringHeaderValue);
            // Set the same header on the proxy request
            httpMethodProxyRequest.setRequestHeader(header);
        }
    }
}

From source file:com.erudika.para.rest.Signer.java

private Request<?> buildAWSRequest(HttpServletRequest req, Set<String> headersUsed) {
    Map<String, String> headers = new HashMap<String, String>();
    for (Enumeration<String> e = req.getHeaderNames(); e.hasMoreElements();) {
        String head = e.nextElement().toLowerCase();
        if (headersUsed.contains(head)) {
            headers.put(head, req.getHeader(head));
        }//from  www  .  j a v a  2 s . c  o  m
    }

    Map<String, String> params = new HashMap<String, String>();
    for (Map.Entry<String, String[]> param : req.getParameterMap().entrySet()) {
        params.put(param.getKey(), param.getValue()[0]);
    }

    String path = req.getRequestURI();
    String endpoint = StringUtils.removeEndIgnoreCase(req.getRequestURL().toString(), path);
    String httpMethod = req.getMethod();
    InputStream entity;
    try {
        entity = new BufferedInputStream(req.getInputStream());
        if (entity.available() <= 0) {
            entity = null;
        }
    } catch (IOException ex) {
        logger.error(null, ex);
        entity = null;
    }

    return buildAWSRequest(httpMethod, endpoint, path, headers, params, entity);
}

From source file:csiro.pidsvc.servlet.info.java

/**
 * Echoes HTTP headers./*  ww  w  .ja v a 2s  .  c  o m*/
 *
 * @param request
 * @param response
 * @throws IOException
 * @throws URISyntaxException
 */
protected void echo(HttpServletRequest request, HttpServletResponse response)
        throws IOException, URISyntaxException {
    String ret = "HTTP " + request.getMethod() + " " + request.getRequestURL() + "?" + request.getQueryString()
            + "\n\n";

    // Retrieve HTTP headers.
    for (@SuppressWarnings("unchecked")
    Enumeration<String> header = request.getHeaderNames(); header.hasMoreElements();) {
        String headerName = (String) header.nextElement();
        ret += headerName + ": " + request.getHeader(headerName) + "\n";
    }

    response.setContentType("text/plain");
    response.getWriter().write(ret);
}

From source file:org.n52.iceland.service.Service.java

private long logRequest(HttpServletRequest request) {
    long count = counter.incrementAndGet();
    this.serviceEventBus.submit(new IncomingRequestEvent(request, count));

    if (LOGGER.isDebugEnabled()) {
        Enumeration<?> headerNames = request.getHeaderNames();
        StringBuilder headers = new StringBuilder();
        while (headerNames.hasMoreElements()) {
            String name = (String) headerNames.nextElement();
            headers.append("> ").append(name).append(": ").append(request.getHeader(name)).append("\n");
        }/*  ww  w .  j a v  a 2  s . c o  m*/
        LOGGER.debug("Incoming request No. {}:\n> [{} {} {}] from {} {}\n{}", count, request.getMethod(),
                request.getRequestURI(), request.getProtocol(), request.getRemoteAddr(),
                request.getRemoteHost(), headers);
    }
    return count;
}

From source file:net.sourceforge.jwebunit.tests.util.HeadersServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.write(HtmlHelper.getStart("Received headers"));
    out.write("<h1>Received headers</h1>\n<p>Headers are:<br/>");
    /*//from  w w w . jav  a 2s . c  o m
     * Prints headers as name=[value] separated
     * by <BR/>
     */
    java.util.Enumeration headers = request.getHeaderNames();
    for (; headers.hasMoreElements();) {
        String h = headers.nextElement().toString();
        String v = request.getHeader(h);
        out.write(h + "=[" + v);
        if (headers.hasMoreElements()) {
            out.write("]<br/>\n");
        }
    }
    out.write("]</p>\n");
    String ref = request.getHeader("Referer");
    if (ref == null) {
        if (request.getParameterValues("myReferer") != null) {
            ref = request.getParameterValues("myReferer")[0];
        }
    }
    out.write(HtmlHelper.getLinkParagraph("return", ref));
    out.write(HtmlHelper.getEnd());
}

From source file:it.greenvulcano.gvesb.adapter.http.utils.DumpUtils.java

public static void dump(HttpServletRequest request, StringBuffer log) throws IOException {
    String hN;/*  w  ww. j a v a  2  s. com*/

    log.append("-- DUMP HttpServletRequest START").append("\n");
    log.append("Method             : ").append(request.getMethod()).append("\n");
    log.append("RequestedSessionId : ").append(request.getRequestedSessionId()).append("\n");
    log.append("Scheme             : ").append(request.getScheme()).append("\n");
    log.append("IsSecure           : ").append(request.isSecure()).append("\n");
    log.append("Protocol           : ").append(request.getProtocol()).append("\n");
    log.append("ContextPath        : ").append(request.getContextPath()).append("\n");
    log.append("PathInfo           : ").append(request.getPathInfo()).append("\n");
    log.append("QueryString        : ").append(request.getQueryString()).append("\n");
    log.append("RequestURI         : ").append(request.getRequestURI()).append("\n");
    log.append("RequestURL         : ").append(request.getRequestURL()).append("\n");
    log.append("ContentType        : ").append(request.getContentType()).append("\n");
    log.append("ContentLength      : ").append(request.getContentLength()).append("\n");
    log.append("CharacterEncoding  : ").append(request.getCharacterEncoding()).append("\n");

    log.append("---- Headers START\n");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        hN = headerNames.nextElement();
        log.append("[" + hN + "]=");
        Enumeration<String> headers = request.getHeaders(hN);
        while (headers.hasMoreElements()) {
            log.append("[" + headers.nextElement() + "]");
        }
        log.append("\n");
    }
    log.append("---- Headers END\n");

    log.append("---- Body START\n");
    log.append(IOUtils.toString(request.getInputStream())).append("\n");
    log.append("---- Body END\n");

    log.append("-- DUMP HttpServletRequest END \n");
}

From source file:org.wso2.carbon.identity.oauth.endpoint.token.OAuth2TokenEndpoint.java

private void logAccessTokenRequest(HttpServletRequest request) {

    if (log.isDebugEnabled()) {
        log.debug("Received a request : " + request.getRequestURI());
        // log the headers.
        log.debug("----------logging request headers.----------");

        Enumeration headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = (String) headerNames.nextElement();
            Enumeration headers = request.getHeaders(headerName);
            while (headers.hasMoreElements()) {
                log.debug(headerName + " : " + headers.nextElement());
            }//  www.j a  v  a 2s  .  co m
        }
        // log the parameters.
        log.debug("----------logging request parameters.----------");
        log.debug(OAuth.OAUTH_GRANT_TYPE + " - " + request.getParameter(OAuth.OAUTH_GRANT_TYPE));
        log.debug(OAuth.OAUTH_CLIENT_ID + " - " + request.getParameter(OAuth.OAUTH_CLIENT_ID));
        log.debug(OAuth.OAUTH_CODE + " - " + request.getParameter(OAuth.OAUTH_CODE));
        log.debug(OAuth.OAUTH_REDIRECT_URI + " - " + request.getParameter(OAuth.OAUTH_REDIRECT_URI));
    }
}