Hi - I am trying to write a gateway script in DataPower 10.x firmware version which could route the message to either XML rule or JSON rule based on contentType but the JSON msg is always failing in this case.
/*
GatewayScript to read incoming msg type & route to different rule
*/
var hm = require('header-metadata');
var service = require('service-metadata');
var contentType = hm.current.get('content-type');
console.debug('contentType: %s', contentType);
session.input.readAsXML(
function (readAsXMLError, data) {
if (readAsXMLError) {
session.input.readAsJSON(function (readAsJSONError, jsonData) {
if (readAsJSONError) {
session.input.readAsBuffers(function (readAsBuffersError, blob) {
console.error('Data is neither xml nor json ', blob);
});
} else {
if (contentType.includes("contentType", "*json*")) {
// processing as json message
session.INPUT.setVariable('callrule', 'RESTJSON-v01_Request_Handler')
} else {
console.error('Failed to process json message ', jsonData);
}
}
});
} else {
if (contentType.includes("contentType", "*xml*")) {
// processing as xml message
session.INPUT.setVariable('callrule', 'RESTXML-v01_Request_Handler');
} else {
console.error("Failed to process xml message ", data);
}
}
}
);
#DataPower#Support#SupportMigration