[英]In Mule how could I log the http response without changing the original output stream
My Mule will do a HTTP call and response to my client, I want to log the HTTP call result, like status code and response body. 我的Mule将进行HTTP调用并响应我的客户端,我想记录HTTP调用结果,例如状态代码和响应正文。 At first I log the #[payload], but it's a stream, I know <object-to-string-transformer/> works, but I don't want to change the response, so I put the transformer into an enricher, but the result is still changed, why? 起初,我记录了#[payload],但这是一个流,我知道<object-to-string-transformer />可以工作,但是我不想更改响应,所以我将转换器放入了一个浓缩器,但是结果仍然改变,为什么?
My code: 我的代码:
<http:outbound-endpoint exchange-pattern="request-response" address="http://#[payload]" doc:name="Call Service in Pool"/>
<enricher source="#[payload]" target="#[flowVars['responseBody']]" doc:name="Message Enricher">
<object-to-string-transformer doc:name="Object to String"/>
</enricher>
<logger level="INFO" doc:name="Log Response" message="response, http status: #[message.inboundProperties['http.status']], body: #[flowVars['responseBody']], org: #[payload]"/>
Log output: 日志输出:
org.mule.api.processor.LoggerMessageProcessor: response, http status: 200, body: {"groupId":"group1", "formParam":"null"}, org: org.mule.transport.http.ReleasingInputStream@51dfd9b8
Client receives no body: 客户没有收到任何遗体:
HTTP/1.1 200 OK
Content-Type: application/json
Date: Sat, 24 Aug 2013 10:55:49 +0800
Server: Mule EE Core Extensions/3.4.0
X-MULE_SESSION: rO0ABXNyACNvcmcubXVsZS5zZXNzaW9uLkRlZmF1bHRNdWxlU2Vzc2lvbi7rdtEW7GGKAwAEWgAFdmFsaWRMAA1mbG93Q29uc3RydWN0dAAmTG9yZy9tdWxlL2FwaS9jb25zdHJ1Y3QvRmxvd0NvbnN0cnVjdDtMAAJpZHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wAD3NlY3VyaXR5Q29udGV4dHQAJ0xvcmcvbXVsZS9hcGkvc2VjdXJpdHkvU2VjdXJpdHlDb250ZXh0O3hwAXB0ACRhZWFhODZjOS0wYzY4LTExZTMtYjhkZS0xNTQzZDIwNjFkNWZwc3IAJWphdmEudXRpbC5Db2xsZWN0aW9ucyRTeW5jaHJvbml6ZWRNYXAbc/kJS0s5ewMAAkwAAW10AA9MamF2YS91dGlsL01hcDtMAAVtdXRleHQAEkxqYXZhL2xhbmcvT2JqZWN0O3hwc3IAJG9yZy5tdWxlLnV0aWwuQ2FzZUluc2Vuc2l0aXZlSGFzaE1hcJ3R2e9nRc4AAwAAeHB3DD9AAAAAAAAQAAAAAHhxAH4ACXh4
X-MULE_ENCODING: UTF-8
Transfer-Encoding: chunked
Connection: close
This is the standard behavior of streams: once you consumed it, it's consumed and, unless you reset it, it stays consumed with no more data available. 这是流的标准行为:一旦使用它,它就会被使用;除非重置它,否则它将保持消耗状态,而没有更多可用数据。
You can try using mark()
before logging then reset()
after (in MEL expression components) but there is no guarantee the actual stream implementation produced by Mule supports these methods. 您可以尝试在登录之前使用mark()
,然后在MEL表达式组件中使用reset()
,但不能保证Mule生成的实际流实现支持这些方法。
Read the InputStream JavaDoc for more information. 阅读InputStream JavaDoc以获取更多信息。
Mule allows you to use Java in the MEL expressions. Mule允许您在MEL表达式中使用Java。 You could try something like this: 您可以尝试这样的事情:
#[String str = message.payloadAs(java.lang.String); java.io.InputStream ins = new java.io.ByteArrayInputStream(str.getBytes()); message.payload = ins; return str;]"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.