How do I parse an MTOM Response from a rest web service call?

0 votes
asked Feb 6, 2019 by ben-s-7515 (12,320 points)

I am making a simple REST web service call, and the response content is MTOM formatted with multiple parts in it.  Is there an easy way to parse this and process each part individually?


Here is an example of the message received back:

Content-Type: application/xml

Content-Type: application/json


1 Answer

0 votes

Yes, from your script you will call the code wizard function "qie.parseMtomContent()".  This will parse the content for you and return an easy to work with XML structure with the data.

To parse the MTOM content for the sample message above and place it as your new XML message you would execute the following script:

// parse mtom content, and place in new XML message
var mtomContent = qie.parseMtomContent(source.getNode('/'));
message = qie.createXMLMessage(mtomContent);

The message will now be an XML message that looks like this:

   <part name="QveraGeneratedRootContentId_0">
      <partType>Content-Type: application/json</partType>
   <part name="QveraGeneratedRootContentId">
      <partType>Content-Type: application/xml</partType>

To cycle each of the parts, you will run a for loop on the different parts like this:

// cycle content parts
var parts = message.getAllNodes('/mtomContent/part');
for (var currentPart = 0; currentPart < parts.length; currentPart++) {
   var part = qie.parseXMLString(parts[currentPart]);
   qie.debug('Part: ' + part.toString());
   var content = qie.base64Decode(part.getNode('/part/content'));
   qie.debug('Content: ' + content);

This will log out each part individually, and then log out the content for that part.

answered Feb 6, 2019 by ben-s-7515 (12,320 points)