提交审批 dogfooding 修复:桥接清洗 joda 时间变量避免 Flowable 序列化崩
P4 写路径巡检(HR_HOLIDAYAPPLY_SUBMIT)揪到:业务变量含 org.joda.time.DateTime(BEGINTIME), FlowableClient POST 时 Jackson 无 joda 模块→InvalidDefinitionException 起审批崩+泄露类名。 桥接 jsonSafeValue 反射检测 joda 时间类→epoch 毫秒(不引 joda 编译依赖)。集成重跑 status 0。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -83,6 +83,11 @@ public class ProcessCoreServiceBridge {
|
|||||||
vars.put(ProcessCoreService.INITIATORDEPARTID, currentDepart);
|
vars.put(ProcessCoreService.INITIATORDEPARTID, currentDepart);
|
||||||
vars.put(INITIATORTIME, new java.util.Date());
|
vars.put(INITIATORTIME, new java.util.Date());
|
||||||
|
|
||||||
|
// dogfooding(HR_HOLIDAYAPPLY_SUBMIT)实测:保真层 POJO 的日期列是 org.joda.time.DateTime,
|
||||||
|
// FlowableClient 经 RestClient 序列化 POST 时 Jackson 默认无 joda 模块 → InvalidDefinitionException
|
||||||
|
// 起审批崩(且 msg 泄露类名)。此处把变量里的 joda 时间类型清洗为 JSON 安全形态。
|
||||||
|
vars.replaceAll((k, v) -> jsonSafeValue(v));
|
||||||
|
|
||||||
Map<String, Object> startRequest = new LinkedHashMap<>();
|
Map<String, Object> startRequest = new LinkedHashMap<>();
|
||||||
startRequest.put("processDefinitionKey", processName);
|
startRequest.put("processDefinitionKey", processName);
|
||||||
startRequest.put("businessKey", businessKey);
|
startRequest.put("businessKey", businessKey);
|
||||||
@@ -101,4 +106,21 @@ public class ProcessCoreServiceBridge {
|
|||||||
processName, businessKey, tableName, inst != null && inst.ended, target);
|
processName, businessKey, tableName, inst != null && inst.ended, target);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把流程变量值清洗成 JSON 可序列化形态:joda 时间类型(Jackson 默认不支持)→ epoch 毫秒
|
||||||
|
* (Instant 族有 getMillis)或 ISO 字符串(LocalDate 等无 getMillis)。其它类型原样保留。
|
||||||
|
*
|
||||||
|
* <p>用反射按类名检测,避免对 joda-time 形成编译期硬依赖(其仅为保真层传递依赖)。
|
||||||
|
*/
|
||||||
|
private static Object jsonSafeValue(Object v) {
|
||||||
|
if (v == null || !v.getClass().getName().startsWith("org.joda.time.")) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return (Long) v.getClass().getMethod("getMillis").invoke(v);
|
||||||
|
} catch (ReflectiveOperationException | ClassCastException e) {
|
||||||
|
return v.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,27 @@ class ProcessCoreServiceBridgeTest {
|
|||||||
eq("BK-2"), eq("OA_NOTICE"), eq(ProcessCoreService.STATUS_PASS));
|
eq("BK-2"), eq("OA_NOTICE"), eq(ProcessCoreService.STATUS_PASS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void joda时间变量_清洗为epoch毫秒_避免FlowableClient序列化崩() {
|
||||||
|
// dogfooding(HR_HOLIDAYAPPLY_SUBMIT)实测:业务变量含 org.joda.time.DateTime(如 BEGINTIME),
|
||||||
|
// FlowableClient POST 时 Jackson 无 joda 模块 → InvalidDefinitionException 起审批崩。
|
||||||
|
// 桥接须把 joda 时间类型清洗为 epoch 毫秒(Jackson 安全 + flowable 可存)。
|
||||||
|
when(flowableClient.start(org.mockito.ArgumentMatchers.anyMap())).thenReturn(instance(false));
|
||||||
|
|
||||||
|
Map<String, Object> variables = new LinkedHashMap<>();
|
||||||
|
variables.put("BEGINTIME", new org.joda.time.DateTime(1700000000000L));
|
||||||
|
variables.put("AMOUNT", 100); // 非时间类型原样保留
|
||||||
|
|
||||||
|
bridge().startWorkflow("请假审批", variables, "HR_HOLIDAYAPPLY", "BK-3", ctxWith("U-1", "D-1"));
|
||||||
|
|
||||||
|
ArgumentCaptor<Map<String, Object>> reqCap = ArgumentCaptor.forClass(Map.class);
|
||||||
|
verify(flowableClient).start(reqCap.capture());
|
||||||
|
Map<String, Object> vars = (Map<String, Object>) reqCap.getValue().get("variables");
|
||||||
|
assertThat(vars.get("BEGINTIME")).isInstanceOf(Long.class).isEqualTo(1700000000000L);
|
||||||
|
assertThat(vars.get("AMOUNT")).isEqualTo(100);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void businessKey空_抛ValidationException_不起流程不回写() {
|
void businessKey空_抛ValidationException_不起流程不回写() {
|
||||||
ProcessCoreServiceBridge b = bridge();
|
ProcessCoreServiceBridge b = bridge();
|
||||||
|
|||||||
Reference in New Issue
Block a user