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

Added callback for soap.listen #1055

Merged
merged 2 commits into from Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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