Skip to content

Commit

Permalink
[FIX] Possible fix vpulim#933 (regression because of introduction of …
Browse files Browse the repository at this point in the history
…new behaviour in vpulim#914)
  • Loading branch information
herom committed May 29, 2017
1 parent 94a8b54 commit b18e382
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
37 changes: 19 additions & 18 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var HttpClient = require('./http'),

var Client = function(wsdl, endpoint, options) {
events.EventEmitter.call(this);
options = options || {};
options = Object.assign({}, options);
this.wsdl = wsdl;
this._initializeOptions(options);
this._initializeServices(endpoint);
Expand Down Expand Up @@ -136,6 +136,8 @@ Client.prototype._initializeOptions = function(options) {
this.wsdl.options.overrideRootElement = options.overrideRootElement;
}
this.wsdl.options.forceSoap12Headers = !!options.forceSoap12Headers;

this.useSequence = !!options.useSequence;
};

Client.prototype._defineService = function(service, endpoint) {
Expand Down Expand Up @@ -183,55 +185,54 @@ Client.prototype._defineMethod = function(method, location) {
};

Client.prototype._isSequenceRequired = function(methodName) {
var tns = this.wsdl.definitions.$targetNamespace;
var methodRequestName = _.result(this.wsdl.definitions, 'messages.' + methodName + '.$name');
var args = _.result(this.wsdl.definitions, 'messages.' + methodRequestName + '.parts');

if(typeof args === 'undefined' && typeof _.pick(args, 'params') !== 'undefined') {
if (!this.useSequence) {
return false;
}
if(Object.keys(args).length === 1) {

var definitions = this.wsdl.definitions;
var tns = definitions.$targetNamespace;
var methodRequestName = _.result(definitions, 'messages.' + methodName + '.$name');
var args = _.result(definitions, 'messages.' + methodRequestName + '.parts');

if(typeof args === 'undefined' || Object.keys(args).length === 1) {
return false;
}

var complexTypeName = _.result(this.wsdl.definitions, 'messages.' + methodRequestName + '.element.$name');
var complexTypeName = _.result(definitions, 'messages.' + methodRequestName + '.element.$name');
var modeOfComplexType = _.result(
this.wsdl.definitions,
definitions,
'schemas[\'' + tns + '\'].elements.' + complexTypeName + '.children[0].children[0].name');

if(modeOfComplexType === 'sequence') {
return true;
}

return false;
return modeOfComplexType === 'sequence';
};

Client.prototype._setSequenceArgs = function(argsScheme, args) {
var result = {};

if(typeof argsScheme !== 'object') {
return args;
}

for (var partIndex in argsScheme) {
if(typeof args[partIndex] === 'undefined') {
continue;
}

if(typeof argsScheme[partIndex] !== 'object') {
result[partIndex] = args[partIndex];
} else {
result[partIndex] = this._setSequenceArgs(argsScheme[partIndex], args[partIndex]);
}
}

return result;
};

Client.prototype._getArgsScheme = function(methodName) {
var methodRequestName = _.result(this.wsdl.definitions, 'messages.'+methodName+'.$name');
var args = _.result(this.wsdl.definitions, 'messages.' + methodRequestName + '.parts');

if(typeof args === 'undefined' && typeof _.pick(args, 'params') !== 'undefined') {
return [];
}
if(Object.keys(args).length === 1) {
if(typeof args === 'undefined' || Object.keys(args).length === 1) {
return [];
}

Expand Down
6 changes: 3 additions & 3 deletions test/sequence-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ var notSequencedRequest = {
describe('Method args sequence', function() {

it('check if method required sequence args', function(done) {
soap.createClient(__dirname + '/wsdl/rpcexample.wsdl', {suffix: '', options: {}}, function(err, client) {
soap.createClient(__dirname + '/wsdl/rpcexample.wsdl', {suffix: '', useSequence: true}, function(err, client) {
assert.ok(client);
assert.ok(client._isSequenceRequired('pullFile') === false);

soap.createClient(__dirname + '/wsdl/sequnceexmple.wsdl', {suffix: '', options: {}}, function(err, client) {
soap.createClient(__dirname + '/wsdl/sequnceexmple.wsdl', {suffix: '', useSequence: true}, function(err, client) {
assert.ok(client);
assert.ok(client._isSequenceRequired('pullFile') === true);
done();
Expand All @@ -44,7 +44,7 @@ describe('Method args sequence', function() {
});

it('check sort args on sequence required method', function(done) {
soap.createClient(__dirname + '/wsdl/sequnceexmple.wsdl', {suffix: '', options: {}}, function(err, client) {
soap.createClient(__dirname + '/wsdl/sequnceexmple.wsdl', {suffix: '', useSequence: true}, function(err, client) {
assert.ok(client);
var sequencedMethodRequest = client._setSequenceArgs(client._getArgsScheme('pullFile'), notSequencedRequest);
assert.ok(JSON.stringify(sequencedMethodRequest) === JSON.stringify(sequencedRequest));
Expand Down

0 comments on commit b18e382

Please sign in to comment.