Skip to content

Commit dedd6dc

Browse files
authored
Merge branch 'vpulim:master' into namespace-redefined-in-element
2 parents 22c8c88 + a7eb0fb commit dedd6dc

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/server.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface Server {
6464
interface IExecuteMethodOptions {
6565
serviceName?: string;
6666
portName?: string;
67+
soapAction?: string;
6768
methodName?: string;
6869
outputName?: string;
6970
args?: any;
@@ -283,6 +284,13 @@ export class Server extends EventEmitter {
283284
}
284285
}
285286

287+
private _getSoapAction(req: Request) {
288+
const soapAction: string = req.headers['soapaction'] as string;
289+
return (soapAction.indexOf('"') === 0)
290+
? soapAction.slice(1, -1)
291+
: soapAction;
292+
}
293+
286294
private _process(input, req: Request, res: Response, cb: (result: any, statusCode?: number) => any) {
287295
const pathname = url.parse(req.url).pathname.replace(/\/$/, '');
288296
const obj = this.wsdl.xmlToObject(input);
@@ -360,6 +368,7 @@ export class Server extends EventEmitter {
360368
this._executeMethod({
361369
serviceName: serviceName,
362370
portName: portName,
371+
soapAction: this._getSoapAction(req),
363372
methodName: methodName,
364373
outputName: methodName + 'Response',
365374
args: body[methodName],
@@ -380,6 +389,7 @@ export class Server extends EventEmitter {
380389
this._executeMethod({
381390
serviceName: serviceName,
382391
portName: portName,
392+
soapAction: this._getSoapAction(req),
383393
methodName: pair.methodName,
384394
outputName: pair.outputName,
385395
args: body[messageElemName],
@@ -464,6 +474,13 @@ export class Server extends EventEmitter {
464474
}
465475
}
466476

477+
private _getMethodNameBySoapAction(binding: BindingElement, soapAction: string) {
478+
for (const methodName in binding.methods) {
479+
if (binding.methods[methodName].soapAction === soapAction)
480+
return methodName;
481+
}
482+
}
483+
467484
private _executeMethod(
468485
options: IExecuteMethodOptions,
469486
req: Request,
@@ -477,7 +494,10 @@ export class Server extends EventEmitter {
477494
let headers;
478495
const serviceName = options.serviceName;
479496
const portName = options.portName;
480-
const methodName = options.methodName;
497+
const binding = this.wsdl.definitions.services[serviceName].ports[portName].binding;
498+
const methodName = options.soapAction
499+
? this._getMethodNameBySoapAction(binding, options.soapAction)
500+
: options.methodName;
481501
const outputName = options.outputName;
482502
const args = options.args;
483503
const style = options.style;
@@ -523,13 +543,13 @@ export class Server extends EventEmitter {
523543
if (style === 'rpc') {
524544
body = this.wsdl.objectToRpcXML(outputName, result, '', this.wsdl.definitions.$targetNamespace);
525545
} else {
526-
const element = this.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output;
546+
const element = binding.methods[methodName].output;
527547
body = this.wsdl.objectToDocumentXML(outputName, result, element.targetNSAlias, element.targetNamespace);
528548
}
529549
callback(this._envelope(body, headers, includeTimestamp));
530550
};
531551

532-
if (!this.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output) {
552+
if (!binding.methods[methodName].output) {
533553
// no output defined = one-way operation so return empty response
534554
handled = true;
535555
body = '';

0 commit comments

Comments
 (0)