Announcement Announcement Module
No announcement yet.
Logging of response message in ws-outbound-gateway Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Logging of response message in ws-outbound-gateway

    I am new to Spring Integration and am trying a POC.

    I have a message flow in which messages arriving in a ws-inbound-gateway and leaves the flow to call the web services ( available from teh service provider ) through a ws-outbound-gateway.

    I want to log ( in LOG 4J generated log ) the detail of the request and response message as it flows through the message flow. On the input flow side from the inbound gateway, I can easily log the messages ( the entire XML payload) using an interceptor ( java based - preSend method). However can someone help me to know how to log response message payload ( XML of the payload) on the return flow?

    I tried defining a reply-channel such as "my-reply-channel"{ in both inbound & outbound gateways and tried to intercept ( using Java interceptor - preSend() method); I could log the response message. However it logs twice and I also see it calls the web service ( offered by the the service provider) twice. I do not expect the web services to be called twice. It has to be only once. Effectively the message flows through outbound channel twice, I could see that in the log. I know I am doing something wrong here. Can someone explain how to do log request and response messages correctly? Not many documents or books explain very well about how the message flows on the return side from outbound to inbound.

  • #2
    It's not entirely clear what you are asking for; whenever asking a question like this you should include your Spring Integration configuration.

    If you want to log the inbound/outbound SOAP messages you can use standard Spring WebServices interceptors

    Adding a logging interceptor will not cause the service to be invoked "twice".

    Turn on DEBUG logging and all should become clear because you can trace the messages through the flow.


    • #3
      Thank you Garry.

      I am giving below both spring integration configuration and the MessageAuditService class I used.

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns=""

      <context:component-scan base-package="com.s.integration.messageaudit"/>

      <int-ws:inbound-gateway id="ws-s-generic-inbound-gateway" request-channel="ws-s-generic-requests"

      <int:channel id="ws-s-generic-requests">
      <ref bean="messageAuditService" />

      <int:header-enricher input-channel="ws-s-generic-requests" output-channel="ws-s-generic-eniched-requests">
      <int:header name="s.message.servicename" expression="payload.node.localName"/>
      <int:reply-channel value="ws-s-generic-ws-reply"></int:reply-channel>


      <int-ws:outbound-gateway id="general-s-outbound-ws-gateway" request-channel="ws-s-generic-eniched-requests"
      <int-ws:uri-variable name="serviceName" expression="headers.get('s.message.servicename')"/>

      <int:channel id="ws-s-generic-ws-reply">
      <ref bean="messageAuditService" />



      package .....

      import org.apache.log4j.Logger;
      import org.springframework.integration.Message;
      import org.springframework.integration.MessageChannel;
      import org.springframework.integration.annotation.Service Activator;
      import r.ChannelInterceptorAdapter;
      import org.springframework.stereotype.Component;
      import javax.xml.transform.dom.DOMSource;
      import javax.xml.transform.*;

      public class MessageAuditService extends ChannelInterceptorAdapter {

      private static final Logger logger = Logger.getLogger("......MessageAuditService");

      public Message<?> preSend(Message<?> message, MessageChannel channel) {

      String channelName= channel.toString();
      if ( channelName != null ) channelName=channelName.trim();

      logger.debug("************************************ ******");
      if ( "ws-s-generic-requests".equalsIgnoreCase(channelName))
      logger.debug("Request recived in " + channelName);
      } else
      logger.debug("Response sent back through " + channelName);
      logger.debug("Channel=" + channel.toString());
      logger.debug("Header - UID=" +message.getHeaders().getId());
      logger.debug("Reply to channel=" + message.getHeaders().getReplyChannel());
      logger.debug("Header - Expirtaion Date=" +message.getHeaders().getExpirationDate());
      logger.debug("Header - Priority=" +message.getHeaders().getPriority());
      logger.debug("Header - Sequence #=" +message.getHeaders().getSequenceNumber());
      logger.debug("Header - Timestamp=" +message.getHeaders().getTimestamp());
      logger.debug("PayLoad - Payload=" + this.getStringFromDocument( (DOMSource) message.getPayload()) );

      logger.debug("************************************ ******");
      return message;

      //method to convert Document to String
      public String getStringFromDocument(DOMSource domSource)

      StringWriter writer = new StringWriter();
      StreamResult result = new StreamResult(writer);
      TransformerFactory tf = TransformerFactory.newInstance();
      Transformer transformer = tf.newTransformer();
      transformer.transform(domSource, result);
      return writer.toString();
      catch(TransformerException ex)
      return null;


      • #4

        1. Your advice to use Interceptor helped and now I can get request & response message details in log

        2. Please ignore my earlier problem of web service being called twice. What happened was by mistake in web.xml & servlet config file, I ended up having two message dispatcher and hence teh issue. When I fixed thta, now I see web service being invoked only once per each request.

        I feel SI is a great product and I am enjoying every bit of working with it.

        Many thanks.