From 847ec163ce55abd693644afddd2ac6de8f6cb57a Mon Sep 17 00:00:00 2001 From: bogdan Date: Mon, 16 Jan 2017 18:08:28 +0700 Subject: [PATCH 1/8] add fields sequence if it's required --- lib/client.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/client.js b/lib/client.js index 58c456f21..a61e473a1 100644 --- a/lib/client.js +++ b/lib/client.js @@ -182,6 +182,44 @@ Client.prototype._defineMethod = function(method, location) { }; }; +Client.prototype._isSequenceRequired = function(method) { + try { + if(method.input.children[0].children[0].name === 'sequence') { + return true; + } + return false; + } catch(err) { + return false; + } +}; + +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) { + try { + return this.wsdl.definitions.messages[methodName].parts; + } catch(err) { + return false; + } +}; + Client.prototype._invoke = function(method, args, location, callback, options, extraHeaders) { var self = this, name = method.$name, @@ -202,6 +240,13 @@ Client.prototype._invoke = function(method, args, location, callback, options, e }, xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://schemas.xmlsoap.org/soap/envelope/\""; + if(this._isSequenceRequired(method)) { + var argsScheme = this._getArgsScheme(name); + if(argsScheme) { + args = this._setSequenceArgs(argsScheme, args); + } + } + if (this.wsdl.options.forceSoap12Headers) { headers["Content-Type"] = "application/soap+xml; charset=utf-8"; xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://www.w3.org/2003/05/soap-envelope\""; From f382547f2cc01712a48fae7e73b9aead2b579e3f Mon Sep 17 00:00:00 2001 From: bogdan Date: Tue, 17 Jan 2017 07:58:06 +0700 Subject: [PATCH 2/8] add test and fix get sequence element method (not ended) --- lib/client.js | 16 +++++++++++----- test/client-test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/client.js b/lib/client.js index a61e473a1..46b4f2957 100644 --- a/lib/client.js +++ b/lib/client.js @@ -184,7 +184,9 @@ Client.prototype._defineMethod = function(method, location) { Client.prototype._isSequenceRequired = function(method) { try { - if(method.input.children[0].children[0].name === 'sequence') { + var tns = this.wsdl.definitions.xmlns.tns; + var childrenName = this.wsdl.definitions.schemas[tns].complexTypes.pullFileParams.children[0].name; + if(childrenName === 'sequence') { return true; } return false; @@ -240,13 +242,17 @@ Client.prototype._invoke = function(method, args, location, callback, options, e }, xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://schemas.xmlsoap.org/soap/envelope/\""; - if(this._isSequenceRequired(method)) { - var argsScheme = this._getArgsScheme(name); - if(argsScheme) { - args = this._setSequenceArgs(argsScheme, args); + if(name === 'pullFile') { + if(this._isSequenceRequired(method)) { + var argsScheme = this._getArgsScheme(name); + if(argsScheme) { + args = this._setSequenceArgs(argsScheme, args); + } + console.log(args); } } + if (this.wsdl.options.forceSoap12Headers) { headers["Content-Type"] = "application/soap+xml; charset=utf-8"; xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://www.w3.org/2003/05/soap-envelope\""; diff --git a/test/client-test.js b/test/client-test.js index 1331ae6a9..fef168cce 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -838,5 +838,36 @@ var fs = require('fs'), }); }); }); + + describe('Method args sequence', function() { + + // it('check if method required sequence args', function(done) { + // soap.createClient(__dirname + '/wsdl/rpcexample.wsdl', meta.options, function(err, client) { + // assert.ok(client); + // assert.ok(client._isSequenceRequired(client.wsdl.definitions.bindings.RpcExample.methods.pullFile) === true); + // done(); + // }); + // }); + + it('check sort args on sequence required method', function(done) { + soap.createClient(__dirname + '/wsdl/rpcexample.wsdl', meta.options, function(err, client) { + assert.ok(client); + assert.ok(true); + client.pullFile({ + 'password': 'qwerty', + 'base64EncodedCallback': '123', + 'username': 'qwert', + 'forceOverwrite': true, + 'fileMode': 1, + 'fileName': 'qwe.txt', + 'url': 'https://github.com' + }, function(err, result) { + assert.ok(result); + done(); + }); + }); + }); + + }); }); }); From 4cecdeca11be84e53fe6f4001a50f8b802b7e3e5 Mon Sep 17 00:00:00 2001 From: bogdan Date: Fri, 20 Jan 2017 18:05:02 +0700 Subject: [PATCH 3/8] sequence set for wsdl files where params right parsed in wsdl.js --- lib/client.js | 54 ++++++++++++++++++++----------- lib/wsdl.js | 2 +- test/client-test.js | 31 ------------------ test/sequence-test.js | 55 +++++++++++++++++++++++++++++++ test/wsdl/sequnceexmple.wsdl | 63 ++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 51 deletions(-) create mode 100644 test/sequence-test.js create mode 100644 test/wsdl/sequnceexmple.wsdl diff --git a/lib/client.js b/lib/client.js index 46b4f2957..06a6f2377 100644 --- a/lib/client.js +++ b/lib/client.js @@ -182,17 +182,27 @@ Client.prototype._defineMethod = function(method, location) { }; }; -Client.prototype._isSequenceRequired = function(method) { - try { - var tns = this.wsdl.definitions.xmlns.tns; - var childrenName = this.wsdl.definitions.schemas[tns].complexTypes.pullFileParams.children[0].name; - if(childrenName === 'sequence') { - return true; - } +Client.prototype._isSequenceRequired = function(methodName) { + var tns = this.wsdl.definitions.$targetNamespace; + var tnsObject = this.wsdl._splitQName(tns); + var methodRequestName = _.result(this.wsdl.definitions, 'bindings.'+tnsObject.name+'.methods.'+methodName+'.input.$name'); + + // here must be declare method args if declared only params we can't get service methods args and set sequence fields + var args = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.parts'); + if(typeof args === 'undefined' && typeof _.pick(args, 'params') !== 'undefined') { return false; - } catch(err) { + } + if(Object.keys(args).length === 1) { return false; } + + + var complexTypeName = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.element.$name'); + var modeOfComplexType = _.result(this.wsdl.definitions, 'schemas.'+tns+'.elements.'+complexTypeName+'.children[0].children[0].name'); + if(modeOfComplexType === 'sequence') { + return true; + } + return false; }; Client.prototype._setSequenceArgs = function(argsScheme, args) { @@ -215,11 +225,19 @@ Client.prototype._setSequenceArgs = function(argsScheme, args) { }; Client.prototype._getArgsScheme = function(methodName) { - try { - return this.wsdl.definitions.messages[methodName].parts; - } catch(err) { - return false; + var tns = this.wsdl.definitions.$targetNamespace; + var tnsObject = this.wsdl._splitQName(tns); + var methodRequestName = _.result(this.wsdl.definitions, 'bindings.'+tnsObject.name+'.methods.'+methodName+'.input.$name'); + + // here must be declare method args if declared only params we can't get service methods args and set sequence fields + 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) { + return []; } + return args; }; Client.prototype._invoke = function(method, args, location, callback, options, extraHeaders) { @@ -242,17 +260,15 @@ Client.prototype._invoke = function(method, args, location, callback, options, e }, xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://schemas.xmlsoap.org/soap/envelope/\""; - if(name === 'pullFile') { - if(this._isSequenceRequired(method)) { - var argsScheme = this._getArgsScheme(name); - if(argsScheme) { - args = this._setSequenceArgs(argsScheme, args); - } - console.log(args); + if(this._isSequenceRequired(name)) { + var argsScheme = this._getArgsScheme(name); + if(argsScheme) { + args = this._setSequenceArgs(argsScheme, args); } } + if (this.wsdl.options.forceSoap12Headers) { headers["Content-Type"] = "application/soap+xml; charset=utf-8"; xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://www.w3.org/2003/05/soap-envelope\""; diff --git a/lib/wsdl.js b/lib/wsdl.js index 8b069ae1c..68b7bfcb2 100644 --- a/lib/wsdl.js +++ b/lib/wsdl.js @@ -2079,7 +2079,7 @@ WSDL.prototype._fromServices = function(services) { }; - +WSDL.prototype._splitQName = splitQName; WSDL.prototype._xmlnsMap = function() { var xmlns = this.definitions.xmlns; diff --git a/test/client-test.js b/test/client-test.js index fef168cce..1331ae6a9 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -838,36 +838,5 @@ var fs = require('fs'), }); }); }); - - describe('Method args sequence', function() { - - // it('check if method required sequence args', function(done) { - // soap.createClient(__dirname + '/wsdl/rpcexample.wsdl', meta.options, function(err, client) { - // assert.ok(client); - // assert.ok(client._isSequenceRequired(client.wsdl.definitions.bindings.RpcExample.methods.pullFile) === true); - // done(); - // }); - // }); - - it('check sort args on sequence required method', function(done) { - soap.createClient(__dirname + '/wsdl/rpcexample.wsdl', meta.options, function(err, client) { - assert.ok(client); - assert.ok(true); - client.pullFile({ - 'password': 'qwerty', - 'base64EncodedCallback': '123', - 'username': 'qwert', - 'forceOverwrite': true, - 'fileMode': 1, - 'fileName': 'qwe.txt', - 'url': 'https://github.com' - }, function(err, result) { - assert.ok(result); - done(); - }); - }); - }); - - }); }); }); diff --git a/test/sequence-test.js b/test/sequence-test.js new file mode 100644 index 000000000..af7d6bedc --- /dev/null +++ b/test/sequence-test.js @@ -0,0 +1,55 @@ +'use strict'; + +var fs = require('fs'), + soap = require('..'), + http = require('http'), + assert = require('assert'), + _ = require('lodash'), + sinon = require('sinon'), + wsdl = require('../lib/wsdl'); + +var sequencedRequest = { + 'url': 'https://github.com', + 'fileName': 'qwe.txt', + 'fileMode': 1, + 'forceOverwrite': true, + 'username': 'qwert', + 'password': 'qwerty', + 'base64EncodedCallback': '123' +}; + +var notSequencedRequest = { + 'password': 'qwerty', + 'base64EncodedCallback': '123', + 'username': 'qwert', + 'forceOverwrite': true, + 'fileMode': 1, + 'fileName': 'qwe.txt', + 'url': 'https://github.com' +}; + +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) { + assert.ok(client); + assert.ok(client._isSequenceRequired('pullFile') === false); + + soap.createClient(__dirname + '/wsdl/sequnceexmple.wsdl', { suffix: '', options: {} }, function(err, client) { + assert.ok(client); + assert.ok(client._isSequenceRequired('pullFile') === true); + done(); + }); + }); + }); + + it('check sort args on sequence required method', function(done) { + soap.createClient(__dirname + '/wsdl/sequnceexmple.wsdl', { suffix: '', options: {} }, function(err, client) { + assert.ok(client); + var sequencedMethodRequest = client._setSequenceArgs(client._getArgsScheme('pullFile'), notSequencedRequest); + assert.ok(JSON.stringify(sequencedMethodRequest) === JSON.stringify(sequencedRequest)); + done(); + }); + }); + +}); \ No newline at end of file diff --git a/test/wsdl/sequnceexmple.wsdl b/test/wsdl/sequnceexmple.wsdl new file mode 100644 index 000000000..4c33b9537 --- /dev/null +++ b/test/wsdl/sequnceexmple.wsdl @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Generate an indicium. + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From f94684c2bac7b50f90aefcc554dc710236aaf3f5 Mon Sep 17 00:00:00 2001 From: bogdan Date: Fri, 20 Jan 2017 18:07:50 +0700 Subject: [PATCH 4/8] fix style --- lib/client.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index 06a6f2377..d0e25f4aa 100644 --- a/lib/client.js +++ b/lib/client.js @@ -216,8 +216,7 @@ Client.prototype._setSequenceArgs = function(argsScheme, args) { } if(typeof argsScheme[partIndex] !== 'object') { result[partIndex] = args[partIndex]; - } - else { + } else { result[partIndex] = this._setSequenceArgs(argsScheme[partIndex], args[partIndex]); } } From 73dcc1d325a49862ebabe6d39b9201babdac7574 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 25 Jan 2017 06:49:30 +0700 Subject: [PATCH 5/8] sequence args if sequence args is known --- lib/client.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/client.js b/lib/client.js index d0e25f4aa..c39a84c5e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -183,11 +183,9 @@ Client.prototype._defineMethod = function(method, location) { }; Client.prototype._isSequenceRequired = function(methodName) { - var tns = this.wsdl.definitions.$targetNamespace; - var tnsObject = this.wsdl._splitQName(tns); - var methodRequestName = _.result(this.wsdl.definitions, 'bindings.'+tnsObject.name+'.methods.'+methodName+'.input.$name'); - + var methodRequestName = _.result(this.wsdl.definitions, 'messages.'+methodName+'.$name'); // here must be declare method args if declared only params we can't get service methods args and set sequence fields + var args = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.parts'); if(typeof args === 'undefined' && typeof _.pick(args, 'params') !== 'undefined') { return false; @@ -196,13 +194,7 @@ Client.prototype._isSequenceRequired = function(methodName) { return false; } - - var complexTypeName = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.element.$name'); - var modeOfComplexType = _.result(this.wsdl.definitions, 'schemas.'+tns+'.elements.'+complexTypeName+'.children[0].children[0].name'); - if(modeOfComplexType === 'sequence') { - return true; - } - return false; + return true; }; Client.prototype._setSequenceArgs = function(argsScheme, args) { @@ -224,9 +216,7 @@ Client.prototype._setSequenceArgs = function(argsScheme, args) { }; Client.prototype._getArgsScheme = function(methodName) { - var tns = this.wsdl.definitions.$targetNamespace; - var tnsObject = this.wsdl._splitQName(tns); - var methodRequestName = _.result(this.wsdl.definitions, 'bindings.'+tnsObject.name+'.methods.'+methodName+'.input.$name'); + var methodRequestName = _.result(this.wsdl.definitions, 'messages.'+methodName+'.$name'); // here must be declare method args if declared only params we can't get service methods args and set sequence fields var args = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.parts'); From 7b5feec135192f73ea4958760967f86f4d1fe171 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 26 Jan 2017 00:45:05 +0700 Subject: [PATCH 6/8] fix sequence reuire check --- lib/client.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/client.js b/lib/client.js index c39a84c5e..ab28423e4 100644 --- a/lib/client.js +++ b/lib/client.js @@ -183,9 +183,8 @@ 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'); - // here must be declare method args if declared only params we can't get service methods args and set sequence fields - var args = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.parts'); if(typeof args === 'undefined' && typeof _.pick(args, 'params') !== 'undefined') { return false; @@ -193,8 +192,12 @@ Client.prototype._isSequenceRequired = function(methodName) { if(Object.keys(args).length === 1) { return false; } - - return true; + var complexTypeName = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.element.$name'); + var modeOfComplexType = _.result(this.wsdl.definitions, 'schemas[\''+tns+'\'].elements.'+complexTypeName+'.children[0].children[0].name'); + if(modeOfComplexType === 'sequence') { + return true; + } + return false; }; Client.prototype._setSequenceArgs = function(argsScheme, args) { @@ -217,8 +220,6 @@ Client.prototype._setSequenceArgs = function(argsScheme, args) { Client.prototype._getArgsScheme = function(methodName) { var methodRequestName = _.result(this.wsdl.definitions, 'messages.'+methodName+'.$name'); - - // here must be declare method args if declared only params we can't get service methods args and set sequence fields var args = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.parts'); if(typeof args === 'undefined' && typeof _.pick(args, 'params') !== 'undefined') { return []; From 923cfb637819a1f6be043c6d9301814b4f8ff5fa Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 26 Jan 2017 00:49:19 +0700 Subject: [PATCH 7/8] fix test wrong parsed params for sequnce --- .../readMetadata__should_respect_xsi_type_attribute/soap.wsdl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/soap.wsdl b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/soap.wsdl index 3d9e07588..0a63b8bd6 100644 --- a/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/soap.wsdl +++ b/test/request-response-samples/readMetadata__should_respect_xsi_type_attribute/soap.wsdl @@ -11,7 +11,7 @@ Copyright 2006-2015 Salesforce.com, inc. All Rights Reserved - + From b59b1e73dfb2c71e6a94865f859ad13bd8632a31 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 26 Jan 2017 04:16:04 +0700 Subject: [PATCH 8/8] code style fixes --- lib/client.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/client.js b/lib/client.js index ab28423e4..f60cd45d9 100644 --- a/lib/client.js +++ b/lib/client.js @@ -184,19 +184,25 @@ 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'); + 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 false; } if(Object.keys(args).length === 1) { return false; } - var complexTypeName = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.element.$name'); - var modeOfComplexType = _.result(this.wsdl.definitions, 'schemas[\''+tns+'\'].elements.'+complexTypeName+'.children[0].children[0].name'); + + var complexTypeName = _.result(this.wsdl.definitions, 'messages.' + methodRequestName + '.element.$name'); + var modeOfComplexType = _.result( + this.wsdl.definitions, + 'schemas[\'' + tns + '\'].elements.' + complexTypeName + '.children[0].children[0].name'); + if(modeOfComplexType === 'sequence') { return true; } + return false; }; @@ -220,13 +226,15 @@ Client.prototype._setSequenceArgs = function(argsScheme, args) { Client.prototype._getArgsScheme = function(methodName) { var methodRequestName = _.result(this.wsdl.definitions, 'messages.'+methodName+'.$name'); - var args = _.result(this.wsdl.definitions, 'messages.'+methodRequestName+'.parts'); + 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) { return []; } + return args; }; @@ -257,8 +265,6 @@ Client.prototype._invoke = function(method, args, location, callback, options, e } } - - if (this.wsdl.options.forceSoap12Headers) { headers["Content-Type"] = "application/soap+xml; charset=utf-8"; xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://www.w3.org/2003/05/soap-envelope\"";