diff --git a/src/server.ts b/src/server.ts index e1ef5cb9a..42fb321af 100644 --- a/src/server.ts +++ b/src/server.ts @@ -81,6 +81,7 @@ export class Server extends EventEmitter { private onewayOptions: IOneWayOptions & { statusCode?: number; }; private enableChunkedEncoding: boolean; private soapHeaders: any[]; + private callback?: (err: any, res: any) => void; constructor(server: ServerType, path: string, services: IServices, wsdl: WSDL, options?: IServerOptions) { super(); @@ -97,7 +98,7 @@ export class Server extends EventEmitter { this.onewayOptions = options && options.oneWay || {}; this.enableChunkedEncoding = options.enableChunkedEncoding === undefined ? true : !!options.enableChunkedEncoding; - + this.callback = options.callback ? options.callback : () => { }; if (path[path.length - 1] !== '/') { path += '/'; } @@ -113,6 +114,7 @@ export class Server extends EventEmitter { } this._requestListener(req, res); }); + this.callback(err, this); } else { const listeners = server.listeners('request').slice(); server.removeAllListeners('request'); @@ -135,6 +137,7 @@ export class Server extends EventEmitter { } } }); + this.callback(err, this); } }); diff --git a/src/soap.ts b/src/soap.ts index 06ab02ef3..04dcc9dac 100644 --- a/src/soap.ts +++ b/src/soap.ts @@ -98,9 +98,9 @@ export function createClientAsync(url: string, options: IOptions, endpoint?: str }); } -export function listen(server: ServerType, path: string, services: IServices, wsdl: string): Server; +export function listen(server: ServerType, path: string, services: IServices, wsdl: string, callback?: (err: any, res: any) => void): Server; export function listen(server: ServerType, options: IServerOptions): Server; -export function listen(server: ServerType, p2: string | IServerOptions, services?: IServices, xml?: string): Server { +export function listen(server: ServerType, p2: string | IServerOptions, services?: IServices, xml?: string, callback?: (err: any, res: any) => void): Server { let options: IServerOptions; let path: string; let uri = ''; @@ -120,6 +120,7 @@ export function listen(server: ServerType, p2: string | IServerOptions, services options = { path: p2, services: services, + callback: callback, }; } diff --git a/src/types.ts b/src/types.ts index ba78f9123..5591416b9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -128,6 +128,7 @@ export interface IServerOptions extends IWsdlBaseOptions { services: IServices; xml?: string; uri?: string; + callback?: (err: any, res: any) => void; /** suppress the full stack trace for error messages. */ suppressStack?: boolean; oneWay?: IOneWayOptions; diff --git a/test/server-options-test.js b/test/server-options-test.js index 726557fed..00778cf39 100644 --- a/test/server-options-test.js +++ b/test/server-options-test.js @@ -104,6 +104,37 @@ describe('SOAP Server with Options', function() { }); }); + it('should start server with callback in options parameter', function(done) { + test.server.listen(15099, null, null, function() { + test.soapServer = soap.listen(test.server, { + path: '/stockquote', + services: test.service, + xml: test.wsdl, + uri: __dirname + '/wsdl/strict/', + escapeXML: false, + callback: function (err) { + assert.ifError(err); + done(); + } + }, test.service, test.wsdl); + }); + }); + + it('should start server with callback as normal parameter', function(done) { + test.server.listen(15099, null, null, function () { + test.soapServer = soap.listen( + test.server, + "/stockquote", + test.service, + test.wsdl, + function (err) { + assert.ifError(err); + done(); + } + ); + }); + }); + it('should be running with escapeXML false', function(done) { test.server.listen(15099, null, null, function() { test.soapServer = soap.listen(test.server, {