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:irille.pub.verify.RandomImageServlet.java

public static String getHeader(HttpServletRequest req, String name) {
    String value = req.getHeader(name);
    if (value != null)
        return value;
    Enumeration names = req.getHeaderNames();
    while (names.hasMoreElements()) {
        String n = (String) names.nextElement();
        if (n.equalsIgnoreCase(name)) {
            return req.getHeader(n);
        }// w w w.java 2s.  c om
    }
    return null;
}

From source file:org.opendatakit.odktables.util.ServiceUtils.java

@SuppressWarnings({ "rawtypes", "unused" })
public static void examineRequest(ServletContext sc, HttpServletRequest req) {
    Log logger = LogFactory.getLog(ServiceUtils.class);

    Enumeration headers = req.getHeaderNames();
    StringBuilder b = new StringBuilder();
    while (headers.hasMoreElements()) {
        String headerName = (String) headers.nextElement();
        Enumeration fieldValues = req.getHeaders(headerName);
        while (fieldValues.hasMoreElements()) {
            String fieldValue = (String) fieldValues.nextElement();
            b.append(headerName).append(": ").append(fieldValue).append("\n");
        }//w ww . j a v a 2s  .c o  m
    }

    String contentType = req.getContentType();
    logger.info("Content type: " + contentType);

    String charEncoding = req.getCharacterEncoding();
    logger.info("Character encoding: " + charEncoding);

    String headerSet = b.toString();
    logger.info("Headers: " + headerSet);

    Cookie[] cookies = req.getCookies();
    logger.info("Cookies: " + cookies);

    String method = req.getMethod();
    logger.info("Method: " + method);

    String ctxtPath = req.getContextPath();
    logger.info("Context Path: " + ctxtPath);

    String pathInfo = req.getPathInfo();
    logger.info("Path Info: " + pathInfo);

    String query = req.getQueryString();
    logger.info("Query String: " + query);

    String ace = req.getHeader(ApiConstants.ACCEPT_CONTENT_ENCODING_HEADER);
    boolean sessionId = req.isRequestedSessionIdValid();
}

From source file:org.ambraproject.wombat.util.HttpMessageUtil.java

/**
 * Return a list of headers from a request, using an optional whitelist
 *
 * @param request a request/*from   w  w  w . j  a va 2  s .com*/
 * @return its headers
 */
public static Collection<Header> getRequestHeaders(HttpServletRequest request,
        ImmutableSet<String> headerWhitelist) {
    Enumeration headerNames = request.getHeaderNames();
    List<Header> headers = Lists.newArrayList();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        if (headerWhitelist.contains(headerName)) {
            String headerValue = request.getHeader(headerName);
            headers.add(new BasicHeader(headerName, headerValue));
        }
    }
    return headers;
}

From source file:org.openo.nfvo.resmanagement.common.util.request.RequestUtil.java

/**
 * Get the context header<br/>/* w  w w . j a v a2  s  .c  o m*/
 *
 * @param context
 *         The http context
 * @return Map context header
 * @since NFVO 0.5
 */
@SuppressWarnings("unchecked")
private static Map<String, String> getContextHeader(HttpServletRequest context) {
    Map<String, String> header = new HashMap<String, String>();
    Enumeration<String> headerNames = context.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        String value = context.getHeader(headerName);
        header.put(headerName, value);
    }
    return header;
}

From source file:org.carewebframework.ui.util.RequestUtil.java

/**
 * Logs at trace level the request headers
 * /* w  w w .  j a  v  a2 s .c  om*/
 * @throws IllegalStateException if called outside scope of an HttpServletRequest
 */
public static void logHeaderNames() throws IllegalStateException {
    final HttpServletRequest request = assertRequest();
    final Enumeration<?> enumeration = request.getHeaderNames();
    while (enumeration.hasMoreElements()) {
        final String headerName = (String) enumeration.nextElement();
        log.trace(String.format("HeaderName: %s", headerName));
    }
}

From source file:com.pushinginertia.commons.net.util.HttpServletRequestUtils.java

/**
 * Converts all of the headers in a request to a newline-separated string of name-value pairs. This is required
 * because not all implementations of {@link javax.servlet.http.HttpServletRequest} implement the toString method.
 * @param req request received from the user agent
 * @return null if req is null//  w w  w. j av a  2s .  c  o  m
 */
public static String toString(final HttpServletRequest req) {
    ValidateAs.notNull(req, "req");

    final StringBuilder sb = new StringBuilder();
    for (Enumeration<String> headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) {
        final String headerName = headerNames.nextElement();
        for (Enumeration<String> headers = req.getHeaders(headerName); headers.hasMoreElements();) {
            final String value = headers.nextElement();
            sb.append(headerName).append('=').append(value).append('\n');
        }
    }
    return sb.toString();
}

From source file:org.sonar.server.authentication.SsoAuthenticator.java

private static Map<String, String> getHeaders(HttpServletRequest request) {
    Map<String, String> headers = new HashMap<>();
    Collections.list(request.getHeaderNames())
            .forEach(header -> headers.put(header.toLowerCase(Locale.ENGLISH), request.getHeader(header)));
    return headers;
}

From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java

/**
 * @param request/*from w  w w.ja v a2 s .  c  o m*/
 */
public static void printRequestHeaders(final HttpServletRequest request) {
    log.debug("Request headers:");
    final Enumeration<?> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        final String name = (String) headerNames.nextElement();
        log.debug(name + " = " + request.getHeader(name));
    }
}

From source file:com.liusoft.dlog4j.util.RequestUtils.java

/**
 * ??/*from   www .j a  v  a  2s  .  c om*/
 * @param out
 * @param req
 */
public static void dumpHeaders(PrintStream out, HttpServletRequest req) {
    Enumeration names = req.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        out.println(name + "=" + req.getHeader(name));
    }
}

From source file:org.artifactory.common.wicket.util.WicketUtils.java

public static Map<String, String> getHeadersMap() {
    Map<String, String> map = new HashMap<>();
    HttpServletRequest request = getHttpServletRequest();
    if (request != null) {
        Enumeration headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = (String) headerNames.nextElement();
            map.put(headerName.toUpperCase(), request.getHeader(headerName));
        }/*  w  ww. ja va2  s  .  c o  m*/
    }
    return map;
}