Example usage for javax.servlet.http HttpServletRequest getHeaders

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

Introduction

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

Prototype

public Enumeration<String> getHeaders(String name);

Source Link

Document

Returns all the values of the specified request header as an Enumeration of String objects.

Usage

From source file:org.frontcache.core.FCUtils.java

public static Map<String, List<String>> buildRequestHeaders(HttpServletRequest request) {

    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    Enumeration<String> headerNames = request.getHeaderNames();
    if (headerNames != null) {
        while (headerNames.hasMoreElements()) {
            String name = headerNames.nextElement();
            if (isIncludedHeader(name)) {
                Enumeration<String> values = request.getHeaders(name);
                while (values.hasMoreElements()) {
                    String value = values.nextElement();

                    List<String> hValues = headers.get(name);
                    if (null == hValues) {
                        hValues = new ArrayList<String>();
                        headers.put(name, hValues);
                    }//from  www  .  j ava2s .c  o m
                    hValues.add(value);
                }
            }
        }
    }

    return headers;
}

From source file:spring.travel.site.request.RequestInfoInterceptor.java

private Optional<String> getSessionCookie(HttpServletRequest request) {
    Enumeration<String> cookies = request.getHeaders("Cookie");
    if (cookies != null) {
        while (cookies.hasMoreElements()) {
            String cookie = cookies.nextElement();
            if (cookie.startsWith(cookieName) && cookie.indexOf('=') > 0) {
                return getCookieValue(cookie);
            }//from  w w w .  java2 s.  co  m
        }
    }
    return Optional.empty();
}

From source file:org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor.java

/**
 * Extract the OAuth bearer token from a header.
 * //from   www.  j  a v  a  2s.  c  o  m
 * @param request The request.
 * @return The token, or null if no OAuth authorization header was supplied.
 */
protected String extractHeaderToken(HttpServletRequest request) {
    Enumeration<String> headers = request.getHeaders("Authorization");
    while (headers.hasMoreElements()) { // typically there is only one (most servers enforce that)
        String value = headers.nextElement();
        if ((value.toLowerCase().startsWith(OAuth2AccessToken.BEARER_TYPE.toLowerCase()))) {
            String authHeaderValue = value.substring(OAuth2AccessToken.BEARER_TYPE.length()).trim();
            int commaIndex = authHeaderValue.indexOf(',');
            if (commaIndex > 0) {
                authHeaderValue = authHeaderValue.substring(0, commaIndex);
            }
            return authHeaderValue;
        }
    }

    return null;
}

From source file:org.squashtest.tm.web.internal.exceptionresolver.HandlerGenericValidation.java

private boolean clientAcceptsJson(HttpServletRequest request) {
    Enumeration<String> e = request.getHeaders(RequestHeaders.ACCEPT);

    while (e.hasMoreElements()) {
        String header = e.nextElement();
        if (StringUtils.containsIgnoreCase(StringUtils.trimToEmpty(header),
                MimeType.ANYTHING.requestHeaderValue())
                || StringUtils.containsIgnoreCase(StringUtils.trimToEmpty(header),
                        MimeType.APPLICATION_JSON.requestHeaderValue())) {
            return true;
        }//from w  ww  .ja v a  2  s  .  c  o m
    }
    return false;
}

From source file:org.apache.openaz.xacml.rest.XACMLRest.java

/**
 * Helper routine to dump the HTTP servlet request being serviced. Primarily for debugging.
 *
 * @param request - Servlet request (from a POST/GET/PUT/etc.)
 *//*from  w  ww.java2s . c o m*/
public static void dumpRequest(HttpServletRequest request) {
    if (logger.isDebugEnabled()) {
        // special-case for receiving heartbeat - don't need to repeatedly output all of the information
        // in multiple lines
        if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type"))) {
            logger.debug("GET type=hb : heartbeat received");
            return;
        }
        logger.debug(request.getMethod() + ":" + request.getRemoteAddr() + " " + request.getRemoteHost() + " "
                + request.getRemotePort());
        logger.debug(request.getLocalAddr() + " " + request.getLocalName() + " " + request.getLocalPort());
        Enumeration<String> en = request.getHeaderNames();
        logger.debug("Headers:");
        while (en.hasMoreElements()) {
            String element = en.nextElement();
            Enumeration<String> values = request.getHeaders(element);
            while (values.hasMoreElements()) {
                String value = values.nextElement();
                logger.debug(element + ":" + value);
            }
        }
        logger.debug("Attributes:");
        en = request.getAttributeNames();
        while (en.hasMoreElements()) {
            String element = en.nextElement();
            logger.debug(element + ":" + request.getAttribute(element));
        }
        logger.debug("ContextPath: " + request.getContextPath());
        if (request.getMethod().equals("PUT") || request.getMethod().equals("POST")) {
            // POST and PUT are allowed to have parameters in the content, but in our usage the parameters
            // are always in the Query string.
            // More importantly, there are cases where the POST and PUT content is NOT parameters (e.g. it
            // might contain a Policy file).
            // Unfortunately the request.getParameterMap method reads the content to see if there are any
            // parameters,
            // and once the content is read it cannot be read again.
            // Thus for PUT and POST we must avoid reading the content here so that the main code can read
            // it.
            logger.debug("Query String:" + request.getQueryString());
            try {
                if (request.getInputStream() == null) {
                    logger.debug("Content: No content inputStream");
                } else {
                    logger.debug("Content available: " + request.getInputStream().available());
                }
            } catch (Exception e) {
                logger.debug("Content: inputStream exception: " + e.getMessage() + ";  (May not be relevant)");
            }
        } else {
            logger.debug("Parameters:");
            Map<String, String[]> params = request.getParameterMap();
            Set<String> keys = params.keySet();
            for (String key : keys) {
                String[] values = params.get(key);
                logger.debug(key + "(" + values.length + "): " + (values.length > 0 ? values[0] : ""));
            }
        }
        logger.debug("Request URL:" + request.getRequestURL());
    }
}

From source file:com.adobe.acs.commons.http.headers.impl.AbstractExpiresHeaderFilter.java

@Override
@SuppressWarnings("unchecked")
protected boolean accepts(HttpServletRequest request) {

    if (super.accepts(request)) {
        Enumeration<String> expiresheaders = request.getHeaders(EXPIRES_NAME);
        return expiresheaders == null || !expiresheaders.hasMoreElements();
    }//from w w w.  j  a va  2 s.  c  o m
    return false;
}

From source file:net.sf.j2ep.servers.ClusterRequestWrapper.java

/**
 * Constructor, will check all cookies if they include
 * JSESSIONID. If they do any extra information about
 * which server this session was created for is removed.
 * // w  w w  .  jav  a 2 s. c  o m
 * @param request The request we wrap.
 */
@SuppressWarnings("unchecked")
public ClusterRequestWrapper(HttpServletRequest request) {
    super(request);
    cookies = new Vector();

    Enumeration reqCookies = request.getHeaders("Cookie");
    while (reqCookies.hasMoreElements()) {
        String value = (String) reqCookies.nextElement();
        Matcher matcher = sessionPattern.matcher(value);
        String replaced = matcher.replaceAll("$1");
        if (log.isDebugEnabled() && !replaced.equals(value)) {
            log.debug("Session processed, serverId removed \"" + value + "\" >> " + replaced);
        }
        cookies.add(replaced);
    }
}

From source file:se.vgregion.portal.auditlog.AuditLogInfoContainerFactoryImpl.java

private String getRemoteIpAddress(HttpServletRequest request) {
    StringBuilder ipAddress = new StringBuilder();

    Enumeration forwardedForEnum = request.getHeaders(HEADER_X_FORWARDED_FOR);
    while (forwardedForEnum.hasMoreElements()) {
        ipAddress.append(forwardedForEnum.nextElement()).append(" ");
    }/*from  w w  w  . j a v a 2 s  .c o m*/
    if (ipAddress.length() == 0) {
        ipAddress.append(request.getRemoteAddr()).append(" [Default]");
    }

    return ipAddress.toString().trim();
}

From source file:com.adobe.acs.commons.http.headers.impl.AbstractDispatcherCacheHeaderFilter.java

@SuppressWarnings("unchecked")
protected boolean accepts(final HttpServletRequest request) {

    Enumeration<String> agentsEnum = request.getHeaders(SERVER_AGENT_NAME);
    List<String> serverAgents = agentsEnum != null ? Collections.list(agentsEnum)
            : Collections.<String>emptyList();

    // Only inject when:
    // - GET request
    // - No Params
    // - From Dispatcher
    if (StringUtils.equalsIgnoreCase("get", request.getMethod()) && request.getParameterMap().isEmpty()
            && serverAgents.contains(DISPATCHER_AGENT_HEADER_VALUE)) {

        return true;
    }//  w ww  .  j  av  a2s. c  o  m
    return false;
}

From source file:net.oauth.signatures.SignedOAuthTokenParser.java

private String getAuthHeader(HttpServletRequest request) {
    @SuppressWarnings("unchecked")
    Enumeration<String> authHeaders = request.getHeaders("Authorization");

    if (authHeaders == null) {
        return null;
    }//from www.ja  v  a2  s.  co  m

    while (authHeaders.hasMoreElements()) {
        String header = (String) authHeaders.nextElement();
        if (header.trim().startsWith(SignedOAuthToken.AUTH_METHOD)) {
            return header.trim();
        }
    }

    return null;
}