Merge branch 'hotfix/starter_decode' into feature/REQ-3769

This commit is contained in:
wangli 2025-04-28 13:56:16 +08:00
commit c4bd1bcdfb
3 changed files with 17 additions and 2 deletions

View File

@ -24,6 +24,7 @@ public class WorkflowRequestInterceptor implements RequestInterceptor {
public static final String HEADER_HTTP_CLIENT_VALUE = "WorkflowEngine-Feign";
public static final String HEADER_API_VERSION = "Service-Version";
public static final String HEADER_SERVER_NAME = "X-SERVER-NAME";
public static final String HEADER_W_E = "WE";
@Override

View File

@ -21,6 +21,8 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import static cn.axzo.workflow.client.config.WorkflowRequestInterceptor.HEADER_W_E;
/**
* Workflow Engine Starter Complex Invoke Client Decoder
*
@ -39,13 +41,13 @@ final class WorkflowEngineStarterDecoder implements Decoder {
@Override
public Object decode(Response response, Type type) throws IOException {
if (!isOptional(type)) {
return convert(response, type);
return convertWrapper(response, type);
}
if (response.status() == 404 || response.status() == 204) {
return Optional.empty();
}
Type enclosedType = Util.resolveLastTypeParameter(type, Optional.class);
return Optional.ofNullable(convert(response, enclosedType));
return Optional.ofNullable(convertWrapper(response, enclosedType));
}
static boolean isOptional(Type type) {
@ -56,6 +58,14 @@ final class WorkflowEngineStarterDecoder implements Decoder {
return parameterizedType.getRawType().equals(Optional.class);
}
Object convertWrapper(Response response, Type enclosedType) throws IOException {
if (response.request().headers().containsKey(HEADER_W_E)) {
return delegate.decode(response, enclosedType);
} else {
return convert(response, enclosedType);
}
}
/**
* 这里做返回数据的解析并处理引擎返回的一些正常的业务异常
*

View File

@ -35,6 +35,7 @@ import static cn.axzo.workflow.client.config.WorkflowRequestInterceptor.HEADER_A
import static cn.axzo.workflow.client.config.WorkflowRequestInterceptor.HEADER_HTTP_CLIENT;
import static cn.axzo.workflow.client.config.WorkflowRequestInterceptor.HEADER_HTTP_CLIENT_VALUE;
import static cn.axzo.workflow.client.config.WorkflowRequestInterceptor.HEADER_SERVER_NAME;
import static cn.axzo.workflow.client.config.WorkflowRequestInterceptor.HEADER_W_E;
import static cn.axzo.workflow.common.constant.StarterConstants.ENABLE_MANAGEABLE;
import static cn.axzo.workflow.common.constant.StarterConstants.STARTER_INVOKE_MODE;
import static java.util.concurrent.TimeUnit.SECONDS;
@ -76,6 +77,9 @@ public class WorkflowEngineStarterFeignConfiguration {
// 通过服务端的校验
Target.HardCodedTarget target = (Target.HardCodedTarget) template.feignTarget();
String apiClassPath = target.type().getName();
if (apiClassPath.contains("cn.axzo.workflow.client")) {
template.header(HEADER_W_E, "true");
}
if (apiClassPath.contains("cn.axzo.workflow.starter.api")) {
template.header(HEADER_HTTP_CLIENT, HEADER_HTTP_CLIENT_VALUE);
template.header(HEADER_API_VERSION, serviceVersion);