soap 0.45.0 → 1.0.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/History.md +7 -0
- package/Readme.md +12 -0
- package/lib/client.d.ts +1 -0
- package/lib/client.js +168 -187
- package/lib/client.js.map +1 -1
- package/lib/http.d.ts +1 -0
- package/lib/http.js +91 -101
- package/lib/http.js.map +1 -1
- package/lib/nscontext.js +38 -40
- package/lib/nscontext.js.map +1 -1
- package/lib/security/BasicAuthSecurity.js +11 -12
- package/lib/security/BasicAuthSecurity.js.map +1 -1
- package/lib/security/BearerSecurity.js +11 -12
- package/lib/security/BearerSecurity.js.map +1 -1
- package/lib/security/ClientSSLSecurity.js +12 -13
- package/lib/security/ClientSSLSecurity.js.map +1 -1
- package/lib/security/ClientSSLSecurityPFX.js +11 -12
- package/lib/security/ClientSSLSecurityPFX.js.map +1 -1
- package/lib/security/NTLMSecurity.js +12 -13
- package/lib/security/NTLMSecurity.js.map +1 -1
- package/lib/security/WSSecurity.js +21 -22
- package/lib/security/WSSecurity.js.map +1 -1
- package/lib/security/WSSecurityCert.d.ts +1 -0
- package/lib/security/WSSecurityCert.js +74 -56
- package/lib/security/WSSecurityCert.js.map +1 -1
- package/lib/security/WSSecurityPlusCert.d.ts +9 -0
- package/lib/security/WSSecurityPlusCert.js +17 -0
- package/lib/security/WSSecurityPlusCert.js.map +1 -0
- package/lib/security/index.d.ts +1 -0
- package/lib/security/index.js +8 -3
- package/lib/security/index.js.map +1 -1
- package/lib/server.d.ts +1 -0
- package/lib/server.js +189 -209
- package/lib/server.js.map +1 -1
- package/lib/soap.d.ts +1 -1
- package/lib/soap.js +45 -40
- package/lib/soap.js.map +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.js +1 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +55 -53
- package/lib/utils.js.map +1 -1
- package/lib/wsdl/elements.js +393 -515
- package/lib/wsdl/elements.js.map +1 -1
- package/lib/wsdl/index.js +322 -322
- package/lib/wsdl/index.js.map +1 -1
- package/package.json +8 -7
- package/tsconfig.json +2 -1
package/lib/server.js
CHANGED
|
@@ -3,25 +3,12 @@
|
|
|
3
3
|
* Copyright (c) 2011 Vinay Pulim <vinay@milewise.com>
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
var extendStatics = function (d, b) {
|
|
8
|
-
extendStatics = Object.setPrototypeOf ||
|
|
9
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
10
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
11
|
-
return extendStatics(d, b);
|
|
12
|
-
};
|
|
13
|
-
return function (d, b) {
|
|
14
|
-
extendStatics(d, b);
|
|
15
|
-
function __() { this.constructor = d; }
|
|
16
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
17
|
-
};
|
|
18
|
-
})();
|
|
19
|
-
exports.__esModule = true;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
7
|
exports.Server = void 0;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
const events_1 = require("events");
|
|
9
|
+
const url = require("url");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
let zlib;
|
|
25
12
|
try {
|
|
26
13
|
zlib = require('zlib');
|
|
27
14
|
}
|
|
@@ -44,104 +31,102 @@ function getDateString(d) {
|
|
|
44
31
|
+ pad(d.getUTCMinutes()) + ':'
|
|
45
32
|
+ pad(d.getUTCSeconds()) + 'Z';
|
|
46
33
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var _this_1 = _super.call(this) || this;
|
|
34
|
+
class Server extends events_1.EventEmitter {
|
|
35
|
+
constructor(server, path, services, wsdl, options) {
|
|
36
|
+
super();
|
|
51
37
|
options = options || {
|
|
52
38
|
path: path,
|
|
53
|
-
services: services
|
|
39
|
+
services: services,
|
|
54
40
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
41
|
+
this.path = path;
|
|
42
|
+
this.services = services;
|
|
43
|
+
this.wsdl = wsdl;
|
|
44
|
+
this.suppressStack = options && options.suppressStack;
|
|
45
|
+
this.returnFault = options && options.returnFault;
|
|
46
|
+
this.onewayOptions = options && options.oneWay || {};
|
|
47
|
+
this.enableChunkedEncoding =
|
|
62
48
|
options.enableChunkedEncoding === undefined ? true : !!options.enableChunkedEncoding;
|
|
63
|
-
|
|
49
|
+
this.callback = options.callback ? options.callback : () => { };
|
|
64
50
|
if (typeof path === 'string' && path[path.length - 1] !== '/') {
|
|
65
51
|
path += '/';
|
|
66
52
|
}
|
|
67
53
|
else if (path instanceof RegExp && path.source[path.source.length - 1] !== '/') {
|
|
68
54
|
path = new RegExp(path.source + '(?:\\/|)');
|
|
69
55
|
}
|
|
70
|
-
wsdl.onReady(
|
|
56
|
+
wsdl.onReady((err) => {
|
|
71
57
|
if (isExpress(server)) {
|
|
72
58
|
// handle only the required URL path for express server
|
|
73
|
-
server.route(path).all(
|
|
74
|
-
if (typeof
|
|
75
|
-
if (!
|
|
59
|
+
server.route(path).all((req, res) => {
|
|
60
|
+
if (typeof this.authorizeConnection === 'function') {
|
|
61
|
+
if (!this.authorizeConnection(req, res)) {
|
|
76
62
|
res.end();
|
|
77
63
|
return;
|
|
78
64
|
}
|
|
79
65
|
}
|
|
80
|
-
|
|
66
|
+
this._requestListener(req, res);
|
|
81
67
|
});
|
|
82
|
-
|
|
68
|
+
this.callback(err, this);
|
|
83
69
|
}
|
|
84
70
|
else {
|
|
85
|
-
|
|
71
|
+
const listeners = server.listeners('request').slice();
|
|
86
72
|
server.removeAllListeners('request');
|
|
87
|
-
server.addListener('request',
|
|
88
|
-
if (typeof
|
|
89
|
-
if (!
|
|
73
|
+
server.addListener('request', (req, res) => {
|
|
74
|
+
if (typeof this.authorizeConnection === 'function') {
|
|
75
|
+
if (!this.authorizeConnection(req, res)) {
|
|
90
76
|
res.end();
|
|
91
77
|
return;
|
|
92
78
|
}
|
|
93
79
|
}
|
|
94
|
-
|
|
80
|
+
let reqPath = url.parse(req.url).pathname;
|
|
95
81
|
if (reqPath[reqPath.length - 1] !== '/') {
|
|
96
82
|
reqPath += '/';
|
|
97
83
|
}
|
|
98
84
|
if (path === reqPath || (path instanceof RegExp && reqPath.match(path))) {
|
|
99
|
-
|
|
85
|
+
this._requestListener(req, res);
|
|
100
86
|
}
|
|
101
87
|
else {
|
|
102
|
-
for (
|
|
103
|
-
|
|
88
|
+
for (let i = 0, len = listeners.length; i < len; i++) {
|
|
89
|
+
listeners[i].call(this, req, res);
|
|
104
90
|
}
|
|
105
91
|
}
|
|
106
92
|
});
|
|
107
|
-
|
|
93
|
+
this.callback(err, this);
|
|
108
94
|
}
|
|
109
95
|
});
|
|
110
|
-
|
|
111
|
-
return _this_1;
|
|
96
|
+
this._initializeOptions(options);
|
|
112
97
|
}
|
|
113
|
-
|
|
98
|
+
addSoapHeader(soapHeader, name, namespace, xmlns) {
|
|
114
99
|
if (!this.soapHeaders) {
|
|
115
100
|
this.soapHeaders = [];
|
|
116
101
|
}
|
|
117
102
|
soapHeader = this._processSoapHeader(soapHeader, name, namespace, xmlns);
|
|
118
103
|
return this.soapHeaders.push(soapHeader) - 1;
|
|
119
|
-
}
|
|
120
|
-
|
|
104
|
+
}
|
|
105
|
+
changeSoapHeader(index, soapHeader, name, namespace, xmlns) {
|
|
121
106
|
if (!this.soapHeaders) {
|
|
122
107
|
this.soapHeaders = [];
|
|
123
108
|
}
|
|
124
109
|
soapHeader = this._processSoapHeader(soapHeader, name, namespace, xmlns);
|
|
125
110
|
this.soapHeaders[index] = soapHeader;
|
|
126
|
-
}
|
|
127
|
-
|
|
111
|
+
}
|
|
112
|
+
getSoapHeaders() {
|
|
128
113
|
return this.soapHeaders;
|
|
129
|
-
}
|
|
130
|
-
|
|
114
|
+
}
|
|
115
|
+
clearSoapHeaders() {
|
|
131
116
|
this.soapHeaders = null;
|
|
132
|
-
}
|
|
133
|
-
|
|
117
|
+
}
|
|
118
|
+
_processSoapHeader(soapHeader, name, namespace, xmlns) {
|
|
134
119
|
switch (typeof soapHeader) {
|
|
135
120
|
case 'object':
|
|
136
121
|
return this.wsdl.objectToXML(soapHeader, name, namespace, xmlns, true);
|
|
137
122
|
case 'function':
|
|
138
|
-
|
|
123
|
+
const _this = this;
|
|
139
124
|
// arrow function does not support arguments variable
|
|
140
125
|
// tslint:disable-next-line
|
|
141
126
|
return function () {
|
|
142
|
-
|
|
127
|
+
const result = soapHeader.apply(null, arguments);
|
|
143
128
|
if (typeof result === 'object') {
|
|
144
|
-
return
|
|
129
|
+
return _this.wsdl.objectToXML(result, name, namespace, xmlns, true);
|
|
145
130
|
}
|
|
146
131
|
else {
|
|
147
132
|
return result;
|
|
@@ -150,32 +135,31 @@ var Server = /** @class */ (function (_super) {
|
|
|
150
135
|
default:
|
|
151
136
|
return soapHeader;
|
|
152
137
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
138
|
+
}
|
|
139
|
+
_initializeOptions(options) {
|
|
155
140
|
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
|
|
156
141
|
this.onewayOptions.statusCode = this.onewayOptions.responseCode || 200;
|
|
157
142
|
this.onewayOptions.emptyBody = !!this.onewayOptions.emptyBody;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var error;
|
|
143
|
+
}
|
|
144
|
+
_processRequestXml(req, res, xml) {
|
|
145
|
+
let error;
|
|
162
146
|
try {
|
|
163
147
|
if (typeof this.log === 'function') {
|
|
164
148
|
this.log('received', xml);
|
|
165
149
|
}
|
|
166
|
-
this._process(xml, req, res,
|
|
167
|
-
|
|
168
|
-
if (typeof
|
|
169
|
-
|
|
150
|
+
this._process(xml, req, res, (result, statusCode) => {
|
|
151
|
+
this._sendHttpResponse(res, statusCode, result);
|
|
152
|
+
if (typeof this.log === 'function') {
|
|
153
|
+
this.log('replied', result);
|
|
170
154
|
}
|
|
171
155
|
});
|
|
172
156
|
}
|
|
173
157
|
catch (err) {
|
|
174
158
|
if (err.Fault !== undefined) {
|
|
175
|
-
return this._sendError(err.Fault,
|
|
176
|
-
|
|
177
|
-
if (typeof
|
|
178
|
-
|
|
159
|
+
return this._sendError(err.Fault, (result, statusCode) => {
|
|
160
|
+
this._sendHttpResponse(res, statusCode || 500, result);
|
|
161
|
+
if (typeof this.log === 'function') {
|
|
162
|
+
this.log('error', err);
|
|
179
163
|
}
|
|
180
164
|
}, new Date().toISOString());
|
|
181
165
|
}
|
|
@@ -187,12 +171,11 @@ var Server = /** @class */ (function (_super) {
|
|
|
187
171
|
}
|
|
188
172
|
}
|
|
189
173
|
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
var reqQuery = reqParse.search;
|
|
174
|
+
}
|
|
175
|
+
_requestListener(req, res) {
|
|
176
|
+
const reqParse = url.parse(req.url);
|
|
177
|
+
const reqPath = reqParse.pathname;
|
|
178
|
+
const reqQuery = reqParse.search;
|
|
196
179
|
if (typeof this.log === 'function') {
|
|
197
180
|
this.log('info', 'Handling ' + req.method + ' on ' + req.url);
|
|
198
181
|
}
|
|
@@ -218,55 +201,54 @@ var Server = /** @class */ (function (_super) {
|
|
|
218
201
|
if (req.body && req.body.length > 0) {
|
|
219
202
|
return this._processRequestXml(req, res, req.body.toString());
|
|
220
203
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
204
|
+
const chunks = [];
|
|
205
|
+
let gunzip;
|
|
206
|
+
let source = req;
|
|
224
207
|
if (req.headers['content-encoding'] === 'gzip') {
|
|
225
208
|
gunzip = zlib.createGunzip();
|
|
226
209
|
req.pipe(gunzip);
|
|
227
210
|
source = gunzip;
|
|
228
211
|
}
|
|
229
|
-
source.on('data',
|
|
230
|
-
|
|
212
|
+
source.on('data', (chunk) => {
|
|
213
|
+
chunks.push(chunk);
|
|
231
214
|
});
|
|
232
|
-
source.on('end',
|
|
233
|
-
|
|
234
|
-
|
|
215
|
+
source.on('end', () => {
|
|
216
|
+
const xml = Buffer.concat(chunks).toString();
|
|
217
|
+
this._processRequestXml(req, res, xml);
|
|
235
218
|
});
|
|
236
219
|
}
|
|
237
220
|
else {
|
|
238
221
|
res.end();
|
|
239
222
|
}
|
|
240
|
-
}
|
|
241
|
-
|
|
223
|
+
}
|
|
224
|
+
_getSoapAction(req) {
|
|
242
225
|
if (typeof req.headers.soapaction === 'undefined') {
|
|
243
226
|
return;
|
|
244
227
|
}
|
|
245
|
-
|
|
228
|
+
const soapAction = req.headers.soapaction;
|
|
246
229
|
return (soapAction.indexOf('"') === 0)
|
|
247
230
|
? soapAction.slice(1, -1)
|
|
248
231
|
: soapAction;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
_this_1.emit('response', response, methodName);
|
|
232
|
+
}
|
|
233
|
+
_process(input, req, res, cb) {
|
|
234
|
+
const pathname = url.parse(req.url).pathname.replace(/\/$/, '');
|
|
235
|
+
const obj = this.wsdl.xmlToObject(input);
|
|
236
|
+
const body = obj.Body;
|
|
237
|
+
const headers = obj.Header;
|
|
238
|
+
let binding;
|
|
239
|
+
let methodName;
|
|
240
|
+
let serviceName;
|
|
241
|
+
let portName;
|
|
242
|
+
const includeTimestamp = obj.Header && obj.Header.Security && obj.Header.Security.Timestamp;
|
|
243
|
+
const authenticate = this.authenticate || function defaultAuthenticate() { return true; };
|
|
244
|
+
const callback = (result, statusCode) => {
|
|
245
|
+
const response = { result: result };
|
|
246
|
+
this.emit('response', response, methodName);
|
|
265
247
|
cb(response.result, statusCode);
|
|
266
248
|
};
|
|
267
|
-
|
|
268
|
-
if (typeof
|
|
269
|
-
|
|
249
|
+
const process = () => {
|
|
250
|
+
if (typeof this.log === 'function') {
|
|
251
|
+
this.log('info', 'Attempting to bind to ' + pathname);
|
|
270
252
|
}
|
|
271
253
|
// Avoid Cannot convert undefined or null to object due to Object.keys(body)
|
|
272
254
|
// and throw more meaningful error
|
|
@@ -274,20 +256,20 @@ var Server = /** @class */ (function (_super) {
|
|
|
274
256
|
throw new Error('Failed to parse the SOAP Message body');
|
|
275
257
|
}
|
|
276
258
|
// use port.location and current url to find the right binding
|
|
277
|
-
binding = (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
259
|
+
binding = (() => {
|
|
260
|
+
const services = this.wsdl.definitions.services;
|
|
261
|
+
let firstPort;
|
|
262
|
+
let name;
|
|
281
263
|
for (name in services) {
|
|
282
264
|
serviceName = name;
|
|
283
|
-
|
|
284
|
-
|
|
265
|
+
const service = services[serviceName];
|
|
266
|
+
const ports = service.ports;
|
|
285
267
|
for (name in ports) {
|
|
286
268
|
portName = name;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if (typeof
|
|
290
|
-
|
|
269
|
+
const port = ports[portName];
|
|
270
|
+
const portPathname = url.parse(port.location).pathname.replace(/\/$/, '');
|
|
271
|
+
if (typeof this.log === 'function') {
|
|
272
|
+
this.log('info', 'Trying ' + portName + ' from path ' + portPathname);
|
|
291
273
|
}
|
|
292
274
|
if (portPathname === pathname) {
|
|
293
275
|
return port.binding;
|
|
@@ -304,68 +286,68 @@ var Server = /** @class */ (function (_super) {
|
|
|
304
286
|
throw new Error('Failed to bind to WSDL');
|
|
305
287
|
}
|
|
306
288
|
try {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
289
|
+
const soapAction = this._getSoapAction(req);
|
|
290
|
+
const messageElemName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
|
|
291
|
+
const pair = binding.topElements[messageElemName];
|
|
310
292
|
if (soapAction) {
|
|
311
|
-
methodName =
|
|
293
|
+
methodName = this._getMethodNameBySoapAction(binding, soapAction);
|
|
312
294
|
}
|
|
313
295
|
else {
|
|
314
296
|
methodName = pair ? pair.methodName : messageElemName;
|
|
315
297
|
}
|
|
316
298
|
/** Style can be defined in method. If method has no style then look in binding */
|
|
317
|
-
|
|
318
|
-
|
|
299
|
+
const style = binding.methods[methodName].style || binding.style;
|
|
300
|
+
this.emit('request', obj, methodName);
|
|
319
301
|
if (headers) {
|
|
320
|
-
|
|
302
|
+
this.emit('headers', headers, methodName);
|
|
321
303
|
}
|
|
322
304
|
if (style === 'rpc') {
|
|
323
|
-
|
|
305
|
+
this._executeMethod({
|
|
324
306
|
serviceName: serviceName,
|
|
325
307
|
portName: portName,
|
|
326
308
|
methodName: methodName,
|
|
327
309
|
outputName: messageElemName + 'Response',
|
|
328
310
|
args: body[messageElemName],
|
|
329
311
|
headers: headers,
|
|
330
|
-
style: 'rpc'
|
|
312
|
+
style: 'rpc',
|
|
331
313
|
}, req, res, callback);
|
|
332
314
|
}
|
|
333
315
|
else {
|
|
334
|
-
|
|
316
|
+
this._executeMethod({
|
|
335
317
|
serviceName: serviceName,
|
|
336
318
|
portName: portName,
|
|
337
319
|
methodName: methodName,
|
|
338
320
|
outputName: pair.outputName,
|
|
339
321
|
args: body[messageElemName],
|
|
340
322
|
headers: headers,
|
|
341
|
-
style: 'document'
|
|
323
|
+
style: 'document',
|
|
342
324
|
}, req, res, callback, includeTimestamp);
|
|
343
325
|
}
|
|
344
326
|
}
|
|
345
327
|
catch (error) {
|
|
346
328
|
if (error.Fault !== undefined) {
|
|
347
|
-
return
|
|
329
|
+
return this._sendError(error.Fault, callback, includeTimestamp);
|
|
348
330
|
}
|
|
349
331
|
throw error;
|
|
350
332
|
}
|
|
351
333
|
};
|
|
352
334
|
// Authentication
|
|
353
335
|
if (typeof authenticate === 'function') {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (
|
|
336
|
+
let authResultProcessed = false;
|
|
337
|
+
const processAuthResult = (authResult) => {
|
|
338
|
+
if (authResultProcessed) {
|
|
357
339
|
return;
|
|
358
340
|
}
|
|
359
|
-
|
|
341
|
+
authResultProcessed = true;
|
|
360
342
|
// Handle errors
|
|
361
343
|
if (authResult instanceof Error) {
|
|
362
|
-
return
|
|
344
|
+
return this._sendError({
|
|
363
345
|
Code: {
|
|
364
346
|
Value: 'SOAP-ENV:Server',
|
|
365
|
-
Subcode: { Value: 'InternalServerError' }
|
|
347
|
+
Subcode: { Value: 'InternalServerError' },
|
|
366
348
|
},
|
|
367
349
|
Reason: { Text: authResult.toString() },
|
|
368
|
-
statusCode: 500
|
|
350
|
+
statusCode: 500,
|
|
369
351
|
}, callback, includeTimestamp);
|
|
370
352
|
}
|
|
371
353
|
// Handle actual results
|
|
@@ -376,70 +358,69 @@ var Server = /** @class */ (function (_super) {
|
|
|
376
358
|
}
|
|
377
359
|
catch (error) {
|
|
378
360
|
if (error.Fault !== undefined) {
|
|
379
|
-
return
|
|
361
|
+
return this._sendError(error.Fault, callback, includeTimestamp);
|
|
380
362
|
}
|
|
381
|
-
return
|
|
363
|
+
return this._sendError({
|
|
382
364
|
Code: {
|
|
383
365
|
Value: 'SOAP-ENV:Server',
|
|
384
|
-
Subcode: { Value: 'InternalServerError' }
|
|
366
|
+
Subcode: { Value: 'InternalServerError' },
|
|
385
367
|
},
|
|
386
368
|
Reason: { Text: error.toString() },
|
|
387
|
-
statusCode: 500
|
|
369
|
+
statusCode: 500,
|
|
388
370
|
}, callback, includeTimestamp);
|
|
389
371
|
}
|
|
390
372
|
}
|
|
391
373
|
else {
|
|
392
|
-
return
|
|
374
|
+
return this._sendError({
|
|
393
375
|
Code: {
|
|
394
376
|
Value: 'SOAP-ENV:Client',
|
|
395
|
-
Subcode: { Value: 'AuthenticationFailure' }
|
|
377
|
+
Subcode: { Value: 'AuthenticationFailure' },
|
|
396
378
|
},
|
|
397
379
|
Reason: { Text: 'Invalid username or password' },
|
|
398
|
-
statusCode: 401
|
|
380
|
+
statusCode: 401,
|
|
399
381
|
}, callback, includeTimestamp);
|
|
400
382
|
}
|
|
401
383
|
}
|
|
402
384
|
};
|
|
403
|
-
|
|
385
|
+
const functionResult = authenticate(obj.Header && obj.Header.Security, processAuthResult, req, obj);
|
|
404
386
|
if (isPromiseLike(functionResult)) {
|
|
405
|
-
functionResult.then(
|
|
406
|
-
|
|
407
|
-
},
|
|
408
|
-
|
|
387
|
+
functionResult.then((result) => {
|
|
388
|
+
processAuthResult(result);
|
|
389
|
+
}, (err) => {
|
|
390
|
+
processAuthResult(err);
|
|
409
391
|
});
|
|
410
392
|
}
|
|
411
393
|
if (typeof functionResult === 'boolean') {
|
|
412
|
-
|
|
394
|
+
processAuthResult(functionResult);
|
|
413
395
|
}
|
|
414
396
|
}
|
|
415
397
|
else {
|
|
416
398
|
throw new Error('Invalid authenticate function (not a function)');
|
|
417
399
|
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
for (
|
|
400
|
+
}
|
|
401
|
+
_getMethodNameBySoapAction(binding, soapAction) {
|
|
402
|
+
for (const methodName in binding.methods) {
|
|
421
403
|
if (binding.methods[methodName].soapAction === soapAction) {
|
|
422
404
|
return methodName;
|
|
423
405
|
}
|
|
424
406
|
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
var _this_1 = this;
|
|
407
|
+
}
|
|
408
|
+
_executeMethod(options, req, res, callback, includeTimestamp) {
|
|
428
409
|
options = options || {};
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
410
|
+
let method;
|
|
411
|
+
let body;
|
|
412
|
+
let headers;
|
|
413
|
+
const serviceName = options.serviceName;
|
|
414
|
+
const portName = options.portName;
|
|
415
|
+
const binding = this.wsdl.definitions.services[serviceName].ports[portName].binding;
|
|
416
|
+
const methodName = options.methodName;
|
|
417
|
+
const outputName = options.outputName;
|
|
418
|
+
const args = options.args;
|
|
419
|
+
const style = options.style;
|
|
439
420
|
if (this.soapHeaders) {
|
|
440
|
-
headers = this.soapHeaders.map(
|
|
421
|
+
headers = this.soapHeaders.map((header) => {
|
|
441
422
|
if (typeof header === 'function') {
|
|
442
|
-
return header(methodName, args, options.headers, req, res,
|
|
423
|
+
return header(methodName, args, options.headers, req, res, this);
|
|
443
424
|
}
|
|
444
425
|
else {
|
|
445
426
|
return header;
|
|
@@ -452,46 +433,46 @@ var Server = /** @class */ (function (_super) {
|
|
|
452
433
|
catch (error) {
|
|
453
434
|
return callback(this._envelope('', headers, includeTimestamp));
|
|
454
435
|
}
|
|
455
|
-
|
|
456
|
-
|
|
436
|
+
let handled = false;
|
|
437
|
+
const handleResult = (error, result) => {
|
|
457
438
|
if (handled) {
|
|
458
439
|
return;
|
|
459
440
|
}
|
|
460
441
|
handled = true;
|
|
461
442
|
if (error) {
|
|
462
443
|
if (error.Fault !== undefined) {
|
|
463
|
-
return
|
|
444
|
+
return this._sendError(error.Fault, callback, includeTimestamp);
|
|
464
445
|
}
|
|
465
446
|
else {
|
|
466
|
-
return
|
|
447
|
+
return this._sendError({
|
|
467
448
|
Code: {
|
|
468
449
|
Value: 'SOAP-ENV:Server',
|
|
469
|
-
Subcode: { Value: 'InternalServerError' }
|
|
450
|
+
Subcode: { Value: 'InternalServerError' },
|
|
470
451
|
},
|
|
471
452
|
Reason: { Text: error.toString() },
|
|
472
|
-
statusCode: 500
|
|
453
|
+
statusCode: 500,
|
|
473
454
|
}, callback, includeTimestamp);
|
|
474
455
|
}
|
|
475
456
|
}
|
|
476
457
|
if (style === 'rpc') {
|
|
477
|
-
body =
|
|
458
|
+
body = this.wsdl.objectToRpcXML(outputName, result, '', this.wsdl.definitions.$targetNamespace);
|
|
478
459
|
}
|
|
479
460
|
else if (style === 'document') {
|
|
480
|
-
|
|
481
|
-
body =
|
|
461
|
+
const element = binding.methods[methodName].output;
|
|
462
|
+
body = this.wsdl.objectToDocumentXML(outputName, result, element.targetNSAlias, element.targetNamespace);
|
|
482
463
|
}
|
|
483
464
|
else {
|
|
484
|
-
|
|
465
|
+
const element = binding.methods[methodName].output;
|
|
485
466
|
// Check for targetNamespace on the element
|
|
486
|
-
|
|
487
|
-
|
|
467
|
+
const elementTargetNamespace = element.$targetNamespace;
|
|
468
|
+
let outputNameWithNamespace = outputName;
|
|
488
469
|
if (elementTargetNamespace) {
|
|
489
470
|
// if targetNamespace is set on the element concatinate it with the outputName
|
|
490
|
-
outputNameWithNamespace = elementTargetNamespace
|
|
471
|
+
outputNameWithNamespace = `${elementTargetNamespace}:${outputNameWithNamespace}`;
|
|
491
472
|
}
|
|
492
|
-
body =
|
|
473
|
+
body = this.wsdl.objectToDocumentXML(outputNameWithNamespace, result, element.targetNSAlias, element.targetNamespace);
|
|
493
474
|
}
|
|
494
|
-
callback(
|
|
475
|
+
callback(this._envelope(body, headers, includeTimestamp));
|
|
495
476
|
};
|
|
496
477
|
if (!binding.methods[methodName].output) {
|
|
497
478
|
// no output defined = one-way operation so return empty response
|
|
@@ -502,7 +483,7 @@ var Server = /** @class */ (function (_super) {
|
|
|
502
483
|
}
|
|
503
484
|
callback(body, this.onewayOptions.responseCode);
|
|
504
485
|
}
|
|
505
|
-
|
|
486
|
+
const methodCallback = (error, result) => {
|
|
506
487
|
if (error && error.Fault !== undefined) {
|
|
507
488
|
// do nothing
|
|
508
489
|
}
|
|
@@ -513,12 +494,12 @@ var Server = /** @class */ (function (_super) {
|
|
|
513
494
|
}
|
|
514
495
|
handleResult(error, result);
|
|
515
496
|
};
|
|
516
|
-
|
|
497
|
+
const result = method(args, methodCallback, options.headers, req, res, this);
|
|
517
498
|
if (typeof result !== 'undefined') {
|
|
518
499
|
if (isPromiseLike(result)) {
|
|
519
|
-
result.then(
|
|
500
|
+
result.then((value) => {
|
|
520
501
|
handleResult(null, value);
|
|
521
|
-
},
|
|
502
|
+
}, (err) => {
|
|
522
503
|
handleResult(err);
|
|
523
504
|
});
|
|
524
505
|
}
|
|
@@ -526,24 +507,24 @@ var Server = /** @class */ (function (_super) {
|
|
|
526
507
|
handleResult(null, result);
|
|
527
508
|
}
|
|
528
509
|
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
510
|
+
}
|
|
511
|
+
_envelope(body, headers, includeTimestamp) {
|
|
512
|
+
const defs = this.wsdl.definitions;
|
|
513
|
+
const ns = defs.$targetNamespace;
|
|
514
|
+
const encoding = '';
|
|
515
|
+
const alias = (0, utils_1.findPrefix)(defs.xmlns, ns);
|
|
516
|
+
const envelopeDefinition = this.wsdl.options.forceSoap12Headers
|
|
536
517
|
? 'http://www.w3.org/2003/05/soap-envelope'
|
|
537
518
|
: 'http://schemas.xmlsoap.org/soap/envelope/';
|
|
538
|
-
|
|
519
|
+
let xml = '<?xml version="1.0" encoding="utf-8"?>' +
|
|
539
520
|
'<soap:Envelope xmlns:soap="' + envelopeDefinition + '" ' +
|
|
540
521
|
encoding +
|
|
541
522
|
this.wsdl.xmlnsInEnvelope + '>';
|
|
542
523
|
headers = headers || '';
|
|
543
524
|
if (includeTimestamp) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
525
|
+
const now = new Date();
|
|
526
|
+
const created = getDateString(now);
|
|
527
|
+
const expires = getDateString(new Date(now.getTime() + (1000 * 600)));
|
|
547
528
|
headers += '<o:Security soap:mustUnderstand="1" ' +
|
|
548
529
|
'xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" ' +
|
|
549
530
|
'xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">' +
|
|
@@ -559,10 +540,10 @@ var Server = /** @class */ (function (_super) {
|
|
|
559
540
|
xml += body ? '<soap:Body>' + body + '</soap:Body>' : '<soap:Body/>';
|
|
560
541
|
xml += '</soap:Envelope>';
|
|
561
542
|
return xml;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
543
|
+
}
|
|
544
|
+
_sendError(soapFault, callback, includeTimestamp) {
|
|
545
|
+
let fault;
|
|
546
|
+
let statusCode;
|
|
566
547
|
if (soapFault.statusCode) {
|
|
567
548
|
statusCode = soapFault.statusCode;
|
|
568
549
|
soapFault.statusCode = undefined;
|
|
@@ -580,8 +561,8 @@ var Server = /** @class */ (function (_super) {
|
|
|
580
561
|
fault = this.wsdl.objectToDocumentXML('Fault', soapFault, 'soap');
|
|
581
562
|
}
|
|
582
563
|
return callback(this._envelope(fault, '', includeTimestamp), statusCode);
|
|
583
|
-
}
|
|
584
|
-
|
|
564
|
+
}
|
|
565
|
+
_sendHttpResponse(res, statusCode, result) {
|
|
585
566
|
if (statusCode) {
|
|
586
567
|
res.statusCode = statusCode;
|
|
587
568
|
}
|
|
@@ -598,8 +579,7 @@ var Server = /** @class */ (function (_super) {
|
|
|
598
579
|
else {
|
|
599
580
|
res.end(result);
|
|
600
581
|
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
}(events_1.EventEmitter));
|
|
582
|
+
}
|
|
583
|
+
}
|
|
604
584
|
exports.Server = Server;
|
|
605
585
|
//# sourceMappingURL=server.js.map
|