Skip to content

Commit

Permalink
Add WSDL xmlns header attribute (#1093)
Browse files Browse the repository at this point in the history
* Update client.ts

* Add xmlnsInHeader attribute

* Add missing whitespace

* Do not modify the initial header options

Since I've modified the initial spec of the package, the tests will fail

* Add custom client test for user defined header arguments

* Add custom client test for user defined header arguments
  • Loading branch information
mateioprea authored and jsdevel committed Nov 5, 2019
1 parent 6b5ba3e commit af93a6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export class Client extends EventEmitter {
this.wsdl.xmlnsInEnvelope + '>' +
((decodedHeaders || this.security) ?
(
'<' + envelopeKey + ':Header>' +
'<' + envelopeKey + ':Header' + (this.wsdl.xmlnsInHeader ? (' ' + this.wsdl.xmlnsInHeader) : '') + '>' +
(decodedHeaders ? decodedHeaders : '') +
(this.security && !this.security.postProcess ? this.security.toXML() : '') +
'</' + envelopeKey + ':Header>'
Expand Down
1 change: 1 addition & 0 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class WSDL {
public valueKey = '$value';
public xmlKey = '$xml';
public xmlnsInEnvelope: string;
public xmlnsInHeader: string;
public uri: string;
public definitions: elements.DefinitionsElement;
public options: IInitializedOptions;
Expand Down
14 changes: 14 additions & 0 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,20 @@ var fs = require('fs'),
});
});

it('shall generate correct header for custom defined header arguments', function(done) {
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl').then(function (client) {
client.addSoapHeader('test-header-namespace')
client.wsdl.xmlnsInHeader = 'xmlns="https://example.com/v1"';
var expectedDefinedHeader = '<soap:Header xmlns="https://example.com/v1">';

client.MyOperation(function(err, result, rawResponse, soapHeader, rawRequest) {
var definedSoapHeader = client.lastRequest.match(/<soap:Header xmlns=("(.*?)">)/)[0];
assert.ok(definedSoapHeader === expectedDefinedHeader);
done();
});
});
});

it('should create async client without options', function (done) {
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl').then(function (client) {
assert.ok(client);
Expand Down

0 comments on commit af93a6f

Please sign in to comment.