在请求通过应用程序中的ApiKit路由器后,从多部分/表单数据中读取数据有问题。
在ApiKit路由器中有一个RAML,用于验证和路由请求。
#%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路由器之前的有效载荷数据(接收到app)的可读格式:
----------------------------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,下面的数据编织脚本工作得很好,但是在ApiKit调用的流中不能工作:
%dw 2.0
output application/json
---
payload.parts[1].content如果在上面的DW中使用了输出示例,则在之前使用 ApiKit:
{
"json2": "2"
}如果在之后使用相同的DW,则输出示例ApiKit如下:
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".在任意点的Studio 7.8.0中进行测试,一旦完成并准备部署,就应该在Mule4-CE运行时上使用。使用PostmanV8.5.1进行测试。发送带有qualifyResult和raceOneResult部件的表单数据体,其中包含JSON数据、默认头、基本auth、查询param positionsRotated=30。https://localhost:443/api/acc/reverse/entrylist?positionsRotated=30试图使用原始的有效负载类型手动生成多部分/表单数据体,但是结果是相同的。如果没有ApiKit,一切都很好。但我想用它来验证请求的有效性。
感谢每个人回复任何有用的提示!
发布于 2021-05-24 12:50:51
我用最新的版本测试了一个类似的场景,我没有遇到这个问题。如果您使用的是HTTP连接器和APIKit模块的旧版本,请尝试升级到最新版本。Anypoint有一个功能来检测新版本的连接器:https://docs.mulesoft.com/studio/7.9/update-modules
https://stackoverflow.com/questions/67672096
复制相似问题