Announcement Announcement Module
Collapse
No announcement yet.
Logging of response message in ws-outbound-gateway Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 http://static.springsource.org/sprin...r.html#d5e1439

    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.

    Comment


    • #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="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:int="http://www.springframework.org/schema/integration"
      xmlns:stream="http://www.springframework.org/schema/integration/stream"
      xmlns:int-ws="http://www.springframework.org/schema/integration/ws"
      xsi:schemaLocation="http://www.springframework.org/schema/integration/ws
      http://www.springframework.org/schem...gration-ws.xsd
      http://www.springframework.org/schema/integration
      http://www.springframework.org/schem...ntegration.xsd
      http://www.springframework.org/schem...gration/stream
      http://www.springframework.org/schem...ion-stream.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schem...ontext-3.0.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd">


      <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"
      reply-channel="ws-s-generic-ws-reply"
      />





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









      <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:header-enricher>



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

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

      </int:channel>



      </beans>





      package .....

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

      @Component
      public class MessageAuditService extends ChannelInterceptorAdapter {

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




      @Override
      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)
      {
      try
      {

      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)
      {
      ex.printStackTrace();
      return null;
      }
      }
      }

      Comment


      • #4
        Gary,

        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.

        Comment

        Working...
        X