| | | | Browse by category |
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.
Action
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"/>
</logger>
<!-- Filter for mylog logger -->
<logger name="mylog.info" class="leifcore.createLogLevelFilter">
<property name="logger" value="mylog"/>
<property name="filter" value="info"/>
</logger>
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 << myString.data() << std::endl;
LEIF::Logger logger = LEIF::LogManager::getLogger("mylog.info");
logger.info(myString.data());
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:
- Generate code with the following command: leifgen example-project.xml.
- 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
- cd HandlersExample
- make (UNIX) or nmake (Windows)
- make deploy (UNIX) or nmake deploy (Windows)
- leifserver start
- cd bin
- 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();