Skip to content

Commit

Permalink
Merge pull request #228 from futurice/master
Browse files Browse the repository at this point in the history
Fix requests if SOAP service is not on port 80, do not crash on errors
  • Loading branch information
aheckmann committed Jan 28, 2014
2 parents 52e857d + 488e141 commit 860eecc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Client.prototype._invoke = function(method, args, location, callback, options) {
var result;
var obj;
self.lastResponse = body;
self.lastResponseHeaders = response.headers;
self.lastResponseHeaders = response && response.headers;
if (err) {
callback(err);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.request = function(rurl, data, callback, exheaders, exoptions) {
"Accept-Encoding": "none",
"Accept-Charset": "utf-8",
"Connection": "close",
"Host" : host
"Host" : host + (port ? ":"+port : "")
};
var attr;

Expand Down
43 changes: 34 additions & 9 deletions test/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,29 @@ wsdlNonStrictTests['should not parse connection error'] = function(done) {
});
};


var server = null;
module.exports = {
beforeEach: function() {
var wsdl = fs.readFileSync(__dirname+'/wsdl/strict/stockquote.wsdl', 'utf8');
server = http.createServer(function(req, res) {
res.statusCode = 404;
res.end();
});
server.listen(15099);
soap.listen(server, '/stockquote', service, wsdl);
},
afterEach: function(done) {
if (!server) return done()
server.close(function() {
server = null;
done();
});
},

'SOAP Server': {

'should start': function(done) {
var wsdl = fs.readFileSync(__dirname+'/wsdl/strict/stockquote.wsdl', 'utf8'),
server = http.createServer(function(req, res) {
res.statusCode = 404;
res.end();
});
server.listen(15099);
soap.listen(server, '/stockquote', service, wsdl);
'should be running': function(done) {
request('http://localhost:15099', function(err, res, body) {
assert.ok(!err);
done();
Expand All @@ -82,6 +94,19 @@ module.exports = {
})
},

'should return a valid error if the server stops responding': function(done) {
soap.createClient('http://localhost:15099/stockquote?wsdl', function(err, client) {
assert.ok(!err);
server.close(function() {
server = null;
client.GetLastTradePrice({ tickerSymbol: 'trigger error' }, function(err, response, body) {
assert.ok(err);
done();
});
});
});
},

'should return complete client description': function(done) {
soap.createClient('http://localhost:15099/stockquote?wsdl', function(err, client) {
assert.ok(!err);
Expand Down Expand Up @@ -113,7 +138,7 @@ module.exports = {
done();
});
});
}
},
},
'WSDL Parser (strict)': wsdlStrictTests,
'WSDL Parser (non-strict)': wsdlNonStrictTests
Expand Down

0 comments on commit 860eecc

Please sign in to comment.