Skip to content

Commit

Permalink
Merge pull request vpulim#243 from godaddy/parse-response-operation-e…
Browse files Browse the repository at this point in the history
…nding-with-out

Fixing undefined value for json in client method when message names end with Out or Output.
  • Loading branch information
Vinay Pulim committed Feb 15, 2014
2 parents 796f8b4 + 46406ab commit 04b1dc9
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,15 @@ Client.prototype._invoke = function(method, args, location, callback, options) {
error.body = body;
return callback(error, response, body);
}

result = obj.Body[output.$name];
// RPC/literal response body may contain element named after the method + 'Response'
// RPC/literal response body may contain elements with added suffixes I.E.
// 'Response', or 'Output', or 'Out'
// This doesn't necessarily equal the ouput message name. See WSDL 1.1 Section 2.4.5
if (!result) {
result = obj.Body[name + 'Response'];
if(!result){
result = obj.Body[output.$name.replace(/(?:Out(?:put)?|Response)$/, '')];
}

callback(null, result, body);
}
}, headers, options);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"mocha": "mocha -R spec -u exports test/*-test.js",
"jshint" : "jshint index.js lib/http.js lib/client.js lib/soap.js lib/server.js lib/wsdl.js",
"jshint": "jshint index.js lib/http.js lib/client.js lib/soap.js lib/server.js lib/wsdl.js",
"test": "npm run-script jshint && npm run-script mocha"
},
"keywords": [
Expand All @@ -34,6 +34,7 @@
],
"devDependencies": {
"mocha": "~1.17.0",
"jshint": "~2.4.2"
"jshint": "~2.4.2",
"glob": "~3.2.8"
}
}
73 changes: 73 additions & 0 deletions test/request-response-samples-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"use strict";

var assert = require('assert');
var fs = require('fs');
var glob = require('glob');
var http = require('http');
var path = require('path');
var soap = require('../');
var server;
var port;
var endpoint;
var tests = glob.sync('./request-response-samples/*', {cwd:__dirname})
.map(function(node){return path.resolve(__dirname, node);})
.filter(function(node){return fs.statSync(node).isDirectory();});
var suite = {};

var requestContext = {
//set these two within each test
expectedRequest:null,
responseToSend:null,
requestHandler:function(req, res){
var chunks = [];
req.on('data', function(chunk){
chunks.push(chunk);
});
req.on('end', function(){
assert.equal(chunks.join(''), requestContext.expectedRequest);
res.end(requestContext.responseToSend);
requestContext.expectedRequest = null;
requestContext.responseToSend = null;
});
}
};

module.exports = {
before:function(done){
server = http.createServer(requestContext.requestHandler);
server.listen(0, function(e){
if(e)return done(e);
port = server.address().port;
done();
});
},
after:function(){
server.close();
},
'Request Response Sampling':suite
};

tests.forEach(function(test){
var name = path.basename(test);
var wsdl = path.resolve(test, 'soap.wsdl');
var requestJSON = require(path.resolve(test, 'request.json'));
var requestXML = ""+fs.readFileSync(path.resolve(test, 'request.xml'));
var responseJSON = require(path.resolve(test, 'response.json'));
var responseXML = ""+fs.readFileSync(path.resolve(test, 'response.xml'));

generateTest(name, wsdl, requestXML, requestJSON, responseXML, responseJSON);
});

function generateTest(name, wsdlPath, requestXML, requestJSON, responseXML, responseJSON){
suite[name] = function(done){
requestContext.expectedRequest = requestXML;
requestContext.responseToSend = responseXML;
soap.createClient(wsdlPath, function(err, client){
client.Message(requestJSON, function(err, json, body){
assert.deepEqual(json, responseJSON);
assert.deepEqual(body, responseXML);
done();
});
}, 'http://localhost:'+port+'/Message/Message.dll?Handler=Default');
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bstrResourceId": "034b7ea5-8a04-11e3-9710-0050569575d8"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s0="urn:MessageService" xmlns:atls="http://tempuri.org/vc/atl/server/"><soap:Header></soap:Header><soap:Body><s0:Message><bstrResourceId>034b7ea5-8a04-11e3-9710-0050569575d8</bstrResourceId></s0:Message></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"return":"-1",
"bstrError":{}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError></bstrError></snp:Message></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<!-- ATL Server generated Web Service Description -->
<definitions
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s0="urn:MessageService"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:atls="http://tempuri.org/vc/atl/server/"
targetNamespace="urn:MessageService"
xmlns="http://schemas.xmlsoap.org/wsdl/"
>
<types>
<s:schema targetNamespace="urn:MessageService" attributeFormDefault="qualified" elementFormDefault="qualified">
<s:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</s:schema>
</types>
<message name="MessageIn">
<part name="bstrResourceID" type="s:string"/>
</message>
<message name="MessageOut">
<part name="return" type="s:string"/>
<part name="bstrError" type="s:string"/>
</message>
<portType name="MessageServiceSoap">
<operation name="Message">
<input message="s0:MessageIn"/>
<output message="s0:MessageOut"/>
</operation>
</portType>
<binding name="MessageServiceSoap" type="s0:MessageServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="Message">
<soap:operation soapAction="#Message" style="rpc"/>
<input>
<soap:body use="encoded" namespace="urn:MessageService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:MessageService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="MessageService">
<port name="MessageServiceSoap" binding="s0:MessageServiceSoap">
<soap:address location="http://localhost/Message/Message.dll?Handler=Default"/>
</port>
</service>
</definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bstrResourceId": "034b7ea5-8a04-11e3-9710-0050569575d8"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s0="urn:MessageService" xmlns:atls="http://tempuri.org/vc/atl/server/"><soap:Header></soap:Header><soap:Body><s0:Message><bstrResourceId>034b7ea5-8a04-11e3-9710-0050569575d8</bstrResourceId></s0:Message></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"return":"-1",
"bstrError":{}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError></bstrError></snp:Message></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<!-- ATL Server generated Web Service Description -->
<definitions
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s0="urn:MessageService"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:atls="http://tempuri.org/vc/atl/server/"
targetNamespace="urn:MessageService"
xmlns="http://schemas.xmlsoap.org/wsdl/"
>
<types>
<s:schema targetNamespace="urn:MessageService" attributeFormDefault="qualified" elementFormDefault="qualified">
<s:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</s:schema>
</types>
<message name="MessageInput">
<part name="bstrResourceID" type="s:string"/>
</message>
<message name="MessageOutput">
<part name="return" type="s:string"/>
<part name="bstrError" type="s:string"/>
</message>
<portType name="MessageServiceSoap">
<operation name="Message">
<input message="s0:MessageInput"/>
<output message="s0:MessageOutput"/>
</operation>
</portType>
<binding name="MessageServiceSoap" type="s0:MessageServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="Message">
<soap:operation soapAction="#Message" style="rpc"/>
<input>
<soap:body use="encoded" namespace="urn:MessageService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:MessageService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="MessageService">
<port name="MessageServiceSoap" binding="s0:MessageServiceSoap">
<soap:address location="http://localhost/Message/Message.dll?Handler=Default"/>
</port>
</service>
</definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bstrResourceId": "034b7ea5-8a04-11e3-9710-0050569575d8"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s0="urn:MessageService" xmlns:atls="http://tempuri.org/vc/atl/server/"><soap:Header></soap:Header><soap:Body><s0:Message><bstrResourceId>034b7ea5-8a04-11e3-9710-0050569575d8</bstrResourceId></s0:Message></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"return":"-1",
"bstrError":{}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError></bstrError></snp:Message></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<!-- ATL Server generated Web Service Description -->
<definitions
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s0="urn:MessageService"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:atls="http://tempuri.org/vc/atl/server/"
targetNamespace="urn:MessageService"
xmlns="http://schemas.xmlsoap.org/wsdl/"
>
<types>
<s:schema targetNamespace="urn:MessageService" attributeFormDefault="qualified" elementFormDefault="qualified">
<s:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</s:schema>
</types>
<message name="MessageRequest">
<part name="bstrResourceID" type="s:string"/>
</message>
<message name="MessageResponse">
<part name="return" type="s:string"/>
<part name="bstrError" type="s:string"/>
</message>
<portType name="MessageServiceSoap">
<operation name="Message">
<input message="s0:MessageRequest"/>
<output message="s0:MessageResponse"/>
</operation>
</portType>
<binding name="MessageServiceSoap" type="s0:MessageServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="Message">
<soap:operation soapAction="#Message" style="rpc"/>
<input>
<soap:body use="encoded" namespace="urn:MessageService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:MessageService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="MessageService">
<port name="MessageServiceSoap" binding="s0:MessageServiceSoap">
<soap:address location="http://localhost/Message/Message.dll?Handler=Default"/>
</port>
</service>
</definitions>

0 comments on commit 04b1dc9

Please sign in to comment.