Skip to content

Commit

Permalink
* prefer SOAPAction header over the body name to get the actual metho…
Browse files Browse the repository at this point in the history
…d name (#1152)
  • Loading branch information
paulish authored Jul 26, 2021
1 parent 03d1f78 commit a7eb0fb
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface Server {
interface IExecuteMethodOptions {
serviceName?: string;
portName?: string;
soapAction?: string;
methodName?: string;
outputName?: string;
args?: any;
Expand Down Expand Up @@ -283,6 +284,13 @@ export class Server extends EventEmitter {
}
}

private _getSoapAction(req: Request) {
const soapAction: string = req.headers['soapaction'] as string;
return (soapAction.indexOf('"') === 0)

This comment has been minimized.

Copy link
@MrOldProger

MrOldProger Oct 20, 2021

If SOAPActin header is not sent, this causes 500 Internal server error, because soapAction is undefined.

This comment has been minimized.

Copy link
@jsdevel

jsdevel Nov 3, 2021

Collaborator

please submit a PR

? soapAction.slice(1, -1)
: soapAction;
}

private _process(input, req: Request, res: Response, cb: (result: any, statusCode?: number) => any) {
const pathname = url.parse(req.url).pathname.replace(/\/$/, '');
const obj = this.wsdl.xmlToObject(input);
Expand Down Expand Up @@ -360,6 +368,7 @@ export class Server extends EventEmitter {
this._executeMethod({
serviceName: serviceName,
portName: portName,
soapAction: this._getSoapAction(req),
methodName: methodName,
outputName: methodName + 'Response',
args: body[methodName],
Expand All @@ -380,6 +389,7 @@ export class Server extends EventEmitter {
this._executeMethod({
serviceName: serviceName,
portName: portName,
soapAction: this._getSoapAction(req),
methodName: pair.methodName,
outputName: pair.outputName,
args: body[messageElemName],
Expand Down Expand Up @@ -464,6 +474,13 @@ export class Server extends EventEmitter {
}
}

private _getMethodNameBySoapAction(binding: BindingElement, soapAction: string) {
for (const methodName in binding.methods) {
if (binding.methods[methodName].soapAction === soapAction)
return methodName;
}
}

private _executeMethod(
options: IExecuteMethodOptions,
req: Request,
Expand All @@ -477,7 +494,10 @@ export class Server extends EventEmitter {
let headers;
const serviceName = options.serviceName;
const portName = options.portName;
const methodName = options.methodName;
const binding = this.wsdl.definitions.services[serviceName].ports[portName].binding;
const methodName = options.soapAction
? this._getMethodNameBySoapAction(binding, options.soapAction)
: options.methodName;
const outputName = options.outputName;
const args = options.args;
const style = options.style;
Expand Down Expand Up @@ -523,13 +543,13 @@ export class Server extends EventEmitter {
if (style === 'rpc') {
body = this.wsdl.objectToRpcXML(outputName, result, '', this.wsdl.definitions.$targetNamespace);
} else {
const element = this.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output;
const element = binding.methods[methodName].output;
body = this.wsdl.objectToDocumentXML(outputName, result, element.targetNSAlias, element.targetNamespace);
}
callback(this._envelope(body, headers, includeTimestamp));
};

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

0 comments on commit a7eb0fb

Please sign in to comment.