Skip to content

Commit 66f8a65

Browse files
authoredSep 29, 2016
Merge pull request #22 from strongloop/soap-fixes
Remove and re-implement forceSoap12Headers wsdl option
2 parents b468d4f + 9ace3a0 commit 66f8a65

File tree

15 files changed

+74
-59
lines changed

15 files changed

+74
-59
lines changed
 

‎example/weather.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ soap.createClient(url, clientOptions, function(err, client) {
2323
//custom request header
2424
var customRequestHeader = {timeout: 5000};
2525
var options = {};
26+
//navigate to the correct operation in the client using [service][port][operation] since GetCityWeatherByZIP operation is used
27+
//by more than one port.
28+
var method = client['Weather']['WeatherSoap']['GetCityWeatherByZIP'];
2629
//you can also call
27-
client.GetCityWeatherByZIP(requestArgs, function(err, result, envelope, soapHeader) {
30+
method(requestArgs, function(err, result, envelope, soapHeader) {
2831
//response envelope
2932
console.log(envelope);
3033
//result in SOAP envelope body which is the wrapper element. In this case, result object corresponds to GetCityForecastByZIPResponse

‎example/xsds.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ WSDL.open('./wsdls/weather.wsdl', options,
1010
//User can traverse the WSDL tree and get to bindings - > operations, services, portTypes, messages, parts and XSD elements/Attributes
1111
function(err, wsdl) {
1212
var getCityForecastOp = wsdl.definitions.bindings.WeatherSoap.operations.GetCityForecastByZIP;
13-
console.log(getCityForecastOp.name);
13+
console.log(getCityForecastOp.$name);
1414
var service = wsdl.definitions.services['Weather'];
15-
console.log(service.name);;
15+
console.log(service.$name);
1616
});

‎src/base.js

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class Base extends EventEmitter {
5858
options = options || {};
5959
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
6060
this.wsdl.options.envelopeKey = options.envelopeKey || 'soap';
61-
this.wsdl.options.forceSoap12Headers = !!options.forceSoap12Headers;
6261
}
6362

6463
static createSOAPEnvelope(prefix, nsURI) {

‎src/client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Client extends Base {
120120
var soapNsURI = 'http://schemas.xmlsoap.org/soap/envelope/';
121121
var soapNsPrefix = this.wsdl.options.envelopeKey || 'soap';
122122

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

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

‎src/parser/wsdl.js

-4
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ class WSDL {
139139
this.options.ignoreBaseNameSpaces = ignoreBaseNameSpaces;
140140
else
141141
this.options.ignoreBaseNameSpaces = this.ignoreBaseNameSpaces;
142-
143-
// Works only in client
144-
this.options.forceSoap12Headers = options.forceSoap12Headers;
145-
146142
}
147143

148144
_processNextInclude(includes, callback) {

‎src/parser/wsdl/operation.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ class Operation extends WSDLElement {
211211
}
212212
};
213213
this.descriptor.inputEnvelope =
214-
Operation.createEnvelopeDescriptor(this.descriptor.input, false);
214+
Operation.createEnvelopeDescriptor(this.descriptor.input, false, this.soapVersion);
215215
this.descriptor.outputEnvelope =
216-
Operation.createEnvelopeDescriptor(this.descriptor.output, true);
216+
Operation.createEnvelopeDescriptor(this.descriptor.output, true, this.soapVersion);
217217
this.descriptor.faultEnvelope =
218218
Operation.createEnvelopeDescriptor(this.descriptor.faults, true, this.soapVersion);
219219

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

223223
static createEnvelopeDescriptor(parameterDescriptor, isOutput, soapVersion, prefix, nsURI) {
224224
prefix = prefix || 'soap';
225-
nsURI = nsURI || 'http://schemas.xmlsoap.org/soap/envelope/';
225+
var soapNsURI;
226+
if (soapVersion === '1.1') {
227+
soapNsURI = 'http://schemas.xmlsoap.org/soap/envelope/';
228+
} else if (soapVersion === '1.2') {
229+
soapNsURI = 'http://www.w3.org/2003/05/soap-envelope';
230+
}
231+
232+
nsURI = nsURI || soapNsURI;
226233
var descriptor = new TypeDescriptor();
227234

228235
var envelopeDescriptor = new ElementDescriptor(

‎src/parser/xmlHandler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class XMLHandler {
278278
{version: '1.0', encoding: 'UTF-8', standalone: true});
279279
nsURI = nsURI || 'http://schemas.xmlsoap.org/soap/envelope/'
280280
doc.attribute('xmlns:' + prefix,
281-
'http://schemas.xmlsoap.org/soap/envelope/');
281+
nsURI);
282282
let header = doc.element(prefix + ':Header');
283283
let body = doc.element(prefix + ':Body');
284284
return {

‎src/server.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ class Server extends Base {
299299
var soapNsURI = 'http://schemas.xmlsoap.org/soap/envelope/';
300300
var soapNsPrefix = self.wsdl.options.envelopeKey || 'soap';
301301

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

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

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

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

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

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

401398
//serialize Fault object into XML as per faultDescriptor
402-
this.xmlHandler.jsonToXml(env.body, nsContext, faultDescriptor, error.Fault);
399+
this.xmlHandler.jsonToXml(envelope.body, nsContext, faultDescriptor, error.Fault);
403400

404-
self._envelope(env, includeTimestamp);
405-
var message = env.body.toString({pretty: true});
406-
var xml = env.doc.end({pretty: true});
401+
self._envelope(envelope, includeTimestamp);
402+
var message = envelope.body.toString({pretty: true});
403+
var xml = envelope.doc.end({pretty: true});
407404

408405
callback(xml, statusCode);
409406
}

‎test/client-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ describe('SOAP Client', function() {
313313
});
314314

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

320-
client.MyOperation({}, function(err, result) {
320+
client.MyOperation({}, function(err, result, envelope) {
321321
assert.ok(result);
322322
assert.ok(client.lastRequestHeaders);
323323
assert.ok(client.lastRequest);

‎test/request-response-samples-test.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,20 @@ function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requ
133133
if (securityJSON && securityJSON.type === 'ws') {
134134
client.setSecurity(new WSSecurity(securityJSON.username, securityJSON.password, securityJSON.options));
135135
}
136-
client[methodName](requestJSON, function(err, json, body, soapHeader){
136+
//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
137+
//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'].
138+
var method;
139+
if (methodName === 'addPets') { //use soap 1.1 binding operation
140+
method = client ['Service1']['Service1Soap'][methodName];
141+
} else if (methodName === 'GetNodes') {//use soap 1.2 binding operation
142+
method = client ['Service1']['Service1Soap12'][methodName];
143+
} else if (methodName === 'GetAccountXML' ) {//use 1.2 binding operation
144+
method = client ['Service1']['Service1Soap12'][methodName];
145+
} else { //rest of the tests which has unique operation
146+
method = client[methodName];
147+
}
148+
149+
method(requestJSON, function(err, json, body, soapHeader){
137150
if(requestJSON){
138151
if (err) {
139152
assert.notEqual('undefined: undefined', err.message);

‎test/request-response-samples/GetAccountXml__non_xmlns_attributes_should_be_returned/request.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
2+
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
33
<soap:Header/>
44
<soap:Body>
55
<ns1:GetAccountXml xmlns:ns1="#Foo">

‎test/request-response-samples/GetAccountXml__non_xmlns_attributes_should_be_returned/response.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<soap:Envelope
3-
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
3+
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
66
<soap:Body>

‎test/request-response-samples/GetNodes__complex_self_referencing/request.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
2+
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
33
<soap:Header/>
44
<soap:Body>
55
<ns1:GetNodes xmlns:ns1="http://tempuri.org/"/>

‎test/request-response-samples/GetNodes__complex_self_referencing/response.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<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">
1+
<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">
22
<soap:Body>
33
<GetNodesResponse xmlns="http://tempuri.org/">
44
<GetNodesResult>

‎test/server-client-document-test.js

+29-29
Original file line numberDiff line numberDiff line change
@@ -523,42 +523,42 @@ describe('Document style tests', function() {
523523
524524
Client Request
525525
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
526-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
527-
<soap:Header/>
528-
<soap:Body>
529-
<myMethod>
530-
<x>200</x>
531-
<y>10.55</y>
532-
</myMethod>
533-
</soap:Body>
526+
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
527+
<soap:Header/>
528+
<soap:Body>
529+
<ns1:myMethod xmlns:ns1="http://example.com/doc_literal_wrapped_test_soap12.wsdl">
530+
<x>200</x>
531+
<y>10.55</y>
532+
</ns1:myMethod>
533+
</soap:Body>
534534
</soap:Envelope>
535535
536536
Server Response
537537
//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
538538
//and also the response envelope should contain <Fault> and <Detailt> element should contain element <myMethodFault> defined in the wsdl
539539
540540
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
541-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
542-
<soap:Header/>
543-
<soap:Body>
544-
<soap:Fault>
545-
<soap:Code>
546-
<soap:Value>soap:Sender</soap:Value>
547-
<soap:Subcode>
548-
<soap:Value>rpc:BadArguments</soap:Value>
549-
</soap:Subcode>
550-
</soap:Code>
551-
<soap:Reason>
552-
<soap:Text>Processing Error</soap:Text>
553-
</soap:Reason>
554-
<soap:Detail>
555-
<ns1:myMethodFault2 xmlns:ns1="http://example.com/doc_literal_wrapped_test_soap12.wsdl">
556-
<errorMessage2>MyMethod Business Exception message</errorMessage2>
557-
<value2>10</value2>
558-
</ns1:myMethodFault2>
559-
</soap:Detail>
560-
</soap:Fault>
561-
</soap:Body>
541+
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
542+
<soap:Header/>
543+
<soap:Body>
544+
<soap:Fault>
545+
<soap:Code>
546+
<soap:Value>soap:Sender</soap:Value>
547+
<soap:Subcode>
548+
<soap:Value>rpc:BadArguments</soap:Value>
549+
</soap:Subcode>
550+
</soap:Code>
551+
<soap:Reason>
552+
<soap:Text>Processing Error</soap:Text>
553+
</soap:Reason>
554+
<soap:Detail>
555+
<ns1:myMethodFault2 xmlns:ns1="http://example.com/doc_literal_wrapped_test_soap12.wsdl">
556+
<errorMessage2>MyMethod Business Exception message</errorMessage2>
557+
<value2>10</value2>
558+
</ns1:myMethodFault2>
559+
</soap:Detail>
560+
</soap:Fault>
561+
</soap:Body>
562562
</soap:Envelope>
563563
564564
*/

0 commit comments

Comments
 (0)
Please sign in to comment.