use of org.springframework.http.HttpEntity in project OpenClinica by OpenClinica.
the class RandomizeService method addOrUpdateASite.
private void addOrUpdateASite(String randomiseUrl, StudyBean studyBean, HttpHeaders headers, String timezone) {
// mehtod : POST
randomiseUrl = randomiseUrl + "/api/sites";
RestTemplate rest = new RestTemplate(requestFactory);
ResponseEntity<String> response = null;
MultiValueMap<String, String> siteMap = new LinkedMultiValueMap<String, String>();
siteMap.add("siteIdentifier", studyBean.getOid());
siteMap.add("name", studyBean.getName());
siteMap.add("timezone", timezone);
HttpEntity<MultiValueMap<String, String>> siteRequest = new HttpEntity<MultiValueMap<String, String>>(siteMap, headers);
try {
response = rest.exchange(randomiseUrl, HttpMethod.POST, siteRequest, String.class);
} catch (Exception e) {
logger.error(e.getMessage());
logger.error(ExceptionUtils.getStackTrace(e));
}
}
use of org.springframework.http.HttpEntity 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);
}
}
use of org.springframework.http.HttpEntity in project disconf by knightliao.
the class ConfigFetcherController method downloadDspBill.
/**
* 下载
*
* @param fileName
*
* @return
*/
public HttpEntity<byte[]> downloadDspBill(String fileName, String value) {
HttpHeaders header = new HttpHeaders();
byte[] res = value.getBytes();
String name = null;
try {
name = URLEncoder.encode(fileName, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
header.set("Content-Disposition", "attachment; filename=" + name);
header.setContentLength(res.length);
return new HttpEntity<byte[]>(res, header);
}
use of org.springframework.http.HttpEntity in project disconf by knightliao.
the class ConfigReadController method downloadDspBill.
/**
* 下载
*
* @param configId
*
* @return
*/
@RequestMapping(value = "/download/{configId}", method = RequestMethod.GET)
public HttpEntity<byte[]> downloadDspBill(@PathVariable long configId) {
// 业务校验
configValidator.valideConfigExist(configId);
ConfListVo config = configMgr.getConfVo(configId);
HttpHeaders header = new HttpHeaders();
byte[] res = config.getValue().getBytes();
if (res == null) {
throw new DocumentNotFoundException(config.getKey());
}
String name = null;
try {
name = URLEncoder.encode(config.getKey(), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
header.set("Content-Disposition", "attachment; filename=" + name);
header.setContentLength(res.length);
return new HttpEntity<byte[]>(res, header);
}
use of org.springframework.http.HttpEntity in project disconf by knightliao.
the class ConfigReadController method download2.
/**
* 批量下载配置文件
*
* @param confListForm
*
* @return
*/
@RequestMapping(value = "/downloadfilebatch", method = RequestMethod.GET)
public HttpEntity<byte[]> download2(@Valid ConfListForm confListForm) {
LOG.info(confListForm.toString());
//
// get files
//
List<File> fileList = configMgr.getDisconfFileList(confListForm);
//
// prefix
//
String prefixString = "APP" + confListForm.getAppId() + "_" + "ENV" + confListForm.getEnvId() + "_" + "VERSION" + confListForm.getVersion();
HttpHeaders header = new HttpHeaders();
String targetFileString = "";
File targetFile = null;
byte[] res = null;
try {
targetFileString = TarUtils.tarFiles("tmp", prefixString, fileList);
targetFile = new File(targetFileString);
res = IOUtils.toByteArray(new FileInputStream(targetFile));
} catch (Exception e) {
throw new DocumentNotFoundException("");
}
header.set("Content-Disposition", "attachment; filename=" + targetFile.getName());
header.setContentLength(res.length);
return new HttpEntity<byte[]>(res, header);
}
Aggregations