From c416c099bd562e9a35dd70cca0970911f0496c46 Mon Sep 17 00:00:00 2001 From: Otto Kruse Date: Mon, 9 Apr 2018 12:47:41 +0200 Subject: [PATCH 1/2] Create SOAP headers at the end. Support returning Promise --- lib/server.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/server.js b/lib/server.js index 97fedd961..d419d9f81 100644 --- a/lib/server.js +++ b/lib/server.js @@ -340,7 +340,7 @@ Server.prototype._process = function (input, req, callback) { Server.prototype._executeMethod = function (options, req, callback, includeTimestamp) { options = options || {}; var self = this, - method, body, headers, + method, body, serviceName = options.serviceName, portName = options.portName, methodName = options.methodName, @@ -349,20 +349,22 @@ Server.prototype._executeMethod = function (options, req, callback, includeTimes style = options.style, handled = false; - if (this.soapHeaders) { - headers = this.soapHeaders.map(function(header) { - if (typeof header === 'function') { - return header(methodName, args, options.headers, req); - } else { - return header; - } - }).join("\n"); + function getSoapHeaders() { + if (this.soapHeaders) { + return this.soapHeaders.map(function(header) { + if (typeof header === 'function') { + return header(methodName, args, options.headers, req); + } else { + return header; + } + }).join("\n"); + } } try { method = this.services[serviceName][portName][methodName]; } catch (error) { - return callback(this._envelope('', headers, includeTimestamp)); + return callback(this._envelope('', getSoapHeaders(), includeTimestamp)); } function handleResult(error, result) { @@ -384,7 +386,7 @@ Server.prototype._executeMethod = function (options, req, callback, includeTimes var element = self.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output; body = self.wsdl.objectToDocumentXML(outputName, result, element.targetNSAlias, element.targetNamespace); } - callback(self._envelope(body, headers, includeTimestamp)); + callback(self._envelope(body, getSoapHeaders(), includeTimestamp)); } if (!self.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output) { @@ -392,13 +394,13 @@ Server.prototype._executeMethod = function (options, req, callback, includeTimes handled = true; body = ''; if (this.onewayOptions.emptyBody) { - body = self._envelope('', headers, includeTimestamp); + body = self._envelope('', getSoapHeaders(), includeTimestamp); } callback(body, this.onewayOptions.responseCode); } var result = method(args, handleResult, options.headers, req); - if (typeof result !== 'undefined') { + if (typeof result !== 'undefined' && typeof result.then !== 'function') { handleResult(result); } }; From b83e434c1a9068510d135c778317021f09516d29 Mon Sep 17 00:00:00 2001 From: Otto Kruse Date: Mon, 9 Apr 2018 12:47:41 +0200 Subject: [PATCH 2/2] Create SOAP headers at the end. Support returning Promise --- lib/server.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/server.js b/lib/server.js index 97fedd961..918302605 100644 --- a/lib/server.js +++ b/lib/server.js @@ -340,7 +340,7 @@ Server.prototype._process = function (input, req, callback) { Server.prototype._executeMethod = function (options, req, callback, includeTimestamp) { options = options || {}; var self = this, - method, body, headers, + method, body, serviceName = options.serviceName, portName = options.portName, methodName = options.methodName, @@ -349,20 +349,22 @@ Server.prototype._executeMethod = function (options, req, callback, includeTimes style = options.style, handled = false; - if (this.soapHeaders) { - headers = this.soapHeaders.map(function(header) { - if (typeof header === 'function') { - return header(methodName, args, options.headers, req); - } else { - return header; - } - }).join("\n"); + function getSoapHeaders() { + if (self.soapHeaders) { + return self.soapHeaders.map(function(header) { + if (typeof header === 'function') { + return header(methodName, args, options.headers, req); + } else { + return header; + } + }).join("\n"); + } } try { method = this.services[serviceName][portName][methodName]; } catch (error) { - return callback(this._envelope('', headers, includeTimestamp)); + return callback(this._envelope('', getSoapHeaders(), includeTimestamp)); } function handleResult(error, result) { @@ -384,7 +386,7 @@ Server.prototype._executeMethod = function (options, req, callback, includeTimes var element = self.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output; body = self.wsdl.objectToDocumentXML(outputName, result, element.targetNSAlias, element.targetNamespace); } - callback(self._envelope(body, headers, includeTimestamp)); + callback(self._envelope(body, getSoapHeaders(), includeTimestamp)); } if (!self.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output) { @@ -392,13 +394,13 @@ Server.prototype._executeMethod = function (options, req, callback, includeTimes handled = true; body = ''; if (this.onewayOptions.emptyBody) { - body = self._envelope('', headers, includeTimestamp); + body = self._envelope('', getSoapHeaders(), includeTimestamp); } callback(body, this.onewayOptions.responseCode); } var result = method(args, handleResult, options.headers, req); - if (typeof result !== 'undefined') { + if (typeof result !== 'undefined' && typeof result.then !== 'function') { handleResult(result); } };