Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 56a4690

Browse files
committedSep 21, 2016
Add globalization
1 parent 222dd2b commit 56a4690

16 files changed

+84
-37
lines changed
 

‎intl/en/messages.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"1b12432ead1b2b9902c4b9801aa0317b": "supplied {{pfx}} file should be a {{buffer}} or a file location",
3+
"1f2c65133b5bb463e7d1fceda5b31156": "The key element {0} {1} MUST contain one and only one selector element",
4+
"28c828192eb440b64b8efd7f08cc37b3": "Attribute {{itemType}} is not allowed if the content contains a {{simpleType}} element",
5+
"2d6dbd73e7a3abc468b95ca530caca9b": "Target namespace \"{0}\" already in use by another Schema",
6+
"37e4bf66d90c313e7adb3317345be046": "{{WSDL}} style not supported: {0}",
7+
"39e07c5a6797c4923d6a924999b62f8c": "Invalid qname: {0}",
8+
"3ab7c6dbb4e0c38f80e360957b0c8c82": "Schema {0} not found: {1} {2}",
9+
"46ad858fdf2e460aa3b626d6455362f2": "The key element {0} {1} MUST contain one or more field elements",
10+
"49569f279dd1e347fd90d448fdafbb93": "Unexpected root element of {{WSDL}} or include",
11+
"552f3502256707b8c5b12ddb64e3f74e": "Module {{ursa}} must be installed to use {{WSSecurityCert}}",
12+
"5dbe5d24686aa4e6d0cac19636b26cad": "no client stubbed for {0}",
13+
"61b096fd390a169fc86698a3fe30387f": "Found unexpected element ({0}) inside {1}",
14+
"6623e372e766ea11d932836035404a2b": "{{key}} should be a {{buffer}} or a {{string}}!",
15+
"738cd872b93488bfd87f26224d09e26d": "Cannot parse response",
16+
"7f7cb47259df769f2d3b3f7133f1a1ea": "{{cert}} should be a {{buffer}} or a {{string}}!",
17+
"902622149b2525f3d802f7c9ace5d312": " {{operationName}}: {0} {{outputName}}: {1}",
18+
"97ed6b53b9b594fb90c6bfb2e0ba0286": "List must have an item type",
19+
"9d1255b943657eca7c1a17eac8da02d0": "Schema not found: {0} ({1})",
20+
"b85a3a174c41fd29d1459ef484c985e3": "Element {0} is not allowed within {1}",
21+
"bcb4356ee2e7a196b9671acf3989741d": "Invalid username or password",
22+
"d40b6f905bf039c4d627ecafb7fdcac5": "No security header",
23+
"d7bda8e2c3faafdf0988f8cb4719a01d": "List can only contain one {{simpleType}} element",
24+
"da96ad47da6be6a613f921b260a33ce0": "{{WS-I}} violation: {{http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113}} part {0}",
25+
"e158dd1d250f1cc3df497728da556be1": "Failed to bind to {{WSDL}}",
26+
"e5c6b66d41ec0037a6322c5b0dd8da0b": "forced error on {{createClient}}",
27+
"fab749587c48e724a661d77a44084214": "Invalid {{WSDL URL}}: {0}\n\n\r Code: {1}\n\n\r Response Body: {2}"
28+
}

‎package.json

+2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
"lodash": "^4.13.1",
1212
"node-uuid": "^1.4.7",
1313
"optional": "^0.1.3",
14+
"path": "^0.12.7",
1415
"request": "^2.72.0",
1516
"sax": "^1.2",
1617
"selectn": "^1.0.20",
1718
"strip-bom": "^3.0.0",
19+
"strong-globalize": "^2.8.0",
1820
"xml-crypto": "^0.8.4",
1921
"xmlbuilder": "^8.2.2"
2022
},

‎soap-stub.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var g = require('./globalize');
12
var _ = require('lodash');
23

34
var aliasedClientStubs = {};
@@ -46,7 +47,7 @@ function createClient(wsdlUrl, options, cb) {
4647
}
4748

4849
if (this.errOnCreateClient) {
49-
return setTimeout(cb.bind(null, new Error('forced error on createClient')));
50+
return setTimeout(cb.bind(null, new Error(g.f('forced error on {{createClient}}'))));
5051
}
5152

5253
var client = getStub(wsdlUrl);
@@ -55,7 +56,7 @@ function createClient(wsdlUrl, options, cb) {
5556
resetStubbedMethods(client);
5657
setTimeout(cb.bind(null, null, client));
5758
} else {
58-
setTimeout(cb.bind(null, new Error('no client stubbed for ' + wsdlUrl)));
59+
setTimeout(cb.bind(null, new Error(g.f('no client stubbed for %s', wsdlUrl))));
5960
}
6061
}
6162

‎src/client.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
'use strict';
77

8+
var g = require('./globalize');
89
var HttpClient = require('./http'),
910
assert = require('assert'),
1011
xmlBuilder = require('xmlbuilder'),
@@ -261,7 +262,7 @@ class Client extends Base {
261262
return callback(null, null, body, obj.Header);
262263
}
263264
if (typeof obj.Body !== 'object') {
264-
var error = new Error('Cannot parse response');
265+
var error = new Error(g.f('Cannot parse response'));
265266
error.response = response;
266267
error.body = body;
267268
return callback(error, obj, body);

‎src/globalize.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var path = require('path');
2+
var SG = require('strong-globalize');
3+
4+
SG.SetRootDir(path.join(__dirname, '..'), {autonomousMsgLoading: 'all'});
5+
module.exports = SG();

‎src/parser/element.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var g = require('../globalize');
12
var assert = require('assert');
23
var QName = require('./qname');
34
var typeRegistry = require('./typeRegistry');
@@ -79,7 +80,7 @@ class Element {
7980
var ElementType = typeRegistry.getElementType(qname);
8081
if (this.constructor.allowedChildren.indexOf(qname.name) === -1 &&
8182
this.constructor.allowedChildren.indexOf('any') === -1) {
82-
console.warn('Element %s is not allowed within %j', qname, this.nsName);
83+
g.warn('Element %s is not allowed within %j', qname, this.nsName);
8384
}
8485

8586
if (ElementType) {
@@ -124,7 +125,7 @@ class Element {
124125
}
125126

126127
unexpected(name) {
127-
throw new Error('Found unexpected element (' + name + ') inside ' + this.nsName);
128+
throw new Error(g.f('Found unexpected element (%s) inside %s', name, this.nsName));
128129
}
129130

130131
describe(definitions) {
@@ -191,7 +192,7 @@ class Element {
191192
}
192193
var schema = schemas[nsURI];
193194
if (!schema) {
194-
console.warn('Schema not found: %s (%s)', qname, elementType);
195+
g.warn('Schema not found: %s (%s)', qname, elementType);
195196
return null;
196197
}
197198
var found = null;
@@ -219,8 +220,7 @@ class Element {
219220
break;
220221
}
221222
if (!found) {
222-
console.warn('Schema ' + elementType + ' not found: ' + nsURI +
223-
' ' + nsName);
223+
g.warn('Schema %s not found: %s %s', elementType, nsURI, nsName);
224224
return null;
225225
}
226226
return found;

‎src/parser/qname.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var g = require('../globalize');
12
var assert = require('assert');
23
var qnameExp = /^(?:\{([^\{\}]*)\})?(?:([^\{\}]+):)?([^\{\}\:]+)$/;
34

@@ -22,7 +23,7 @@ class QName {
2223
this.prefix = qname[2] || '';
2324
this.name = qname[3] || '';
2425
} else {
25-
throw new Error('Invalid qname: ' + nsURI);
26+
throw new Error(g.f('Invalid qname: %s', nsURI));
2627
}
2728
} else {
2829
this.nsURI = nsURI || '';

‎src/parser/wsdl.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var g = require('../globalize');
12
var sax = require('sax');
23
var HttpClient = require('./../http');
34
var fs = require('fs');
@@ -261,7 +262,7 @@ class WSDL {
261262
root.addChild(types);
262263
stack.push(schema);
263264
} else {
264-
throw new Error('Unexpected root element of WSDL or include');
265+
throw new Error(g.f('Unexpected root element of {{WSDL}} or include'));
265266
}
266267
}
267268
};
@@ -389,8 +390,8 @@ class WSDL {
389390
wsdl.WSDL_CACHE = WSDL_CACHE;
390391
wsdl.load(callback);
391392
} else {
392-
callback(new Error('Invalid WSDL URL: ' + uri + "\n\n\r Code: " +
393-
response.statusCode + "\n\n\r Response Body: " + response.body));
393+
callback(new Error(g.f('Invalid {{WSDL URL}}: %s\n\n\r Code: %s' +
394+
"\n\n\r Response Body: %j", uri, response.statusCode, response.body)));
394395
}
395396
}, request_headers, request_options);
396397
}

‎src/parser/wsdl/operation.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var g = require('../../globalize');
12
var WSDLElement = require('./wsdlElement');
23
var descriptor = require('../xsd/descriptor');
34
var ElementDescriptor = descriptor.ElementDescriptor;
@@ -72,9 +73,9 @@ class Operation extends WSDLElement {
7273
if (part && part.element) {
7374
headers.addElement(part.element.describe(definitions));
7475
} else if (part && part.type) {
75-
console.warn('WS-I violation: ' +
76-
'http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113' +
77-
' part ' + part.$name);
76+
g.warn('{{WS-I}} violation: ' +
77+
'{{http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113}}' +
78+
' part %s', part.$name);
7879
}
7980
});
8081
return headers;
@@ -88,9 +89,9 @@ class Operation extends WSDLElement {
8889
if (part && part.element) {
8990
faults[f] = part.element.describe(definitions);
9091
} else {
91-
console.warn('WS-I violation: ' +
92-
'http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113' +
93-
' part ' + part.$name);
92+
g.warn('{{WS-I}} violation: ' +
93+
'{{http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113}}' +
94+
' part %s', part.$name);
9495
}
9596
}
9697
return faults;
@@ -185,7 +186,7 @@ class Operation extends WSDLElement {
185186
output.elements = outputParts.elements;
186187
break;
187188
case Style.documentEncoded:
188-
throw new Error('WSDL style not supported: ' + Style.documentEncoded);
189+
throw new Error(g.f('{{WSDL}} style not supported: %s', Style.documentEncoded));
189190
}
190191

191192
let faults = this.describeFaults(definitions);

‎src/parser/wsdl/types.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var g = require('../../globalize');
12
var WSDLElement = require('./wsdlElement');
23
var assert = require('assert');
34
var Schema = require('../xsd/schema');
@@ -16,8 +17,8 @@ class Types extends WSDLElement {
1617
if (!this.schemas.hasOwnProperty(targetNamespace)) {
1718
this.schemas[targetNamespace] = child;
1819
} else {
19-
console.error('Target namespace "' + targetNamespace +
20-
'" already in use by another Schema');
20+
g.error('Target namespace "%s" already in use by another Schema',
21+
targetNamespace);
2122
}
2223
};
2324
}

‎src/parser/xsd/keybase.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var g = require('../../globalize');
12
var XSDElement = require('./xsdElement');
23

34
class KeyBase extends XSDElement {
@@ -10,7 +11,7 @@ class KeyBase extends XSDElement {
1011
addChild(child) {
1112
if (child.name === 'selector') {
1213
if (this.selector) {
13-
console.warn(
14+
g.warn(
1415
'The key element %s %s MUST contain one and only one selector element',
1516
this.nsName, this.$name);
1617
}
@@ -22,12 +23,12 @@ class KeyBase extends XSDElement {
2223

2324
postProcess(definitions) {
2425
if (!this.selector) {
25-
console.warn(
26+
g.warn(
2627
'The key element %s %s MUST contain one and only one selector element',
2728
this.nsName, this.$name);
2829
}
2930
if (!this.fields.length) {
30-
console.warn(
31+
g.warn(
3132
'The key element %s %s MUST contain one or more field elements',
3233
this.nsName, this.$name);
3334
}

‎src/parser/xsd/list.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var g = require('../../globalize');
12
var XSDElement = require('./xsdElement');
23
var helper = require('../helper');
34
var QName = require('../qname');
@@ -21,16 +22,16 @@ class List extends XSDElement {
2122
this.children.forEach(function(c) {
2223
if (c instanceof SimpleType) {
2324
if (self.$itemType) {
24-
console.warn('Attribute itemType is not allowed if the content ' +
25-
'contains a simpleType element');
25+
g.warn('Attribute {{itemType}} is not allowed if the content ' +
26+
'contains a {{simpleType}} element');
2627
} else if (self.itemType) {
27-
console.warn('List can only contain one simpleType element');
28+
g.warn('List can only contain one {{simpleType}} element');
2829
}
2930
self.itemType = c;
3031
}
3132
});
3233
if (!this.itemType) {
33-
console.warn('List must have an item type');
34+
g.warn('List must have an item type');
3435
}
3536
}
3637
}

‎src/security/ClientSSLSecurity.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var g = require('../globalize');
34
var fs = require('fs')
45
, https = require('https')
56
, _ = require('lodash')
@@ -25,7 +26,7 @@ class ClientSSLSecurity extends Security {
2526
} else if (typeof key === 'string') {
2627
this.key = fs.readFileSync(key);
2728
} else {
28-
throw new Error('key should be a buffer or a string!');
29+
throw new Error(g.f('{{key}} should be a {{buffer}} or a {{string}}!'));
2930
}
3031
}
3132

@@ -35,7 +36,7 @@ class ClientSSLSecurity extends Security {
3536
} else if (typeof cert === 'string') {
3637
this.cert = fs.readFileSync(cert);
3738
} else {
38-
throw new Error('cert should be a buffer or a string!');
39+
throw new Error(g.f('{{cert}} should be a {{buffer}} or a {{string}}!'));
3940
}
4041
}
4142

‎src/security/ClientSSLSecurityPFX.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var g = require('../globalize');
34
var fs = require('fs')
45
, https = require('https')
56
, _ = require('lodash')
@@ -27,8 +28,8 @@ class ClientSSLSecurityPFX extends Security {
2728
} else if (typeof pfx === 'string') {
2829
this.pfx = fs.readFileSync(pfx);
2930
} else {
30-
throw new Error(
31-
'supplied pfx file should be a buffer or a file location');
31+
throw new Error(g.f(
32+
'supplied {{pfx}} file should be a {{buffer}} or a file location'));
3233
}
3334
}
3435

‎src/security/WSSecurityCert.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var g = require('../globalize');
34
var optional = require('optional');
45
var ursa = optional('ursa');
56
var fs = require('fs');
@@ -42,7 +43,7 @@ class WSSecurityCert extends Security {
4243
constructor(privatePEM, publicP12PEM, password, encoding) {
4344
super();
4445
if (!ursa) {
45-
throw new Error('Module ursa must be installed to use WSSecurityCert');
46+
throw new Error(g.f('Module {{ursa}} must be installed to use {{WSSecurityCert}}'));
4647
}
4748
this.privateKey = ursa.createPrivateKey(privatePEM, password, encoding);
4849
this.publicP12PEM = publicP12PEM.toString()

‎src/server.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
'use strict';
77

8+
var g = require('./globalize');
89
var url = require('url'),
910
compress = null,
1011
events = require('events'),
@@ -141,10 +142,10 @@ class Server extends Base {
141142

142143
if (typeof self.authenticate === 'function') {
143144
if (!obj.Header || !obj.Header.Security) {
144-
throw new Error('No security header');
145+
throw new Error(g.f('No security header'));
145146
}
146147
if (!self.authenticate(obj.Header.Security)) {
147-
throw new Error('Invalid username or password');
148+
throw new Error(g.f('Invalid username or password'));
148149
}
149150
}
150151

@@ -183,7 +184,7 @@ class Server extends Base {
183184
})(this);
184185

185186
if (!binding) {
186-
throw new Error('Failed to bind to WSDL');
187+
throw new Error(g.f('Failed to bind to {{WSDL}}'));
187188
}
188189

189190
try {
@@ -227,7 +228,7 @@ class Server extends Base {
227228
}
228229
}
229230

230-
console.log(' operationName: ' + operationName + ' outputName: ' + outputName);
231+
g.log(' {{operationName}}: %s {{outputName}}: %s', operationName, outputName);
231232
self.emit('request', obj, operationName);
232233
if (headers)
233234
self.emit('headers', headers, operationName);

0 commit comments

Comments
 (0)
Please sign in to comment.