fix(vsp): 修复 RestTemplate 发送空 JSON body 的问题
VspNotifyClientImpl.executeWithRetry 传裸 POJO 给 postForObject,
RestTemplate 默认 converter 顺序下可能选用 FormHttpMessageConverter
导致序列化为空 {}。改为 HttpEntity 显式设置 Content-Type: application/json,
确保使用 Jackson 序列化。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,9 @@ import com.viewsh.module.ops.infrastructure.vsp.dto.VspSendCardReqDTO;
|
||||
import com.viewsh.module.ops.infrastructure.vsp.dto.VspSyncStatusReqDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.ResourceAccessException;
|
||||
@@ -44,9 +47,13 @@ public class VspNotifyClientImpl implements VspNotifyClient {
|
||||
|
||||
private void executeWithRetry(String url, Object req,
|
||||
String action, String orderId, String alarmId) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<Object> entity = new HttpEntity<>(req, headers);
|
||||
|
||||
for (int i = 0; i <= properties.getMaxRetry(); i++) {
|
||||
try {
|
||||
VspResponseDTO resp = restTemplate.postForObject(url, req, VspResponseDTO.class);
|
||||
VspResponseDTO resp = restTemplate.postForObject(url, entity, VspResponseDTO.class);
|
||||
if (resp != null && resp.isSuccess()) {
|
||||
log.info("[{}] vsp通知成功, orderId={}, alarmId={}", action, orderId, alarmId);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user