mule - apiKit 路由器 Mule4 后多部分/表单数据损坏
问题描述
在请求通过 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,一切正常。但我想用它来验证请求的有效性。
感谢大家回复任何有用的提示!
解决方案
I tested a similar scenario I had with the latest versions and I didn't had that problem. If you are using older versions of the HTTP connector and APIKit module try upgrading to the latest releases. Anypoint Studio has a feature to detect newer releases of connectors: https://docs.mulesoft.com/studio/7.9/update-modules
推荐阅读
- sqlite - SQLite 将连字符视为算术运算符
- javascript - 如何与 AJAX 响应一起传递额外的变量?
- vue.js - VueJS - 使用过滤器或基础组件来格式化数字
- html - Flex 面包屑:如何设置相等的高度并换行
- sql - Sql通配符不是结束字符串
- java - 查找奇偶校验异常值 CodeWars
- python - 用python抓取网页的所有颜色
- node.js - 使用“--experimental-modules”编译时如何修复“ReferenceError:require is not defined”错误?
- angular - 在 IE11 中更新 ngModel 后触发 ngbRadioGroup 点击事件
- excel - 将一列中所有单元格中的值添加到另一列中的相应单元格中,然后清除原始单元格