Example usage for javax.servlet.http HttpServletResponse getHeader

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

Introduction

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

Prototype

public String getHeader(String name);

Source Link

Document

Gets the value of the response header with the given name.

Usage

From source file:nl.dtls.fairdatapoint.api.controller.utils.LoggerUtils.java

/**
 * Log the request.//from  w  w  w  . j  av a2s.  co  m
 * 
 * Log message pattern [Time\t IP\t requestMethod\t requestedURL]
 * @param logger    Class logger
 * @param request   Client request
 * @param response  Server response
 */
public static void logRequest(Logger logger, HttpServletRequest request, HttpServletResponse response) {
    ThreadContext.put("requestMethod", request.getMethod());
    ThreadContext.put("requestURI", request.getRequestURI());
    ThreadContext.put("requestProtocol", request.getProtocol());
    ThreadContext.put("responseStatus", String.valueOf(response.getStatus()));
    String contentLength = response.getHeader(HttpHeaders.CONTENT_LENGTH);
    ThreadContext.put("contentSize", contentLength);
    logger.log(Level.getLevel("API-REQUEST"), "");
}

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 v  a  2 s .c  o m*/

    return hdrsMap;
}

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

/**
 * Obtain newline-delimited headers from response
 *
 * @param response/*from ww  w .  ja va  2s  . co 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   ww w.  j  a  va  2s . c o  m*/
            }
            hValues.add(response.getHeader(name));
        }
    }
    return map;
}

From source file:fr.mycellar.interfaces.web.security.SecurityContextTokenRepository.java

@Override
public void saveContext(SecurityContext context, HttpServletRequest request, HttpServletResponse response) {
    Object key = response.getHeader(SpringSecurityConfiguration.TOKEN_HEADER_NAME);
    if ((key != null) && (key instanceof String)) {
        securityContexts.put(keyBasedPersistenceTokenService.verifyToken((String) key),
                new TimedSecurityContext(context, new LocalDateTime()));
    }// w w  w.j  ava 2 s  . c  om
}

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  .ja v a 2 s .  c  om*/
    for (String s : response.getHeaderNames()) {
        log.debug(s + ":" + response.getHeader(s));
    }
}

From source file:com.yoho.core.trace.instrument.web.TraceInterceptor.java

private void addToResponseIfNotPresent(HttpServletResponse response, String name, String value) {
    if (!hasText(response.getHeader(name))) {
        response.addHeader(name, value);
    }/* w  w  w  .  jav  a2 s.  c om*/
}

From source file:com.snv.guard.AuthenticationServiceTest.java

@Test
public void should_return_user_with_security_information_when_authenticate() throws HmacException {
    when(this.authenticationManager.authenticate(Matchers.any(UsernamePasswordAuthenticationToken.class)))
            .thenReturn(this.authentication);
    when(this.userService.byLogin(Matchers.any(Credential.class))).thenReturn(this.user);
    HttpServletResponse response = new MockHttpServletResponse();
    User actual = this.authenticationService.authenticate(this.credential, response);

    assertEquals(this.user, actual);
    assertTrue(response.getHeader(HmacUtils.X_SECRET) != null);
    assertEquals(actual.getPublicSecret(), response.getHeader(HmacUtils.X_SECRET));
    assertTrue(response.getHeader(HttpHeaders.WWW_AUTHENTICATE) != null);
    assertEquals(response.getHeader(HttpHeaders.WWW_AUTHENTICATE), HmacUtils.HMAC_SHA_256);
    assertTrue(response.getHeader(CSRF_CLAIM_HEADER) != null);
}

From source file:net.eusashead.hateoas.conditional.interceptor.ConditionalResponseInterceptor.java

/**
 * Store the ETag for// www  . ja  va  2  s  .  c om
 * the supplied URL after a
 * GET or HEAD
 * 
 * @param request
 * @param response
 */
private void postHandleGetOrHead(HttpServletRequest request, HttpServletResponse response) {

    if (response.getHeader(ETAG) != null) {
        service.store(getUri(request), response.getHeader(ETAG));
    }
}

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);//  w w w  . ja va  2s. c  o  m
    }
    headers.put("status", "" + response.getStatus());
    @SuppressWarnings("unchecked")
    Map<String, Object> allHeaders = (Map<String, Object>) trace.get("headers");
    allHeaders.put("response", headers);
}