Display SMO Contents using Custom Mediations and the BOXMLSerializer

Updated 2007-08-28: incorporated Art’s suggestion, which makes the code simpler.

Sometimes you might want to display the contents of a message that’s being processed in a WebSphere ESB mediation flow. One option is to use the Message Logger mediation. However, this has some limitations: it can only log to a database, and by default, this is an embedded Cloudscape database, which is hard to access whilst the server is running. The WebSphere Integration Developer debugger is another option, but this isn’t always suitable if you want to do this repeatedly.

Often, a lighter-weight way is to use the BOXMLSerializer class inside a custom mediation. This enables you to serialize the entire Service Message Object (which contains the body of your message, the headers, and so on) that is being processed in the flow, and output it as XML. This also has the advantage of clearly illustrating the structure of the SMO. Here’s some example code that you could put in a method inside a custom mediation to do exactly that (you’ll probably want to do this using the ‘Invoke’ method to invoke an external Java SCA component, although you could use the ‘Java’ snippet method instead):

public DataObject mediate(
        DataObject input1) {
    BOFactory factoryService = (BOFactory)
            new ServiceManager()
            .locateService
            ("com/ibm/websphere/bo/BOFactory");
    BOXMLSerializer xmlSerializerService
             = (BOXMLSerializer) new ServiceManager()
            .locateService
            ("com/ibm/websphere/bo/BOXMLSerializer");
    try {
        xmlSerializerService
                .writeDataObject(
                        input1,
                        input1.getType().getURI(),
                        "",
                        System.out);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return input1;
}

The code above prints the contents of the SMO onto standard out – which should appear in the SystemOut.log file for your WebSphere ESB and in the Console view of Websphere Integration Developer. The SMO will look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<ServiceMessageObject:ServiceMessageObject
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ServiceMessageObject=
      "http://www.ibm.com/websphere/sibx/smo/v6.0.1"
    xmlns:info="http://mm1/getPartInfo">
    <context />
    <headers>
        <SMOHeader>
            <MessageUUID>
                BE73C754-0112-4000-E000-61EE09B4A5D7
            </MessageUUID>
            <Version>
                <Version>6</Version>
                <Release>0</Release>
                <Modification>2</Modification>
            </Version>
            <MessageType>Request</MessageType>
        </SMOHeader>
    </headers>
    <body xsi:type="info:operation1RequestMsg">
        <operation1>
            <partNumber>23</partNumber>
        </operation1>
    </body>
</ServiceMessageObject:ServiceMessageObject>

You can see in the SMO above both the headers and the body, and the operation name defined by the interface I was using (operation1), as well the data structure I was using (which was just a single integer called partNumber).

This trick can be very useful for problem diagnosis, or just to keep an eye on what’s going on.

Latest support information

If you are interested in getting the latest support information on IBM products then check out the set of RSS feeds here which will provide you with information on when individual fixes are released, when fix packs are released and other important announcements. For those people who are interested in WebSphere Integration Developer, WebSphere Process Server, WebSphere ESB and WebSphere Service Registry and Repository you may want to check out the pipe I have created here.

From now on, rather than post about individual fix packs on here I will assume people have subscribed to the relevant feeds.