fix: restTemplate请求添加try-catch
This commit is contained in:
parent
533e5c3bf5
commit
f1296c59eb
|
@ -22,6 +22,7 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -79,15 +80,23 @@ public class BpmUserTaskListener implements TaskListener {
|
||||||
// 3. 异步发起请求
|
// 3. 异步发起请求
|
||||||
// TODO @芋艿:确认要同步,还是异步
|
// TODO @芋艿:确认要同步,还是异步
|
||||||
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers);
|
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
// TODO @lesan:可能需要 try catch 哇? RestClientException
|
try {
|
||||||
ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST,
|
ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST,
|
||||||
requestEntity, String.class);
|
requestEntity, String.class);
|
||||||
log.info("[notify][监听器:{},事件类型:{},请求头:{},请求体:{},响应结果:{}]",
|
log.info("[notify][监听器:{},事件类型:{},请求头:{},请求体:{},响应结果:{}]",
|
||||||
DELEGATE_EXPRESSION,
|
DELEGATE_EXPRESSION,
|
||||||
delegateTask.getEventName(),
|
delegateTask.getEventName(),
|
||||||
headers,
|
headers,
|
||||||
body,
|
body,
|
||||||
responseEntity);
|
responseEntity);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
log.error("[error][监听器:{},事件类型:{},请求头:{},请求体:{},请求出错:{}]",
|
||||||
|
DELEGATE_EXPRESSION,
|
||||||
|
delegateTask.getEventName(),
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
// 4. 是否需要后续操作?TODO 芋艿:待定!
|
// 4. 是否需要后续操作?TODO 芋艿:待定!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue