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:se.inera.certificate.proxy.mappings.remote.RemoteDispatcher.java

private void addHeaders(HttpServletRequest request, HttpUriRequest req) {
    for (String headerName : list(request.getHeaderNames())) {
        if (!BLOCKED_HEADERS.contains(lowerCase(headerName))) {
            req.addHeader(headerName, request.getHeader(headerName));
        }//  w w w  .j a  v a  2  s.c  o m
    }
    for (Map.Entry<String, String> headers : getRequestContext().getHeaders(request).entrySet()) {
        req.setHeader(headers.getKey(), headers.getValue());
    }
}

From source file:guru.nidi.raml.doc.servlet.MirrorServlet.java

private void headers(HttpServletRequest req, PrintWriter out) {
    out.println("headers");
    final Enumeration<String> headerNames = req.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        final String name = headerNames.nextElement();
        out.print(name + ": ");
        final Enumeration<String> headers = req.getHeaders(name);
        while (headers.hasMoreElements()) {
            out.print("'" + headers.nextElement() + "', ");
        }/*www . ja v a2  s  .  com*/
        out.println();
    }
    out.println();
}

From source file:org.ajax4jsf.tests.MockExternalContext.java

public Map getRequestHeaderMap() {
    if (null == requestHeaderMap) {
        requestHeaderMap = new TreeMap(CASE_INSENSITIVE_COMPARATOR);

        HttpServletRequest request = (HttpServletRequest) getRequest();

        for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) {
            String name = (String) e.nextElement();

            requestHeaderMap.put(name, request.getHeader(name));
        }//from   www. ja v  a 2 s.c  o  m
    }

    return Collections.unmodifiableMap(requestHeaderMap);
}

From source file:org.ajax4jsf.tests.MockExternalContext.java

public Map getRequestHeaderValuesMap() {
    if (null == requestHeaderValuesMap) {
        requestHeaderValuesMap = new TreeMap(CASE_INSENSITIVE_COMPARATOR);

        HttpServletRequest request = (HttpServletRequest) getRequest();

        for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) {
            String name = (String) e.nextElement();

            requestHeaderValuesMap.put(name, EnumerationUtils.toList(request.getHeaders(name)).toArray());
        }//from ww  w  .  j  av  a2s  .c o m
    }

    return Collections.unmodifiableMap(requestHeaderValuesMap);
}

From source file:guru.nidi.raml.doc.servlet.MirrorServlet.java

private Map<String, Object> headers(HttpServletRequest req) {
    final Map<String, Object> map = new HashMap<>();
    final Enumeration<String> headerNames = req.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        final String name = headerNames.nextElement();
        final List<String> values = new ArrayList<>();
        final Enumeration<String> headers = req.getHeaders(name);
        while (headers.hasMoreElements()) {
            values.add(headers.nextElement());
        }//from  ww w  . j a  v  a2s .com
        map.put(name, values);
    }
    return map;
}

From source file:HeaderSnoop.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    out.println("Request Headers:");
    Enumeration names = req.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        Enumeration values = req.getHeaders(name); // support multiple values
        if (values != null) {
            while (values.hasMoreElements()) {
                String value = (String) values.nextElement();
                out.println(name + ": " + value);
            }//from  w w w.j a v a 2s .  c o  m
        }
    }
}

From source file:org.apache.flume.sink.solr.morphline.BlobHandler.java

private Map<String, String> getHeaders(HttpServletRequest request) {
    if (LOGGER.isDebugEnabled()) {
        Map requestHeaders = new HashMap();
        Enumeration iter = request.getHeaderNames();
        while (iter.hasMoreElements()) {
            String name = (String) iter.nextElement();
            requestHeaders.put(name, request.getHeader(name));
        }//from   w w w. j  av a2  s. com
        LOGGER.debug("requestHeaders: {}", requestHeaders);
    }
    Map<String, String> headers = new HashMap();
    if (request.getContentType() != null) {
        headers.put(Metadata.CONTENT_TYPE, request.getContentType());
    }
    Enumeration iter = request.getParameterNames();
    while (iter.hasMoreElements()) {
        String name = (String) iter.nextElement();
        headers.put(name, request.getParameter(name));
    }
    return headers;
}

From source file:kziomek.filter.logging.MvcLoggingFilter.java

private Map<String, String> getHeadersInfo(HttpServletRequest request) {
    Map<String, String> map = new HashMap<>();
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String key = (String) headerNames.nextElement();
        String value = request.getHeader(key);
        map.put(key, value);/*  w  ww .j a  v a2  s  .c  om*/
    }
    return map;
}

From source file:org.springframework.boot.ops.trace.WebRequestTraceFilter.java

protected Map<String, Object> getTrace(HttpServletRequest request) {

    Map<String, Object> map = new LinkedHashMap<String, Object>();
    Enumeration<String> names = request.getHeaderNames();

    while (names.hasMoreElements()) {
        String name = names.nextElement();
        List<String> values = Collections.list(request.getHeaders(name));
        Object value = values;/*from w ww. jav a2 s .  co  m*/
        if (values.size() == 1) {
            value = values.get(0);
        } else if (values.isEmpty()) {
            value = "";
        }
        map.put(name, value);

    }
    Map<String, Object> trace = new LinkedHashMap<String, Object>();
    trace.put("method", request.getMethod());
    trace.put("path", request.getRequestURI());
    trace.put("headers", map);
    return trace;
}

From source file:org.jasig.portal.security.provider.SamlAssertionFilter.java

private String headersAsString(HttpServletRequest req) {
    StringBuilder sb = new StringBuilder();
    Enumeration<?> headers = req.getHeaderNames();

    while (headers.hasMoreElements()) {
        String headerName = (String) headers.nextElement();
        String headerValue = req.getHeader(headerName);
        sb.append(headerName).append("=").append(headerValue).append(", ");
    }//from w w  w. j  av  a  2s . com
    return sb.toString();
}