Search in sources :

Example 11 with ByteArrayHttpMessageConverter

use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project OpenClinica by OpenClinica.

the class XformMetaDataService method saveAttachedFiles.

public void saveAttachedFiles(String uri, String dir, String fileName) throws IOException {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));
    HttpEntity<String> entity = new HttpEntity<String>(headers);
    ResponseEntity<byte[]> response = restTemplate.exchange(uri, HttpMethod.GET, entity, byte[].class, "1");
    if (response.getStatusCode().equals(HttpStatus.OK)) {
        FileOutputStream output = new FileOutputStream(new File(dir + File.separator + fileName));
        IOUtils.write(response.getBody(), output);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) FileOutputStream(java.io.FileOutputStream) RestTemplate(org.springframework.web.client.RestTemplate) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) File(java.io.File)

Aggregations

ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)11 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)6 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)6 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)6 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)5 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)4 RestTemplate (org.springframework.web.client.RestTemplate)4 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 Method (java.lang.reflect.Method)2 MethodParameter (org.springframework.core.MethodParameter)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 HandlerMethod (org.springframework.web.method.HandlerMethod)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 URI (java.net.URI)1