Commit f1296c59ebb9bcb21ae6e2c511d2b7b7ffdeeebc
1 parent
533e5c3b
fix: restTemplate请求添加try-catch
Showing
1 changed file
with
18 additions
and
9 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/listener/BpmUserTaskListener.java
| @@ -22,6 +22,7 @@ import org.springframework.http.ResponseEntity; | @@ -22,6 +22,7 @@ import org.springframework.http.ResponseEntity; | ||
| 22 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
| 23 | import org.springframework.util.LinkedMultiValueMap; | 23 | import org.springframework.util.LinkedMultiValueMap; |
| 24 | import org.springframework.util.MultiValueMap; | 24 | import org.springframework.util.MultiValueMap; |
| 25 | +import org.springframework.web.client.RestClientException; | ||
| 25 | import org.springframework.web.client.RestTemplate; | 26 | import org.springframework.web.client.RestTemplate; |
| 26 | 27 | ||
| 27 | import java.util.List; | 28 | import java.util.List; |
| @@ -79,15 +80,23 @@ public class BpmUserTaskListener implements TaskListener { | @@ -79,15 +80,23 @@ public class BpmUserTaskListener implements TaskListener { | ||
| 79 | // 3. 异步发起请求 | 80 | // 3. 异步发起请求 |
| 80 | // TODO @芋艿:确认要同步,还是异步 | 81 | // TODO @芋艿:确认要同步,还是异步 |
| 81 | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); | 82 | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); |
| 82 | - // TODO @lesan:可能需要 try catch 哇? RestClientException | ||
| 83 | - ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST, | ||
| 84 | - requestEntity, String.class); | ||
| 85 | - log.info("[notify][监听器:{},事件类型:{},请求头:{},请求体:{},响应结果:{}]", | ||
| 86 | - DELEGATE_EXPRESSION, | ||
| 87 | - delegateTask.getEventName(), | ||
| 88 | - headers, | ||
| 89 | - body, | ||
| 90 | - responseEntity); | 83 | + try { |
| 84 | + ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST, | ||
| 85 | + requestEntity, String.class); | ||
| 86 | + log.info("[notify][监听器:{},事件类型:{},请求头:{},请求体:{},响应结果:{}]", | ||
| 87 | + DELEGATE_EXPRESSION, | ||
| 88 | + delegateTask.getEventName(), | ||
| 89 | + headers, | ||
| 90 | + body, | ||
| 91 | + responseEntity); | ||
| 92 | + } catch (RestClientException e) { | ||
| 93 | + log.error("[error][监听器:{},事件类型:{},请求头:{},请求体:{},请求出错:{}]", | ||
| 94 | + DELEGATE_EXPRESSION, | ||
| 95 | + delegateTask.getEventName(), | ||
| 96 | + headers, | ||
| 97 | + body, | ||
| 98 | + e.getMessage()); | ||
| 99 | + } | ||
| 91 | // 4. 是否需要后续操作?TODO 芋艿:待定! | 100 | // 4. 是否需要后续操作?TODO 芋艿:待定! |
| 92 | } | 101 | } |
| 93 | 102 |