Hi All,
I have a requirement where i need to invoke live service from vsm, capture its response and add some of the xml element values from response and send the new response as the virtual response.
For invoking "Live Invocation step" i have added "return ExecutionMode.LIVE;" in the Virtual service router step. Also in the Live Invocation Step i have given Target Server and Target Port of the live service.
After "Live Invocation Step" i have added "Execute Script" step.
Pleas find the below script which i have used for the same.
var fs = require('fs');
var DOMParser = require('xmldom').DOMParser;
var XMLSerializer = require('xmldom').XMLSerializer;
var filename = "RPM2-rsp.xml";
fs.readFile(filename, "utf-8", function(err, data) {
var customerConfig = new DOMParser().parseFromString(data, "text/xml");
var flight_info = customerConfig.getElementsByTagName("io30:FlightInfo");
for (i = 0; i < flight_info.lenght; i++) {
flight_info[i].setAttribute("CASSEquipmentCode", "C-045");
}
var passengerColumn = customerConfig.getElementsByTagName("io13:PassengerColumn");
for (i = 0; i < passengerColumn.length; i++) {
passengerColumn[i].setAttribute("ProductId", "ASY");
}
var purchase = customerConfig.getElementsByTagName("io13:Offer");
for (i = 0; i < purchase.length; i++) {
purchase[i].setAttribute("Purchasable", "true");
}
var xmlString = new XMLSerializer().serializeToString(customerConfig);
console.log(xmlString);
console.log(flight_info.length);
console.log(purchase.length);
console.log(passengerColumn.length);
fs.unlink(filename, function(err) {
if (err) throw err;
console.log('File deleted!');
});
fs.appendFile(filename, xmlString, function(err) {
if (err) throw err;
console.log('Saved!');
});
});
The code is working fine when executed in Eclipse IDE. But when using the same in the java script step, the code is not working.
I am struck here. Am i missing something? Please guide me how to proceed further.
Thanks,
Ganga