Comparing version 0.2.7 to 0.3.0
@@ -71,3 +71,3 @@ /* | ||
def[name] = this._defineMethod(methods[name], location); | ||
if (!this[name]) this[name] = def[name]; | ||
this[name] = def[name]; | ||
} | ||
@@ -79,3 +79,3 @@ return def; | ||
var self = this; | ||
return function(args, callback) { | ||
return function(args, callback, options) { | ||
if (typeof args === 'function') { | ||
@@ -87,7 +87,7 @@ callback = args; | ||
callback(error, result, raw); | ||
}) | ||
}, options) | ||
} | ||
} | ||
Client.prototype._invoke = function(method, arguments, location, callback) { | ||
Client.prototype._invoke = function(method, arguments, location, callback, options) { | ||
var self = this, | ||
@@ -108,3 +108,3 @@ name = method.$name, | ||
}, | ||
options = {}, | ||
options = options || {}, | ||
alias = findKey(defs.xmlns, ns); | ||
@@ -146,2 +146,3 @@ | ||
http.request(location, xml, function(err, response, body) { | ||
self.lastResponse = body; | ||
if (err) { | ||
@@ -155,2 +156,4 @@ callback(err); | ||
catch (error) { | ||
error.response = response; | ||
error.body = body; | ||
return callback(error, response, body); | ||
@@ -157,0 +160,0 @@ } |
@@ -20,3 +20,3 @@ /* | ||
"User-Agent": "node-soap/" + VERSION, | ||
"Accept" : "text/html,application/xhtml+xml,application/xml", | ||
"Accept" : "text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8", | ||
"Accept-Encoding": "none", | ||
@@ -23,0 +23,0 @@ "Accept-Charset": "utf-8", |
@@ -16,5 +16,5 @@ /* | ||
var Server = function(server, path, services, wsdl) { | ||
var self = this, | ||
listeners = server.listeners('request'); | ||
var self = this; | ||
this.path = path; | ||
this.services = services; | ||
@@ -25,2 +25,4 @@ this.wsdl = wsdl; | ||
wsdl.onReady(function(err) { | ||
var listeners = server.listeners('request').slice(); | ||
server.removeAllListeners('request'); | ||
@@ -50,5 +52,15 @@ server.addListener('request', function(req, res) { | ||
var self = this; | ||
var reqParse = url.parse(req.url); | ||
var reqPath = reqParse.pathname; | ||
var reqQuery = reqParse.search; | ||
if (typeof self.log === 'function') { | ||
self.log("info", "Handling "+req.method+" on "+req.url); | ||
} | ||
if (req.method === 'GET') { | ||
var search = url.parse(req.url).search; | ||
if (search && search.toLowerCase() === '?wsdl') { | ||
if (reqQuery && reqQuery.toLowerCase() === '?wsdl') { | ||
if (typeof self.log === 'function') { | ||
self.log("info", "Wants the WSDL"); | ||
} | ||
res.setHeader("Content-Type", "application/xml"); | ||
@@ -118,2 +130,6 @@ res.write(self.wsdl.toXML()); | ||
} | ||
if (typeof self.log === 'function') { | ||
self.log("info", "Attempting to bind to "+pathname); | ||
} | ||
@@ -123,2 +139,3 @@ // use port.location and current url to find the right binding | ||
var services = self.wsdl.definitions.services; | ||
var firstPort = undefined; | ||
for(serviceName in services ) { | ||
@@ -130,32 +147,47 @@ var service = services[serviceName]; | ||
var portPathname = url.parse(port.location).pathname.replace(/\/$/,''); | ||
if (typeof self.log === 'function') { | ||
self.log("info", "Trying "+portName+" from path "+portPathname); | ||
} | ||
if(portPathname===pathname) | ||
return port.binding; | ||
// The port path is almost always wrong for genrated WSDLs | ||
if(firstPort == undefined) { | ||
firstPort = port; | ||
} | ||
} | ||
} | ||
return firstPort == undefined ? undefined : firstPort.binding; | ||
})(this); | ||
if (!binding) { | ||
throw new Error('Failed to bind to WSDL'); | ||
} | ||
methods = binding.methods; | ||
if(binding.style === 'rpc') { | ||
methodName = Object.keys(body)[0]; | ||
self._executeMethod({ | ||
serviceName: serviceName, | ||
portName: portName, | ||
methodName: methodName, | ||
outputName: methodName + 'Response', | ||
args: body[methodName], | ||
style: 'rpc' | ||
}, callback); | ||
} else { | ||
var messageElemName = Object.keys(body)[0]; | ||
var pair = binding.topElements[messageElemName]; | ||
self._executeMethod({ | ||
serviceName: serviceName, | ||
portName: portName, | ||
methodName: pair.methodName, | ||
outputName: pair.outputName, | ||
args: body[messageElemName], | ||
style: 'document' | ||
}, callback); | ||
} | ||
if(binding.style === 'rpc') { | ||
methodName = Object.keys(body)[0]; | ||
self._executeMethod({ | ||
serviceName: serviceName, | ||
portName: portName, | ||
methodName: methodName, | ||
outputName: methodName + 'Response', | ||
args: body[methodName], | ||
style: 'rpc' | ||
}, callback); | ||
} else { | ||
var messageElemName = Object.keys(body)[0]; | ||
var pair = binding.topElements[messageElemName]; | ||
self._executeMethod({ | ||
serviceName: serviceName, | ||
portName: portName, | ||
methodName: pair.methodName, | ||
outputName: pair.outputName, | ||
args: body[messageElemName], | ||
style: 'document' | ||
}, callback); | ||
} | ||
} | ||
@@ -162,0 +194,0 @@ |
@@ -144,2 +144,3 @@ /* | ||
var MessageElement = Element.createSubClass(); | ||
var DocumentationElement = Element.createSubClass(); | ||
@@ -156,3 +157,3 @@ var SchemaElement = Element.createSubClass(); | ||
var ElementTypeMap = { | ||
types: [TypesElement, 'schema'], | ||
types: [TypesElement, 'schema documentation'], | ||
schema: [SchemaElement, 'element complexType simpleType include import'], | ||
@@ -168,5 +169,5 @@ element: [ElementElement, 'annotation complexType'], | ||
service: [ServiceElement, 'port documentation'], | ||
port: [PortElement, 'address'], | ||
binding: [BindingElement, '_binding SecuritySpec operation'], | ||
portType: [PortTypeElement, 'operation'], | ||
port: [PortElement, 'address documentation'], | ||
binding: [BindingElement, '_binding SecuritySpec operation documentation'], | ||
portType: [PortTypeElement, 'operation documentation'], | ||
message: [MessageElement, 'part documentation'], | ||
@@ -176,4 +177,5 @@ operation: [OperationElement, 'documentation input output fault _operation'], | ||
output : [OutputElement, 'body SecuritySpecRef documentation header'], | ||
fault : [Element, '_fault'], | ||
definitions: [DefinitionsElement, 'types message portType binding service'] | ||
fault : [Element, '_fault documentation'], | ||
definitions: [DefinitionsElement, 'types message portType binding service documentation'], | ||
documentation: [DocumentationElement, ''] | ||
}; | ||
@@ -238,2 +240,3 @@ | ||
} | ||
DocumentationElement.prototype.init = function(){} | ||
@@ -323,2 +326,4 @@ SchemaElement.prototype.addChild = function(child) { | ||
} | ||
else if (child instanceof DocumentationElement) { | ||
} | ||
else { | ||
@@ -492,3 +497,4 @@ assert(false, "Invalid child type"); | ||
schema; | ||
if (this.$minOccurs !== this.$maxOccurs) { | ||
var maxOccurs = this.$maxOccurs || 1; | ||
if ((isNaN(maxOccurs) && maxOccurs == 'unbounded') || maxOccurs > 1) { | ||
name += '[]'; | ||
@@ -747,3 +753,3 @@ } | ||
if(!refs[id]) refs[id] = {hrefs:[],obj:null}; | ||
refs[id].hrefs.push({par:top.object,key:name}); | ||
refs[id].hrefs.push({par:top.object,key:name,obj:obj}); | ||
} | ||
@@ -812,11 +818,21 @@ if(id=attrs.id) { | ||
} | ||
for(var n in refs) { | ||
var ref = refs[n]; | ||
var obj = ref.obj; | ||
ref.hrefs.forEach(function(href) { | ||
href.par[href.key] = obj; | ||
}); | ||
} | ||
// merge obj with href | ||
var merge = function(href, obj) { | ||
for (var j in obj) { | ||
if (obj.hasOwnProperty(j)) { | ||
href.obj[j] = obj[j]; | ||
} | ||
} | ||
}; | ||
// MultiRef support: merge objects instead of replacing | ||
for(var n in refs) { | ||
var ref = refs[n]; | ||
for (var i = 0; i < ref.hrefs.length; i++) { | ||
merge(ref.hrefs[i], ref.obj); | ||
} | ||
} | ||
var body = root.Envelope.Body; | ||
@@ -832,3 +848,3 @@ if (body.Fault) { | ||
args[name] = params; | ||
return this.objectToXML(args, null, ns, xmlns); | ||
return this.objectToXML(args, null, ns, xmlns, true); | ||
} | ||
@@ -857,6 +873,6 @@ | ||
WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns) { | ||
WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first) { | ||
var self = this, | ||
parts = [], | ||
xmlnsAttrib = false ? ' xmlns:'+namespace+'="'+xmlns+'"'+' xmlns="'+xmlns+'"' : '', | ||
xmlnsAttrib = first ? ' xmlns:'+namespace+'="'+xmlns+'"'+' xmlns="'+xmlns+'"' : '', | ||
ns = namespace ? namespace + ':' : ''; | ||
@@ -870,3 +886,3 @@ | ||
} | ||
parts.push(self.objectToXML(item, name)); | ||
parts.push(self.objectToXML(item, name, namespace, xmlns)); | ||
} | ||
@@ -878,7 +894,7 @@ } | ||
parts.push(['<',ns,name,xmlnsAttrib,'>'].join('')); | ||
parts.push(self.objectToXML(child, name)); | ||
parts.push(self.objectToXML(child, name, namespace, xmlns)); | ||
parts.push(['</',ns,name,'>'].join('')); | ||
} | ||
} | ||
else if (obj) { | ||
else if (obj !== undefined) { | ||
parts.push(xmlEscape(obj)); | ||
@@ -979,2 +995,7 @@ } | ||
request_headers = options.wsdl_headers; | ||
delete options.wsdl_headers; | ||
request_options = options.wsdl_options; | ||
delete options.wsdl_options; | ||
var wsdl; | ||
@@ -992,3 +1013,3 @@ if (!/^http/.test(uri)) { | ||
} | ||
else { | ||
else { | ||
http.request(uri, null /* options */, function (err, response, definition) { | ||
@@ -1003,5 +1024,5 @@ if (err) { | ||
else { | ||
callback(new Error('Invalid WSDL URL: '+uri)) | ||
callback(new Error('Invalid WSDL URL: '+uri + "\n\n\r Code: "+ response.statusCode + "\n\n\r Response Body: " + response.body)); | ||
} | ||
}); | ||
}, request_headers, request_options); | ||
} | ||
@@ -1008,0 +1029,0 @@ |
{ | ||
"name": "soap", | ||
"version": "0.2.7", | ||
"version": "0.3.0", | ||
"description": "A minimal node SOAP client", | ||
@@ -5,0 +5,0 @@ "engines": { "node": ">=0.8.0" }, |
@@ -7,7 +7,11 @@ var fs = require('fs'), | ||
var service = { | ||
StockQuoteService: { | ||
StockQuotePort: { | ||
var service = { | ||
StockQuoteService: { | ||
StockQuotePort: { | ||
GetLastTradePrice: function(args) { | ||
return { price: 19.56 }; | ||
if (args.tickerSymbol == 'trigger error') { | ||
throw new Error('triggered server error'); | ||
} else { | ||
return { price: 19.56 }; | ||
} | ||
} | ||
@@ -27,3 +31,3 @@ } | ||
done(); | ||
}); | ||
}); | ||
}; | ||
@@ -38,3 +42,3 @@ }) | ||
done(); | ||
}); | ||
}); | ||
}; | ||
@@ -74,3 +78,3 @@ }) | ||
done(); | ||
}) | ||
}) | ||
}, | ||
@@ -95,8 +99,20 @@ | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}, | ||
'should include response and body in error object': function(done) { | ||
soap.createClient('http://localhost:15099/stockquote?wsdl', function(err, client) { | ||
assert.ok(!err); | ||
client.GetLastTradePrice({ tickerSymbol: 'trigger error' }, function(err, response, body) { | ||
assert.ok(err); | ||
assert.strictEqual(err.response, response); | ||
assert.strictEqual(err.body, body); | ||
done(); | ||
}); | ||
}); | ||
} | ||
}, | ||
'WSDL Parser (strict)': wsdlStrictTests, | ||
'WSDL Parser (non-strict)': wsdlNonStrictTests | ||
'WSDL Parser (non-strict)': wsdlNonStrictTests | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30
1952
204278