in docker_images/node/wrapper/glue/internalGlue.js [256:284]
exports.internal_WaitForMethodAndReturnResponse = function(objectCache, connectionId,methodName,requestAndResponse) {
debug(`internal_WaitForMethodAndReturnResponse called with ${connectionId}, ${methodName}`);
debug(JSON.stringify(requestAndResponse, null, 2));
return glueUtils.makePromise('internal_RoundtripMethodCall', function(callback) {
var client = objectCache.getObject(connectionId);
var onMethod = client.onMethod || client.onDeviceMethod;
onMethod.bind(client)(methodName, function(request, response) {
debug(`function ${methodName} invoked from service`);
debug(JSON.stringify(request, null, 2));
// Java stringifies the payload. This is why we have the second comparison.
if ((JSON.stringify(request.payload) !== JSON.stringify(requestAndResponse.requestPayload.payload)) &&
(request.payload !== JSON.stringify(requestAndResponse.requestPayload.payload))) {
debug('payload expected:' + JSON.stringify(requestAndResponse.requestPayload.payload));
debug('payload received:' + JSON.stringify(request.payload));
callback(new Error('request payload did not arrive as expected'))
} else {
debug('payload received as expected');
response.send(requestAndResponse.statusCode, requestAndResponse.responsePayload, function(err) {
debug('response sent');
if (err) {
callback(err);
} else {
callback(null, requestAndResponse.responsePayload);
}
});
}
});
});
}