我想将内容类型为 application/json-patch+json 的负载从 wso2 传递到外部 api。我尝试将其设置为传输标头属性,但它是 application/json 而不是我想要的类型。
<header name="Content-Type" scope="transport" value="application/json-patch+json"/>
我还在 axis2.xml 文件中设置了以下属性
<messageBuilder contentType="application/json-patch+json"
class="org.wso2.micro.integrator.core.json.JsonStreamBuilder"/>
有人可以帮我解决这个问题吗,我不知道如何发送正确的内容类型。
尝试设置以下两个属性。
<property name="messageType" value="application/json" scope="axis2"/>
<property name="ContentType" value="application/json-patch+json" scope="axis2"/>
更新
以上应该确实有效。如果您设置了 messageType 属性,则消息将构建为 JSON 内容,并且 Content-type 标头将从
ContentType
属性中获取。
因为它不起作用,请尝试更改消息生成器和格式化程序。消息生成器在消息进入 MI 时被激活,格式化程序在消息传出时被激活。将以下内容添加到
deployment.toml
[[custom_message_formatters]]
class = "org.wso2.micro.integrator.core.json.JsonStreamFormatter"
content_type = "application/json-patch+json"
[[custom_message_builders]]
class = "org.wso2.micro.integrator.core.json.JsonStreamBuilder"
content_type = "application/json-patch+json"