在我与Mule的第一步时,我正在编写一个基本的Http代理.目前我将请求转发给api服务器,我想做的是在响应客户端之前读取我从中收到的有效负载.
当我尝试使用#[payload]进行记录时,会打印出来
org.glassfish.grizzly.utils.BufferInputStream@2306df30
Run Code Online (Sandbox Code Playgroud)
如何以JSON格式正确打印?
完整代码:
<flow name="proxy">
<http:listener config-ref="http-lc-0.0.0.0-8081" path="![p['proxy.path']]" parseRequest="false"/>
<http:request config-ref="http-request-config" method="#[message.inboundProperties['http.method']]"
path="#[message.inboundProperties['http.request.path'].substring(message.inboundProperties['http.listener.path'].length()-2)]" parseResponse="false">
<http:request-builder>
<http:query-params expression="#[message.inboundProperties.'http.query.params']"/>
</http:request-builder>
<http:success-status-code-validator values="0..599" />
</http:request>
<logger doc:name="Logger" level="INFO" message="Payload #[payload]"/>
Run Code Online (Sandbox Code Playgroud)
Ani*_*ary 17
HTTP请求后的有效负载通常采用流格式,参考: - https://docs.mulesoft.com/mule-user-guide/v/3.7/http-request-connector
有两种方法可以获得有效负载http:request
1)<object-to-string-transformer doc:name="Object to String"/>
之后http:request
或
2)使用记录器并使用MEL表达式<logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>