1

In Spring Integration, using inbound-gateway, do you know how to save each SOAP WS Request to separated files ?

Currently, I stuck at:

<!-- 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"/>

But it just log all requests in 1 file.

OR I have to write another class like LogToFile which has a method to save that request to file, replace int:logging-channel-adapter with int:service-activator ? Does Spring support out-of-the-box logging each SOAP request ? I read the reference document, but couldn't find any thing.

OR there is any better way ? ^_^

Regards,

Nha Nguyen
  • 81
  • 8
  • 1
    I found out Spring support PayloadLoggingInterceptor & SoapEnvelopeLoggingInterceptor by reading the book Spring Web Service 2 Cookbook at first, then check the reference document. It is there ^_^ – Nha Nguyen Jan 18 '17 at 06:42
  • Please, form a proper answer to the question and accept it. That will help other people to find a solution and the question will disappear from my dashboard. Or just remove it :-) – Artem Bilan Jan 18 '17 at 14:37
  • Hi @Artem Bilan, actually, it is not the solution yet as PayloadLoggingInterceptor use log4j2 to log the payload. Currently, I don't know how to configure log4j2 to log each request/response separately. Anyway, I put an temporary answer. – Nha Nguyen Jan 20 '17 at 02:13

2 Answers2

1

I found out Spring support PayloadLoggingInterceptor & SoapEnvelopeLoggingInterceptor by reading the book Spring Web Service 2 Cookbook at first, then check the reference document. It is there ^

I will combine with how to log4j2 log to separated files as describe here Log4j2: How to write logs to separate files for each user?

Community
  • 1
  • 1
Nha Nguyen
  • 81
  • 8
1

First of all PayloadLoggingInterceptor is based on the org.apache.commons.logging.Log and that is already your application responsibility which target logging system to use. Yes, Log4j2 is one of them. There is only just need to have a proper bridge from Commons Logging to the target impl. Looks like it is out-of-the-box for Log4j...

If you want to store each request to its own file, consider to use <int-file:outbound-channel-adapter> for that purpose.

You just need to build a proper content based on the incoming Message:

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

Where source is a payload of the message after <ws:inbound-gateway>.

And you will just need to figure out the file name based on that message or some other environment.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118