Sidebar

evaluateTemplate against HTTP Content

0 votes
231 views
asked Mar 31, 2021 by bryan-b-6726 (210 points)
I am looking to run evaulateTemplate against my XML HTTP content. I essentially want to "Update" the source to be the value of source.getNode('/Request/Part/Content') so my template can be processed.  I attempted to set the source in the mapping function by doing

source = qie.parseXMLString(source.getNode('/Request/Part/Content'));

but that doesn't seem to be the correct solution. I also don't want to overwrite what I have in message if possible. Any tips?

Thanks!

1 Answer

+1 vote
 
Best answer

The source is a read-only copy that cannot be modified once the message is put into the channel. However, we can do what you need using the "Extract content as message" option. Below is the screenshot  how to set the source to the content:

Script that will apppear in the Script window:

// this script will extract the first content from the HTTP Request and use it as the message
try {
   // parse the bytes as an XML message
   var originalMessage = qie.parseXMLString(new java.lang.String(bytesIn, qie.getChannelEncoding()), qie.getChannelEncoding());
   var result = null;

   // check if we need to base64 decode the content or not
   if ('binary' === originalMessage.getNode('/Request/Part/content-transfer-encoding') + '') {
      result = qie.base64DecodeToBytes(originalMessage.getNode('/Request/Part/Content').trim());
   } else {
      result = originalMessage.getNode('/Request/Part/Content').trim().getBytes(qie.getChannelEncoding());
   }

   bytesOut = result;

   if (bytesOut === null) {  //When null, the message is discarded and no further processing is done
      qie.warn('Discarding message because no content was found: ' + new java.lang.String(bytesIn));
      //todo: when bytesOut = null, set responseBytes to acknowledge the receipt of discarded messages as needed
      responseBytes = new java.lang.String('HTTP Status: 400').getBytes(qie.getChannelEncoding());
   }
} catch (err) {
   qie.warn('Unable to run Preprocess script: ' + err);
   bytesOut = bytesIn;
}

answered Mar 31, 2021 by brandon-w-8204 (33,170 points)
selected Mar 31, 2021 by bryan-b-6726
...