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

Fixed rpc path, added rpc/literal test and fixed a wsdl #7

Merged
merged 2 commits into from
Aug 29, 2016
Merged
Changes from 1 commit
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
Next Next commit
fixed rpc path and added a test for rpc/literal style
  • Loading branch information
rashmihunt committed Aug 29, 2016

Verified

This commit was signed with the committer’s verified signature.
vidhyamanisankar vidhyamanisankar
commit 05842a6fe1df119478e64f8ae452a9d48949b3b6
37 changes: 14 additions & 23 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -277,35 +277,26 @@ class Server extends Base {
// Backward compatibility to support one argument callback style
result = error;
}
var operation = self.wsdl.definitions.services[serviceName]
.ports[portName].binding.operations[operationName];
var element = operation.output;

var operationDescriptor = operation.describe(self.wsdl.definitions);
var outputBodyDescriptor = operationDescriptor.output.body;

if (style === 'rpc') {
//[rashmi] this needs a fix, calling non existent api
var env = XMLHandler.createSOAPEnvelope();
body = self.wsdl.objectToRpcXML(outputName, result, '', self.wsdl.definitions.$targetNamespace);
} else {

var operation = self.wsdl.definitions.services[serviceName]
.ports[portName].binding.operations[operationName];
var element = operation.output;

var operationDescriptor = operation.describe(self.wsdl.definitions);
var outputBodyDescriptor = operationDescriptor.output.body;

var soapNsURI = 'http://schemas.xmlsoap.org/soap/envelope/';
var soapNsPrefix = self.wsdl.options.envelopeKey || 'soap';
var soapNsURI = 'http://schemas.xmlsoap.org/soap/envelope/';
var soapNsPrefix = self.wsdl.options.envelopeKey || 'soap';

if (self.wsdl.options.forceSoap12Headers) {
headers['Content-Type'] = 'application/soap+xml; charset=utf-8';
soapNsURI = 'http://www.w3.org/2003/05/soap-envelope';
}
if (self.wsdl.options.forceSoap12Headers) {
headers['Content-Type'] = 'application/soap+xml; charset=utf-8';
soapNsURI = 'http://www.w3.org/2003/05/soap-envelope';
}

var nsContext = self.createNamespaceContext(soapNsPrefix, soapNsURI);
var envelope = XMLHandler.createSOAPEnvelope(soapNsPrefix, soapNsURI);
var nsContext = self.createNamespaceContext(soapNsPrefix, soapNsURI);
var envelope = XMLHandler.createSOAPEnvelope(soapNsPrefix, soapNsURI);

self.xmlHandler.jsonToXml(envelope.body, nsContext, outputBodyDescriptor, result);
self.xmlHandler.jsonToXml(envelope.body, nsContext, outputBodyDescriptor, result);

}
self._envelope(envelope, includeTimestamp);
var message = envelope.body.toString({pretty: true});
var xml = envelope.doc.end({pretty: true});
76 changes: 76 additions & 0 deletions test/server-client-rpc-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"use strict";

var fs = require('fs'),
soap = require('..').soap,
assert = require('assert'),
request = require('request'),
http = require('http'),
lastReqAddress;

var test = {};
test.server = null;
test.service = {
StockQuoteServiceRPC: {
StockQuotePortRPC: {
setLastTradePrice: function(args, cb, soapHeader) {
if (args.tradePrice) {
var jsonResponse = {"result": true};
return jsonResponse;
}
}
}
}
};

describe('SOAP Server', function() {
before(function(done) {
fs.readFile(__dirname + '/wsdl/strict/stockquoterpc.wsdl', 'utf8', function(err, data) {
assert.ok(!err);
test.wsdl = data;
done();
});
});

beforeEach(function(done) {
test.server = http.createServer(function(req, res) {
res.statusCode = 404;
res.end();
});

test.server.listen(15099, null, null, function() {
test.soapServer = soap.listen(test.server, '/stockquoterpc', test.service, test.wsdl);
test.baseUrl =
'http://' + test.server.address().address + ":" + test.server.address().port;

//windows return 0.0.0.0 as address and that is not
//valid to use in a request
if (test.server.address().address === '0.0.0.0' || test.server.address().address === '::') {
test.baseUrl =
'http://127.0.0.1:' + test.server.address().port;
}

done();
});
});
afterEach(function(done) {
test.server.close(function() {
test.server = null;
delete test.soapServer;
test.soapServer = null;
done();
});
});

//rpc/literal test
it('should return correct results', function(done) {
soap.createClient(test.baseUrl + '/stockquoterpc?wsdl', function(err, client) {
assert.ok(!err);
client.setLastTradePrice( {tradePrice: 100}, function(err, result, body) {
assert.ok(!err);
assert.ok(result.result);
done();
});
});
});

});
4 changes: 2 additions & 2 deletions test/wsdl/json_response.wsdl
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@
elementFormDefault="qualified"
targetNamespace="http://www.example.com/v1"
xmlns="http://www.example.com/v1">
<xs:element name="Request" type="xsd:string"/>
<xs:element name="Response" type="xsd:string"/>
<xs:element name="Request" type="xs:string"/>
<xs:element name="Response" type="xs:string"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="InputMessage">
74 changes: 74 additions & 0 deletions test/wsdl/strict/stockquoterpc.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0"?>

<!-- rpc/literal example -->

<wsdl:definitions name="StockQuoteRPC"
targetNamespace="http://example.com/stockquoterpc.wsdl"
xmlns:tns="http://example.com/stockquoterpc.wsdl"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

<wsdl:types>
<xsd:schema targetNamespace="http://example.com/stockquoterpc.xsd"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns="http://example.com/stockquoterpc.xsd" elementFormDefault="qualified">

<xsd:element name="setLastTradePriceResponse" type="setLastTradePriceResponseType"/>
<xsd:element name="setLastTradePriceResponseType">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="tradePrice" type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="setLastTradePriceResponse" type="setLastTradePriceResponseType"/>
<xsd:element name="setLastTradePriceResponseType">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="result" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>


<wsdl:message name="setLastTradePriceRequest">
<wsdl:part name="tradePrice"
type="xsd:float"/>
</wsdl:message>
<wsdl:message name="setLastTradePriceResponse">
<wsdl:part name="result"
type="xsd:boolean"/>
</wsdl:message>

<wsdl:portType name="StockQuoteUpdater">
<wsdl:operation name="setLastTradePrice">
<wsdl:input message="tns:setLastTradePriceRequest"/>
<wsdl:output message="tns:setLastTradePriceResponse"/>
</wsdl:operation>
</wsdl:portType>


<wsdl:binding name="StockQuoteSoapBindingRPC" type="tns:StockQuoteUpdater">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="setLastTradePrice">
<soap:operation soapAction="http://example.com/StockQuoteUpdater"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="StockQuoteServiceRPC">
<wsdl:port name="StockQuotePortRPC" binding="tns:StockQuoteSoapBindingRPC">
<soap:address location="http://localhost:15099/stockquoterpc"/>
</wsdl:port>
</wsdl:service>

</wsdl:definitions>