Skip to content

Commit

Permalink
Handles faults with no params.
Browse files Browse the repository at this point in the history
A fault in the form `<methodResponse><fault></value></fault></methodResponse>`
was not calling the callback properly since no param fields were being hit. This
problem was noticed when trying to chain functions in the example code. A test
case was added to prevent regression.

See Issue baalexander#32.
  • Loading branch information
baalexander committed Oct 27, 2011
1 parent 182b2bb commit 879f826
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
51 changes: 29 additions & 22 deletions example/client-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,40 +159,47 @@ setTimeout(function () {
var client = xmlrpc.createSecureClient(secureClientOptions)
*/

client.methodCall('setArray', [['value1', 'value2']], function (error, value) {})
client.methodCall('getArray', null, function (error, value) {
console.log('Get Array Response: ' + value)
client.methodCall('setArray', [['value1', 'value2']], function(error, value) {
client.methodCall('getArray', null, function (error, value) {
console.log('Get Array Response: ' + value)
})
})

client.methodCall('setBoolean', [true], function (error, value) {})
client.methodCall('getBoolean', null, function (error, value) {
console.log('Get Boolean Response: ' + value)
client.methodCall('setBoolean', [true], function (error, value) {
client.methodCall('getBoolean', null, function (error, value) {
console.log('Get Boolean Response: ' + value)
})
})

client.methodCall('setDate', [new Date(2016, 05, 08, 11, 35, 10)], function (error, value) {})
client.methodCall('getDate', null, function (error, value) {
console.log('Get Date Response: ' + value)
client.methodCall('setDate', [new Date(2016, 05, 08, 11, 35, 10)], function (error, value) {
client.methodCall('getDate', null, function (error, value) {
console.log('Get Date Response: ' + value)
})
})

client.methodCall('setDouble', [24.99], function (error, value) {})
client.methodCall('getDouble', null, function (error, value) {
console.log('Get Double Response: ' + value)
client.methodCall('setDouble', [24.99], function (error, value) {
client.methodCall('getDouble', null, function (error, value) {
console.log('Get Double Response: ' + value)
})
})

client.methodCall('setInteger', [23], function (error, value) {})
client.methodCall('getInteger', null, function (error, value) {
console.log('Get Integer Response: ' + value)
client.methodCall('setInteger', [23], function (error, value) {
client.methodCall('getInteger', null, function (error, value) {
console.log('Get Integer Response: ' + value)
})
})

client.methodCall('setString', ['testString1'], function (error, value) {})
client.methodCall('getString', null, function (error, value) {
console.log('Get String Response: ' + value)
client.methodCall('setString', ['testString1'], function (error, value) {
client.methodCall('getString', null, function (error, value) {
console.log('Get String Response: ' + value)
})
})

client.methodCall('setStruct', [{ nameOfValue: 'Go 1998!' }], function (error, value) {})
client.methodCall('getStruct', null, function (error, value) {
console.log('Get Struct Response (on next line): ')
console.log(value)
client.methodCall('setStruct', [{ nameOfValue: 'Go 1998!' }], function (error, value) {
client.methodCall('getStruct', null, function (error, value) {
console.log('Get Struct Response (on next line): ')
console.log(value)
})
})

client.methodCall('fakeFault', null, function (error, value) {
Expand Down
3 changes: 2 additions & 1 deletion lib/xmlrpc-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function deserializeParams(parser, callback) {
}
})

parser.onStartElementNS(handleStartElement)
resetListeners(parser, handleStartElement)

function handleStartElement(element, attributes, prefix, uri, namespaces) {
// Parses each param in the message
Expand All @@ -137,6 +137,7 @@ function deserializeParams(parser, callback) {
}
// If the message response is a fault, parse the error
else if (element === 'fault') {
fault = {}
deserializeParam(parser, function (error, value, parser) {
resetListeners(parser, handleStartElement)
fault = value
Expand Down
13 changes: 13 additions & 0 deletions test/xmlrpc-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ vows.describe('XML-RPC Parser').addBatch({
assert.strictEqual(error.faultCode, 4)
}
}
, 'with an empty fault' : {
topic: function() {
var xml = '<?xml version="1.0"?><methodResponse><fault>'
+ '<value/>'
+ '</fault></methodResponse>'
xmlrpcParser.parseMethodResponse(null, xml, this.callback)
}
, 'contains the error object' : function (error, value) {
assert.isObject(error)
assert.instanceOf(error, Error)
assert.include(error, 'stack')
}
}
// Test Integer
, 'with a positive Int param' : {
topic: function() {
Expand Down

0 comments on commit 879f826

Please sign in to comment.