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/server.js
CHANGED
|
@@ -1,444 +1,474 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2011 Vinay Pulim <vinay@milewise.com>
|
|
3
|
-
* MIT Licensed
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
"use strict";
|
|
7
|
-
|
|
8
|
-
function getDateString(d) {
|
|
9
|
-
function pad(n) {
|
|
10
|
-
return n < 10 ? '0' + n : n;
|
|
11
|
-
}
|
|
12
|
-
return d.getUTCFullYear() + '-'
|
|
13
|
-
+ pad(d.getUTCMonth() + 1) + '-'
|
|
14
|
-
+ pad(d.getUTCDate()) + 'T'
|
|
15
|
-
+ pad(d.getUTCHours()) + ':'
|
|
16
|
-
+ pad(d.getUTCMinutes()) + ':'
|
|
17
|
-
+ pad(d.getUTCSeconds()) + 'Z';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
var url = require('url'),
|
|
21
|
-
|
|
22
|
-
events = require('events'),
|
|
23
|
-
util = require('util'),
|
|
24
|
-
findPrefix = require('./utils').findPrefix;
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
|
|
28
|
-
} catch (error) {
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
var Server = function (server, path, services, wsdl, options) {
|
|
32
|
-
var self = this;
|
|
33
|
-
|
|
34
|
-
events.EventEmitter.call(this);
|
|
35
|
-
|
|
36
|
-
options = options || {};
|
|
37
|
-
this.path = path;
|
|
38
|
-
this.services = services;
|
|
39
|
-
this.wsdl = wsdl;
|
|
40
|
-
this.suppressStack = options && options.suppressStack;
|
|
41
|
-
this.returnFault = options && options.returnFault;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
server.
|
|
60
|
-
server.
|
|
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
|
-
res.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
if (
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2011 Vinay Pulim <vinay@milewise.com>
|
|
3
|
+
* MIT Licensed
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
function getDateString(d) {
|
|
9
|
+
function pad(n) {
|
|
10
|
+
return n < 10 ? '0' + n : n;
|
|
11
|
+
}
|
|
12
|
+
return d.getUTCFullYear() + '-'
|
|
13
|
+
+ pad(d.getUTCMonth() + 1) + '-'
|
|
14
|
+
+ pad(d.getUTCDate()) + 'T'
|
|
15
|
+
+ pad(d.getUTCHours()) + ':'
|
|
16
|
+
+ pad(d.getUTCMinutes()) + ':'
|
|
17
|
+
+ pad(d.getUTCSeconds()) + 'Z';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var url = require('url'),
|
|
21
|
+
zlib = null,
|
|
22
|
+
events = require('events'),
|
|
23
|
+
util = require('util'),
|
|
24
|
+
findPrefix = require('./utils').findPrefix;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
zlib = require("zlib");
|
|
28
|
+
} catch (error) {
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var Server = function (server, path, services, wsdl, options) {
|
|
32
|
+
var self = this;
|
|
33
|
+
|
|
34
|
+
events.EventEmitter.call(this);
|
|
35
|
+
|
|
36
|
+
options = options || {};
|
|
37
|
+
this.path = path;
|
|
38
|
+
this.services = services;
|
|
39
|
+
this.wsdl = wsdl;
|
|
40
|
+
this.suppressStack = options && options.suppressStack;
|
|
41
|
+
this.returnFault = options && options.returnFault;
|
|
42
|
+
this.onewayOptions = options && options.oneWay || {};
|
|
43
|
+
|
|
44
|
+
if (path[path.length - 1] !== '/')
|
|
45
|
+
path += '/';
|
|
46
|
+
wsdl.onReady(function (err) {
|
|
47
|
+
if (typeof server.route === 'function' && typeof server.use === 'function') {
|
|
48
|
+
//handle only the required URL path for express server
|
|
49
|
+
server.route(path).all(function (req, res, next) {
|
|
50
|
+
if (typeof self.authorizeConnection === 'function') {
|
|
51
|
+
if (!self.authorizeConnection(req)) {
|
|
52
|
+
res.end();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
self._requestListener(req, res);
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
var listeners = server.listeners('request').slice();
|
|
60
|
+
server.removeAllListeners('request');
|
|
61
|
+
server.addListener('request', function (req, res) {
|
|
62
|
+
if (typeof self.authorizeConnection === 'function') {
|
|
63
|
+
if (!self.authorizeConnection(req)) {
|
|
64
|
+
res.end();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
var reqPath = url.parse(req.url).pathname;
|
|
69
|
+
if (reqPath[reqPath.length - 1] !== '/') {
|
|
70
|
+
reqPath += '/';
|
|
71
|
+
}
|
|
72
|
+
if (path === reqPath) {
|
|
73
|
+
self._requestListener(req, res);
|
|
74
|
+
} else {
|
|
75
|
+
for (var i = 0, len = listeners.length; i < len; i++) {
|
|
76
|
+
listeners[i].call(this, req, res);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
this._initializeOptions(options);
|
|
84
|
+
};
|
|
85
|
+
util.inherits(Server, events.EventEmitter);
|
|
86
|
+
|
|
87
|
+
Server.prototype._processSoapHeader = function (soapHeader, name, namespace, xmlns) {
|
|
88
|
+
var self = this;
|
|
89
|
+
|
|
90
|
+
switch (typeof soapHeader) {
|
|
91
|
+
case 'object':
|
|
92
|
+
return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
|
|
93
|
+
case 'function':
|
|
94
|
+
return function() {
|
|
95
|
+
var result = soapHeader.apply(null, arguments);
|
|
96
|
+
|
|
97
|
+
if (typeof result === 'object') {
|
|
98
|
+
return self.wsdl.objectToXML(result, name, namespace, xmlns, true);
|
|
99
|
+
} else {
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
default:
|
|
104
|
+
return soapHeader;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
Server.prototype.addSoapHeader = function (soapHeader, name, namespace, xmlns) {
|
|
109
|
+
if (!this.soapHeaders) {
|
|
110
|
+
this.soapHeaders = [];
|
|
111
|
+
}
|
|
112
|
+
soapHeader = this._processSoapHeader(soapHeader, name, namespace, xmlns);
|
|
113
|
+
return this.soapHeaders.push(soapHeader) - 1;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Server.prototype.changeSoapHeader = function (index, soapHeader, name, namespace, xmlns) {
|
|
117
|
+
if (!this.soapHeaders) {
|
|
118
|
+
this.soapHeaders = [];
|
|
119
|
+
}
|
|
120
|
+
soapHeader = this._processSoapHeader(soapHeader, name, namespace, xmlns);
|
|
121
|
+
this.soapHeaders[index] = soapHeader;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
Server.prototype.getSoapHeaders = function () {
|
|
125
|
+
return this.soapHeaders;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
Server.prototype.clearSoapHeaders = function () {
|
|
129
|
+
this.soapHeaders = null;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
Server.prototype._initializeOptions = function (options) {
|
|
133
|
+
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
|
|
134
|
+
this.onewayOptions.statusCode = this.onewayOptions.responseCode || 200;
|
|
135
|
+
this.onewayOptions.emptyBody = !!this.onewayOptions.emptyBody;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
Server.prototype._processRequestXml = function (req, res, xml) {
|
|
139
|
+
var self = this;
|
|
140
|
+
var result;
|
|
141
|
+
var error;
|
|
142
|
+
try {
|
|
143
|
+
if (typeof self.log === 'function') {
|
|
144
|
+
self.log("received", xml);
|
|
145
|
+
}
|
|
146
|
+
self._process(xml, req, function (result, statusCode) {
|
|
147
|
+
if (statusCode) {
|
|
148
|
+
res.statusCode = statusCode;
|
|
149
|
+
}
|
|
150
|
+
res.write(result);
|
|
151
|
+
res.end();
|
|
152
|
+
if (typeof self.log === 'function') {
|
|
153
|
+
self.log("replied", result);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
} catch (err) {
|
|
157
|
+
if (err.Fault !== undefined) {
|
|
158
|
+
return self._sendError(err.Fault, function (result, statusCode) {
|
|
159
|
+
res.statusCode = statusCode || 500;
|
|
160
|
+
res.write(result);
|
|
161
|
+
res.end();
|
|
162
|
+
if (typeof self.log === 'function') {
|
|
163
|
+
self.log("error", err);
|
|
164
|
+
}
|
|
165
|
+
}, new Date().toISOString());
|
|
166
|
+
} else {
|
|
167
|
+
error = err.stack ? (self.suppressStack === true ? err.message : err.stack) : err;
|
|
168
|
+
res.statusCode = 500;
|
|
169
|
+
res.write(error);
|
|
170
|
+
res.end();
|
|
171
|
+
if (typeof self.log === 'function') {
|
|
172
|
+
self.log("error", error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
Server.prototype._requestListener = function (req, res) {
|
|
179
|
+
var self = this;
|
|
180
|
+
var reqParse = url.parse(req.url);
|
|
181
|
+
var reqPath = reqParse.pathname;
|
|
182
|
+
var reqQuery = reqParse.search;
|
|
183
|
+
|
|
184
|
+
if (typeof self.log === 'function') {
|
|
185
|
+
self.log("info", "Handling " + req.method + " on " + req.url);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (req.method === 'GET') {
|
|
189
|
+
if (reqQuery && reqQuery.toLowerCase() === '?wsdl') {
|
|
190
|
+
if (typeof self.log === 'function') {
|
|
191
|
+
self.log("info", "Wants the WSDL");
|
|
192
|
+
}
|
|
193
|
+
res.setHeader("Content-Type", "application/xml");
|
|
194
|
+
res.write(self.wsdl.toXML());
|
|
195
|
+
}
|
|
196
|
+
res.end();
|
|
197
|
+
} else if (req.method === 'POST') {
|
|
198
|
+
if (typeof req.headers['content-type'] !== "undefined") {
|
|
199
|
+
res.setHeader('Content-Type', req.headers['content-type']);
|
|
200
|
+
} else {
|
|
201
|
+
res.setHeader('Content-Type', "application/xml");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//request body is already provided by an express middleware
|
|
205
|
+
//in this case unzipping should also be done by the express middleware itself
|
|
206
|
+
if (req.body) {
|
|
207
|
+
return self._processRequestXml(req, res, req.body.toString());
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
var chunks = [], gunzip, source = req;
|
|
211
|
+
if (req.headers["content-encoding"] === "gzip") {
|
|
212
|
+
gunzip = zlib.createGunzip();
|
|
213
|
+
req.pipe(gunzip);
|
|
214
|
+
source = gunzip;
|
|
215
|
+
}
|
|
216
|
+
source.on('data', function (chunk) {
|
|
217
|
+
chunks.push(chunk);
|
|
218
|
+
});
|
|
219
|
+
source.on('end', function () {
|
|
220
|
+
var xml = chunks.join('');
|
|
221
|
+
var result;
|
|
222
|
+
var error;
|
|
223
|
+
self._processRequestXml(req, res, xml);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
res.end();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
Server.prototype._process = function (input, req, callback) {
|
|
232
|
+
var self = this,
|
|
233
|
+
pathname = url.parse(req.url).pathname.replace(/\/$/, ''),
|
|
234
|
+
obj = this.wsdl.xmlToObject(input),
|
|
235
|
+
body = obj.Body,
|
|
236
|
+
headers = obj.Header,
|
|
237
|
+
bindings = this.wsdl.definitions.bindings, binding,
|
|
238
|
+
method, methodName,
|
|
239
|
+
serviceName, portName,
|
|
240
|
+
includeTimestamp = obj.Header && obj.Header.Security && obj.Header.Security.Timestamp;
|
|
241
|
+
|
|
242
|
+
if (typeof self.authenticate === 'function') {
|
|
243
|
+
if (!obj.Header || !obj.Header.Security) {
|
|
244
|
+
throw new Error('No security header');
|
|
245
|
+
}
|
|
246
|
+
if (!self.authenticate(obj.Header.Security)) {
|
|
247
|
+
throw new Error('Invalid username or password');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (typeof self.log === 'function') {
|
|
252
|
+
self.log("info", "Attempting to bind to " + pathname);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//Avoid Cannot convert undefined or null to object due to Object.keys(body)
|
|
256
|
+
//and throw more meaningful error
|
|
257
|
+
if (!body) {
|
|
258
|
+
throw new Error('Failed to parse the SOAP Message body');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// use port.location and current url to find the right binding
|
|
262
|
+
binding = (function (self) {
|
|
263
|
+
var services = self.wsdl.definitions.services;
|
|
264
|
+
var firstPort;
|
|
265
|
+
var name;
|
|
266
|
+
for (name in services) {
|
|
267
|
+
serviceName = name;
|
|
268
|
+
var service = services[serviceName];
|
|
269
|
+
var ports = service.ports;
|
|
270
|
+
for (name in ports) {
|
|
271
|
+
portName = name;
|
|
272
|
+
var port = ports[portName];
|
|
273
|
+
var portPathname = url.parse(port.location).pathname.replace(/\/$/, '');
|
|
274
|
+
|
|
275
|
+
if (typeof self.log === 'function') {
|
|
276
|
+
self.log("info", "Trying " + portName + " from path " + portPathname);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (portPathname === pathname)
|
|
280
|
+
return port.binding;
|
|
281
|
+
|
|
282
|
+
// The port path is almost always wrong for generated WSDLs
|
|
283
|
+
if (!firstPort) {
|
|
284
|
+
firstPort = port;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return !firstPort ? void 0 : firstPort.binding;
|
|
289
|
+
})(this);
|
|
290
|
+
|
|
291
|
+
if (!binding) {
|
|
292
|
+
throw new Error('Failed to bind to WSDL');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
if (binding.style === 'rpc') {
|
|
297
|
+
methodName = Object.keys(body)[0];
|
|
298
|
+
|
|
299
|
+
self.emit('request', obj, methodName);
|
|
300
|
+
if (headers)
|
|
301
|
+
self.emit('headers', headers, methodName);
|
|
302
|
+
|
|
303
|
+
self._executeMethod({
|
|
304
|
+
serviceName: serviceName,
|
|
305
|
+
portName: portName,
|
|
306
|
+
methodName: methodName,
|
|
307
|
+
outputName: methodName + 'Response',
|
|
308
|
+
args: body[methodName],
|
|
309
|
+
headers: headers,
|
|
310
|
+
style: 'rpc'
|
|
311
|
+
}, req, callback);
|
|
312
|
+
} else {
|
|
313
|
+
var messageElemName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
|
|
314
|
+
var pair = binding.topElements[messageElemName];
|
|
315
|
+
|
|
316
|
+
self.emit('request', obj, pair.methodName);
|
|
317
|
+
if (headers)
|
|
318
|
+
self.emit('headers', headers, pair.methodName);
|
|
319
|
+
|
|
320
|
+
self._executeMethod({
|
|
321
|
+
serviceName: serviceName,
|
|
322
|
+
portName: portName,
|
|
323
|
+
methodName: pair.methodName,
|
|
324
|
+
outputName: pair.outputName,
|
|
325
|
+
args: body[messageElemName],
|
|
326
|
+
headers: headers,
|
|
327
|
+
style: 'document'
|
|
328
|
+
}, req, callback, includeTimestamp);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
if (error.Fault !== undefined) {
|
|
333
|
+
return self._sendError(error.Fault, callback, includeTimestamp);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
throw error;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
Server.prototype._executeMethod = function (options, req, callback, includeTimestamp) {
|
|
341
|
+
options = options || {};
|
|
342
|
+
var self = this,
|
|
343
|
+
method, body, headers,
|
|
344
|
+
serviceName = options.serviceName,
|
|
345
|
+
portName = options.portName,
|
|
346
|
+
methodName = options.methodName,
|
|
347
|
+
outputName = options.outputName,
|
|
348
|
+
args = options.args,
|
|
349
|
+
style = options.style,
|
|
350
|
+
handled = false;
|
|
351
|
+
|
|
352
|
+
if (this.soapHeaders) {
|
|
353
|
+
headers = this.soapHeaders.map(function(header) {
|
|
354
|
+
if (typeof header === 'function') {
|
|
355
|
+
return header(methodName, args, options.headers, req);
|
|
356
|
+
} else {
|
|
357
|
+
return header;
|
|
358
|
+
}
|
|
359
|
+
}).join("\n");
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
try {
|
|
363
|
+
method = this.services[serviceName][portName][methodName];
|
|
364
|
+
} catch (error) {
|
|
365
|
+
return callback(this._envelope('', headers, includeTimestamp));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function handleResult(error, result) {
|
|
369
|
+
if (handled)
|
|
370
|
+
return;
|
|
371
|
+
handled = true;
|
|
372
|
+
|
|
373
|
+
if (error && error.Fault !== undefined) {
|
|
374
|
+
return self._sendError(error.Fault, callback, includeTimestamp);
|
|
375
|
+
}
|
|
376
|
+
else if (result === undefined) {
|
|
377
|
+
// Backward compatibility to support one argument callback style
|
|
378
|
+
result = error;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (style === 'rpc') {
|
|
382
|
+
body = self.wsdl.objectToRpcXML(outputName, result, '', self.wsdl.definitions.$targetNamespace);
|
|
383
|
+
} else {
|
|
384
|
+
var element = self.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output;
|
|
385
|
+
body = self.wsdl.objectToDocumentXML(outputName, result, element.targetNSAlias, element.targetNamespace);
|
|
386
|
+
}
|
|
387
|
+
callback(self._envelope(body, headers, includeTimestamp));
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (!self.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output) {
|
|
391
|
+
// no output defined = one-way operation so return empty response
|
|
392
|
+
handled = true;
|
|
393
|
+
body = '';
|
|
394
|
+
if (this.onewayOptions.emptyBody) {
|
|
395
|
+
body = self._envelope('', headers, includeTimestamp);
|
|
396
|
+
}
|
|
397
|
+
callback(body, this.onewayOptions.responseCode);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
var result = method(args, handleResult, options.headers, req);
|
|
401
|
+
if (typeof result !== 'undefined') {
|
|
402
|
+
handleResult(result);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
Server.prototype._envelope = function (body, headers, includeTimestamp) {
|
|
407
|
+
var defs = this.wsdl.definitions,
|
|
408
|
+
ns = defs.$targetNamespace,
|
|
409
|
+
encoding = '',
|
|
410
|
+
alias = findPrefix(defs.xmlns, ns);
|
|
411
|
+
|
|
412
|
+
var envelopeDefinition = this.wsdl.options.forceSoap12Headers
|
|
413
|
+
? "http://www.w3.org/2003/05/soap-envelope"
|
|
414
|
+
: "http://schemas.xmlsoap.org/soap/envelope/"
|
|
415
|
+
|
|
416
|
+
var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
|
417
|
+
"<soap:Envelope xmlns:soap=\"" + envelopeDefinition + "\" " +
|
|
418
|
+
encoding +
|
|
419
|
+
this.wsdl.xmlnsInEnvelope + '>';
|
|
420
|
+
|
|
421
|
+
headers = headers || '';
|
|
422
|
+
|
|
423
|
+
if (includeTimestamp) {
|
|
424
|
+
var now = new Date();
|
|
425
|
+
var created = getDateString(now);
|
|
426
|
+
var expires = getDateString(new Date(now.getTime() + (1000 * 600)));
|
|
427
|
+
|
|
428
|
+
headers += "<o:Security soap:mustUnderstand=\"1\" " +
|
|
429
|
+
"xmlns:o=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" " +
|
|
430
|
+
"xmlns:u=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" +
|
|
431
|
+
" <u:Timestamp u:Id=\"_0\">" +
|
|
432
|
+
" <u:Created>" + created + "</u:Created>" +
|
|
433
|
+
" <u:Expires>" + expires + "</u:Expires>" +
|
|
434
|
+
" </u:Timestamp>" +
|
|
435
|
+
" </o:Security>\n";
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (headers !== '') {
|
|
439
|
+
xml += "<soap:Header>" + headers + "</soap:Header>";
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
xml += body ? "<soap:Body>" + body + "</soap:Body>" : "<soap:Body/>";
|
|
443
|
+
|
|
444
|
+
xml += "</soap:Envelope>";
|
|
445
|
+
return xml;
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
Server.prototype._sendError = function (soapFault, callback, includeTimestamp) {
|
|
449
|
+
var self = this,
|
|
450
|
+
fault;
|
|
451
|
+
|
|
452
|
+
var statusCode;
|
|
453
|
+
if (soapFault.statusCode) {
|
|
454
|
+
statusCode = soapFault.statusCode;
|
|
455
|
+
soapFault.statusCode = undefined;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (soapFault.faultcode) {
|
|
459
|
+
// Soap 1.1 error style
|
|
460
|
+
// Root element will be prependend with the soap NS
|
|
461
|
+
// It must match the NS defined in the Envelope (set by the _envelope method)
|
|
462
|
+
fault = self.wsdl.objectToDocumentXML("soap:Fault", soapFault, undefined);
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
// Soap 1.2 error style.
|
|
466
|
+
// 3rd param is the NS prepended to all elements
|
|
467
|
+
// It must match the NS defined in the Envelope (set by the _envelope method)
|
|
468
|
+
fault = self.wsdl.objectToDocumentXML("Fault", soapFault, "soap");
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return callback(self._envelope(fault, '', includeTimestamp), statusCode);
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
exports.Server = Server;
|