简体   繁体   English

在Mule中如何记录http响应而不更改原始输出流

[英]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.

相关问题 如何读取和复制 HTTP servlet 响应输出流内容以进行日志记录 - How to read and copy the HTTP servlet response output stream content for logging Mule - 创建http多部分响应 - Mule - create http multipart response 如何在没有传输编码的情况下发送HTTP响应:chunked? - How do I send an HTTP response without Transfer Encoding: chunked? 无法从Mule接收HTTP响应 - Can't receive an HTTP response from Mule 将Http响应转换为对象Mule esb - Transform Http Response to object mule esb 如何使用FFMPEG转码文件并在Java servlet的响应中流式传输输出文件? - How can I transcode a file with FFMPEG and stream the output file in the response of a Java servlet? 如何从日志中提取带有 Http 响应 200 的 GET 请求请求的 gif 文件? - How can I extract the gif files requested by a GET request with Http response 200 from a log? 如何在不召唤无限的平台调试日志记录的情况下使用日志级别FINE? - How can I use log level FINE without summoning an infinite stream of platform debug logging? 如何在不更改原始列表的情况下过滤列表中的对象列表 - How to filter the list of objects in the list without changing the original list 如何解析 JSON 响应并从已知键 output 中获取值? - How can I parse the JSON response and could get value from known key as output?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM