From f25ee5091e3902d1bc0490234a3f78dbf6a125dd Mon Sep 17 00:00:00 2001 From: chenbowen Date: Thu, 6 Nov 2025 23:08:55 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=B0=83=E6=95=B4=20databus=20api=20?= =?UTF-8?q?=E7=AD=96=E7=95=A5=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=AF=8F=E6=AC=A1?= =?UTF-8?q?=E9=87=8D=E8=AF=95=E6=96=B0=E5=BB=BA=E8=AF=B7=E6=B1=82=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/step/impl/HttpStepHandler.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/framework/integration/gateway/step/impl/HttpStepHandler.java b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/framework/integration/gateway/step/impl/HttpStepHandler.java index 6be45216..fc271c96 100644 --- a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/framework/integration/gateway/step/impl/HttpStepHandler.java +++ b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/framework/integration/gateway/step/impl/HttpStepHandler.java @@ -50,14 +50,14 @@ public class HttpStepHandler implements ApiStepHandler { private static final int RETRY_ATTEMPTS = 3; private static final Set DEFAULT_FORWARDED_HEADERS = Set.of( - "authorization", - "zt-auth-token", - "tenant-id", - "visit-tenant-id", - "visit-company-id", - "visit-company-name", - "visit-dept-id", - "visit-dept-name" + "authorization", + "zt-auth-token", + "tenant-id", + "visit-tenant-id", + "visit-company-id", + "visit-company-name", + "visit-dept-id", + "visit-dept-name" ); @Override @@ -112,8 +112,17 @@ public class HttpStepHandler implements ApiStepHandler { Map headerMap = resolveHeaders(stepDefinition, payload); Duration timeout = resolveTimeout(stepDefinition); WebClient client = webClientBuilder.build(); - WebClient.RequestHeadersSpec requestSpec = buildRequest(client, callSpec, requestPayload, headerMap, supportsBody); - Mono responseMono = requestSpec.retrieve().bodyToMono(Object.class); + final HttpRequestPayload resolvedPayload = requestPayload; + boolean finalSupportsBody = supportsBody; + Mono responseMono = Mono.defer(() -> { + // 每次订阅(含重试)都会重新构建请求,避免缓存第一次结果 + HttpRequestPayload payloadForAttempt = resolvedPayload == null + ? HttpRequestPayload.of(null, Collections.emptyMap()) + : resolvedPayload; + return buildRequest(client, callSpec, payloadForAttempt, headerMap, finalSupportsBody) + .retrieve() + .bodyToMono(Object.class); + }); responseMono = applyResilientRetry(responseMono, stepDefinition); Object response = timeout == null ? responseMono.block() : responseMono.block(timeout); payload.addStepResult(ApiStepResult.builder() @@ -353,12 +362,12 @@ public class HttpStepHandler implements ApiStepHandler { private record HttpRequestPayload(Object body, Map queryParams) { - private HttpRequestPayload { - Map safeQuery = queryParams == null - ? Collections.emptyMap() - : Collections.unmodifiableMap(new LinkedHashMap<>(queryParams)); - queryParams = safeQuery; - } + private HttpRequestPayload { + Map safeQuery = queryParams == null + ? Collections.emptyMap() + : Collections.unmodifiableMap(new LinkedHashMap<>(queryParams)); + queryParams = safeQuery; + } static HttpRequestPayload of(Object body, Map queryParams) { return new HttpRequestPayload(body, queryParams);