- 在对应需要调的服务配置文件加上路径
#===============审批方案微服务配置================
server.port: 9004
upload.path: /alldev/u01/
schedule.cron.countDown: 0 0 8-18 * * ?
statistics.syskey: ywsp
schedule.countDown.isExecute: true
post.url.updateStatus: http://10.3.2.222:8888/ecological-retrieval/ZbStZtgl/updateState(对应调用的方法路径)
- 依赖
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.10</version>
</dependency>
- 获取服务器配置文件调用方法路径
@Value("${post.url.updateStatus}")
private String updateStatusUrl;
- 调用方法
public SendResponse sendHttpPublish(ShzbDoSendRequest doSendRequest) {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost request = new HttpPost(updateStatusUrl);
request.addHeader("Token-Auth", authUtil.getToken());
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
ContentType contentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
builder.addTextBody("ids", doSendRequest.getInstId(), contentType);
builder.addTextBody("state", doSendRequest.getState().toString(), contentType);
builder.addTextBody("mkmc", doSendRequest.getMkmc(), contentType);
HttpEntity build = builder.build();
request.setEntity(build);
CloseableHttpResponse response = httpClient.execute(request);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
throw new RuntimeException("请求ecological-retrieval服务统一状态更新接口失败, 请联系管理员!");
}
} catch (Exception e) {
throw new RuntimeException("更新项目状态失败!" + e.getMessage());
}
return caseService.doSend(doSendRequest);
}