Example usage for org.springframework.http HttpHeaders get

List of usage examples for org.springframework.http HttpHeaders get

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders get.

Prototype

@Override
    @Nullable
    public List<String> get(Object key) 

Source Link

Usage

From source file:org.lightadmin.core.web.util.ResponseUtils.java

public static void addImageResourceHeaders(HttpServletResponse response, HttpHeaders httpHeaders) {
    for (String httpHeaderKey : httpHeaders.keySet()) {
        response.setHeader(httpHeaderKey, httpHeaders.get(httpHeaderKey).get(0));
    }/*from   w w  w.j a  va  2 s. c o  m*/
}

From source file:de.zib.gndms.gndmc.utils.DefaultResponseExtractor.java

public static String getLocation(final HttpHeaders headers) {
    for (String header : headers.keySet()) {
        if ("Location".equals(header)) {
            try {
                return URLDecoder.decode(headers.get(header).get(0), "utf8");
            } catch (UnsupportedEncodingException e) {
                throw new IllegalStateException("The system does not support utf8 decoding!");
            }//from   w  w  w .  j  a  v a 2  s  . c  o m
        }
    }

    return null;
}

From source file:de.zib.gndms.gndmc.utils.DefaultResponseExtractor.java

public static List<String> getCookies(final HttpHeaders headers) {
    final List<String> cookies = new LinkedList<String>();

    for (String header : headers.keySet()) {
        if ("Set-Cookie".equals(header)) {
            for (String value : headers.get(header)) {
                cookies.add(value);//w  w  w .ja va  2  s .co m
            }
        }
    }

    return cookies;
}

From source file:io.github.restdocsext.jersey.JerseyRequestConverter.java

/**
 * Create an {@code OperationRequestPart} from a Jersey {@code FormDataBodyPart}.
 *
 * @param part the Jersey part.//from w w w .j  a v  a2s  . co m
 * @return the converted operation request part.
 */
// can't test this on it's own as the part is not a body part entity
private static OperationRequestPart createOperationRequestPart(FormDataBodyPart part) {
    final HttpHeaders partHeaders = extractHeaders(part.getHeaders());
    final List<String> contentTypeHeader = partHeaders.get(HttpHeaders.CONTENT_TYPE);
    if (part.getMediaType() != null && contentTypeHeader == null) {
        partHeaders.setContentType(
                org.springframework.http.MediaType.parseMediaType(part.getMediaType().toString()));
    }

    final String filename = StringUtils.hasText(part.getContentDisposition().getFileName())
            ? part.getContentDisposition().getFileName()
            : null;
    return new OperationRequestPartFactory().create(part.getName(), filename, part.getEntityAs(byte[].class),
            partHeaders);
}

From source file:web.rufer.swisscom.sms.api.factory.HeaderFactoryTest.java

@Test
public void createHeadersWithNullValueReturnsHeadersWithNullApiKey() {
    HttpHeaders headers = HeaderFactory.createHeaders(null);
    assertEquals(null, headers.get(CLIENT_ID).get(0));
}

From source file:web.rufer.swisscom.sms.api.factory.HeaderFactoryTest.java

@Test
public void createHeadersReturnsHeadersWithAPIKey() {
    HttpHeaders headers = HeaderFactory.createHeaders(API_KEY);
    assertEquals(API_KEY, headers.get(CLIENT_ID).get(0));
}

From source file:org.zkybase.cmdb.connector.impl.ApplicationTemplate.java

@Override
public String create(Application application) {
    ResponseEntity<String> response = restTemplate.postForEntity(getListUri(), application, String.class);
    HttpHeaders headers = response.getHeaders();
    List<String> locations = headers.get("Location");

    // There's only one.
    return locations.get(0);
}

From source file:com.art4ul.jcoon.handlers.CookiesAnnotationAfterHandler.java

@Override
public void doHandle(Context context, Annotation annotation, Object paramValue) {
    if (paramValue != null && paramValue instanceof Wrapper) {
        Wrapper wrapper = ((Wrapper) paramValue);
        Object wrappedParam = wrapper.getValue();
        HttpHeaders httpHeaders = context.getResponseEntity().getHeaders();
        List<String> cookies = httpHeaders.get("Set-Cookie");
        if (cookies != null) {
            if (wrappedParam instanceof String) {
                String resultString = Joiner.on(";").join(cookies);
                wrapper.setValue(resultString);
            } else if (wrappedParam instanceof List) {
                wrapper.setValue(cookies);
            }//  w  ww  . ja va  2  s. co m
        }
    }
}

From source file:com.art4ul.jcoon.handlers.CookieValueAnnotationAfterHandler.java

@Override
public void doHandle(Context context, Annotation annotation, Object paramValue) {
    if (paramValue != null && paramValue instanceof Wrapper) {
        Wrapper wrapper = ((Wrapper) paramValue);
        Object paramValueparamObj = wrapper.getValue();
        CookieValue cookieValueAnnotation = (CookieValue) annotation;

        HttpHeaders httpHeaders = context.getResponseEntity().getHeaders();
        List<String> cookies = httpHeaders.get("Set-Cookie");
        String cookie = getCookieByNameFromList(cookies, cookieValueAnnotation.value());
        wrapper.setValue(cookie);/*from   w w  w.ja va  2 s.co m*/
    }
}

From source file:org.meteogrou.jbrotli.servlet.HelloBrotliHttpControllerTest.java

@Test
public void brotli_content_encoding_is_set() throws Exception {
    // given//from   ww w  .ja  va 2s.  com
    String textFileUrl = root_url + "/canterbury-corpus/asyoulik.txt";

    // when
    restTemplate.setInterceptors(createAcceptBrotliEncodingInterceptor());
    HttpHeaders headers = restTemplate.getForEntity(textFileUrl, String.class).getHeaders();

    // then
    assertThat(headers.get("Content-Encoding")).containsOnly(BROTLI_HTTP_CONTENT_CODING);
}