use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project OpenClinica by OpenClinica.
the class XformMetaDataService method getMediaFileItemFromFormManager.
public FileItem getMediaFileItemFromFormManager(String fileLink, String crfOid, String formLayoutOid) {
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(fileLink, HttpMethod.GET, entity, byte[].class, "1");
FileItem fileItem = null;
if (response.getStatusCode() == HttpStatus.OK) {
String fileName = "";
FileOutputStream output = null;
try {
String disposition = response.getHeaders().get("Content-Disposition").get(0);
fileName = disposition.replaceFirst("(?i)^.*filename=\"([^\"]+)\".*$", "$1");
String dir = Utils.getCrfMediaFilePath(crfOid, formLayoutOid);
if (!new File(dir).exists()) {
new File(dir).mkdirs();
logger.debug("Made the directory " + dir);
}
File file = new File(dir + fileName);
output = new FileOutputStream(file);
IOUtils.write(response.getBody(), output);
fileItem = new DiskFileItem("media_file", response.getHeaders().get("Content-Type").get(0), false, fileName, 100000000, file);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (output != null) {
output.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
return fileItem;
}
use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project geode by apache.
the class RestTestUtils method getRestTemplate.
public static RestTemplate getRestTemplate() {
if (restTemplate == null) {
restTemplate = new RestTemplate();
final List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new ByteArrayHttpMessageConverter());
messageConverters.add(new ResourceHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
messageConverters.add(createMappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);
}
return restTemplate;
}
use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project apollo by ctripcorp.
the class HttpMessageConverterConfiguration method messageConverters.
@Bean
public HttpMessageConverters messageConverters() {
GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
gsonHttpMessageConverter.setGson(new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create());
final List<HttpMessageConverter<?>> converters = Lists.newArrayList(new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(), new AllEncompassingFormHttpMessageConverter(), gsonHttpMessageConverter);
return new HttpMessageConverters() {
@Override
public List<HttpMessageConverter<?>> getConverters() {
return converters;
}
};
}
use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project ArachneCentralAPI by OHDSI.
the class IntegrationConfig method centralRestTemplate.
@Bean(name = "restTemplate")
public RestTemplate centralRestTemplate() {
RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(getHttpClient()));
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
return restTemplate;
}
use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project crnk-framework by crnk-project.
the class SpringParameterProvider method getHttpMessageConverters.
private List<HttpMessageConverter<?>> getHttpMessageConverters() {
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
// see SPR-7316
stringHttpMessageConverter.setWriteAcceptCharset(false);
List<HttpMessageConverter<?>> converters = new ArrayList<>(4);
converters.add(new ByteArrayHttpMessageConverter());
converters.add(stringHttpMessageConverter);
converters.add(new SourceHttpMessageConverter<>());
converters.add(new AllEncompassingFormHttpMessageConverter());
return converters;
}
Aggregations