Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): add rawRequest to callback arguments #992

Merged
merged 1 commit into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,11 @@ An instance of `Client` is passed to the `soap.createClient` callback. It is us
### Client.*method*(args, callback, options) - call *method* on the SOAP service.

``` javascript
client.MyFunction({name: 'value'}, function(err, result, raw, soapHeader) {
client.MyFunction({name: 'value'}, function(err, result, rawResponse, soapHeader, rawRequest) {
// result is a javascript object
// raw is the raw response
// rawResponse is the raw xml response string
// soapHeader is the response soap header as a javascript object
// rawRequest is the raw xml request string
})
```

Expand Down
24 changes: 12 additions & 12 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ Client.prototype._defineMethod = function(method, location) {
extraHeaders = options;
options = temp;
}
self._invoke(method, args, location, function(error, result, raw, soapHeader) {
callback(error, result, raw, soapHeader);
self._invoke(method, args, location, function(error, result, rawResponse, soapHeader, rawRequest) {
callback(error, result, rawResponse, soapHeader, rawRequest);
}, options, extraHeaders);
};
};
Expand Down Expand Up @@ -279,7 +279,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e
if(options && options.postProcess){
xml = options.postProcess(xml);
}

self.lastMessage = message;
self.lastRequest = xml;
self.lastEndpoint = location;
Expand Down Expand Up @@ -309,7 +309,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e
self.lastElapsedTime = null;
self.emit('response', null, null, eid);

callback(err);
callback(err, undefined, undefined, undefined, xml);
};
req.on('error', onError);
req.on('response', function (response) {
Expand Down Expand Up @@ -340,7 +340,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e
error.response = response;
error.body = '<stream>';
self.emit('soapError', error, eid);
return callback(error, response);
return callback(error, response, undefined, undefined, xml);
}

return finish(obj, '<stream>', response);
Expand All @@ -356,7 +356,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e
self.emit('response', body, response, eid);

if (err) {
callback(err);
callback(err, undefined, undefined, undefined, xml);
} else {
return parseSync(body, response);
}
Expand All @@ -374,13 +374,13 @@ Client.prototype._invoke = function(method, args, location, callback, options, e
// If the response is JSON then return it as-is.
var json = _.isObject(body) ? body : tryJSONparse(body);
if (json) {
return callback(null, response, json);
return callback(null, response, json, undefined, xml);
}
}
error.response = response;
error.body = body;
self.emit('soapError', error, eid);
return callback(error, response, body);
return callback(error, response, body, undefined, xml);
}
return finish(obj, body, response);
}
Expand All @@ -390,19 +390,19 @@ Client.prototype._invoke = function(method, args, location, callback, options, e

if (!output){
// one-way, no output expected
return callback(null, null, body, obj.Header);
return callback(null, null, body, obj.Header, xml);
}

if( typeof obj.Body !== 'object' ) {
var error = new Error('Cannot parse response');
error.response = response;
error.body = body;
return callback(error, obj, body);
return callback(error, obj, body, undefined, xml);
}

// if Soap Body is empty
if (!obj.Body) {
return callback(null, obj, body, obj.Header);
return callback(null, obj, body, obj.Header, xml);
}

result = obj.Body[output.$name];
Expand All @@ -420,7 +420,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e
});
}

callback(null, result, body, obj.Header);
callback(null, result, body, obj.Header, xml);
}

// Added mostly for testability, but possibly useful for debugging
Expand Down
14 changes: 14 additions & 0 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ var fs = require('fs'),
}, baseUrl);
});

it('should have rawRequest available in the callback', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ifError(err);

client.MyOperation({}, function (err, result, rawResponse, headers, rawRequest) {
assert.ok(rawRequest);
assert.ok(typeof rawRequest === 'string');

done();
}, null, { 'test-header': 'test' });
}, baseUrl);
});

it('should have lastElapsedTime after a call with the time option passed', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
Expand Down