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

Remove and re-implement forceSoap12Headers wsdl option #22

Merged
merged 1 commit into from
Sep 29, 2016
Merged
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: 4 additions & 1 deletion example/weather.js
Original file line number Diff line number Diff line change
@@ -23,8 +23,11 @@ soap.createClient(url, clientOptions, function(err, client) {
//custom request header
var customRequestHeader = {timeout: 5000};
var options = {};
//navigate to the correct operation in the client using [service][port][operation] since GetCityWeatherByZIP operation is used
//by more than one port.
var method = client['Weather']['WeatherSoap']['GetCityWeatherByZIP'];
//you can also call
client.GetCityWeatherByZIP(requestArgs, function(err, result, envelope, soapHeader) {
method(requestArgs, function(err, result, envelope, soapHeader) {
//response envelope
console.log(envelope);
//result in SOAP envelope body which is the wrapper element. In this case, result object corresponds to GetCityForecastByZIPResponse
4 changes: 2 additions & 2 deletions example/xsds.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ WSDL.open('./wsdls/weather.wsdl', options,
//User can traverse the WSDL tree and get to bindings - > operations, services, portTypes, messages, parts and XSD elements/Attributes
function(err, wsdl) {
var getCityForecastOp = wsdl.definitions.bindings.WeatherSoap.operations.GetCityForecastByZIP;
console.log(getCityForecastOp.name);
console.log(getCityForecastOp.$name);
var service = wsdl.definitions.services['Weather'];
console.log(service.name);;
console.log(service.$name);
});
1 change: 0 additions & 1 deletion src/base.js
Original file line number Diff line number Diff line change
@@ -58,7 +58,6 @@ class Base extends EventEmitter {
options = options || {};
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
this.wsdl.options.envelopeKey = options.envelopeKey || 'soap';
this.wsdl.options.forceSoap12Headers = !!options.forceSoap12Headers;
}

static createSOAPEnvelope(prefix, nsURI) {
4 changes: 2 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ class Client extends Base {
var soapNsURI = 'http://schemas.xmlsoap.org/soap/envelope/';
var soapNsPrefix = this.wsdl.options.envelopeKey || 'soap';

if (this.wsdl.options.forceSoap12Headers) {
if (operation.soapVersion === '1.2') {
headers['Content-Type'] = 'application/soap+xml; charset=utf-8';
soapNsURI = 'http://www.w3.org/2003/05/soap-envelope';
}
@@ -133,7 +133,7 @@ class Client extends Base {
soapAction = ((ns.lastIndexOf("/") !== ns.length - 1) ? ns + "/" : ns) + name;
}

if (!this.wsdl.options.forceSoap12Headers) {
if (operation.soapVersion !== '1.2') {
headers.SOAPAction = '"' + soapAction + '"';
}

4 changes: 0 additions & 4 deletions src/parser/wsdl.js
Original file line number Diff line number Diff line change
@@ -139,10 +139,6 @@ class WSDL {
this.options.ignoreBaseNameSpaces = ignoreBaseNameSpaces;
else
this.options.ignoreBaseNameSpaces = this.ignoreBaseNameSpaces;

// Works only in client
this.options.forceSoap12Headers = options.forceSoap12Headers;

}

_processNextInclude(includes, callback) {
13 changes: 10 additions & 3 deletions src/parser/wsdl/operation.js
Original file line number Diff line number Diff line change
@@ -211,9 +211,9 @@ class Operation extends WSDLElement {
}
};
this.descriptor.inputEnvelope =
Operation.createEnvelopeDescriptor(this.descriptor.input, false);
Operation.createEnvelopeDescriptor(this.descriptor.input, false, this.soapVersion);
this.descriptor.outputEnvelope =
Operation.createEnvelopeDescriptor(this.descriptor.output, true);
Operation.createEnvelopeDescriptor(this.descriptor.output, true, this.soapVersion);
this.descriptor.faultEnvelope =
Operation.createEnvelopeDescriptor(this.descriptor.faults, true, this.soapVersion);

@@ -222,7 +222,14 @@ class Operation extends WSDLElement {

static createEnvelopeDescriptor(parameterDescriptor, isOutput, soapVersion, prefix, nsURI) {
prefix = prefix || 'soap';
nsURI = nsURI || 'http://schemas.xmlsoap.org/soap/envelope/';
var soapNsURI;
if (soapVersion === '1.1') {
soapNsURI = 'http://schemas.xmlsoap.org/soap/envelope/';
} else if (soapVersion === '1.2') {
soapNsURI = 'http://www.w3.org/2003/05/soap-envelope';
}

nsURI = nsURI || soapNsURI;
var descriptor = new TypeDescriptor();

var envelopeDescriptor = new ElementDescriptor(
2 changes: 1 addition & 1 deletion src/parser/xmlHandler.js
Original file line number Diff line number Diff line change
@@ -278,7 +278,7 @@ class XMLHandler {
{version: '1.0', encoding: 'UTF-8', standalone: true});
nsURI = nsURI || 'http://schemas.xmlsoap.org/soap/envelope/'
doc.attribute('xmlns:' + prefix,
'http://schemas.xmlsoap.org/soap/envelope/');
nsURI);
let header = doc.element(prefix + ':Header');
let body = doc.element(prefix + ':Body');
return {
15 changes: 6 additions & 9 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -299,8 +299,7 @@ class Server extends Base {
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';
if (operation.soapVersion === '1.2') {
soapNsURI = 'http://www.w3.org/2003/05/soap-envelope';
}

@@ -375,16 +374,14 @@ class Server extends Base {
error.Fault.statusCode = undefined;
}

var env = XMLHandler.createSOAPEnvelope();
var operationDescriptor = operation.describe(this.wsdl.definitions);
//get envelope descriptor
var faultEnvDescriptor = operation.descriptor.faultEnvelope.elements[0];

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';
if (operation.soapVersion === '1.2') {
soapNsURI = 'http://www.w3.org/2003/05/soap-envelope';
}

@@ -399,11 +396,11 @@ class Server extends Base {
var faultDescriptor = bodyDescriptor.elements[0];

//serialize Fault object into XML as per faultDescriptor
this.xmlHandler.jsonToXml(env.body, nsContext, faultDescriptor, error.Fault);
this.xmlHandler.jsonToXml(envelope.body, nsContext, faultDescriptor, error.Fault);

self._envelope(env, includeTimestamp);
var message = env.body.toString({pretty: true});
var xml = env.doc.end({pretty: true});
self._envelope(envelope, includeTimestamp);
var message = envelope.body.toString({pretty: true});
var xml = envelope.doc.end({pretty: true});

callback(xml, statusCode);
}
4 changes: 2 additions & 2 deletions test/client-test.js
Original file line number Diff line number Diff line change
@@ -313,11 +313,11 @@ describe('SOAP Client', function() {
});

it('should add proper headers for soap12', function(done) {
soap.createClient(__dirname+'/wsdl/default_namespace_soap12.wsdl', {forceSoap12Headers: true}, function(err, client) {
soap.createClient(__dirname+'/wsdl/default_namespace_soap12.wsdl', function(err, client) {
assert.ok(client);
assert.ok(!err);

client.MyOperation({}, function(err, result) {
client.MyOperation({}, function(err, result, envelope) {
assert.ok(result);
assert.ok(client.lastRequestHeaders);
assert.ok(client.lastRequest);
15 changes: 14 additions & 1 deletion test/request-response-samples-test.js
Original file line number Diff line number Diff line change
@@ -133,7 +133,20 @@ function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requ
if (securityJSON && securityJSON.type === 'ws') {
client.setSecurity(new WSSecurity(securityJSON.username, securityJSON.password, securityJSON.options));
}
client[methodName](requestJSON, function(err, json, body, soapHeader){
//For the test cases with method names 'addPets'/'GetAccountXML'/'GetNodes', the corresponding wsdls(see soap.wsdl in corresponding sub directories) has 2 wsdl ports/2 bindings pointing to
//same operation e.g addPets(). The correct way to invoke operation in this case is to pick the operation to be invoked using 'client['Service1']['Service1Soap']['addPets'].
var method;
if (methodName === 'addPets') { //use soap 1.1 binding operation
method = client ['Service1']['Service1Soap'][methodName];
} else if (methodName === 'GetNodes') {//use soap 1.2 binding operation
method = client ['Service1']['Service1Soap12'][methodName];
} else if (methodName === 'GetAccountXML' ) {//use 1.2 binding operation
method = client ['Service1']['Service1Soap12'][methodName];
} else { //rest of the tests which has unique operation
method = client[methodName];
}

method(requestJSON, function(err, json, body, soapHeader){
if(requestJSON){
if (err) {
assert.notEqual('undefined: undefined', err.message);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<ns1:GetAccountXml xmlns:ns1="#Foo">
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<ns1:GetNodes xmlns:ns1="http://tempuri.org/"/>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetNodesResponse xmlns="http://tempuri.org/">
<GetNodesResult>
58 changes: 29 additions & 29 deletions test/server-client-document-test.js
Original file line number Diff line number Diff line change
@@ -523,42 +523,42 @@ describe('Document style tests', function() {

Client Request
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<myMethod>
<x>200</x>
<y>10.55</y>
</myMethod>
</soap:Body>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<ns1:myMethod xmlns:ns1="http://example.com/doc_literal_wrapped_test_soap12.wsdl">
<x>200</x>
<y>10.55</y>
</ns1:myMethod>
</soap:Body>
</soap:Envelope>

Server Response
//Doc/Literal-wrapped with soap 1.2 Fault response. In this test case, server sends a Fault response which is returned as an error to the client
//and also the response envelope should contain <Fault> and <Detailt> element should contain element <myMethodFault> defined in the wsdl

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Sender</soap:Value>
<soap:Subcode>
<soap:Value>rpc:BadArguments</soap:Value>
</soap:Subcode>
</soap:Code>
<soap:Reason>
<soap:Text>Processing Error</soap:Text>
</soap:Reason>
<soap:Detail>
<ns1:myMethodFault2 xmlns:ns1="http://example.com/doc_literal_wrapped_test_soap12.wsdl">
<errorMessage2>MyMethod Business Exception message</errorMessage2>
<value2>10</value2>
</ns1:myMethodFault2>
</soap:Detail>
</soap:Fault>
</soap:Body>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Sender</soap:Value>
<soap:Subcode>
<soap:Value>rpc:BadArguments</soap:Value>
</soap:Subcode>
</soap:Code>
<soap:Reason>
<soap:Text>Processing Error</soap:Text>
</soap:Reason>
<soap:Detail>
<ns1:myMethodFault2 xmlns:ns1="http://example.com/doc_literal_wrapped_test_soap12.wsdl">
<errorMessage2>MyMethod Business Exception message</errorMessage2>
<value2>10</value2>
</ns1:myMethodFault2>
</soap:Detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

*/