Skip to content

Commit

Permalink
Merge pull request #1 from casserus/mtom-attachments
Browse files Browse the repository at this point in the history
feat: add mtomAttachments to result
  • Loading branch information
davefej authored Jul 1, 2021
2 parents d3e8954 + 3de5eba commit 49e2e63
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
59 changes: 30 additions & 29 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,12 @@ export class Client extends EventEmitter {
rawResponse: any,
soapHeader: any,
rawRequest: any,
mtomAttachments: any
) => {
if (err) {
reject(err);
} else {
resolve([result, rawResponse, soapHeader, rawRequest]);
resolve([result, rawResponse, soapHeader, rawRequest, mtomAttachments]);
}
};
method(
Expand Down Expand Up @@ -265,31 +266,31 @@ export class Client extends EventEmitter {
extraHeaders = options;
options = temp;
}
this._invoke(method, args, location, (error, result, rawResponse, soapHeader, rawRequest) => {
callback(error, result, rawResponse, soapHeader, rawRequest);
this._invoke(method, args, location, (error, result, rawResponse, soapHeader, rawRequest, mtomAttachments) => {
callback(error, result, rawResponse, soapHeader, rawRequest, mtomAttachments);
}, options, extraHeaders);
};
}

private _processSoapHeader(soapHeader, name, namespace, xmlns) {
switch (typeof soapHeader) {
case 'object':
return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
case 'function':
const _this = this;
// arrow function does not support arguments variable
// tslint:disable-next-line
return function() {
const result = soapHeader.apply(null, arguments);

if (typeof result === 'object') {
return _this.wsdl.objectToXML(result, name, namespace, xmlns, true);
} else {
return result;
}
};
default:
return soapHeader;
case 'object':
return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
case 'function':
const _this = this;
// arrow function does not support arguments variable
// tslint:disable-next-line
return function () {
const result = soapHeader.apply(null, arguments);

if (typeof result === 'object') {
return _this.wsdl.objectToXML(result, name, namespace, xmlns, true);
} else {
return result;
}
};
default:
return soapHeader;
}
}

Expand Down Expand Up @@ -317,7 +318,7 @@ export class Client extends EventEmitter {

if (!output) {
// one-way, no output expected
return callback(null, null, body, obj.Header, xml);
return callback(null, null, body, obj.Header, xml, response.mtomResponseAttachments);
}

// If it's not HTML and Soap Body is empty
Expand All @@ -332,7 +333,7 @@ export class Client extends EventEmitter {
return callback(null, obj, body, obj.Header);
}

if ( typeof obj.Body !== 'object' ) {
if (typeof obj.Body !== 'object') {
const error: ISoapError = new Error('Cannot parse response');
error.response = response;
error.body = body;
Expand All @@ -354,7 +355,7 @@ export class Client extends EventEmitter {
});
}

callback(null, result, body, obj.Header, xml);
callback(null, result, body, obj.Header, xml, response.mtomResponseAttachments);
};

const parseSync = (body, response) => {
Expand All @@ -375,7 +376,7 @@ export class Client extends EventEmitter {
error.response = response;
error.body = body;
this.emit('soapError', error, eid);
return callback(error, response, body, undefined, xml);
return callback(error, response, body, undefined, xml, response.mtomResponseAttachments);
}
return finish(obj, body, response);
};
Expand All @@ -401,7 +402,7 @@ export class Client extends EventEmitter {
if (this.httpHeaders === null) {
headers = {};
} else {
for (const header in this.httpHeaders) { headers[header] = this.httpHeaders[header]; }
for (const header in this.httpHeaders) { headers[header] = this.httpHeaders[header]; }
for (const attr in extraHeaders) { headers[attr] = extraHeaders[attr]; }
}

Expand All @@ -413,9 +414,9 @@ export class Client extends EventEmitter {
this.security.addOptions(options);
}

if ((style === 'rpc') && ( ( input.parts || input.name === 'element' ) || args === null) ) {
if ((style === 'rpc') && ((input.parts || input.name === 'element') || args === null)) {
assert.ok(!style || style === 'rpc', 'invalid message definition for document style binding');
message = this.wsdl.objectToRpcXML(name, args, alias, ns, (input.name !== 'element' ));
message = this.wsdl.objectToRpcXML(name, args, alias, ns, (input.name !== 'element'));
(method.inputSoap === 'encoded') && (encoding = 'soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ');
} else {
assert.ok(!style || style === 'document', 'invalid message definition for rpc style binding');
Expand Down Expand Up @@ -448,8 +449,8 @@ export class Client extends EventEmitter {
'</' + envelopeKey + ':Header>'
)
:
''
) +
''
) +
'<' + envelopeKey + ':Body' +
(this.bodyAttributes ? this.bodyAttributes.join(' ') : '') +
(this.security && this.security.postProcess ? ' Id="_0"' : '') +
Expand Down
7 changes: 4 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ export interface IHttpClient {
export type ISoapMethod = SoapMethod;
export type SoapMethod = (
args: any,
callback: (err: any, result: any, rawResponse: any, soapHeader: any, rawRequest: any) => void,
callback: (err: any, result: any, rawResponse: any, soapHeader: any, rawRequest: any, mtomAttachments?: IMTOMAttachments) => void,
options?: any,
extraHeaders?: any,
mtomAttachments?: IMTOMAttachments
) => void;

export type SoapMethodAsync = (
args: any,
options?: any,
extraHeaders?: any,
) => Promise<[any, any, any, any]>;
) => Promise<[any, any, any, any, IMTOMAttachments?]>;

export type ISoapServiceMethod = (args: any, callback?: (data: any) => void, headers?: any, req?: any, res?: any, sender?: any) => any;

Expand Down Expand Up @@ -157,6 +158,6 @@ export interface IServerOptions extends IWsdlBaseOptions {
export interface IMTOMAttachments {
parts: Array<{
body: Buffer,
headers: {[key: string]: string},
headers: { [key: string]: string },
}>;
}

0 comments on commit 49e2e63

Please sign in to comment.