Commit 6dfc6f61 authored by 汪昱's avatar 汪昱

金安易-临安区村级小微权力智慧监管平台数据接口,增加请求heard

parent 81c5a1ab
package com.mth.requestsecret.controller;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.HttpHead;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.core.io.Resource;
......@@ -52,6 +53,7 @@ public class JAYSmartController {
.append("&apiName=onlyOrganize").toString();
log.info("访问临安区村级小微权力平台数据接口/获取单位列表 -->" + url);
HttpHeaders headers = new HttpHeaders();
headers.add("x-real-ip","101.69.248.16");
HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(null, headers);
return restTemplate.exchange(url, HttpMethod.GET, request, String.class);
}
......@@ -72,7 +74,9 @@ public class JAYSmartController {
.append("&year=").append(null == year ? "" : year)
.append("&apiName=onlyOrganize").toString();
log.info("访问临安区村级小微权力平台数据接口/获取公开表数据 -->" + url);
HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(null, new HttpHeaders());
HttpHeaders headers = new HttpHeaders();
headers.add("x-real-ip","101.69.248.16");
HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(null, headers);
return restTemplate.exchange(url, HttpMethod.GET, request, String.class);
}
......@@ -88,7 +92,9 @@ public class JAYSmartController {
.append(authCode)
.append("&unitCode=").append(unitCode).toString();
log.info("访问临安区村级小微权力平台数据接口/获取村级工程 -->" + url);
HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(null, new HttpHeaders());
HttpHeaders headers = new HttpHeaders();
headers.add("x-real-ip","101.69.248.16");
HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(null, headers);
return restTemplate.exchange(url, HttpMethod.GET, request, String.class);
}
......@@ -104,7 +110,9 @@ public class JAYSmartController {
.append(authCode)
.append("&unitCode=").append(unitCode).toString();
log.info("访问临安区村级小微权力平台数据接口/获取村级工程付款情况表数据 -->" + url);
HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(null, new HttpHeaders());
HttpHeaders headers = new HttpHeaders();
headers.add("x-real-ip","101.69.248.16");
HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(null, headers);
return restTemplate.exchange(url, HttpMethod.GET, request, String.class);
}
......@@ -120,7 +128,9 @@ public class JAYSmartController {
.append(authCode)
.append("&unitCode=").append(unitCode).toString();
log.info("访问临安区村级小微权力平台数据接口/获取资产资源处置表数据 -->" + url);
HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(null, new HttpHeaders());
HttpHeaders headers = new HttpHeaders();
headers.add("x-real-ip","101.69.248.16");
HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(null, headers);
return restTemplate.exchange(url, HttpMethod.GET, request, String.class);
}
......@@ -132,7 +142,10 @@ public class JAYSmartController {
RestTemplate template = restTemplateBuilder
.basicAuthentication(username, password, Charset.forName("UTF-8")).build();
ResponseEntity<Resource> entity = template.postForEntity(url, null, Resource.class);
HttpHeaders headers = new HttpHeaders();
headers.add("x-real-ip","101.69.248.16");
HttpEntity<HashMap<String, Object>> httpEntity = new HttpEntity<>(null, headers);
ResponseEntity<Resource> entity = template.postForEntity(url, httpEntity, Resource.class);
InputStream bis = null;
OutputStream outputStream = null;
......@@ -140,7 +153,6 @@ public class JAYSmartController {
bis = entity.getBody().getInputStream();
outputStream = response.getOutputStream();
// DataInputStream dataInputStream = new DataInputStream(bis);
String filename = contractAddr.substring(contractAddr.lastIndexOf("/") + 1);
// 解决文件名乱码问题,获取浏览器类型,转换对应文件名编码格式,IE要求文件名必须是utf-8, firefo要求是iso-8859-1编码
......@@ -151,8 +163,6 @@ public class JAYSmartController {
filename = URLEncoder.encode(filename, "UTF-8");
}
log.info("访问临安区村级小微权力平台数据接口/下载合同文书 -->" + url + ";文件 -->" + filename);
// String path = "D:/wangy/test/" + file;
// FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
// 设置下载文件的mineType,告诉浏览器下载文件类型
String mineType = request.getServletContext().getMimeType(filename);
......@@ -165,26 +175,29 @@ public class JAYSmartController {
outputStream.write(buffer, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
log.info("访问临安区村级小微权力平台数据接口,下载合同文书异常");
log.info("访问临安区村级小微权力平台数据接口,下载合同文书异常",e);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
closeStream(bis, outputStream);
}
return ResponseEntity.ok("下载成功!");
}
private void closeStream(InputStream bis, OutputStream outputStream) {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment