Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ Client.prototype._invoke = function(method, arguments, location, callback) {
message = arguments;
}
else {
assert.ok(!style || style == 'document', 'invalid message definition for rpc style binding');
//Some APIs have no part definitions in AMC WSDL
assert.ok(!style || style == 'document' || !input.parts, 'invalid message definition for rpc style binding');
message = self.wsdl.objectToDocumentXML(input.$name, arguments, input.targetNSAlias, input.targetNamespace);
}
xml = "<soap:Envelope " +
Expand Down Expand Up @@ -160,4 +161,4 @@ Client.prototype._invoke = function(method, arguments, location, callback) {
}, headers, options);
}

exports.Client = Client;
exports.Client = Client;
108 changes: 69 additions & 39 deletions lib/wsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,11 @@ MessageElement.prototype.postProcess = function(definitions) {
} else {
this.parts[part.$name] = part.$type;
}
this.parts[part.$name].namespace = nsName.namespace;
this.parts[part.$name].xmlns = ns;
if(this.parts[part.$name]){
this.parts[part.$name].namespace = nsName.namespace;
this.parts[part.$name].xmlns = ns;
}

this.children.splice(i--,1);
}
}
Expand Down Expand Up @@ -733,23 +736,23 @@ WSDL.prototype.xmlToObject = function(xml) {
topSchema = message.description(self.definitions);
objectName = originalName;
}
if(attrs.href) {
id = attrs.href.substr(1);
if(!refs[id]) refs[id] = {hrefs:[],obj:null};
refs[id].hrefs.push({par:top.object,key:name});
}
if(id=attrs.id) {
if(!refs[id]) refs[id] = {hrefs:[],obj:null};
}
if(attrs.href) {
id = attrs.href.substr(1);
if(!refs[id]) refs[id] = {hrefs:[],obj:null};
refs[id].hrefs.push({par:top.object,key:name});
}
if(id=attrs.id) {
if(!refs[id]) refs[id] = {hrefs:[],obj:null};
}

if (topSchema && topSchema[name+'[]']) name = name + '[]';
stack.push({name: originalName, object: obj, schema: topSchema && topSchema[name], id:attrs.id});
})

p.on('endElement', function(nsName) {
var cur = stack.pop(),
obj = cur.object,
obj = cur.object,
top = stack[stack.length-1],
topObject = top.object,
topSchema = top.schema,
Expand All @@ -768,10 +771,10 @@ WSDL.prototype.xmlToObject = function(xml) {
else {
topObject[name] = obj;
}
if(cur.id) {
refs[cur.id].obj = obj;
}
if(cur.id) {
refs[cur.id].obj = obj;
}
})

p.on('text', function(text) {
Expand Down Expand Up @@ -801,15 +804,15 @@ WSDL.prototype.xmlToObject = function(xml) {
if (!p.parse(xml, false)) {
throw new Error(p.getError());
}
for(var n in refs) {
var ref = refs[n];
var obj = ref.obj;
ref.hrefs.forEach(function(href) {
href.par[href.key] = obj;
});
}
for(var n in refs) {
var ref = refs[n];
var obj = ref.obj;
ref.hrefs.forEach(function(href) {
href.par[href.key] = obj;
});
}
var body = root.Envelope.Body;
if (body.Fault) {
throw new Error(body.Fault.faultcode+': '+body.Fault.faultstring+(body.Fault.detail ? ': ' + body.Fault.detail : ''));
Expand All @@ -822,7 +825,7 @@ WSDL.prototype.objectToDocumentXML = function(name, params, ns, xmlns) {
args[name] = params;
return this.objectToXML(args, null, ns, xmlns);
}

//Code change for array elements handling
WSDL.prototype.objectToRpcXML = function(name, params, namespace, xmlns) {
var self = this,
parts = [],
Expand All @@ -833,38 +836,65 @@ WSDL.prototype.objectToRpcXML = function(name, params, namespace, xmlns) {
parts.push(['<',namespace,':',name,'>'].join(''));
for (var key in params) {
if (key != nsAttrName) {

var value = params[key];
parts.push(['<',key,'>'].join(''));
parts.push((typeof value==='object')?this.objectToXML(value):xmlEscape(value));
parts.push(['</',key,'>'].join(''));
if(Array.isArray(value)){
parts.push(['<',key,' arrayType="item[]"','>'].join(''));
for (var i = 0; i < value.length; i++) {
if(Array.isArray(value[i])){
parts.push('<item arrayType="item[]">');
}else{
parts.push('<item>');
}
parts.push((typeof value==='object')?this.objectToXML(value[i]):xmlEscape(value));
parts.push('</item>');
};
parts.push(['</',key,'>'].join(''));
}else{
parts.push(['<',key,'>'].join(''));
parts.push((typeof value==='object')?this.objectToXML(value):xmlEscape(value));
parts.push(['</',key,'>'].join(''));
}

}
}
parts.push(['</',namespace,':',name,'>'].join(''));

return parts.join('');
}

//Code change for array elements handling
WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns) {

var self = this,
parts = [],
xmlnsAttrib = false ? ' xmlns:'+namespace+'="'+xmlns+'"'+' xmlns="'+xmlns+'"' : '',
ns = namespace ? namespace + ':' : '';

if (Array.isArray(obj)) {
for (var i=0, item; item=obj[i]; i++) {
if (i > 0) {
parts.push(['</',ns,name,'>'].join(''));
parts.push(['<',ns,name,xmlnsAttrib,'>'].join(''));
}
parts.push(self.objectToXML(item, name));
parts.push('<item>');
parts.push(self.objectToXML(item));
parts.push('</item>');
}
}
else if (typeof obj === 'object') {
else
if (typeof obj === 'object') {
for (var name in obj) {
var child = obj[name];
parts.push(['<',ns,name,xmlnsAttrib,'>'].join(''));
parts.push(self.objectToXML(child, name));
parts.push(['</',ns,name,'>'].join(''));

if(Array.isArray(child)){
name ? parts.push('<'+name+' arrayType="item[]">'): parts.push('<item arrayType="item[]">');
parts.push(self.objectToXML(child));
name ? parts.push('</'+name+'>'): parts.push('</item>');

}else{
parts.push(['<',ns,name,xmlnsAttrib,'>'].join(''));
parts.push(self.objectToXML(child));
parts.push(['</',ns,name,'>'].join(''));
}


}
}
else if (obj) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"engines": { "node": ">=0.8.0" },
"author": "Vinay Pulim <[email protected]>",
"dependencies": {
"node-expat": ">=1.6.1",
"node-expat": "~1.6.1",
"request": ">=2.9.0"
},
"repository" : {
Expand Down