Skip to content

Commit

Permalink
Merge pull request #117 from Optum/master
Browse files Browse the repository at this point in the history
Fix  Fix for SOAP services returning only first response (stable)
  • Loading branch information
zparks authored Nov 6, 2018
2 parents 0eef372 + 92b453c commit 4ef52cf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
7 changes: 0 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@ function init() {
const users = require('./routes/users');
app.use('/api/users', users);

//Error Handling
app.use(function(err, req, res, next){
console.log(err.stack);
res.status(404).send(err.message);
});


// ready for testing (see test/test.js)
app.emit('started');
}
Expand Down
83 changes: 44 additions & 39 deletions routes/virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,53 +61,58 @@ function registerRRPair(service, rrpair) {
}
}

// match request body based on template
let templates = service.matchTemplates;
// try exact math
match = deepEquals(payload, reqData);

if (templates && templates.length) {
for (let template of templates) {
if (rrpair.payloadType === 'XML') {
xml2js.parseString(template, function(err, xmlTemplate) {
if (err) {
debug(err);
return;
if (!match) {
// match based on template
let templates = service.matchTemplates;

if (templates && templates.length) {
for (let template of templates) {
if (!template) {
break;
}

if (rrpair.payloadType === 'XML') {
xml2js.parseString(template, function(err, xmlTemplate) {
if (err) {
debug(err);
return;
}
template = xmlTemplate;
});
}
else if (rrpair.payloadType === 'JSON') {
try {
template = JSON.parse(template);
}
catch(e) {
debug(e);
continue;
}
template = xmlTemplate;
});
}
else if (rrpair.payloadType === 'JSON') {
try {
template = JSON.parse(template);
}
catch(e) {
debug(e);
continue;

const flatTemplate = flattenObject(template);
const flatPayload = flattenObject(payload);
const flatReqData = flattenObject(reqData);

const trimmedPayload = {}; const trimmedReqData = {};

for (let field in flatTemplate) {
trimmedPayload[field] = flatPayload[field];
trimmedReqData[field] = flatReqData[field];
}
}

const flatTemplate = flattenObject(template);
const flatPayload = flattenObject(payload);
const flatReqData = flattenObject(reqData);

const trimmedPayload = {}; const trimmedReqData = {};

for (let field in flatTemplate) {
trimmedPayload[field] = flatPayload[field];
trimmedReqData[field] = flatReqData[field];
debug('received payload (from template): ' + JSON.stringify(trimmedPayload, null, 2));
debug('expected payload (from template): ' + JSON.stringify(trimmedReqData, null, 2));

match = deepEquals(trimmedPayload, trimmedReqData);

if (match) break;
}

debug('received payload (from template): ' + JSON.stringify(trimmedPayload, null, 2));
debug('expected payload (from template): ' + JSON.stringify(trimmedReqData, null, 2));

match = deepEquals(trimmedPayload, trimmedReqData);

if (match) break;
}
}
// else match against all fields
else {
match = deepEquals(payload, reqData);
}

if (!rrpair.reqData || match) {
// check request queries
Expand Down

0 comments on commit 4ef52cf

Please sign in to comment.