如何在 Mule4 中强制使用 UTF-8 编码

How to force UTF-8 encoding in Mule4

当我们开始在我们公司实施 Mulesoft 作为试点时,我们注意到 mulesoft 会在看似随机的时刻继承系统代码页 (windows-1252)。尽管设置了 Anypoint studio (7.2.0) 首选项,但运行时 (4.2.1 EE) 默认为 UTF-8。因此,传出连接器(和默认的 http 连接器)将以这种编码发送它们的 http 请求。我们写的任何 API 然后给出以下错误:

Message               : HTTP PUT on resource 'https://mocksvc-proxy.anypoint.mulesoft.com:443/exchange/*********/1.0.2/subscription' failed: media type application/json; charset=windows-1252 not supported (415).

我们发现解决此问题的方法是在连接器之前的消息转换上设置编码,以强制将其转换为 UTF-8,如下所示:

    <ee:transform doc:name="Transform Message" doc:id="-redacted-">
        <ee:message>
            <ee:set-payload><![CDATA[%dw 2.0
             output application/json encoding="UTF-8"
              ---
           {
           "applicatie": "-redacted-",
           "clientid": vars."-redacted-" as Number
            }]]></ee:set-payload>
        </ee:message>
    </ee:transform>

但是,自 Anypoint Studio 7.2.1 起,此修复程序不再有效。 我找不到我们更改的任何内容,所有设置仍设置为 UTF-8。

Project setting set to UTF-8 image

有谁知道我们可以尝试强制编码的方法,或者让我们构建的 api 接受 windows-1252? (如果可能的话,这是可以接受的,但不是更可取的)

或者您认为这是我们需要向 mulesoft 报告的错误?

此问题发生在 Mule Standalone EE 版本:4.1.2 构建:41de9970 上 Windows 服务器 2016 数据中心。 Anypoint studio 嵌入式 Mule 4.1.2 在 Windows 7.

上面尝试的代码和解决方案是正确的,它是 mule runtime 4.2.1(.2) 中的一个错误。

已在4.1.3(.2)版本修复,如遇此问题,请更新修复。