Skip to content

Commit 342a586

Browse files
author
yuerwei
committed
add support for importing external wsdl
1 parent 92216e2 commit 342a586

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

lib/wsdl.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,11 @@ WSDL.prototype._processNextInclude = function(includes, callback) {
10931093
if (err) {
10941094
return callback(err);
10951095
}
1096-
1097-
self.definitions.schemas[include.namespace || wsdl.definitions.$targetNamespace] = deepMerge(self.definitions.schemas[include.namespace || wsdl.definitions.$targetNamespace], wsdl.definitions);
1096+
if(wsdl.definitions instanceof DefinitionsElement){
1097+
_.merge(self.definitions, wsdl.definitions);
1098+
}else{
1099+
self.definitions.schemas[include.namespace || wsdl.definitions.$targetNamespace] = deepMerge(self.definitions.schemas[include.namespace || wsdl.definitions.$targetNamespace], wsdl.definitions);
1100+
}
10981101
self._processNextInclude(includes, function(err) {
10991102
callback(err);
11001103
});

test/wsdl-test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ wsdlNonStrictTests['should catch parse error'] = function(done) {
4444
};
4545

4646
wsdlStrictTests['should catch parse error'] = function(done) {
47-
soap.createClient(__dirname+'/wsdl/bad.txt', function(err) {
47+
soap.createClient(__dirname+'/wsdl/bad.txt', {strict: true}, function(err) {
4848
assert.notEqual(err, null);
4949
done();
5050
});
5151
};
5252

53+
wsdlStrictTests['should parse external wsdl'] = function(done) {
54+
soap.createClient(__dirname+'/wsdl/wsdlImport/main.wsdl', {strict: true}, function(err, client){
55+
assert.ok(!err);
56+
assert.equal(typeof client.getLatestVersion, 'function');
57+
done();
58+
});
59+
};
60+
5361
module.exports = {
5462
'WSDL Parser (strict)': wsdlStrictTests,
5563
'WSDL Parser (non-strict)': wsdlNonStrictTests

test/wsdl/wsdlImport/main.wsdl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="UserRemoteServiceImplService" targetNamespace="http://base.example.com" xmlns:ns1="http://example.com/" xmlns:ns2="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://base.example.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2+
<wsdl:import location="sub.wsdl" namespace="http://example.com/">
3+
</wsdl:import>
4+
<wsdl:binding name="UserRemoteServiceImplServiceSoapBinding" type="ns1:IUserRemoteService">
5+
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
6+
<wsdl:operation name="getLatestVersion">
7+
<soap:operation soapAction="" style="document" />
8+
<wsdl:input name="getLatestVersion">
9+
<soap:body use="literal" />
10+
</wsdl:input>
11+
<wsdl:output name="getLatestVersionResponse">
12+
<soap:body use="literal" />
13+
</wsdl:output>
14+
</wsdl:operation>
15+
16+
</wsdl:binding>
17+
<wsdl:service name="UserRemoteServiceImplService">
18+
<wsdl:port binding="tns:UserRemoteServiceImplServiceSoapBinding" name="UserRemoteServiceImplPort">
19+
<soap:address location="http://example.com/ws/UserRemoteService" />
20+
</wsdl:port>
21+
</wsdl:service>
22+
</wsdl:definitions>

test/wsdl/wsdlImport/sub.wsdl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="IUserRemoteService" targetNamespace="http://example.com/" xmlns:ns1="http://example.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2+
<wsdl:types>
3+
<xs:schema elementFormDefault="unqualified" targetNamespace="http://example.com/" version="1.0" xmlns:tns="http://example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
4+
5+
<xs:element name="getLatestVersion" type="tns:getLatestVersion" />
6+
<xs:element name="getLatestVersionResponse" type="tns:getLatestVersionResponse" />
7+
8+
<xs:complexType name="getLatestVersion">
9+
<xs:sequence />
10+
</xs:complexType>
11+
<xs:complexType name="getLatestVersionResponse">
12+
<xs:sequence>
13+
<xs:element minOccurs="0" name="return" type="xs:long" />
14+
</xs:sequence>
15+
</xs:complexType>
16+
17+
</xs:schema>
18+
</wsdl:types>
19+
<wsdl:message name="getLatestVersion">
20+
<wsdl:part element="ns1:getLatestVersion" name="parameters">
21+
</wsdl:part>
22+
</wsdl:message>
23+
<wsdl:message name="getLatestVersionResponse">
24+
<wsdl:part element="ns1:getLatestVersionResponse" name="parameters"></wsdl:part>
25+
</wsdl:message>
26+
<wsdl:portType name="IUserRemoteService">
27+
<wsdl:operation name="getLatestVersion">
28+
<wsdl:input message="ns1:getLatestVersion" name="getLatestVersion">
29+
</wsdl:input>
30+
<wsdl:output message="ns1:getLatestVersionResponse" name="getLatestVersionResponse">
31+
</wsdl:output>
32+
</wsdl:operation>
33+
34+
</wsdl:portType>
35+
</wsdl:definitions>

0 commit comments

Comments
 (0)