【问题标题】:Multipart/form-data broken after apiKit router Mule4apiKit 路由器 Mule4 后多部分/表单数据损坏
【发布时间】:2021-05-24 12:27:35
【问题描述】:

在请求通过 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"
}

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,一切正常。但我想用它来验证请求的有效性。

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

【问题讨论】:

    标签: mule dataweave anypoint-studio mule4 apikit


    【解决方案1】:

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

    【讨论】:

    • 我正在接收 multipart 并尝试读取这两个文件以生成 json。
    • 对不起。我不清楚这个问题。应用程序使用什么版本的 APIKit 和 HTTP 连接器?
    • Np,APIKit 模块版本是 1.3.6,HTTP 连接器版本是 1.5.6。将 APIKit 版本更新到 1.5.1 有助于解决该问题。感谢您的提示!请用这个建议创建一个答案,这样我就可以给你一张绿色支票来给你信用。
    • 有道理,我对最新版本的测试有效。我已经更新了这个答案。
    猜你喜欢
    • 1970-01-01
    • 2020-09-07
    • 2022-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    相关资源
    最近更新 更多