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

* check method style if exists instead of binding style #1153

Merged
merged 5 commits into from
Aug 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 19 additions & 25 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export interface Server {
interface IExecuteMethodOptions {
serviceName?: string;
portName?: string;
soapAction?: string;
methodName?: string;
outputName?: string;
args?: any;
Expand Down Expand Up @@ -357,40 +356,37 @@ export class Server extends EventEmitter {
}

try {
if (binding.style === 'rpc') {
methodName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
const soapAction = this._getSoapAction(req);
const messageElemName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
const pair = binding.topElements[messageElemName];
if (soapAction) {
methodName = this._getMethodNameBySoapAction(binding, soapAction);
} else {
methodName = pair ? pair.methodName : messageElemName;
}
/** Style can be defined in method. If method has no style then look in binding */
const style = binding.methods[methodName].style || binding.style;

this.emit('request', obj, methodName);
if (headers) {
this.emit('headers', headers, methodName);
}
this.emit('request', obj, methodName);
if (headers) {
this.emit('headers', headers, methodName);
}

if (style === 'rpc') {
this._executeMethod({
serviceName: serviceName,
portName: portName,
soapAction: this._getSoapAction(req),
methodName: methodName,
outputName: methodName + 'Response',
args: body[methodName],
outputName: messageElemName + 'Response',
args: body[messageElemName],
headers: headers,
style: 'rpc',
}, req, res, callback);
} else {
const messageElemName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
const pair = binding.topElements[messageElemName];

this.emit('request', obj, pair.methodName);
if (headers) {
this.emit('headers', headers, pair.methodName);
}

methodName = pair.methodName;

this._executeMethod({
serviceName: serviceName,
portName: portName,
soapAction: this._getSoapAction(req),
methodName: pair.methodName,
methodName: methodName,
outputName: pair.outputName,
args: body[messageElemName],
headers: headers,
Expand Down Expand Up @@ -496,9 +492,7 @@ export class Server extends EventEmitter {
const serviceName = options.serviceName;
const portName = options.portName;
const binding = this.wsdl.definitions.services[serviceName].ports[portName].binding;
const methodName = options.soapAction
? this._getMethodNameBySoapAction(binding, options.soapAction)
: options.methodName;
const methodName = options.methodName;
const outputName = options.outputName;
const args = options.args;
const style = options.style;
Expand Down
6 changes: 3 additions & 3 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ export class WSDL {
if (typeof binding.style === 'undefined') {
binding.style = 'document';
}
if (binding.style !== 'document') {
continue;
}
const methods = binding.methods;
const topEls: elements.ITopElements = binding.topElements = {};
for (const methodName in methods) {
if ((methods[methodName].style || binding.style) !== 'document') {
continue;
}
if (methods[methodName].input) {
const inputName = methods[methodName].input.$name;
let outputName = '';
Expand Down
80 changes: 80 additions & 0 deletions test/server-style-mix-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

var fs = require('fs');
var request = require('request');
var assert = require('assert');
var http = require('http');
var soap = require('..');
var server;
var url;

var path = 'test/wsdl/wsdl_style_mix.wsdl';
var wsdl = fs.readFileSync(path, 'utf8');;

/**
* requested operation has 'document' style while the binding itself has 'rpc' style
**/
var requestXML = `
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:hl7-org:v3">
<soapenv:Header/>
<soapenv:Body>
<urn:hl7Message>
<test></test>
</urn:hl7Message>
</soapenv:Body>
</soapenv:Envelope>`;

var responseXMLGood = `<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://tempuri.org/" xmlns:urn="urn:hl7-org:v3"><soap:Body><urn:hl7Message xmlns:urn="urn:hl7-org:v3" xmlns="urn:hl7-org:v3"><urn:result></urn:result></urn:hl7Message></soap:Body></soap:Envelope>`;

var service = {
HL7Service: {
Hl7MessageBinding: {
opHl7Message: function (args, callback) {
callback({ result: {} });
}
}
}
};

describe('server has mixed style', function () {

before(function (done) {

server = http.createServer(function (request, response) {
response.end('404: Not Found: ' + request.url);
});

server.listen(51515, function () {
soap.listen(server, '/', service, wsdl);

url = 'http://' + server.address().address + ':' + server.address().port;
if (server.address().address === '0.0.0.0' || server.address().address === '::') {
url = 'http://127.0.0.1:' + server.address().port;
}
done();
});
});

after(function () {
server.close();
});

it('should return good response', function (done) {
request({
url: url,
method: 'POST',
headers: {
SOAPAction: "urn:#opHl7Message",
"Content-Type": 'text/xml; charset="utf-8"'
},
body: requestXML
}, function (err, response, body) {
if (err) {
throw err;
}
assert.strictEqual(body, responseXMLGood);
done();
});
});

});
54 changes: 54 additions & 0 deletions test/wsdl/wsdl_style_mix.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://tempuri.org/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:urn="urn:hl7-org:v3" name="HL7Service"
targetNamespace="http://tempuri.org/">

<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="urn:hl7-org:v3" elementFormDefault="qualified" targetNamespace="urn:hl7-org:v3">
<xs:element name="hl7Message">
<xs:complexType>
<xs:sequence>
<xs:any/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>

<wsdl:message name="opHl7MessageRequest">
<wsdl:part name="hl7Message" element="urn:hl7Message"/>
</wsdl:message>
<wsdl:message name="opHl7MessageResponse">
<wsdl:part name="hl7Message" element="urn:hl7Message"/>
</wsdl:message>

<wsdl:portType name="portHl7Message">
<wsdl:operation name="opHl7Message">
<wsdl:input wsaw:Action="urn:#opHl7Message" name="opHl7MessageRequest" message="tns:opHl7MessageRequest"/>
<wsdl:output wsaw:Action="urn:#opHl7MessageResponse" name="opHl7MessageResponse" message="tns:opHl7MessageResponse"/>
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="Hl7MessageBinding" type="tns:portHl7Message">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<wsdl:operation name="opHl7Message">
<soap:operation soapAction="urn:#opHl7Message" style="document"/>
<wsdl:input name="opHl7MessageRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="opHl7MessageResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="HL7Service">
<wsdl:port name="Hl7MessageBinding" binding="tns:Hl7MessageBinding">
<soap:address location="http://127.0.0.1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>