Comparing version 0.0.11 to 0.1.0
@@ -20,2 +20,3 @@ /* | ||
Client.prototype.describe = function() { | ||
var types = this.wsdl.definitions.types; | ||
return this.wsdl.describeServices(); | ||
@@ -64,4 +65,4 @@ } | ||
} | ||
self._invoke(method, args, location, function(error, result) { | ||
callback(error, result); | ||
self._invoke(method, args, location, function(error, result, raw) { | ||
callback(error, result, raw); | ||
}) | ||
@@ -95,3 +96,3 @@ } | ||
if (input.parts) { | ||
assert.ok(style == 'rpc', 'invalid message definition for document style binding'); | ||
assert.ok(!style || style == 'rpc', 'invalid message definition for document style binding'); | ||
message = self.wsdl.objectToRpcXML(name, arguments); | ||
@@ -101,7 +102,6 @@ encoding = 'soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" '; | ||
else { | ||
assert.ok(style == 'document', 'invalid message definition for rpc style binding'); | ||
assert.ok(!style || style == 'document', 'invalid message definition for rpc style binding'); | ||
message = self.wsdl.objectToDocumentXML(input.$name, arguments); | ||
} | ||
xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + | ||
"<soap:Envelope " + | ||
xml = "<soap:Envelope " + | ||
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + | ||
@@ -125,6 +125,6 @@ encoding + | ||
var obj = self.wsdl.xmlToObject(body); | ||
callback(null, obj[output.$name]); | ||
callback(null, obj[output.$name], body); | ||
} | ||
catch (error) { | ||
callback(error); | ||
callback(error, null, body); | ||
} | ||
@@ -131,0 +131,0 @@ } |
@@ -19,15 +19,17 @@ /* | ||
if (path[path.length-1] != '/') path += '/'; | ||
server.removeAllListeners('request'); | ||
server.addListener('request', function(req, res) { | ||
var reqPath = url.parse(req.url).pathname; | ||
if (reqPath[reqPath.length-1] != '/') reqPath += '/'; | ||
if (path === reqPath) { | ||
self._requestListener(req, res); | ||
} | ||
else { | ||
for (var i = 0, len = listeners.length; i < len; i++){ | ||
listeners[i].call(this, req, res); | ||
} | ||
} | ||
}); | ||
wsdl.onReady(function(err) { | ||
server.removeAllListeners('request'); | ||
server.addListener('request', function(req, res) { | ||
var reqPath = url.parse(req.url).pathname; | ||
if (reqPath[reqPath.length-1] != '/') reqPath += '/'; | ||
if (path === reqPath) { | ||
self._requestListener(req, res); | ||
} | ||
else { | ||
for (var i = 0, len = listeners.length; i < len; i++){ | ||
listeners[i].call(this, req, res); | ||
} | ||
} | ||
}); | ||
}) | ||
} | ||
@@ -34,0 +36,0 @@ |
@@ -8,5 +8,3 @@ /* | ||
Server = require('./server').Server, | ||
WSDL = require('./wsdl').WSDL, | ||
http = require('./http'), | ||
fs = require('fs'), | ||
open_wsdl = require('./wsdl').open_wsdl, | ||
crypto = require('crypto'); | ||
@@ -21,29 +19,8 @@ | ||
} | ||
else if (!/^http/.test(url)) { | ||
fs.readFile(url, 'utf8', function (err, data) { | ||
if (err) { | ||
callback(err) | ||
} | ||
else { | ||
wsdl = new WSDL(data); | ||
_wsdlCache[url] = wsdl; | ||
callback(null, wsdl); | ||
} | ||
else { | ||
open_wsdl(url, function(err, wsdl) { | ||
if (!err) _wsdlCache[url] = wsdl; | ||
callback(null, wsdl); | ||
}) | ||
} | ||
else { | ||
http.request(url, null /* options */, function(err, response, body) { | ||
if (err) { | ||
callback(err); | ||
} | ||
else if (response && response.statusCode == 200){ | ||
wsdl = new WSDL(body); | ||
_wsdlCache[url] = wsdl; | ||
callback(null, wsdl); | ||
} | ||
else { | ||
callback(new Error('Invalid WSDL URL: '+url)) | ||
} | ||
}); | ||
} | ||
} | ||
@@ -122,3 +99,2 @@ | ||
exports.WSDL = WSDL; | ||
exports.BasicAuthSecurity = BasicAuthSecurity; | ||
@@ -125,0 +101,0 @@ exports.WSSecurity = WSSecurity; |
148
lib/wsdl.js
@@ -8,2 +8,5 @@ /* | ||
inherits = require('util').inherits, | ||
http = require('./http'), | ||
fs = require('fs'), | ||
url = require('url'), | ||
assert = require('assert').ok; | ||
@@ -13,2 +16,4 @@ | ||
string: 1, boolean: 1, decimal: 1, float: 1, double: 1, | ||
anyType: 1, byte: 1, int: 1, long: 1, short: 1, | ||
unsignedByte: 1, unsignedInt: 1, unsignedLong: 1, unsignedShort: 1, | ||
duration: 0, dateTime: 0, time: 0, date: 0, | ||
@@ -128,3 +133,2 @@ gYearMonth: 0, gYear: 0, gMonthDay: 0, gDay: 0, gMonth: 0, | ||
name = this.$name; | ||
if (this.$minOccurs !== this.$maxOccurs) { | ||
@@ -136,4 +140,4 @@ name += '[]'; | ||
var typeName = splitNSName(this.$type).name, | ||
typeElement = definitions.types[typeName]; | ||
if (typeElement) { | ||
typeElement = definitions.complexTypes[typeName] || definitions.types[typeName]; | ||
if (typeElement && !(typeName in Primitives)) { | ||
element[name] = typeElement.description(definitions); | ||
@@ -176,3 +180,5 @@ } | ||
Element.apply(this, arguments); | ||
this.complexTypes = {}; | ||
this.types = {}; | ||
this.includes = []; | ||
} | ||
@@ -185,2 +191,3 @@ inherits(SchemaElement, Element); | ||
simpleType: SimpleTypeElement, | ||
include: Element, | ||
import: Element | ||
@@ -191,3 +198,11 @@ } | ||
if (child.$name in Primitives) return; | ||
this.types[child.$name] = child; | ||
if (child.name === 'include' || child.name === 'import') { | ||
this.includes.push(child.$schemaLocation); | ||
} | ||
else if (child.name === 'complexType') { | ||
this.complexTypes[child.$name] = child; | ||
} | ||
else if (child.$name) { | ||
this.types[child.$name] = child; | ||
} | ||
} | ||
@@ -197,3 +212,5 @@ | ||
Element.apply(this, arguments); | ||
this.complexTypes = {}; | ||
this.types = {}; | ||
this.includes = []; | ||
} | ||
@@ -206,3 +223,5 @@ inherits(TypesElement, Element); | ||
assert(child instanceof SchemaElement); | ||
this.complexTypes = child.complexTypes; | ||
this.types = child.types; | ||
this.includes = child.includes; | ||
} | ||
@@ -221,2 +240,4 @@ | ||
var part = this.children[0]; | ||
if (!part) return; | ||
assert(part.name === 'part', 'Expected part element'); | ||
@@ -230,3 +251,3 @@ if (part.$element) { | ||
// rpc encoding | ||
for (var i=0, child; child = this.children[i]; i++) { | ||
for (var i=0, part; part = this.children[i]; i++) { | ||
assert(part.name === 'part', 'Expected part element'); | ||
@@ -277,4 +298,4 @@ this.parts[part.$name] = part.$type; | ||
OperationElement.prototype.description = function(definitions) { | ||
var inputDesc = this.input.description(definitions), | ||
outputDesc = this.output.description(definitions); | ||
var inputDesc = this.input.description(definitions); | ||
var outputDesc = this.output.description(definitions); | ||
return { | ||
@@ -405,2 +426,3 @@ input: inputDesc && inputDesc[Object.keys(inputDesc)[0]], | ||
if (this.name !== 'definitions') this.unexpected(nsName); | ||
this.complexTypes = {}; | ||
this.types = {}; | ||
@@ -426,3 +448,5 @@ this.messages = {}; | ||
if (child instanceof TypesElement) { | ||
self.complexTypes = child.complexTypes; | ||
self.types = child.types; | ||
self.includes = child.includes; | ||
} | ||
@@ -448,8 +472,14 @@ else if (child instanceof MessageElement) { | ||
var WSDL = function(definition) { | ||
var WSDL = function(definition, uri) { | ||
var self = this, | ||
fromFunc; | ||
this.uri = uri; | ||
this.callback = function() {}; | ||
if (typeof definition === 'string') { | ||
this._fromXML(definition); | ||
fromFunc = this._fromXML; | ||
} | ||
else if (typeof definition === 'object') { | ||
this._fromServices(definition); | ||
fromFunc = this._fromServices; | ||
} | ||
@@ -459,4 +489,43 @@ else { | ||
} | ||
process.nextTick(function() { | ||
fromFunc.call(self, definition); | ||
self.processIncludes(function(err) { | ||
var services = self.services = self.definitions.services ; | ||
if (services) { | ||
for (var name in services) { | ||
services[name].postProcess(self.definitions); | ||
} | ||
} | ||
self.callback(err, self); | ||
}); | ||
}) | ||
} | ||
WSDL.prototype.onReady = function(callback) { | ||
if (callback) this.callback = callback; | ||
} | ||
WSDL.prototype.processIncludes = function(callback) { | ||
var self = this, | ||
uri = this.definitions && this.definitions.includes.shift(); | ||
if (!uri) { | ||
callback(null, this); | ||
return; | ||
} | ||
open_wsdl(url.resolve(self.uri, uri), function(err, wsdl) { | ||
for (var name in wsdl.definitions.complexTypes) { | ||
self.definitions.complexTypes[name] = wsdl.definitions.complexTypes[name]; | ||
} | ||
for (var name in wsdl.definitions.types) { | ||
self.definitions.types[name] = wsdl.definitions.types[name]; | ||
} | ||
self.processIncludes(function(err, wsdl) { | ||
callback(err, wsdl); | ||
}) | ||
}); | ||
} | ||
WSDL.prototype.describeServices = function() { | ||
@@ -630,13 +699,21 @@ var services = {}; | ||
stack = [], | ||
definitions = null; | ||
root = null; | ||
p.on('startElement', function(name, attrs) { | ||
p.on('startElement', function(nsName, attrs) { | ||
var top = stack[stack.length - 1]; | ||
if (top) { | ||
top.startElement(stack, name, attrs); | ||
top.startElement(stack, nsName, attrs); | ||
} | ||
else { | ||
definitions = new DefinitionsElement(name, attrs); | ||
stack.push(definitions); | ||
var name = splitNSName(nsName).name; | ||
if (name === 'definitions') { | ||
root = new DefinitionsElement(nsName, attrs); | ||
} | ||
else if (name === 'schema') { | ||
root = new SchemaElement(nsName, attrs); | ||
} | ||
else { | ||
throw new Error('Unexpected root element of WSDL or include'); | ||
} | ||
stack.push(root); | ||
} | ||
@@ -656,3 +733,3 @@ }) | ||
return definitions; | ||
return root; | ||
} | ||
@@ -663,7 +740,2 @@ | ||
this.xml = xml; | ||
var services = this.services = this.definitions.services; | ||
for (var name in services) { | ||
services[name].postProcess(this.definitions); | ||
} | ||
} | ||
@@ -675,2 +747,34 @@ | ||
function open_wsdl(uri, callback) { | ||
var wsdl; | ||
if (!/^http/.test(uri)) { | ||
fs.readFile(uri, 'utf8', function (err, definition) { | ||
if (err) { | ||
callback(err) | ||
} | ||
else { | ||
wsdl = new WSDL(definition, uri); | ||
wsdl.onReady(callback); | ||
} | ||
}) | ||
} | ||
else { | ||
http.request(uri, null /* options */, function (err, response, definition) { | ||
if (err) { | ||
callback(err); | ||
} | ||
else if (response && response.statusCode == 200) { | ||
wsdl = new WSDL(definition, uri); | ||
wsdl.onReady(callback); | ||
} | ||
else { | ||
callback(new Error('Invalid WSDL URL: '+uri)) | ||
} | ||
}); | ||
} | ||
return wsdl; | ||
} | ||
exports.open_wsdl = open_wsdl; | ||
exports.WSDL = WSDL; |
{ | ||
"name": "soap", | ||
"version": "0.0.11", | ||
"version": "0.1.0", | ||
"description": "A minimal node SOAP client", | ||
@@ -5,0 +5,0 @@ "engines": { "node": ">=0.4.0" }, |
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
39001
1050