Example usage for javax.servlet.http HttpServletResponse getHeaderNames

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

Introduction

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

Prototype

public Collection<String> getHeaderNames();

Source Link

Document

Gets the names of the headers of this response.

Usage

From source file:net.community.chest.gitcloud.facade.ServletUtils.java

public static final Map<String, String> getResponseHeaders(HttpServletResponse rsp) {
    // NOTE: map must be case insensitive as per HTTP requirements
    Map<String, String> hdrsMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    for (String hdrName : rsp.getHeaderNames()) {
        String hdrValue = rsp.getHeader(hdrName);
        hdrsMap.put(capitalizeHttpHeaderName(hdrName), StringUtils.trimToEmpty(hdrValue));
    }/*from   w  w w. j  a va2  s  .c om*/

    return hdrsMap;
}

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

public static void dump(HttpServletResponse response, ByteArrayOutputStream body, StringBuffer log) {

    log.append("-- DUMP HttpServletResponse START").append("\n");
    log.append("Status: ").append(response.getStatus()).append("\n");
    log.append("---- Headers START\n");

    response.getHeaderNames().stream()
            .map(headerName -> "[" + headerName + "]=[" + response.getHeaders(headerName) + "]")
            .forEach(h -> log.append(h));

    log.append("---- Headers END\n");

    log.append("---- Body START\n");
    log.append(body.toString()).append("\n");
    log.append("---- Body END\n");

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

From source file:com.groupon.odo.HttpUtilities.java

/**
 * Obtain newline-delimited headers from response
 *
 * @param response//from  www.  jav a  2 s.  c  o  m
 * @return
 */
public static String getHeaders(HttpServletResponse response) {
    String headerString = "";
    Collection<String> headerNames = response.getHeaderNames();
    for (String headerName : headerNames) {
        if (headerString.length() != 0)
            headerString += "\n";

        headerString += headerName + ": " + response.getHeader(headerName);
    }

    return headerString;
}

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

public static Map<String, List<String>> revertHeaders(HttpServletResponse response) {
    Map<String, List<String>> map = new HashMap<String, List<String>>();
    for (String name : response.getHeaderNames()) {
        if (isIncludedHeaderToResponse(name)) {
            List<String> hValues = map.get(name);
            if (null == hValues) {
                hValues = new ArrayList<String>();
                map.put(name, hValues);//from   www  . j  a  v  a  2 s  .c om
            }
            hValues.add(response.getHeader(name));
        }
    }
    return map;
}

From source file:se.inera.certificate.proxy.module.RequestInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) {//from  ww  w  . j ava  2 s  .  c  o  m
    for (String s : response.getHeaderNames()) {
        log.debug(s + ":" + response.getHeader(s));
    }
}

From source file:cn.sel.wetty.interceptor.AccessLogger.java

private String getHeaders(HttpServletResponse response) {
    List<String> headers = response.getHeaderNames().stream().collect(Collectors.toList());
    for (int i = 0; i < headers.size(); i++) {
        String header = headers.get(i);
        headers.set(i, String.format("%s=%s", header, response.getHeader(header)));
    }//ww  w .j a v  a  2  s  .c  o m
    return Arrays.toString(headers.toArray(new String[headers.size()]));
}

From source file:org.bessle.neo4j.proxy.HttpRequestLoggingFilter.java

protected void enhanceTrace(Map<String, Object> trace, HttpServletResponse response) {
    Map<String, String> headers = new LinkedHashMap<String, String>();
    for (String header : response.getHeaderNames()) {
        String value = response.getHeader(header);
        headers.put(header, value);//from   w w w  .  j  ava 2 s  .co  m
    }
    headers.put("status", "" + response.getStatus());
    @SuppressWarnings("unchecked")
    Map<String, Object> allHeaders = (Map<String, Object>) trace.get("headers");
    allHeaders.put("response", headers);
}

From source file:com.zimbra.cs.dav.service.DavServlet.java

public static StringBuilder addResponseHeaderLoggingInfo(HttpServletResponse resp, StringBuilder sb) {
    if (!ZimbraLog.dav.isDebugEnabled()) {
        return sb;
    }/*from w w w . j av  a 2 s  .  com*/
    sb.append("DAV RESPONSE:\n");
    String statusLine = DavResponse.sStatusTextMap.get(resp.getStatus());
    if (statusLine != null) {
        sb.append(statusLine);
    } else {
        sb.append("HTTP/1.1 ").append(resp.getStatus());
    }
    Collection<String> hdrNames = resp.getHeaderNames();
    if (hdrNames != null && !hdrNames.isEmpty()) {
        for (String hdrName : hdrNames) {
            if (hdrName.contains("Auth") || (hdrName.contains(HttpHeaders.COOKIE))) {
                sb.append("\n").append(hdrName).append(": *** REPLACED ***");
                continue;
            }
            Collection<String> vals = resp.getHeaders(hdrName);
            for (String val : vals) {
                sb.append("\n").append(hdrName).append(": ").append(val);
            }
        }
    }
    sb.append("\n\n");
    return sb;
}

From source file:com.netflix.spinnaker.gate.ratelimit.RateLimitingInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    // Hystrix et-al can return 429's, which we'll want to intercept to provide a reset header
    if (response.getStatus() == 429 && !response.getHeaderNames().contains(Rate.RESET_HEADER)) {
        response.setIntHeader(Rate.CAPACITY_HEADER, -1);
        response.setIntHeader(Rate.REMAINING_HEADER, 0);
        response.setDateHeader(Rate.RESET_HEADER, ZonedDateTime.now().plusSeconds(5).toEpochSecond());
        response.setHeader(Rate.LEARNING_HEADER, "false");
    }/*from w w w  . ja  v  a  2s  .c om*/
}

From source file:cn.guoyukun.spring.web.filter.DebugRequestAndResponseFilter.java

private void debugResponse(HttpServletResponse response) {
    log.debug("=====================response begin==========================");
    log.debug("status:{}", response.getStatus(), response.getContentType());
    log.debug("contentType:{}, characterEncoding:{}", response.getContentType(),
            response.getCharacterEncoding());
    log.debug("===header begin============================================");
    Collection<String> headerNames = response.getHeaderNames();
    for (String name : headerNames) {
        String value = StringUtils.join(response.getHeaders(name), "||");
        log.debug("{}={}", name, value);
    }//  ww w .j a  v a2s . c o  m
    log.debug("===header   end============================================");
    log.debug("=====================response   end==========================");
}