Example usage for org.springframework.http HttpHeaders setContentType

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

Introduction

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

Prototype

public void setContentType(@Nullable MediaType mediaType) 

Source Link

Document

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

Usage

From source file:com.apress.prospringintegration.web.MultipartHttpClient.java

public static void main(String[] args) {
    RestTemplate template = new RestTemplate();
    String uri = "http://localhost:8080/http-adapter-1.0.0/inboundMultipartAdapter.html";
    Resource picture = new ClassPathResource("com/apress/prospringintegration/web/test.png");
    MultiValueMap map = new LinkedMultiValueMap();
    map.add("name", "John Smith");
    map.add("picture", picture);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(new MediaType("multipart", "form-data"));
    HttpEntity request = new HttpEntity(map, headers);
    ResponseEntity<?> httpResponse = template.exchange(uri, HttpMethod.POST, request, null);
    System.out.println("Status: " + httpResponse.getStatusCode().name());
}

From source file:cn.org.once.cstack.utils.RestUtils.java

@SuppressWarnings("rawtypes")
public static String sendPostCommand(String url, String volume) {

    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Accept", "text/plain");
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("Binds", volume);
    @SuppressWarnings("unchecked")
    HttpEntity request = new HttpEntity(params, headers);
    ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
    return response.toString();
}

From source file:org.focusns.common.web.WebUtils.java

public static <T> ResponseEntity<T> getResponseEntity(T body, MediaType mediaType) {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(mediaType);
    if (body instanceof byte[]) {
        httpHeaders.setContentLength(((byte[]) body).length);
    }//from w w w.  j  a  v a  2  s . co  m
    return new ResponseEntity<T>(body, httpHeaders, HttpStatus.OK);
}

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

public static HttpHeaders octetStreamResponseHeader(MediaType mediaType, long length, String eTag) {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentLength(length);
    responseHeaders.setContentType(mediaType);
    responseHeaders.setCacheControl("max-age");
    if (isNotBlank(eTag)) {
        responseHeaders.setETag(eTag);/*from  w  w  w  .j a  v a  2 s. c om*/
    }
    responseHeaders.set("Content-Disposition", "inline; filename=\"file.jpg\"");
    return responseHeaders;
}

From source file:de.codecentric.boot.admin.services.ApplicationRegistrator.java

private static HttpHeaders createHttpHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
    return HttpHeaders.readOnlyHttpHeaders(headers);
}

From source file:edu.infsci2560.LoginHelper.java

public static ResponseEntity<String> login(TestRestTemplate template, String route, String userName,
        String password) {//from   w  w w .j a  v  a2 s .c o m
    HttpHeaders headers = getHeaders(template, route);
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", userName);
    form.set("password", password);
    ResponseEntity<String> entity = template.exchange(route, HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class);
    return entity;

}

From source file:eu.falcon.semantic.client.DenaClient.java

public static String runQuery(String sparqlQuery) {

    final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/query/run";
    //final String uri = "http://localhost:8090/api/v1/ontology/query/run";

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    RestTemplate restTemplate = new RestTemplate();

    HttpEntity<String> entity = new HttpEntity<>(sparqlQuery, headers);

    String result = restTemplate.postForObject(uri, entity, String.class);

    return result;
}

From source file:eu.falcon.semantic.client.DenaClient.java

public static String getInstanceAttributes(String instanceURI) {

    final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/instance/attributes";
    //final String uri = "http://localhost:8090/api/v1/ontology/instance/attributes";

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    RestTemplate restTemplate = new RestTemplate();

    HttpEntity<String> entity = new HttpEntity<>(instanceURI, headers);

    String result = restTemplate.postForObject(uri, entity, String.class);

    return result;
}

From source file:eu.falcon.semantic.client.DenaClient.java

public static String getClassSubclasses(String classURI) {

    final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/class/subclasses";
    //final String uri = "http://localhost:8090/api/v1/ontology/class/subclasses";

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    RestTemplate restTemplate = new RestTemplate();

    HttpEntity<String> entity = new HttpEntity<>(classURI, headers);

    String result = restTemplate.postForObject(uri, entity, String.class);

    return result;
}

From source file:eu.falcon.semantic.client.DenaClient.java

public static JSONObject getClassAttributes(String classURI) {

    final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/class/attributes";
    //final String uri = "http://localhost:8090/api/v1/ontology/class/attributes";

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    RestTemplate restTemplate = new RestTemplate();

    HttpEntity<String> entity = new HttpEntity<>(classURI, headers);

    String result = restTemplate.postForObject(uri, entity, String.class);

    return new JSONObject(result);
}