Capturing and Logging SOAP Messages in a Web Service

Article ID: 1176
Last updated: 07 Feb, 2008
Article ID: 1176
Last updated: 07 Feb, 2008
Revision: 1
Views: 2726
Posted: 01 Jan, 2000
by Dean J.
Updated: 07 Feb, 2008
by Dean J.

It can be helpful to capture and log SOAP messages before they are handled by the LEIF server.  In a web service this can be done with the use of a custom logger and handler.  The custom logger allows us to set a different log file from the default log file that LEIF uses.  The handler captures the SOAP message and logs it before the LEIF server processes it.


For the purposes of this article, we will modify the Handlers tutorial located in <install directory>/examples/webservices/Handlers.


Before we can generate the code for the Handlers tutorial we will first need to add our custom logger to the loggers.xml file located in <install directory>/conf/server.  Here are the lines that we will add to loggers.xml:


  <!-- Define a custom logger for SOAP capture -->

  <logger name="mylog" class="leifcore.createFileLogger">

    <property name="filename" value="$/logs/SOAPCapture.log"/>

    <property name="formatter" value="leifcore.createLogTimeFormatter"/>

    <property name="mode" value="overwrite"/>



  <!-- Filter for mylog logger -->

  <logger name="" class="leifcore.createLogLevelFilter">

    <property name="logger" value="mylog"/>

    <property name="filter" value="info"/>



After saving the changes to the loggers.xml file, navigate to <install directory>/examples/webservices/Handlers.  Here we will modify the SoapSecurityHandler.h file to capture the SOAP message only on the Hydra server.  The following three includes need to be added to SoapSecurityHandler.h:


#include <iostream>

#include <rw/leif/core/LogManager.h>

#include <rw/leif/core/Logger.h>


Next, remove the existing lines within the else clause.  These lines add a security header to the SOAP message and are not needed for this exercise.  Add the following lines of code to the else clause to replace the original code:


LEIF::CString myString = callInfo.getRequest();

std::cout << << std::endl;


LEIF::Logger logger = LEIF::LogManager::getLogger("");;


The code above outputs the SOAP message to the Bobcat (LEIF server) console.  It also logs the SOAP message to the SOAPCapture.log file.


At this point we have defined a custom logging service and added the necessary code to capture and log the SOAP message.  The Handlers tutorial can now be followed exactly as described in the readme.txt file.  Basically the steps are as follows:


  1. Generate code with the following command: leifgen example-project.xml.
  2. Copy the following files to the appropriate locations:

            copy /Y HandlersClient.cpp HandlersExampleappclient

      copy /Y SoapSecurityHandler.h HandlersExampleappclient

copy /Y StringReverseHandler.h HandlersExampleappclient

      copy /Y SoapSecurityHandler.h HandlersExampleappserver

copy /Y StringReverseHandler.h HandlersExampleappserver

      copy /Y HandlersImp.cpp HandlersExampleappserver

      copy /Y *.xml HandlersExampleconf


  1. cd HandlersExample
  2. make (UNIX) or nmake (Windows)
  3. make deploy (UNIX) or nmake deploy (Windows)
  4. leifserver start
  5. cd bin
  6. run HandlersClient (UNIX) or HandlersClient.exe (Windows)


In the Bobcat console notice the outputted SOAP message.  Also, navigate to <install directory>/logs and open the SOAPCapture.log file.  The SOAP message was sent from the client to the server where it was then captured and logged. 


From the LEIF client side it is possible to capture the response SOAP message from the server using the same basic steps that were outlined above.  However, from the client, callInfo.getResponse() would be the appropriate call.  For example:


LEIF::CString myString = callInfo.getResponse();


This article was:   Helpful | Not helpful
Report an issue
Article ID: 1176
Last updated: 07 Feb, 2008
Revision: 1
Views: 2726
Posted: 01 Jan, 2000 by Dean J.
Updated: 07 Feb, 2008 by Dean J.

Others in this category