使用 Mule 在浏览器中显示 JSON 个文件
Display JSON file in browser with Mule
我正在使用 JSON 文件来显示模式并给出了这个配置:
<flow name="api-schema" doc:name="api-schema">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8080" path="schema" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<http:static-resource-handler resourceBase="${app.home}/src/main/resources/" defaultFile="schema" doc:name="HTTP Static Resource Handler"/>
</flow>
但是当我运行它时,它总是要求下载文件。我在 Chrome 和 Safari 中都试过了。如何指示 mule 在浏览器上显示内容而不下载?
浏览器决定如何处理资源的方式是查看 Content-Type header。您可以通过使用名称 "Content-Type" 和值 "application/json" 创建出站 属性 来设置 header,如下所示:
<set-property propertyName="Content-Type" value="application/json" />
由于 static-resource-handler is now deprecated, you could switch to the parse-template 处理器:
<parse-template location="#[message.inboundProperties['http.listener.path']]" />
将"Content-Type" header设置为"application/json",然后响应将采用json格式。
我正在使用 JSON 文件来显示模式并给出了这个配置:
<flow name="api-schema" doc:name="api-schema">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8080" path="schema" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<http:static-resource-handler resourceBase="${app.home}/src/main/resources/" defaultFile="schema" doc:name="HTTP Static Resource Handler"/>
</flow>
但是当我运行它时,它总是要求下载文件。我在 Chrome 和 Safari 中都试过了。如何指示 mule 在浏览器上显示内容而不下载?
浏览器决定如何处理资源的方式是查看 Content-Type header。您可以通过使用名称 "Content-Type" 和值 "application/json" 创建出站 属性 来设置 header,如下所示:
<set-property propertyName="Content-Type" value="application/json" />
由于 static-resource-handler is now deprecated, you could switch to the parse-template 处理器:
<parse-template location="#[message.inboundProperties['http.listener.path']]" />
将"Content-Type" header设置为"application/json",然后响应将采用json格式。