soap 0.20.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +23 -23
- package/.jshintrc +29 -29
- package/.travis.yml +22 -22
- package/CONTRIBUTING.md +52 -58
- package/History.md +52 -2
- package/LICENSE +7 -7
- package/PUBLISHING.md +28 -28
- package/Readme.md +1062 -931
- package/coverage/coverage.json +1 -0
- package/coverage/lcov-report/base.css +212 -0
- package/coverage/lcov-report/index.html +119 -0
- package/coverage/lcov-report/node-soap/index.html +93 -0
- package/coverage/lcov-report/node-soap/index.js.html +74 -0
- package/coverage/lcov-report/node-soap/lib/client.js.html +1001 -0
- package/coverage/lcov-report/node-soap/lib/http.js.html +416 -0
- package/coverage/lcov-report/node-soap/lib/index.html +171 -0
- package/coverage/lcov-report/node-soap/lib/nscontext.js.html +734 -0
- package/coverage/lcov-report/node-soap/lib/security/BasicAuthSecurity.js.html +137 -0
- package/coverage/lcov-report/node-soap/lib/security/BearerSecurity.js.html +134 -0
- package/coverage/lcov-report/node-soap/lib/security/ClientSSLSecurity.js.html +296 -0
- package/coverage/lcov-report/node-soap/lib/security/ClientSSLSecurityPFX.js.html +218 -0
- package/coverage/lcov-report/node-soap/lib/security/WSSecurity.js.html +278 -0
- package/coverage/lcov-report/node-soap/lib/security/index.html +158 -0
- package/coverage/lcov-report/node-soap/lib/security/index.js.html +92 -0
- package/coverage/lcov-report/node-soap/lib/server.js.html +1139 -0
- package/coverage/lcov-report/node-soap/lib/soap.js.html +314 -0
- package/coverage/lcov-report/node-soap/lib/utils.js.html +161 -0
- package/coverage/lcov-report/node-soap/lib/wsdl.js.html +6275 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +1 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +158 -0
- package/coverage/lcov.info +3325 -0
- package/index.js +3 -3
- package/lib/client.js +434 -425
- package/lib/http.js +129 -129
- package/lib/nscontext.js +223 -223
- package/lib/security/BasicAuthSecurity.js +24 -24
- package/lib/security/BearerSecurity.js +23 -23
- package/lib/security/ClientSSLSecurity.js +82 -65
- package/lib/security/ClientSSLSecurityPFX.js +51 -51
- package/lib/security/WSSecurity.js +90 -90
- package/lib/security/WSSecurityCert.js +78 -78
- package/lib/security/index.js +10 -10
- package/lib/security/templates/wsse-security-header.ejs +12 -12
- package/lib/security/templates/wsse-security-token.ejs +3 -3
- package/lib/server.js +474 -444
- package/lib/soap.d.ts +220 -0
- package/lib/soap.js +110 -110
- package/lib/utils.js +30 -30
- package/lib/wsdl.js +2272 -2234
- package/package.json +8 -8
- package/soap-stub.js +148 -148
- package/.npmignore +0 -2
package/lib/client.js
CHANGED
|
@@ -1,425 +1,434 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2011 Vinay Pulim <vinay@milewise.com>
|
|
3
|
-
* MIT Licensed
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
"use strict";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var HttpClient = require('./http'),
|
|
10
|
-
assert = require('assert'),
|
|
11
|
-
events = require('events'),
|
|
12
|
-
util = require('util'),
|
|
13
|
-
debug = require('debug')('node-soap'),
|
|
14
|
-
findPrefix = require('./utils').findPrefix,
|
|
15
|
-
_ = require('lodash'),
|
|
16
|
-
concatStream = require('concat-stream'),
|
|
17
|
-
BluebirdPromise = require("bluebird"),
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.soapHeaders
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
var
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
callback
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
self.
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
req.
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
error
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2011 Vinay Pulim <vinay@milewise.com>
|
|
3
|
+
* MIT Licensed
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var HttpClient = require('./http'),
|
|
10
|
+
assert = require('assert'),
|
|
11
|
+
events = require('events'),
|
|
12
|
+
util = require('util'),
|
|
13
|
+
debug = require('debug')('node-soap'),
|
|
14
|
+
findPrefix = require('./utils').findPrefix,
|
|
15
|
+
_ = require('lodash'),
|
|
16
|
+
concatStream = require('concat-stream'),
|
|
17
|
+
BluebirdPromise = require("bluebird"),
|
|
18
|
+
uuid4 = require('uuid/v4');
|
|
19
|
+
|
|
20
|
+
var nonIdentifierChars = /[^a-z$_0-9]/i;
|
|
21
|
+
|
|
22
|
+
var Client = function(wsdl, endpoint, options) {
|
|
23
|
+
events.EventEmitter.call(this);
|
|
24
|
+
options = options || {};
|
|
25
|
+
this.wsdl = wsdl;
|
|
26
|
+
this._initializeOptions(options);
|
|
27
|
+
this._initializeServices(endpoint);
|
|
28
|
+
this.httpClient = options.httpClient || new HttpClient(options);
|
|
29
|
+
var promiseOptions = { multiArgs: true };
|
|
30
|
+
if (options.overridePromiseSuffix) {
|
|
31
|
+
promiseOptions.suffix = options.overridePromiseSuffix;
|
|
32
|
+
}
|
|
33
|
+
BluebirdPromise.promisifyAll(this, promiseOptions);
|
|
34
|
+
};
|
|
35
|
+
util.inherits(Client, events.EventEmitter);
|
|
36
|
+
|
|
37
|
+
Client.prototype.addSoapHeader = function(soapHeader, name, namespace, xmlns) {
|
|
38
|
+
if (!this.soapHeaders) {
|
|
39
|
+
this.soapHeaders = [];
|
|
40
|
+
}
|
|
41
|
+
if (typeof soapHeader === 'object') {
|
|
42
|
+
soapHeader = this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
|
|
43
|
+
}
|
|
44
|
+
return this.soapHeaders.push(soapHeader) - 1;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
Client.prototype.changeSoapHeader = function(index, soapHeader, name, namespace, xmlns) {
|
|
48
|
+
if (!this.soapHeaders) {
|
|
49
|
+
this.soapHeaders = [];
|
|
50
|
+
}
|
|
51
|
+
if (typeof soapHeader === 'object') {
|
|
52
|
+
soapHeader = this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
|
|
53
|
+
}
|
|
54
|
+
this.soapHeaders[index] = soapHeader;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
Client.prototype.getSoapHeaders = function() {
|
|
58
|
+
return this.soapHeaders;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
Client.prototype.clearSoapHeaders = function() {
|
|
62
|
+
this.soapHeaders = null;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
Client.prototype.addHttpHeader = function(name, value) {
|
|
66
|
+
if (!this.httpHeaders) {
|
|
67
|
+
this.httpHeaders = {};
|
|
68
|
+
}
|
|
69
|
+
this.httpHeaders[name] = value;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
Client.prototype.getHttpHeaders = function() {
|
|
73
|
+
return this.httpHeaders;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
Client.prototype.clearHttpHeaders = function() {
|
|
77
|
+
this.httpHeaders = {};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
Client.prototype.addBodyAttribute = function(bodyAttribute, name, namespace, xmlns) {
|
|
82
|
+
if (!this.bodyAttributes) {
|
|
83
|
+
this.bodyAttributes = [];
|
|
84
|
+
}
|
|
85
|
+
if (typeof bodyAttribute === 'object') {
|
|
86
|
+
var composition = '';
|
|
87
|
+
Object.getOwnPropertyNames(bodyAttribute).forEach(function(prop, idx, array) {
|
|
88
|
+
composition += ' ' + prop + '="' + bodyAttribute[prop] + '"';
|
|
89
|
+
});
|
|
90
|
+
bodyAttribute = composition;
|
|
91
|
+
}
|
|
92
|
+
if (bodyAttribute.substr(0, 1) !== ' ') bodyAttribute = ' ' + bodyAttribute;
|
|
93
|
+
this.bodyAttributes.push(bodyAttribute);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
Client.prototype.getBodyAttributes = function() {
|
|
97
|
+
return this.bodyAttributes;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Client.prototype.clearBodyAttributes = function() {
|
|
101
|
+
this.bodyAttributes = null;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
Client.prototype.setEndpoint = function(endpoint) {
|
|
105
|
+
this.endpoint = endpoint;
|
|
106
|
+
this._initializeServices(endpoint);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
Client.prototype.describe = function() {
|
|
110
|
+
var types = this.wsdl.definitions.types;
|
|
111
|
+
return this.wsdl.describeServices();
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
Client.prototype.setSecurity = function(security) {
|
|
115
|
+
this.security = security;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
Client.prototype.setSOAPAction = function(SOAPAction) {
|
|
119
|
+
this.SOAPAction = SOAPAction;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
Client.prototype._initializeServices = function(endpoint) {
|
|
123
|
+
var definitions = this.wsdl.definitions,
|
|
124
|
+
services = definitions.services;
|
|
125
|
+
for (var name in services) {
|
|
126
|
+
this[name] = this._defineService(services[name], endpoint);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
Client.prototype._initializeOptions = function(options) {
|
|
131
|
+
this.streamAllowed = options.stream;
|
|
132
|
+
this.normalizeNames = options.normalizeNames;
|
|
133
|
+
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
|
|
134
|
+
this.wsdl.options.envelopeKey = options.envelopeKey || 'soap';
|
|
135
|
+
this.wsdl.options.preserveWhitespace = !!options.preserveWhitespace;
|
|
136
|
+
if(options.ignoredNamespaces !== undefined) {
|
|
137
|
+
if(options.ignoredNamespaces.override !== undefined) {
|
|
138
|
+
if(options.ignoredNamespaces.override === true) {
|
|
139
|
+
if(options.ignoredNamespaces.namespaces !== undefined) {
|
|
140
|
+
this.wsdl.options.ignoredNamespaces = options.ignoredNamespaces.namespaces;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if(options.overrideRootElement !== undefined) {
|
|
146
|
+
this.wsdl.options.overrideRootElement = options.overrideRootElement;
|
|
147
|
+
}
|
|
148
|
+
this.wsdl.options.forceSoap12Headers = !!options.forceSoap12Headers;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
Client.prototype._defineService = function(service, endpoint) {
|
|
152
|
+
var ports = service.ports,
|
|
153
|
+
def = {};
|
|
154
|
+
for (var name in ports) {
|
|
155
|
+
def[name] = this._definePort(ports[name], endpoint ? endpoint : ports[name].location);
|
|
156
|
+
}
|
|
157
|
+
return def;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
Client.prototype._definePort = function(port, endpoint) {
|
|
161
|
+
var location = endpoint,
|
|
162
|
+
binding = port.binding,
|
|
163
|
+
methods = binding.methods,
|
|
164
|
+
def = {};
|
|
165
|
+
for (var name in methods) {
|
|
166
|
+
def[name] = this._defineMethod(methods[name], location);
|
|
167
|
+
var methodName = this.normalizeNames ? name.replace(nonIdentifierChars, '_') : name;
|
|
168
|
+
this[methodName] = def[name];
|
|
169
|
+
}
|
|
170
|
+
return def;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
Client.prototype._defineMethod = function(method, location) {
|
|
174
|
+
var self = this;
|
|
175
|
+
var temp;
|
|
176
|
+
return function(args, callback, options, extraHeaders) {
|
|
177
|
+
if (typeof args === 'function') {
|
|
178
|
+
callback = args;
|
|
179
|
+
args = {};
|
|
180
|
+
} else if (typeof options === 'function') {
|
|
181
|
+
temp = callback;
|
|
182
|
+
callback = options;
|
|
183
|
+
options = temp;
|
|
184
|
+
} else if (typeof extraHeaders === 'function') {
|
|
185
|
+
temp = callback;
|
|
186
|
+
callback = extraHeaders;
|
|
187
|
+
extraHeaders = options;
|
|
188
|
+
options = temp;
|
|
189
|
+
}
|
|
190
|
+
self._invoke(method, args, location, function(error, result, rawResponse, soapHeader, rawRequest) {
|
|
191
|
+
callback(error, result, rawResponse, soapHeader, rawRequest);
|
|
192
|
+
}, options, extraHeaders);
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
Client.prototype._invoke = function(method, args, location, callback, options, extraHeaders) {
|
|
197
|
+
var self = this,
|
|
198
|
+
name = method.$name,
|
|
199
|
+
input = method.input,
|
|
200
|
+
output = method.output,
|
|
201
|
+
style = method.style,
|
|
202
|
+
defs = this.wsdl.definitions,
|
|
203
|
+
envelopeKey = this.wsdl.options.envelopeKey,
|
|
204
|
+
ns = defs.$targetNamespace,
|
|
205
|
+
encoding = '',
|
|
206
|
+
message = '',
|
|
207
|
+
xml = null,
|
|
208
|
+
req = null,
|
|
209
|
+
soapAction,
|
|
210
|
+
alias = findPrefix(defs.xmlns, ns),
|
|
211
|
+
headers = {
|
|
212
|
+
"Content-Type": "text/xml; charset=utf-8"
|
|
213
|
+
},
|
|
214
|
+
xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://schemas.xmlsoap.org/soap/envelope/\"";
|
|
215
|
+
|
|
216
|
+
if (this.wsdl.options.forceSoap12Headers) {
|
|
217
|
+
headers["Content-Type"] = "application/soap+xml; charset=utf-8";
|
|
218
|
+
xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://www.w3.org/2003/05/soap-envelope\"";
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (this.SOAPAction) {
|
|
222
|
+
soapAction = this.SOAPAction;
|
|
223
|
+
} else if (method.soapAction !== undefined && method.soapAction !== null) {
|
|
224
|
+
soapAction = method.soapAction;
|
|
225
|
+
} else {
|
|
226
|
+
soapAction = ((ns.lastIndexOf("/") !== ns.length - 1) ? ns + "/" : ns) + name;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (!this.wsdl.options.forceSoap12Headers) {
|
|
230
|
+
headers.SOAPAction = '"' + soapAction + '"';
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
options = options || {};
|
|
234
|
+
|
|
235
|
+
//Add extra headers
|
|
236
|
+
for (var header in this.httpHeaders ) { headers[header] = this.httpHeaders[header]; }
|
|
237
|
+
for (var attr in extraHeaders) { headers[attr] = extraHeaders[attr]; }
|
|
238
|
+
|
|
239
|
+
// Allow the security object to add headers
|
|
240
|
+
if (self.security && self.security.addHeaders)
|
|
241
|
+
self.security.addHeaders(headers);
|
|
242
|
+
if (self.security && self.security.addOptions)
|
|
243
|
+
self.security.addOptions(options);
|
|
244
|
+
|
|
245
|
+
if ((style === 'rpc')&& ( ( input.parts || input.name==="element" ) || args === null) ) {
|
|
246
|
+
assert.ok(!style || style === 'rpc', 'invalid message definition for document style binding');
|
|
247
|
+
message = self.wsdl.objectToRpcXML(name, args, alias, ns,(input.name!=="element" ));
|
|
248
|
+
(method.inputSoap === 'encoded') && (encoding = 'soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ');
|
|
249
|
+
} else {
|
|
250
|
+
assert.ok(!style || style === 'document', 'invalid message definition for rpc style binding');
|
|
251
|
+
// pass `input.$lookupType` if `input.$type` could not be found
|
|
252
|
+
message = self.wsdl.objectToDocumentXML(input.$name, args, input.targetNSAlias, input.targetNamespace, (input.$type || input.$lookupType));
|
|
253
|
+
}
|
|
254
|
+
xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
|
255
|
+
"<" + envelopeKey + ":Envelope " +
|
|
256
|
+
xmlnsSoap + " " +
|
|
257
|
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
|
|
258
|
+
encoding +
|
|
259
|
+
this.wsdl.xmlnsInEnvelope + '>' +
|
|
260
|
+
((self.soapHeaders || self.security) ?
|
|
261
|
+
(
|
|
262
|
+
"<" + envelopeKey + ":Header>" +
|
|
263
|
+
(self.soapHeaders ? self.soapHeaders.join("\n") : "") +
|
|
264
|
+
(self.security && !self.security.postProcess ? self.security.toXML() : "") +
|
|
265
|
+
"</" + envelopeKey + ":Header>"
|
|
266
|
+
)
|
|
267
|
+
:
|
|
268
|
+
''
|
|
269
|
+
) +
|
|
270
|
+
"<" + envelopeKey + ":Body" +
|
|
271
|
+
(self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
|
|
272
|
+
(self.security && self.security.postProcess ? ' Id="_0"' : '') +
|
|
273
|
+
">" +
|
|
274
|
+
message +
|
|
275
|
+
"</" + envelopeKey + ":Body>" +
|
|
276
|
+
"</" + envelopeKey + ":Envelope>";
|
|
277
|
+
|
|
278
|
+
if(self.security && self.security.postProcess){
|
|
279
|
+
xml = self.security.postProcess(xml, envelopeKey);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if(options && options.postProcess){
|
|
283
|
+
xml = options.postProcess(xml);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
self.lastMessage = message;
|
|
287
|
+
self.lastRequest = xml;
|
|
288
|
+
self.lastEndpoint = location;
|
|
289
|
+
|
|
290
|
+
var eid = options.exchangeId || uuid4();
|
|
291
|
+
|
|
292
|
+
self.emit('message', message, eid);
|
|
293
|
+
self.emit('request', xml, eid);
|
|
294
|
+
|
|
295
|
+
var tryJSONparse = function(body) {
|
|
296
|
+
try {
|
|
297
|
+
return JSON.parse(body);
|
|
298
|
+
}
|
|
299
|
+
catch(err) {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
if (this.streamAllowed && typeof self.httpClient.requestStream === 'function') {
|
|
305
|
+
callback = _.once(callback);
|
|
306
|
+
var startTime = Date.now();
|
|
307
|
+
req = self.httpClient.requestStream(location, xml, headers, options, self);
|
|
308
|
+
self.lastRequestHeaders = req.headers;
|
|
309
|
+
var onError = function onError(err) {
|
|
310
|
+
self.lastResponse = null;
|
|
311
|
+
self.lastResponseHeaders = null;
|
|
312
|
+
self.lastElapsedTime = null;
|
|
313
|
+
self.emit('response', null, null, eid);
|
|
314
|
+
|
|
315
|
+
callback(err, undefined, undefined, undefined, xml);
|
|
316
|
+
};
|
|
317
|
+
req.on('error', onError);
|
|
318
|
+
req.on('response', function (response) {
|
|
319
|
+
response.on('error', onError);
|
|
320
|
+
|
|
321
|
+
// When the output element cannot be looked up in the wsdl, play it safe and
|
|
322
|
+
// don't stream
|
|
323
|
+
if(response.statusCode !== 200 || !output || !output.$lookupTypes) {
|
|
324
|
+
response.pipe(concatStream({encoding: 'string'}, function (body) {
|
|
325
|
+
self.lastResponse = body;
|
|
326
|
+
self.lastResponseHeaders = response && response.headers;
|
|
327
|
+
self.lastElapsedTime = Date.now() - startTime;
|
|
328
|
+
self.emit('response', body, response, eid);
|
|
329
|
+
|
|
330
|
+
return parseSync(body, response);
|
|
331
|
+
|
|
332
|
+
}));
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
self.wsdl.xmlToObject(response, function (error, obj) {
|
|
337
|
+
self.lastResponse = response;
|
|
338
|
+
self.lastResponseHeaders = response && response.headers;
|
|
339
|
+
self.lastElapsedTime = Date.now() - startTime;
|
|
340
|
+
self.emit('response', '<stream>', response, eid);
|
|
341
|
+
|
|
342
|
+
if (error) {
|
|
343
|
+
error.response = response;
|
|
344
|
+
error.body = '<stream>';
|
|
345
|
+
self.emit('soapError', error, eid);
|
|
346
|
+
return callback(error, response, undefined, undefined, xml);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return finish(obj, '<stream>', response);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
req = self.httpClient.request(location, xml, function(err, response, body) {
|
|
356
|
+
self.lastResponse = body;
|
|
357
|
+
self.lastResponseHeaders = response && response.headers;
|
|
358
|
+
self.lastElapsedTime = response && response.elapsedTime;
|
|
359
|
+
self.emit('response', body, response, eid);
|
|
360
|
+
|
|
361
|
+
if (err) {
|
|
362
|
+
callback(err, undefined, undefined, undefined, xml);
|
|
363
|
+
} else {
|
|
364
|
+
return parseSync(body, response);
|
|
365
|
+
}
|
|
366
|
+
}, headers, options, self);
|
|
367
|
+
|
|
368
|
+
function parseSync(body, response) {
|
|
369
|
+
var obj;
|
|
370
|
+
try {
|
|
371
|
+
obj = self.wsdl.xmlToObject(body);
|
|
372
|
+
} catch (error) {
|
|
373
|
+
// When the output element cannot be looked up in the wsdl and the body is JSON
|
|
374
|
+
// instead of sending the error, we pass the body in the response.
|
|
375
|
+
if(!output || !output.$lookupTypes) {
|
|
376
|
+
debug('Response element is not present. Unable to convert response xml to json.');
|
|
377
|
+
// If the response is JSON then return it as-is.
|
|
378
|
+
var json = _.isObject(body) ? body : tryJSONparse(body);
|
|
379
|
+
if (json) {
|
|
380
|
+
return callback(null, response, json, undefined, xml);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
error.response = response;
|
|
384
|
+
error.body = body;
|
|
385
|
+
self.emit('soapError', error, eid);
|
|
386
|
+
return callback(error, response, body, undefined, xml);
|
|
387
|
+
}
|
|
388
|
+
return finish(obj, body, response);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function finish(obj, body, response) {
|
|
392
|
+
var result;
|
|
393
|
+
|
|
394
|
+
if (!output){
|
|
395
|
+
// one-way, no output expected
|
|
396
|
+
return callback(null, null, body, obj.Header, xml);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// If it's not HTML and Soap Body is empty
|
|
400
|
+
if (!obj.html && !obj.Body) {
|
|
401
|
+
return callback(null, obj, body, obj.Header);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if( typeof obj.Body !== 'object' ) {
|
|
405
|
+
var error = new Error('Cannot parse response');
|
|
406
|
+
error.response = response;
|
|
407
|
+
error.body = body;
|
|
408
|
+
return callback(error, obj, body, undefined, xml);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
result = obj.Body[output.$name];
|
|
412
|
+
// RPC/literal response body may contain elements with added suffixes I.E.
|
|
413
|
+
// 'Response', or 'Output', or 'Out'
|
|
414
|
+
// This doesn't necessarily equal the ouput message name. See WSDL 1.1 Section 2.4.5
|
|
415
|
+
if(!result){
|
|
416
|
+
result = obj.Body[output.$name.replace(/(?:Out(?:put)?|Response)$/, '')];
|
|
417
|
+
}
|
|
418
|
+
if (!result) {
|
|
419
|
+
['Response', 'Out', 'Output'].forEach(function (term) {
|
|
420
|
+
if (obj.Body.hasOwnProperty(name + term)) {
|
|
421
|
+
return result = obj.Body[name + term];
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
callback(null, result, body, obj.Header, xml);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Added mostly for testability, but possibly useful for debugging
|
|
430
|
+
if(req && req.headers) //fixes an issue when req or req.headers is indefined
|
|
431
|
+
self.lastRequestHeaders = req.headers;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
exports.Client = Client;
|