在请求通过 Mule4 app 中的 ApiKit 路由器后,从 multipart/form-data 读取数据时遇到问题。
有一个 RAML,在 ApiKit 路由器中用于验证和路由请求。
#%RAML 1.0
title: ACC race data API
description: API for designing and updating race data
version: 1
protocols: [ HTTPS, HTTP ]
/acc/reverse/entrylist:
description: Used to manipulate entrylist for ACC reverse grid.
post:
description: Creates new entrylist based on supplied quali result, race one result and race one entrylist.
queryParameters:
positionsRotated:
description: Parameter defining how many positions to rotate.
required: false
type: number
example: 30
body:
multipart/form-data:
properties:
qualifyResult:
description: File containing qualifying result.
type: file
fileTypes: ['application/json']
required: true
raceOneResult:
description: File containing race 1 result.
type: file
fileTypes: ['application/json']
required: true
验证工作正常 - 如果数据以不正确的格式发送,则返回异常。对于格式正确的数据,请求被路由到流post:\acc\reverse\entrylist:multipart\form-data:acc-race-data-config
。在这些步骤之间,有效载荷格式(由 Mule)从可读形式的有效载荷(见下文)更改为java.io.ByteArrayInputStream@379ebdd5
ApiKit 路由器之前有效载荷数据的可读格式(接收到应用程序):
----------------------------180928595588258919887097
Content-Disposition: form-data; name="qualifyResult"; filename="json1.json"
Content-Type: application/json
{
"json1": "1"
}
----------------------------180928595588258919887097
Content-Disposition: form-data; name="raceOneResult"; filename="json2.json"
Content-Type: application/json
{
"json2": "2"
}
----------------------------180928595588258919887097--
如果在 apiKit 之前使用以下 dataweave 脚本可以正常工作,但它在 ApiKit 调用的流程中不起作用:
%dw 2.0
output application/json
---
payload.parts[1].content
在ApiKit之前使用上述 DW 的输出示例:
{
"json2": "2"
}
ApiKit后使用相同DW的输出示例:
org.mule.runtime.core.api.expression.ExpressionRuntimeException: "javax.mail.internet.ParseException - Missing start boundary, while reading `payload` as MultiPart.
Trace:
at main (Unknown)" evaluating expression: "%dw 2.0
output application/json
---
payload.parts[1].content".
在 Anypoint Studio 7.8.0 中进行测试,一旦完成并准备好部署,就应该在 Mule4-CE 运行时使用。使用 Postman v8.5.1 进行测试。发送带有qualifyResult 和raceOneResult 部分的表单数据正文,其中包含JSON 数据、默认标头、基本身份验证、查询参数positionsRotated=30
。网址调用:https://localhost:443/api/acc/reverse/entrylist?positionsRotated=30
尝试使用 RAW 类型的有效负载手动生成 multipart/form-data 正文,但结果相同。如果没有 ApiKit,一切正常。但我想用它来验证请求的有效性。
感谢大家回复任何有用的提示!