1

在 Spring Integration 中,使用入站网关,您知道如何将每个 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 请求?我阅读了参考文件,但找不到任何东西。

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

问候,

4

2 回答 2

1

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

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

于 2017-01-20T00:41:18.180 回答
1

首先PayloadLoggingInterceptor是基于org.apache.commons.logging.Log你的应用程序责任,使用哪个目标日志系统。是的,Log4j2 就是其中之一。只需要从 Commons Logging 到目标 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之后的payload消息在哪里<ws:inbound-gateway>

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

于 2017-01-20T16:22:52.967 回答