弹簧集成入站网关如何将 SOAP 请求保存到文件



在 Spring 集成中,使用入站网关,您知道如何将每个 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"/>

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

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

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

问候

首先,PayloadLoggingInterceptor是基于org.apache.commons.logging.Log的,这已经是您的应用程序责任,使用哪个目标日志记录系统。是的,Log4j2 就是其中之一。只需要有一个从共享资源日志记录到目标impl的适当桥接。看起来它是开箱即用的 Log4j...

如果要将每个请求存储到其自己的文件中,请考虑将<int-file:outbound-channel-adapter>用于此目的。

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

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

其中source<ws:inbound-gateway>后消息的payload

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

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

我将结合如何log4j2日志到单独的文件,如此处所述Log4j2:如何将日志写入每个用户的单独文件?

最新更新