Multipart/form-data 在 apiKit 路由器 Mule4 之后损坏

Multipart/form-data broken after apiKit router Mule4

在请求通过 Mule4 应用程序中的 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

使用上面的DW输出示例之前 ApiKit:

{
  "json2": "2"
}

如果使用相同的DW输出示例after 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".

在 Anypoint Studio 7.8.0 中进行测试,应该在完成并准备好部署后在 Mule4-CE 运行时上使用。 使用 Postman v8.5.1 进行测试。发送 form-data body 以及包含 JSON 数据的 qualifyResult 和 raceOneResult 部分,默认 headers,基本身份验证,查询参数 positionsRotated=30。 Url 呼叫:https://localhost:443/api/acc/reverse/entrylist?positionsRotated=30 尝试使用 RAW 类型的有效负载手动生成 multipart/form-data body,但结果相同。如果没有 ApiKit,一切正常。但我想用它来验证请求有效性。

感谢大家回复任何有用的提示!

我用最新版本测试了一个类似的场景,我没有遇到那个问题。如果您使用的是旧版本的 HTTP 连接器和 APIKit 模块,请尝试升级到最新版本。 Anypoint Studio 具有检测较新版本连接器的功能:https://docs.mulesoft.com/studio/7.9/update-modules