Skip to content

Unwrapping a Vendor Envelope from an HTTP Body

Some HTTP partners deliver their payload inside their own XML wrapper, typically a multi-part envelope such as <Request><Part><Content>...</Content></Part></Request>, sometimes with the inner content base64-encoded. The downstream channel needs just the payload; qie.evaluateTemplate and node-tag expressions need to operate on it directly, not on the wrapper.

The standard Extract Content As Message checkbox on the HTTP Listener strips QIE's own request envelope, but does not peel off a vendor-defined inner envelope. Use a custom preprocess script when the body itself has additional wrapping.

Source-side configuration

Leave Extract Content As Message unchecked. Open the source node's Preprocess Script and replace the default body with the script below, adjusting the node paths to match the partner's schema.

Preprocess script

try {
    var envelope = qie.parseXMLString(
        new java.lang.String(bytesIn, qie.getChannelEncoding()),
        qie.getChannelEncoding()
    );
    var payload;

    // If the partner marks the inner content as base64, decode it; otherwise pass through.
    if ("binary".equals(envelope.getNode("/Request/Part/content-transfer-encoding") + "")) {
        payload = qie.base64DecodeToBytes(envelope.getNode("/Request/Part/Content").trim());
    } else {
        payload = envelope.getNode("/Request/Part/Content")
                          .trim()
                          .getBytes(qie.getChannelEncoding());
    }

    bytesOut = payload;

    if (bytesOut == null) {
        qie.warn("Discarding HTTP message; no content found: " + new java.lang.String(bytesIn));
        responseBytes = new java.lang.String("HTTP Status: 400").getBytes(qie.getChannelEncoding());
    }
} catch (Exception err) {
    qie.warn("Preprocess script error: " + err);
    bytesOut = bytesIn;
}

What the script does:

  1. Parses the raw HTTP body as XML into a working envelope model.
  2. Reads /Request/Part/content-transfer-encoding to decide whether the inner payload is base64-encoded.
  3. Emits just the inner content as bytesOut so the channel sees the real payload.
  4. Falls back to passing the original bytes through on any parse error, so the message reaches the error queue with the original payload preserved.

Adapting to other envelopes

Replace the node paths (/Request/Part/Content, /Request/Part/content-transfer-encoding) with whatever the partner's schema uses. For multi-part bodies that contain more than one content section, iterate envelope.getCount('/Request/Part') and spawn one outbound message per part with qie.spawnNewMessage. See Splitting One Message into Many for the spawn pattern.