Skip to content

Commit d403300

Browse files
smokhovaurelmegn
andauthored
Improve request handling when there is no explicit Body (#1424)
--------- Co-authored-by: Aurel <megnigbetoa@gmail.com>
1 parent c2493a3 commit d403300

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/server.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ function getDateString(d) {
3838
//eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
3939
export interface Server {
4040
emit(event: 'request', request: any, methodName: string): boolean;
41+
4142
emit(event: 'headers', headers: any, methodName: string): boolean;
43+
4244
emit(event: 'response', headers: any, methodName: string): boolean;
4345

4446
/** Emitted for every received messages. */
4547
on(event: 'request', listener: (request: any, methodName: string) => void): this;
48+
4649
/** Emitted when the SOAP Headers are not empty. */
4750
on(event: 'headers', listener: (headers: any, methodName: string) => void): this;
51+
4852
/** Emitted before sending SOAP response. */
4953
on(event: 'response', listener: (response: any, methodName: string) => void): this;
5054
}
@@ -285,7 +289,7 @@ export class Server extends EventEmitter {
285289
private _process(input, req: Request, res: Response, cb: (result: any, statusCode?: number) => any) {
286290
const pathname = url.parse(req.url).pathname.replace(/\/$/, '');
287291
const obj = this.wsdl.xmlToObject(input);
288-
const body = obj.Body;
292+
const body = obj.Body ? obj.Body : obj;
289293
const headers = obj.Header;
290294
let binding: BindingElement;
291295
let methodName: string;
@@ -353,9 +357,9 @@ export class Server extends EventEmitter {
353357
try {
354358
const soapAction = this._getSoapAction(req);
355359
const messageElemName = Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0];
356-
const pair = binding.topElements[messageElemName];
360+
const pair = binding.topElements[messageElemName] ? binding.topElements[messageElemName] : binding.topElements[soapAction];
357361
if (soapAction) {
358-
methodName = this._getMethodNameBySoapAction(binding, soapAction);
362+
methodName = this._getMethodNameBySoapActionSuffix(binding, soapAction);
359363
} else {
360364
methodName = pair ? pair.methodName : messageElemName;
361365
}
@@ -491,12 +495,27 @@ export class Server extends EventEmitter {
491495
}
492496
}
493497

494-
private _getMethodNameBySoapAction(binding: BindingElement, soapAction: string) {
498+
private _getMethodNameBySoapActionSuffix(binding: BindingElement, soapAction: string): string | null {
499+
const methodName = this._getMethodNameBySoapAction(binding, soapAction);
500+
501+
if (methodName) {
502+
return methodName;
503+
}
504+
for (const methodName in binding.methods) {
505+
const parts = binding.methods[methodName].soapAction.split('/');
506+
if (parts.reverse()[0] === soapAction) {
507+
return methodName;
508+
}
509+
}
510+
}
511+
512+
private _getMethodNameBySoapAction(binding: BindingElement, soapAction: string): string | null {
495513
for (const methodName in binding.methods) {
496514
if (binding.methods[methodName].soapAction === soapAction) {
497515
return methodName;
498516
}
499517
}
518+
return null;
500519
}
501520

502521
private _executeMethod(options: IExecuteMethodOptions, req: Request, res: Response, callback: (result: any, statusCode?: number) => any, includeTimestamp?) {

0 commit comments

Comments
 (0)