文档有这个例子:
- path: "/users"
method: POST
capture:
petName:
xPath: "/env:Envelope/env:Body/pets:animal/pets:name"
store: testStore
xmlNamespaces:
env: "http://schemas.xmlsoap.org/soap/envelope/"
pets: "urn:com:example:petstore"
但我收到错误
14:01:37 INFO i.g.i.Imposter - Starting mock engine 4.0.0
14:01:37 DEBUG i.g.i.c.u.ConfigUtil - Loading configuration file: .\configs\gm-dds-config.yaml
14:01:38 DEBUG i.g.i.c.u.ConfigUtil - Loading configuration file: .\configs\single-response-config.yaml
14:01:38 DEBUG i.g.i.p.PluginManager - Loaded 5 plugin(s): [js-detector, store-detector, rest, js-graal, store-inmem]
14:01:39 ERROR i.v.c.i.l.c.VertxIsolatedDeployer - Failed in deploying verticle
java.lang.RuntimeException: Error configuring plugin: rest
at io.gatehill.imposter.plugin.PluginManagerImpl.configurePlugins(PluginManagerImpl.kt:133) ~[imposter.jar:?]
at io.gatehill.imposter.plugin.PluginManagerImpl.startPlugins(PluginManagerImpl.kt:91) ~[imposter.jar:?]
at io.gatehill.imposter.Imposter$start$1.invokeSuspend(Imposter.kt:132) ~[imposter.jar:?]
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[imposter.jar:?]
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) ~[imposter.jar:?]
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) ~[imposter.jar:?]
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) ~[imposter.jar:?]
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) ~[imposter.jar:?]
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684) ~[imposter.jar:?]
Caused by: java.lang.RuntimeException: Error loading configuration file: my-config.yml , reason: Unrecognized field "xPath" (class io.gatehill.imposter.plugin.config.capture.ItemCaptureConfig), not marked as ignorable (12 known properties: "requestBody", "const", "queryParam", "pathParam", "formParam", "phase", "requestHeader", "jsonPath", "key", "store", "expression", "enabled"])
具有以下配置
---
plugin: rest
basePath: "/dds"
system:
xmlNamespaces:
soap: "http://schemas.xmlsoap.org/soap/envelope/"
star: "http://www.starstandard.org/STAR/5"
resources:
- path: "/appointments"
method: POST
capture:
serviceappointmentId:
xPath: "/star:ProcessServiceAppointment/star:ProcessServiceAppointmentDataArea/star:ServiceAppointment/star:ServiceAppointmentHeader/star:SecondaryDealerNumberID"
store: requestData
xmlNamespaces:
star: "http://www.starstandard.org/STAR/5"
requestBody:
xPath: "/star:ProcessServiceAppointment/star:ProcessServiceAppointmentDataArea"
operator: Exists
response:
statusCode: 202
content: "appt received"
实际上我想做的是捕获整个有效负载,但我将其切换为单个数据项,如文档中所示,看看这是否有效。
请注意,如果我省略捕获设置,那么
xPath
匹配就可以正常工作。
这是文档中的一个错误(现已修复)。
xPath
(以及关联的 xmlNamespaces
配置)应显示为嵌套在捕获块中的 requestBody
元素下方。
这是一个更新的示例:
- path: "/users"
method: POST
capture:
petName:
store: testStore
requestBody:
xPath: "/env:Envelope/env:Body/pets:animal/pets:name"
xmlNamespaces:
env: "http://schemas.xmlsoap.org/soap/envelope/"
pets: "urn:com:example:petstore"
对于您的配置,相关的捕获部分将是:
capture:
serviceappointmentId:
store: requestData
requestBody:
xPath: "/star:ProcessServiceAppointment/star:ProcessServiceAppointmentDataArea/star:ServiceAppointment/star:ServiceAppointmentHeader/star:SecondaryDealerNumberID"
xmlNamespaces:
star: "http://www.starstandard.org/STAR/5"
完全披露:这里的项目维护者 - 感谢此问题的作者提交错误。