Skip to content

Commit

Permalink
Added callback for soap.listen (#1055)
Browse files Browse the repository at this point in the history
* Added on ready callback for soap.listen

* Fix: removed early return in wsdl.onReady
  • Loading branch information
Niklas Wigertz Danielsson authored and jsdevel committed Mar 28, 2019
1 parent 0144895 commit 33e170e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/server.ts
Expand Up @@ -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();
Expand All @@ -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 += '/';
}
Expand All @@ -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');
Expand All @@ -135,6 +137,7 @@ export class Server extends EventEmitter {
}
}
});
this.callback(err, this);
}
});

Expand Down
5 changes: 3 additions & 2 deletions src/soap.ts
Expand Up @@ -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 = '';
Expand All @@ -120,6 +120,7 @@ export function listen(server: ServerType, p2: string | IServerOptions, services
options = {
path: p2,
services: services,
callback: callback,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions test/server-options-test.js
Expand Up @@ -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, {
Expand Down

0 comments on commit 33e170e

Please sign in to comment.