Navigation Menu

Skip to content

Commit

Permalink
Return the soapHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenchr committed Jan 14, 2015
1 parent 9fdd739 commit 248cffb
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Readme.md
Expand Up @@ -173,8 +173,10 @@ as default request options to the constructor:
### Client.*method*(args, callback) - call *method* on the SOAP service.

``` javascript
client.MyFunction({name: 'value'}, function(err, result) {
client.MyFunction({name: 'value'}, function(err, result, raw, soapHeader) {
// result is a javascript object
// raw is the raw response
// soapHeader is the response soap header as a javascript object
})
```
### Client.*service*.*port*.*method*(args, callback[, options]) - call a *method* using a specific *service* and *port*
Expand Down
6 changes: 3 additions & 3 deletions lib/client.js
Expand Up @@ -98,8 +98,8 @@ Client.prototype._defineMethod = function(method, location) {
callback = args;
args = {};
}
self._invoke(method, args, location, function(error, result, raw) {
callback(error, result, raw);
self._invoke(method, args, location, function(error, result, raw, soapHeader) {
callback(error, result, raw, soapHeader);
}, options, extraHeaders);
};
};
Expand Down Expand Up @@ -202,7 +202,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e
});
}

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

Expand Down
14 changes: 11 additions & 3 deletions test/request-response-samples-test.js
Expand Up @@ -72,6 +72,7 @@ tests.forEach(function(test){
var requestJSON = path.resolve(test, 'request.json');
var requestXML = path.resolve(test, 'request.xml');
var responseJSON = path.resolve(test, 'response.json');
var responseSoapHeaderJSON = path.resolve(test, 'responseSoapHeader.json');
var responseJSONError = path.resolve(test, 'error_response.json');
var responseXML = path.resolve(test, 'response.xml');
var options = path.resolve(test, 'options.json');
Expand All @@ -91,6 +92,10 @@ tests.forEach(function(test){
else if(fs.existsSync(responseJSONError))responseJSON = require(responseJSONError);
else responseJSON = null;

//responseSoapHeaderJSON is optional
if (fs.existsSync(responseSoapHeaderJSON))responseSoapHeaderJSON = require(responseSoapHeaderJSON);
else responseSoapHeaderJSON = null;

//requestXML is optional
if(fs.existsSync(requestXML))requestXML = ""+fs.readFileSync(requestXML);
else requestXML = null;
Expand All @@ -110,10 +115,10 @@ tests.forEach(function(test){
if(fs.existsSync(wsdlOptionsFile)) wsdlOptions = require(wsdlOptionsFile);
else wsdlOptions = {};

generateTest(name, methodName, wsdl, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, wsdlOptions, options);
generateTest(name, methodName, wsdl, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options);
});

function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, wsdlOptions, options){
function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options){
suite[name] = function(done){
if(requestXML)requestContext.expectedRequest = requestXML;
if(responseXML)requestContext.responseToSend = responseXML;
Expand All @@ -127,13 +132,16 @@ function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requ
if (securityJSON && securityJSON.type === 'ws') {
client.setSecurity(new WSSecurity(securityJSON.username, securityJSON.password));
}
client[methodName](requestJSON, function(err, json, body){
client[methodName](requestJSON, function(err, json, body, soapHeader){
if(requestJSON){
if (err) {
assert.deepEqual(err.root, responseJSON);
} else {
// assert.deepEqual(json, responseJSON);
assert.equal(JSON.stringify(json), JSON.stringify(responseJSON));
if(responseSoapHeaderJSON){
assert.equal(JSON.stringify(soapHeader), JSON.stringify(responseSoapHeaderJSON));
}
}
}
done();
Expand Down
@@ -0,0 +1,3 @@
{
"headerName": "headerContent"
}
@@ -0,0 +1 @@
{ }
@@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><soap:Header>headerContent</soap:Header><soap:Body><Request xmlns="http://www.example.com/v1"></Request></soap:Body></soap:Envelope>
@@ -0,0 +1 @@
{ }
@@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ><soap:Header><SomeToken>abcdefg</SomeToken></soap:Header><soap:Body><Response xmlns="http://www.example.com/v1"></Response></soap:Body></soap:Envelope>
@@ -0,0 +1,3 @@
{
"SomeToken": "abcdefg"
}
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="MyService" targetNamespace="http://www.example.com/v1" xmlns="http://www.example.com/v1" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.example.com/v1" xmlns="http://www.example.com/v1">
<xs:element name="Request">
</xs:element>
<xs:element name="Response">
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="InputMessage">
<wsdl:part name="parameter" element="Request">
</wsdl:part>
</wsdl:message>
<wsdl:message name="OutputMessage">
<wsdl:part name="parameter" element="Response">
</wsdl:part>
</wsdl:message>

<wsdl:portType name="MyServicePortType">
<wsdl:operation name="ResponseHeaders">
<wsdl:input message="InputMessage">
</wsdl:input>
<wsdl:output message="OutputMessage">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="MyServiceBinding" type="MyServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ResponseHeaders">
<soap:operation soapAction="ResponseHeaders"/>
<wsdl:input>
<soap:body use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="MyService">
<wsdl:port name="MyServicePort" binding="MyServiceBinding">
<soap:address location="http://www.example.com/v1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

0 comments on commit 248cffb

Please sign in to comment.