Example usage for org.springframework.http HttpHeaders getContentType

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

Introduction

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

Prototype

@Nullable
public MediaType getContentType() 

Source Link

Document

Return the MediaType media type of the body, as specified by the Content-Type header.

Usage

From source file:guru.nidi.ramltester.spring.SpringUtils.java

static String contentTypeOf(HttpHeaders headers) {
    final MediaType contentType = headers.getContentType();
    return contentType == null ? null : contentType.toString();
}

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

@Test
public void createHeadersReturnsHeadersWithContentTypeApplicationJson() {
    HttpHeaders headers = HeaderFactory.createHeaders(API_KEY);
    assertEquals(MediaType.APPLICATION_JSON, headers.getContentType());
}

From source file:com.golonzovsky.oauth2.google.security.GoogleTokenServices.java

private Map<String, Object> postForMap(String path, MultiValueMap<String, String> formData,
        HttpHeaders headers) {
    if (headers.getContentType() == null) {
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    }//from  www .j a v a  2  s  .  c o m
    ParameterizedTypeReference<Map<String, Object>> map = new ParameterizedTypeReference<Map<String, Object>>() {
    };
    return restTemplate.exchange(path, HttpMethod.POST, new HttpEntity<>(formData, headers), map).getBody();
}

From source file:com.ggk.hrms.authentication.CustomTokenServices.java

private Map<String, Object> postForMap(String path, MultiValueMap<String, String> formData,
        HttpHeaders headers) {
    if (headers.getContentType() == null) {
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    }/*  w  w  w.j  a  v a  2  s .  c  om*/
    ParameterizedTypeReference<Map<String, Object>> map = new ParameterizedTypeReference<Map<String, Object>>() {
    };
    return restTemplate.exchange(path, HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, String>>(formData, headers), map).getBody();
}

From source file:com.facetime.cloud.server.support.UTF8HttpMessageConverter.java

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    HttpHeaders headers = outputMessage.getHeaders();
    if (!"UTF-8".equalsIgnoreCase(headers.getContentType().getCharSet().displayName())) {
        headers.setContentType(UTF_8_MEDIA_TYPE);
    }/*w  w  w  . jav a2s .  c  o m*/

    if (writeAcceptCharset) {
        headers.setAcceptCharset(getAcceptedCharsets());
    }
    MediaType contentType = outputMessage.getHeaders().getContentType();
    Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
    FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset));
}

From source file:biz.c24.io.spring.http.C24HttpMessageConverter.java

public ComplexDataObject read(Class<? extends ComplexDataObject> clazz, HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException {

    HttpHeaders headers = inputMessage.getHeaders();
    MediaType contentType = headers.getContentType();

    Source source = getSourceFor(inputMessage.getBody(), contentType);
    ComplexDataObject result = source.readObject(model.getElementFor(clazz));

    return C24Utils.potentiallyUnwrapDocumentRoot(result);
}

From source file:com.orange.ngsi.client.NgsiClientTest.java

@Test
public void getRequestHeadersWithoutUrl() {
    HttpHeaders httpHeaders = ngsiClient.getRequestHeaders();

    assertEquals(MediaType.APPLICATION_XML, httpHeaders.getContentType());
    assertTrue(httpHeaders.getAccept().contains(MediaType.APPLICATION_XML));
}

From source file:com.cookbook.cq.dao.util.GsonHttpMessageConverter.java

private Charset getCharset(HttpHeaders headers) {
    if (headers != null && headers.getContentType() != null && headers.getContentType().getCharSet() != null) {
        return headers.getContentType().getCharSet();
    }//from w ww  . j  a v a2 s .  c o  m
    return DEFAULT_CHARSET;
}

From source file:com.orange.ngsi.client.NgsiClientTest.java

@Test
public void getRequestHeadersWithNullUrl() {
    HttpHeaders httpHeaders = ngsiClient.getRequestHeaders(null);

    assertEquals(MediaType.APPLICATION_XML, httpHeaders.getContentType());
    assertTrue(httpHeaders.getAccept().contains(MediaType.APPLICATION_XML));
}

From source file:com.orange.ngsi.client.NgsiClientTest.java

@Test
public void getRequestHeadersWithUrlXml() {

    // prepare mock
    when(protocolRegistry.supportXml(any())).thenReturn(true);
    when(protocolRegistry.supportV1Json(any())).thenReturn(false);

    HttpHeaders httpHeaders = ngsiClient.getRequestHeaders("localhost");

    assertEquals(MediaType.APPLICATION_XML, httpHeaders.getContentType());
    assertTrue(httpHeaders.getAccept().contains(MediaType.APPLICATION_XML));
}