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:org.craftercms.engine.http.impl.HttpProxyImpl.java

protected void copyOriginalHeaders(HttpUriRequest httpRequest, HttpServletRequest request) {
    Enumeration headerNames = request.getHeaderNames();
    if (headerNames != null) {
        while (headerNames.hasMoreElements()) {
            String headerName = (String) headerNames.nextElement();
            String headerValue = request.getHeader(headerName);

            if (logger.isTraceEnabled()) {
                logger.trace(getRequestDescription(httpRequest) + " copying request header " + headerName + ": "
                        + headerValue);/*from  ww w .j  a  v  a 2 s.  c  o m*/
            }

            httpRequest.addHeader(headerName, headerValue);
        }
    }
}

From source file:edu.gatech.i3l.fhir.jpa.provider.BaseJpaProvider.java

public void startRequest(HttpServletRequest theRequest) {
    if (theRequest == null) {
        return;//from w w w .j  a  v  a 2  s . c  om
    }

    Set<String> headerNames = new TreeSet<String>();
    for (Enumeration<String> enums = theRequest.getHeaderNames(); enums.hasMoreElements();) {
        headerNames.add(enums.nextElement());
    }
    ourLog.debug("Request headers: {}", headerNames);

    Enumeration<String> forwardedFors = theRequest.getHeaders("x-forwarded-for");
    StringBuilder b = new StringBuilder();
    for (Enumeration<String> enums = forwardedFors; enums.hasMoreElements();) {
        if (b.length() > 0) {
            b.append(" / ");
        }
        b.append(enums.nextElement());
    }

    String forwardedFor = b.toString();
    String ip = theRequest.getRemoteAddr();
    if (StringUtils.isBlank(forwardedFor)) {
        org.slf4j.MDC.put(REMOTE_ADDR, ip);
        ourLog.debug("Request is from address: {}", ip);
    } else {
        org.slf4j.MDC.put(REMOTE_ADDR, forwardedFor);
        ourLog.debug("Request is from forwarded address: {}", forwardedFor);
    }

    String userAgent = StringUtils.defaultString(theRequest.getHeader("user-agent"));
    org.slf4j.MDC.put(REMOTE_UA, userAgent);

}

From source file:com.headissue.pigeon.PigeonContainer.java

@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    long dtStart = System.currentTimeMillis();
    HttpServletRequest httpReq = (HttpServletRequest) req;
    if (log.isTraceEnabled()) {
        LogUtils.trace(log, "%s '%s'", httpReq.getMethod(), httpReq.getRequestURI());
        Enumeration<String> en = httpReq.getHeaderNames();
        while (en.hasMoreElements()) {
            String name = en.nextElement();
            String value = httpReq.getHeader(name);
            LogUtils.trace(log, "request header '%s=%s'", name, value);
        }/*from  w w  w  .j a  va  2s .c om*/
        LogUtils.trace(log, "locale=%s", req.getLocale());
    }
    super.service(req, res);
    // how long?
    LogUtils.debug(log, "%s '%s' in msecs %s", httpReq.getMethod(), httpReq.getRequestURI(),
            System.currentTimeMillis() - dtStart);
}

From source file:MyServlet.java

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

    out.println("Request Headers:");
    out.println();/* w ww . j a  v  a 2  s  . co  m*/
    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 source file:org.sonar.plugins.preauth.PreAuthHelper.java

private void logAvailableHeaders(HttpServletRequest request) {
    if (!LOG.isDebugEnabled()) {
        return;/*ww  w.  ja  va 2  s .  c om*/
    }
    StringBuilder sb = new StringBuilder("Available Headers: ");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        sb.append(headerNames.nextElement());
        if (headerNames.hasMoreElements()) {
            sb.append(", ");
        }
    }
    LOG.debug(sb.toString());
}

From source file:org.frat.common.security.authc.SessionTimeoutAuthenticationFilter.java

private String getHeaderString(ServletRequest request) {
    HttpServletRequest req = (HttpServletRequest) request;
    StringBuilder sb = new StringBuilder();
    Enumeration<?> headerNames = req.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        sb.append("[").append(headerName).append("=").append(req.getHeader(headerName)).append("]");
    }/*from ww w. j  a  va  2 s  . c  o  m*/
    return sb.toString();
}

From source file:com.qualogy.qafe.gwt.server.filter.CORSFilter.java

@SuppressWarnings({ "unused", "unchecked" })
private String getRequestHeader(HttpServletRequest request, String header) {
    String headerInLowerCase = header.toLowerCase();
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        if (!headerInLowerCase.equals(headerName.toLowerCase())) {
            continue;
        }//from   w  ww  . j a va2s . c  o  m
        String headerValue = request.getHeader(headerName);
        return headerValue;
    }
    return null;
}

From source file:org.debux.webmotion.server.render.RenderException.java

protected Map<String, Object> getRequestHeaders(HttpServletRequest request) {
    Map<String, Object> result = new HashMap<String, Object>();
    for (Enumeration<String> names = request.getHeaderNames(); names.hasMoreElements();) {
        String name = names.nextElement();
        Object value = request.getHeader(name);
        result.put(name, value);/*from   w ww . j  av a 2 s .c om*/
    }
    return result;
}

From source file:com.indoqa.httpproxy.HttpClientProxy.java

@SuppressWarnings("unchecked")
private void copyRequestHeaders(HttpServletRequest request, HttpUriRequest proxyRequest) {
    Enumeration<String> headerNames = request.getHeaderNames();

    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();

        if (CONTENT_LENGTH_HEADER.equalsIgnoreCase(headerName)) {
            // content length header will be implicitly set by setEntity() in copyRequestBody()
            continue;
        }//ww w.  j  a va2  s  . c o m

        proxyRequest.setHeader(headerName, request.getHeader(headerName));
    }
}

From source file:org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityRequestFactory.java

public void create(IdentityRequest.IdentityRequestBuilder builder, HttpServletRequest request,
        HttpServletResponse response) throws FrameworkClientException {

    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        builder.addHeader(headerName, request.getHeader(headerName));
    }//  w  w w.  j a v a 2  s.  com

    // We need to create a new map with the parameters sent in servlet request to avoid having a reference.
    Map<String, String[]> paramMap = new HashMap<>(request.getParameterMap());
    builder.setParameters(paramMap);

    Enumeration<String> attrNames = request.getAttributeNames();
    while (attrNames.hasMoreElements()) {
        String attrName = attrNames.nextElement();
        builder.addAttribute(attrName, request.getAttribute(attrName));
    }
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            builder.addCookie(cookie.getName(), cookie);
        }
    }

    String requestURI = request.getRequestURI();

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    if (StringUtils.isNotBlank(tenantDomain)) {
        builder.setTenantDomain(tenantDomain);
    } else {
        builder.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    }

    builder.setContentType(request.getContentType());
    builder.setContextPath(request.getContextPath());
    builder.setMethod(request.getMethod());
    builder.setPathInfo(request.getPathInfo());
    builder.setPathTranslated(request.getPathTranslated());
    builder.setQueryString(request.getQueryString());
    builder.setRequestURI(requestURI);
    builder.setRequestURL(request.getRequestURL());
    builder.setServletPath(request.getServletPath());

}