Skip to content

Commit

Permalink
Resolved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
alanbly committed Jan 17, 2013
2 parents df65e52 + ecdc3ee commit dffc145
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
35 changes: 32 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,23 @@ var Server = function(server, path, services, wsdl) {
})
}


Server.prototype.addHeaderHandler = function (domain, handler) {
var self = this;
if (!self.header_handler) {
self.header_handlers = {};
}
if (!self.header_handlers[domain]) {
self.header_handlers[domain] = [];
}
self.header_handlers[domain].push(handler);
}


Server.prototype._requestListener = function(req, res) {
var self = this;
this.context = {};
this.context.http_headers = req.headers;
var reqParse = url.parse(req.url);
var reqPath = reqParse.pathname;
var reqQuery = reqParse.search;
Expand Down Expand Up @@ -111,6 +126,17 @@ Server.prototype._process = function(input, URL, callback) {
bindings = this.wsdl.definitions.bindings, binding,
methods, method, methodName,
serviceName, portName;

if ((obj.Header) && (self.header_handlers)) {
var context = this.context || {};
Object.keys(self.header_handlers).forEach( function (domain) {
if (obj.Header[domain]) {
self.header_handlers[domain].forEach( function (handler) {
handler(obj.Header[domain], context);
});
}
});
}

if (typeof self.authenticate === 'function') {
if (obj.Header == null || obj.Header.Security == null) {
Expand Down Expand Up @@ -193,12 +219,15 @@ Server.prototype._executeMethod = function(options, callback) {
} catch(e) {
return callback(this._envelope(''));
}
args['_context'] = this.context;

function handleResult(result) {
function handleResult(err, result) {
if (handled) return;
handled = true;

if(style==='rpc') {
if (err) {
body = self.wsdl.faultToRpcXML(err);
} else if (style==='rpc') {
body = self.wsdl.objectToRpcXML(outputName, result, '', self.wsdl.definitions.$targetNamespace);
} else {
var element = self.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output;
Expand All @@ -209,7 +238,7 @@ Server.prototype._executeMethod = function(options, callback) {

var result = method(args, handleResult);
if (typeof result !== 'undefined') {
handleResult(result);
handleResult(err, result);
}
}

Expand Down
27 changes: 24 additions & 3 deletions lib/wsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,8 @@ WSDL.prototype.objectToRpcXML = function(name, params, namespace, xmlns) {
namespace = namespace || findKey(defs.xmlns, xmlns),
xmlns = xmlns || defs.xmlns[namespace],
nsAttrName = '_xmlns';
parts.push(['<',namespace,':',name,'>'].join(''));
// parts.push(['<',namespace,':',name,'>'].join(''));
parts.push(['<',name,' xmlns="'+xmlns+'"','>'].join(''));
for (var key in params) {
if (key != nsAttrName) {
var value = params[key];
Expand All @@ -839,7 +840,27 @@ WSDL.prototype.objectToRpcXML = function(name, params, namespace, xmlns) {
parts.push(['</',key,'>'].join(''));
}
}
parts.push(['</',namespace,':',name,'>'].join(''));
// parts.push(['</',namespace,':',name,'>'].join(''));
parts.push(['</',name,'>'].join(''));

return parts.join('');
}

// bad static namespacing here; should be based off a variable, but seems like
// node-soap uses 'soap' no matter what, in any case..
WSDL.prototype.faultToRpcXML = function(params) {
var parts = [],
nsAttrName = '_xmlns';
parts.push(['<soap:Fault>'].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(''));
}
}
parts.push(['</soap:Fault>'].join(''));

return parts.join('');
}
Expand Down Expand Up @@ -867,7 +888,7 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns) {
parts.push(['</',ns,name,'>'].join(''));
}
}
else if (obj) {
else if ((obj!=undefined) && (obj!=null)) {
parts.push(xmlEscape(obj));
}
return parts.join('');
Expand Down

0 comments on commit dffc145

Please sign in to comment.