Skip to content

Commit

Permalink
Making the first port the default if none match
Browse files Browse the repository at this point in the history
  • Loading branch information
alanbly committed Jan 17, 2013
1 parent b63fd4b commit df65e52
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions lib/server.js
Expand Up @@ -15,7 +15,7 @@ try { compress = require("compress"); } catch(e) {}
var Server = function(server, path, services, wsdl) {
var self = this;

this.path = path;
this.services = services;
this.wsdl = wsdl;

Expand Down Expand Up @@ -47,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());
}
Expand Down Expand Up @@ -114,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) {
Expand Down

0 comments on commit df65e52

Please sign in to comment.