Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Server): method called with apply #1115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 22 additions & 20 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { EventEmitter } from 'events';
import * as http from 'http';
import * as url from 'url';
import { IOneWayOptions, ISecurity, IServerOptions, IServices, ISoapFault, ISoapServiceMethod } from './types';
import { IOneWayOptions, IServerOptions, IServicePort, IServices, ISoapFault, ISoapServiceMethod } from './types';
import { findPrefix } from './utils';
import { WSDL } from './wsdl';
import { BindingElement, IPort } from './wsdl/elements';
Expand Down Expand Up @@ -173,29 +173,29 @@ export class Server extends EventEmitter {

private _processSoapHeader(soapHeader, name, namespace, xmlns) {
switch (typeof soapHeader) {
case 'object':
return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
case 'function':
const _this = this;
// arrow function does not support arguments variable
// tslint:disable-next-line
return function() {
const result = soapHeader.apply(null, arguments);

if (typeof result === 'object') {
return _this.wsdl.objectToXML(result, name, namespace, xmlns, true);
} else {
return result;
}
};
default:
return soapHeader;
case 'object':
return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
case 'function':
const _this = this;
// arrow function does not support arguments variable
// tslint:disable-next-line
return function () {
const result = soapHeader.apply(null, arguments);

if (typeof result === 'object') {
return _this.wsdl.objectToXML(result, name, namespace, xmlns, true);
} else {
return result;
}
};
default:
return soapHeader;
}
}

private _initializeOptions(options: IServerOptions) {
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
this.onewayOptions.statusCode = this.onewayOptions.responseCode || 200;
this.onewayOptions.statusCode = this.onewayOptions.responseCode || 200;
this.onewayOptions.emptyBody = !!this.onewayOptions.emptyBody;
}

Expand Down Expand Up @@ -468,6 +468,7 @@ export class Server extends EventEmitter {
includeTimestamp?,
) {
options = options || {};
let port: IServicePort;
let method: ISoapServiceMethod;
let body;
let headers;
Expand All @@ -490,6 +491,7 @@ export class Server extends EventEmitter {

try {
method = this.services[serviceName][portName][methodName];
port = this.services[serviceName][portName];
} catch (error) {
return callback(this._envelope('', headers, includeTimestamp));
}
Expand Down Expand Up @@ -546,7 +548,7 @@ export class Server extends EventEmitter {
handleResult(error, result);
};

const result = method(args, methodCallback, options.headers, req);
const result = method.apply(this, [args, methodCallback, options.headers, req]);
if (typeof result !== 'undefined') {
if (isPromiseLike<any>(result)) {
result.then((value) => {
Expand Down