Permalink
Browse files

Merge pull request #112 from alanbly/master

Not sure if anyone is listening, fixed a bug.
  • Loading branch information...
milewise committed Apr 10, 2013
2 parents b46eefc + 5260078 commit 0f0382a1ed6b74d35b6ecc8ced29d31a0af92532
View
0 .gitignore 100644 → 100755
No changes.
View
0 Readme.md 100644 → 100755
No changes.
View
0 index.js 100644 → 100755
No changes.
View
0 lib/client.js 100644 → 100755
No changes.
View
0 lib/http.js 100644 → 100755
No changes.
View
76 lib/server.js 100644 → 100755
@@ -13,14 +13,16 @@ var url = require('url'),
try { compress = require("compress"); } catch(e) {}
var Server = function(server, path, services, wsdl) {
- var self = this,
- listeners = server.listeners('request');
-
+ var self = this;
+
+ this.path = path;
this.services = services;
this.wsdl = wsdl;
if (path[path.length-1] != '/') path += '/';
wsdl.onReady(function(err) {
+ var listeners = server.listeners('request').slice();
+
server.removeAllListeners('request');
server.addListener('request', function(req, res) {
if (typeof self.authorizeConnection === 'function') {
@@ -45,9 +47,15 @@ var Server = function(server, path, services, wsdl) {
Server.prototype._requestListener = function(req, res) {
var self = this;
+ var reqParse = url.parse(req.url);
+ var reqPath = reqParse.pathname;
+ var reqQuery = reqParse.search;
+
+ 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') {
+ self.log("info", "Wants the WSDL");
res.setHeader("Content-Type", "application/xml");
res.write(self.wsdl.toXML());
}
@@ -112,46 +120,60 @@ Server.prototype._process = function(input, URL, callback) {
throw new Error('Invalid username or password');
}
}
+
+ self.log("info", "Attempting to bind to "+pathname);
// use port.location and current url to find the right binding
binding = (function(self){
var services = self.wsdl.definitions.services;
+ var firstPort = undefined;
for(serviceName in services ) {
var service = services[serviceName];
var ports = service.ports;
for(portName in ports) {
var port = ports[portName];
var portPathname = url.parse(port.location).pathname.replace(/\/$/,'');
+ 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);
+ }
}
Server.prototype._executeMethod = function(options, callback) {
View
0 lib/soap.js 100644 → 100755
No changes.
View
7 lib/wsdl.js 100644 → 100755
@@ -483,7 +483,8 @@ ElementElement.prototype.description = function(definitions) {
var element = {},
name = this.$name,
schema;
- if (this.$minOccurs !== this.$maxOccurs) {
+ var isMany = !this.$maxOccurs ? false : (isNaN(this.$maxOccurs) ? (this.$maxOccurs == 'unbounded') : (this.$maxOccurs > 1));
+ if (this.$minOccurs !== this.$maxOccurs && isMany) {
name += '[]';
}
@@ -856,14 +857,14 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns) {
parts.push(['</',ns,name,'>'].join(''));
parts.push(['<',ns,name,xmlnsAttrib,'>'].join(''));
}
- parts.push(self.objectToXML(item, name));
+ parts.push(self.objectToXML(item, name, namespace, xmlns));
}
}
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(self.objectToXML(child, name, namespace, xmlns));
parts.push(['</',ns,name,'>'].join(''));
}
}
View
0 package.json 100644 → 100755
No changes.
View
0 test/ip2tele/cfg.js 100644 → 100755
No changes.
View
0 test/ip2tele/fake_server.js 100644 → 100755
No changes.
View
0 test/ip2tele/ip2tele.js 100644 → 100755
No changes.
View
0 test/ip2tele/ip2tele.wsdl 100644 → 100755
No changes.
View
0 test/ip2tele/logs/dummy 100644 → 100755
No changes.
View
0 test/ip2tele/readme.md 100644 → 100755
No changes.
View
0 test/server-test.js 100644 → 100755
No changes.
View
0 test/vac/logs/vac_trace.xml 100644 → 100755
No changes.
View
0 test/vac/vac.js 100644 → 100755
No changes.
View
No changes.
View
No changes.
View
No changes.
View
No changes.
View
0 test/wsdl/strict/DE.wsdl 100644 → 100755
No changes.
View
0 test/wsdl/strict/ip2tele.wsdl 100644 → 100755
No changes.
View
0 test/wsdl/strict/logincms.wsdl 100644 → 100755
No changes.
View
0 test/wsdl/strict/stockquote.wsdl 100644 → 100755
No changes.

0 comments on commit 0f0382a

Please sign in to comment.