【问题标题】:Spring Integration inbound-gateway how to save soap request to file?Spring Integration inbound-gateway 如何将soap请求保存到文件?
【发布时间】:2017-01-18 04:41:32
【问题描述】:

在 Spring Integration 中,使用 inbound-gateway,你知道如何将每个 SOAP WS 请求保存到单独的文件中吗?

目前,我坚持:

<!-- inbound -->
<ws:inbound-gateway id="inbound-gateway" request-channel="SOAPRequestChannel" reply-channel="SOAPResponseChannel"/>
<int:channel id="SOAPRequestChannel">
    <int:interceptors>
        <int:wire-tap channel="SOAPRequestChannelForLog"/>
    </int:interceptors>
</int:channel>
<int:channel id="SOAPResponseChannel" />
<int:channel id="SOAPRequestChannelForLog" />   

<int:logging-channel-adapter id="logger" expression="payload" level="INFO" channel="SOAPRequestChannelForLog"/>

但它只是将所有请求记录在 1 个文件中。

或者我必须编写另一个像 LogToFile 这样的类,它有一种方法可以将该请求保存到文件,将 int:logging-channel-adapter 替换为 int:service-activator ? Spring 是否支持开箱即用地记录每个 SOAP 请求?我阅读了参考文档,但找不到任何东西。

或者有更好的方法吗? ^_^

问候,

【问题讨论】:

  • 我是通过阅读Spring Web Service 2 Cookbook一书发现Spring支持PayloadLoggingInterceptor & SoapEnvelopeLoggingInterceptor,然后查看参考文档。它在那里^_^
  • 请正确回答问题并接受。这将帮助其他人找到解决方案,并且问题将从我的仪表板中消失。或者只是删除它:-)
  • 嗨@Artem Bilan,实际上,这还不是解决方案,因为 PayloadLoggingInterceptor 使用 log4j2 记录有效负载。目前,我不知道如何配置 log4j2 来分别记录每个请求/响应。无论如何,我放了一个临时答案。

标签: web-services spring-integration inbound


【解决方案1】:

首先PayloadLoggingInterceptor 是基于org.apache.commons.logging.Log 的,这已经是您的应用程序的责任,使用哪个目标日志系统。是的,Log4j2 就是其中之一。只需要从 Commons Logging 到目标 impl 建立适当的桥梁。看起来它对于 Log4j 来说是开箱即用的......

如果您想将每个请求存储到其自己的文件中,请考虑为此目的使用&lt;int-file:outbound-channel-adapter&gt;

您只需要根据传入的消息构建适当的内容:

Transformer transformer = createNonIndentingTransformer();
StringWriter writer = new StringWriter();
transformer.transform(source, new StreamResult(writer));
String message = writer.toString();

其中sourcepayload&lt;ws:inbound-gateway&gt; 之后的消息。

您只需要根据该消息或其他环境找出file name

【讨论】:

  • 哦,我不知道有 int-file:outbound-channel ^ _ ^
  • int-file:outbound-channel-adapter 转换为文档链接
【解决方案2】:

我首先通过阅读Spring Web Service 2 Cookbook一书发现Spring支持PayloadLoggingInterceptor & SoapEnvelopeLoggingInterceptor,然后查看参考文档。它在那里^

我将结合如何将 log4j2 记录到单独的文件中,如此处所述 Log4j2: How to write logs to separate files for each user?

【讨论】:

    猜你喜欢
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多