Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions lib/wsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1542,12 +1542,14 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
if (schema) {
var childParameterTypeObject = self.findChildParameterObject(parameterTypeObject, name);
//find sub namespace if not a primitive
if (childParameterTypeObject && childParameterTypeObject.$type && (childParameterTypeObject.$type.indexOf('xsd') === -1)) {
if (childParameterTypeObject &&
((childParameterTypeObject.$type && (childParameterTypeObject.$type.indexOf('xsd') === -1)) ||
childParameterTypeObject.$ref)) {
if(childParameterTypeObject.$baseNameSpace) { //this element has a base with another namespace (the correct one)
ns = childParameterTypeObject.$baseNameSpace + ':';
}

var childParameterType = childParameterTypeObject.$type;
var childParameterType = childParameterTypeObject.$type || childParameterTypeObject.$ref;

var childNamespace = '';
var childName = '';
Expand All @@ -1563,7 +1565,22 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
ancXmlns.push(childXmlns);
}
}
var completeChildParameterTypeObject = self.findChildParameterObjectFromSchema(childName, childXmlns) || childParameterTypeObject;
// There is matching element ref
if (childParameterTypeObject.$ref) {
ns = childNamespace ? childNamespace + ':' : '';
xmlnsAttrib = childXmlnsAttrib;
}

var completeChildParameterTypeObject;
if (childParameterTypeObject.$type) {
completeChildParameterTypeObject =
self.findChildParameterObjectFromSchema(childName, childXmlns) ||
childParameterTypeObject;
} else {
completeChildParameterTypeObject =
self.findParameterObject(childXmlns, childName) ||
childParameterTypeObject;
}

for(var ignoredNamespacesIndex = 0, ignoredNamespacesLength = this.ignoredNamespaces.length; ignoredNamespacesIndex < ignoredNamespacesLength; ignoredNamespacesIndex++) {
if(this.ignoredNamespaces[ignoredNamespacesIndex] === childNamespace) {
Expand Down Expand Up @@ -1671,7 +1688,8 @@ WSDL.prototype.findChildParameterObject = function(parameterTypeObj, childName)
}
var found = null,
i = 0,
child;
child,
ref;

if(parameterTypeObj.$lookupTypes && Array.isArray(parameterTypeObj.$lookupTypes) && parameterTypeObj.$lookupTypes.length) {
var types = parameterTypeObj.$lookupTypes;
Expand All @@ -1683,12 +1701,25 @@ WSDL.prototype.findChildParameterObject = function(parameterTypeObj, childName)
found = typeObj;
break;
}
if(typeObj.$ref) {
ref = splitNSName(typeObj.$ref);
if (ref.name === childName) {
found = typeObj;
break;
}
}
}
} else {
var object = parameterTypeObj;
if (object.$name === childName) {
return object;
}
if (object.$ref) {
ref = splitNSName(object.$ref);
if (ref.name === childName) {
return object;
}
}

if (object.children) {
for (i = 0, child; child = object.children[i]; i++) {
Expand Down
16 changes: 16 additions & 0 deletions test/wsdl-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ wsdlStrictTests['should get the parent namespace when parent namespace is empty
});
};

wsdlStrictTests['should handle element ref'] = function(done) {
var expectedMsg = '<ns1:fooRq xmlns:ns1="http://example.com/bar/xsd"' +
' xmlns="http://example.com/bar/xsd"><bar1:paymentRq' +
' xmlns:bar1="http://example.com/bar1/xsd">' +
'<bar1:bankSvcRq xmlns:bar1="http://example.com/bar1/xsd">' +
'<bar1:requestUID>001</bar1:requestUID></bar1:bankSvcRq>' +
'</bar1:paymentRq></ns1:fooRq>';
soap.createClient(__dirname + '/wsdl/elementref/foo.wsdl', {strict: true}, function(err, client) {
assert.ok(!err);
client.fooOp({paymentRq: {bankSvcRq: {requestUID: '001'}}}, function(err, result) {
assert.equal(client.lastMessage, expectedMsg);
done();
});
});
};

module.exports = {
'WSDL Parser (strict)': wsdlStrictTests,
'WSDL Parser (non-strict)': wsdlNonStrictTests
Expand Down
26 changes: 26 additions & 0 deletions test/wsdl/elementref/bar.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<xsd:schema targetNamespace="http://example.com/bar/xsd"
elementFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:bar1="http://example.com/bar1/xsd"
xmlns:bar="http://example.com/bar/xsd">
<xsd:import namespace="http://example.com/bar1/xsd"
schemaLocation="bar1.xsd"/>
<xsd:element name="fooRq">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="bar1:paymentRq" minOccurs="0"
maxOccurs="unbounded">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="fooRs">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="bar1:paymentRs" minOccurs="0"
maxOccurs="unbounded">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
40 changes: 40 additions & 0 deletions test/wsdl/elementref/bar1.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<xsd:schema targetNamespace="http://example.com/bar1/xsd"
elementFormDefault="qualified" version="2.1.4"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:bar1="http://example.com/bar1/xsd">
<xsd:element name="paymentRq">
<xsd:complexType>
<xsd:sequence>
<xsd:sequence>
<xsd:element name="bankSvcRq" minOccurs="0"
maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="bar1:requestUID"/>
</xsd:sequence>
<xsd:attribute name="Id" type="xsd:ID"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="paymentRs">
<xsd:complexType>
<xsd:sequence>
<xsd:sequence>
<xsd:element name="bankSvcRs" minOccurs="0"
maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="bar1:requestUID"/>
</xsd:sequence>
<xsd:attribute name="Id" type="xsd:ID"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="requestUID" type="xsd:string"/>
</xsd:schema>
53 changes: 53 additions & 0 deletions test/wsdl/elementref/foo.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="foo"
targetNamespace="http://example.com/foo/wsdl"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://example.com/bar/xsd"
xmlns:tns="http://example.com/foo/wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xsd:schema>
<xsd:import
namespace="http://example.com/bar/xsd"
schemaLocation="bar.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="fooRs">
<wsdl:part name="fooRs" element="ns1:fooRs">
</wsdl:part>
</wsdl:message>
<wsdl:message name="fooRq">
<wsdl:part name="fooRq" element="ns1:fooRq">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="foo_PortType">
<wsdl:operation name="fooOp">
<wsdl:input message="tns:fooRq">
</wsdl:input>
<wsdl:output message="tns:fooRs">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="foo_Binding" type="tns:foo_PortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="fooOp">
<soap:operation soapAction="fooPayment"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="foo">
<wsdl:port name="payment_Port"
binding="tns:foo_Binding">
<soap:address
location="http://localhost:8888/mockfoo_Binding"/>
</wsdl:port>
</wsdl:service>
<xsd:attriute fixed="2.1.4" name="version"/>
</wsdl:definitions>