Skip to content

Commit 15542fd

Browse files
committed
feat(Server): method called with applyMethod is "applied" instead of being called directly, which enables access to "this".The owning object for the method is the port, therefore, that's what is being passed as "this".
1 parent 699b984 commit 15542fd

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { EventEmitter } from 'events';
77
import * as http from 'http';
88
import * as url from 'url';
9-
import { IOneWayOptions, ISecurity, IServerOptions, IServices, ISoapFault, ISoapServiceMethod } from './types';
9+
import { IOneWayOptions, IServerOptions, IServicePort, IServices, ISoapFault, ISoapServiceMethod } from './types';
1010
import { findPrefix } from './utils';
1111
import { WSDL } from './wsdl';
1212
import { BindingElement, IPort } from './wsdl/elements';
@@ -173,29 +173,29 @@ export class Server extends EventEmitter {
173173

174174
private _processSoapHeader(soapHeader, name, namespace, xmlns) {
175175
switch (typeof soapHeader) {
176-
case 'object':
177-
return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
178-
case 'function':
179-
const _this = this;
180-
// arrow function does not support arguments variable
181-
// tslint:disable-next-line
182-
return function() {
183-
const result = soapHeader.apply(null, arguments);
184-
185-
if (typeof result === 'object') {
186-
return _this.wsdl.objectToXML(result, name, namespace, xmlns, true);
187-
} else {
188-
return result;
189-
}
190-
};
191-
default:
192-
return soapHeader;
176+
case 'object':
177+
return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
178+
case 'function':
179+
const _this = this;
180+
// arrow function does not support arguments variable
181+
// tslint:disable-next-line
182+
return function () {
183+
const result = soapHeader.apply(null, arguments);
184+
185+
if (typeof result === 'object') {
186+
return _this.wsdl.objectToXML(result, name, namespace, xmlns, true);
187+
} else {
188+
return result;
189+
}
190+
};
191+
default:
192+
return soapHeader;
193193
}
194194
}
195195

196196
private _initializeOptions(options: IServerOptions) {
197197
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
198-
this.onewayOptions.statusCode = this.onewayOptions.responseCode || 200;
198+
this.onewayOptions.statusCode = this.onewayOptions.responseCode || 200;
199199
this.onewayOptions.emptyBody = !!this.onewayOptions.emptyBody;
200200
}
201201

@@ -468,6 +468,7 @@ export class Server extends EventEmitter {
468468
includeTimestamp?,
469469
) {
470470
options = options || {};
471+
let port: IServicePort;
471472
let method: ISoapServiceMethod;
472473
let body;
473474
let headers;
@@ -490,6 +491,7 @@ export class Server extends EventEmitter {
490491

491492
try {
492493
method = this.services[serviceName][portName][methodName];
494+
port = this.services[serviceName][portName];
493495
} catch (error) {
494496
return callback(this._envelope('', headers, includeTimestamp));
495497
}
@@ -546,7 +548,7 @@ export class Server extends EventEmitter {
546548
handleResult(error, result);
547549
};
548550

549-
const result = method(args, methodCallback, options.headers, req);
551+
const result = method.apply(this, [args, methodCallback, options.headers, req]);
550552
if (typeof result !== 'undefined') {
551553
if (isPromiseLike<any>(result)) {
552554
result.then((value) => {

0 commit comments

Comments
 (0)