Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add globalization #17

Merged
merged 1 commit into from
Sep 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions intl/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"1b12432ead1b2b9902c4b9801aa0317b": "supplied {{pfx}} file should be a {{buffer}} or a file location",
"1f2c65133b5bb463e7d1fceda5b31156": "The key element {0} {1} MUST contain one and only one selector element",
"28c828192eb440b64b8efd7f08cc37b3": "Attribute {{itemType}} is not allowed if the content contains a {{simpleType}} element",
"2d6dbd73e7a3abc468b95ca530caca9b": "Target namespace \"{0}\" already in use by another Schema",
"37e4bf66d90c313e7adb3317345be046": "{{WSDL}} style not supported: {0}",
"39e07c5a6797c4923d6a924999b62f8c": "Invalid qname: {0}",
"3ab7c6dbb4e0c38f80e360957b0c8c82": "Schema {0} not found: {1} {2}",
"46ad858fdf2e460aa3b626d6455362f2": "The key element {0} {1} MUST contain one or more field elements",
"49569f279dd1e347fd90d448fdafbb93": "Unexpected root element of {{WSDL}} or include",
"552f3502256707b8c5b12ddb64e3f74e": "Module {{ursa}} must be installed to use {{WSSecurityCert}}",
"5dbe5d24686aa4e6d0cac19636b26cad": "no client stubbed for {0}",
"61b096fd390a169fc86698a3fe30387f": "Found unexpected element ({0}) inside {1}",
"6623e372e766ea11d932836035404a2b": "{{key}} should be a {{buffer}} or a {{string}}!",
"738cd872b93488bfd87f26224d09e26d": "Cannot parse response",
"7f7cb47259df769f2d3b3f7133f1a1ea": "{{cert}} should be a {{buffer}} or a {{string}}!",
"902622149b2525f3d802f7c9ace5d312": " {{operationName}}: {0} {{outputName}}: {1}",
"97ed6b53b9b594fb90c6bfb2e0ba0286": "List must have an item type",
"9d1255b943657eca7c1a17eac8da02d0": "Schema not found: {0} ({1})",
"b85a3a174c41fd29d1459ef484c985e3": "Element {0} is not allowed within {1}",
"bcb4356ee2e7a196b9671acf3989741d": "Invalid username or password",
"d40b6f905bf039c4d627ecafb7fdcac5": "No security header",
"d7bda8e2c3faafdf0988f8cb4719a01d": "List can only contain one {{simpleType}} element",
"da96ad47da6be6a613f921b260a33ce0": "{{WS-I}} violation: {{http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113}} part {0}",
"e158dd1d250f1cc3df497728da556be1": "Failed to bind to {{WSDL}}",
"e5c6b66d41ec0037a6322c5b0dd8da0b": "forced error on {{createClient}}",
"fab749587c48e724a661d77a44084214": "Invalid {{WSDL URL}}: {0}\n\n\r Code: {1}\n\n\r Response Body: {2}"
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -11,9 +11,11 @@
"lodash": "^4.13.1",
"node-uuid": "^1.4.7",
"optional": "^0.1.3",
"path": "^0.12.7",
"request": "^2.72.0",
"sax": "^1.2",
"selectn": "^1.0.20",
"strong-globalize": "^2.8.0",
"xml-crypto": "^0.8.4",
"xmlbuilder": "^8.2.2"
},
5 changes: 3 additions & 2 deletions soap-stub.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var g = require('./globalize');
var _ = require('lodash');

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

if (this.errOnCreateClient) {
return setTimeout(cb.bind(null, new Error('forced error on createClient')));
return setTimeout(cb.bind(null, new Error(g.f('forced error on {{createClient}}'))));
}

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

3 changes: 2 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

'use strict';

var g = require('./globalize');
var HttpClient = require('./http'),
assert = require('assert'),
xmlBuilder = require('xmlbuilder'),
@@ -261,7 +262,7 @@ class Client extends Base {
return callback(null, null, body, obj.Header);
}
if (typeof obj.Body !== 'object') {
var error = new Error('Cannot parse response');
var error = new Error(g.f('Cannot parse response'));
error.response = response;
error.body = body;
return callback(error, obj, body);
5 changes: 5 additions & 0 deletions src/globalize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var path = require('path');
var SG = require('strong-globalize');

SG.SetRootDir(path.join(__dirname, '..'), {autonomousMsgLoading: 'all'});
module.exports = SG();
10 changes: 5 additions & 5 deletions src/parser/element.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var g = require('../globalize');
var assert = require('assert');
var QName = require('./qname');
var typeRegistry = require('./typeRegistry');
@@ -79,7 +80,7 @@ class Element {
var ElementType = typeRegistry.getElementType(qname);
if (this.constructor.allowedChildren.indexOf(qname.name) === -1 &&
this.constructor.allowedChildren.indexOf('any') === -1) {
console.warn('Element %s is not allowed within %j', qname, this.nsName);
g.warn('Element %s is not allowed within %j', qname, this.nsName);
}

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

unexpected(name) {
throw new Error('Found unexpected element (' + name + ') inside ' + this.nsName);
throw new Error(g.f('Found unexpected element (%s) inside %s', name, this.nsName));
}

describe(definitions) {
@@ -191,7 +192,7 @@ class Element {
}
var schema = schemas[nsURI];
if (!schema) {
console.warn('Schema not found: %s (%s)', qname, elementType);
g.warn('Schema not found: %s (%s)', qname, elementType);
return null;
}
var found = null;
@@ -219,8 +220,7 @@ class Element {
break;
}
if (!found) {
console.warn('Schema ' + elementType + ' not found: ' + nsURI +
' ' + nsName);
g.warn('Schema %s not found: %s %s', elementType, nsURI, nsName);
return null;
}
return found;
3 changes: 2 additions & 1 deletion src/parser/qname.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var g = require('../globalize');
var assert = require('assert');
var qnameExp = /^(?:\{([^\{\}]*)\})?(?:([^\{\}]+):)?([^\{\}\:]+)$/;

@@ -22,7 +23,7 @@ class QName {
this.prefix = qname[2] || '';
this.name = qname[3] || '';
} else {
throw new Error('Invalid qname: ' + nsURI);
throw new Error(g.f('Invalid qname: %s', nsURI));
}
} else {
this.nsURI = nsURI || '';
7 changes: 4 additions & 3 deletions src/parser/wsdl.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var g = require('../globalize');
var sax = require('sax');
var HttpClient = require('./../http');
var fs = require('fs');
@@ -261,7 +262,7 @@ class WSDL {
root.addChild(types);
stack.push(schema);
} else {
throw new Error('Unexpected root element of WSDL or include');
throw new Error(g.f('Unexpected root element of {{WSDL}} or include'));
}
}
};
@@ -389,8 +390,8 @@ class WSDL {
wsdl.WSDL_CACHE = WSDL_CACHE;
wsdl.load(callback);
} else {
callback(new Error('Invalid WSDL URL: ' + uri + "\n\n\r Code: " +
response.statusCode + "\n\n\r Response Body: " + response.body));
callback(new Error(g.f('Invalid {{WSDL URL}}: %s\n\n\r Code: %s' +
"\n\n\r Response Body: %j", uri, response.statusCode, response.body)));
}
}, request_headers, request_options);
}
15 changes: 8 additions & 7 deletions src/parser/wsdl/operation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var g = require('../../globalize');
var WSDLElement = require('./wsdlElement');
var descriptor = require('../xsd/descriptor');
var ElementDescriptor = descriptor.ElementDescriptor;
@@ -72,9 +73,9 @@ class Operation extends WSDLElement {
if (part && part.element) {
headers.addElement(part.element.describe(definitions));
} else if (part && part.type) {
console.warn('WS-I violation: ' +
'http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113' +
' part ' + part.$name);
g.warn('{{WS-I}} violation: ' +
'{{http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113}}' +
' part %s', part.$name);
}
});
return headers;
@@ -88,9 +89,9 @@ class Operation extends WSDLElement {
if (part && part.element) {
faults[f] = part.element.describe(definitions);
} else {
console.warn('WS-I violation: ' +
'http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113' +
' part ' + part.$name);
g.warn('{{WS-I}} violation: ' +
'{{http://ws-i.org/profiles/basicprofile-1.2-2010-11-09.html#BP2113}}' +
' part %s', part.$name);
}
}
return faults;
@@ -185,7 +186,7 @@ class Operation extends WSDLElement {
output.elements = outputParts.elements;
break;
case Style.documentEncoded:
throw new Error('WSDL style not supported: ' + Style.documentEncoded);
throw new Error(g.f('{{WSDL}} style not supported: %s', Style.documentEncoded));
}

let faults = this.describeFaults(definitions);
5 changes: 3 additions & 2 deletions src/parser/wsdl/types.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var g = require('../../globalize');
var WSDLElement = require('./wsdlElement');
var assert = require('assert');
var Schema = require('../xsd/schema');
@@ -16,8 +17,8 @@ class Types extends WSDLElement {
if (!this.schemas.hasOwnProperty(targetNamespace)) {
this.schemas[targetNamespace] = child;
} else {
console.error('Target namespace "' + targetNamespace +
'" already in use by another Schema');
g.error('Target namespace "%s" already in use by another Schema',
targetNamespace);
}
};
}
7 changes: 4 additions & 3 deletions src/parser/xsd/keybase.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var g = require('../../globalize');
var XSDElement = require('./xsdElement');

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

postProcess(definitions) {
if (!this.selector) {
console.warn(
g.warn(
'The key element %s %s MUST contain one and only one selector element',
this.nsName, this.$name);
}
if (!this.fields.length) {
console.warn(
g.warn(
'The key element %s %s MUST contain one or more field elements',
this.nsName, this.$name);
}
9 changes: 5 additions & 4 deletions src/parser/xsd/list.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var g = require('../../globalize');
var XSDElement = require('./xsdElement');
var helper = require('../helper');
var QName = require('../qname');
@@ -21,16 +22,16 @@ class List extends XSDElement {
this.children.forEach(function(c) {
if (c instanceof SimpleType) {
if (self.$itemType) {
console.warn('Attribute itemType is not allowed if the content ' +
'contains a simpleType element');
g.warn('Attribute {{itemType}} is not allowed if the content ' +
'contains a {{simpleType}} element');
} else if (self.itemType) {
console.warn('List can only contain one simpleType element');
g.warn('List can only contain one {{simpleType}} element');
}
self.itemType = c;
}
});
if (!this.itemType) {
console.warn('List must have an item type');
g.warn('List must have an item type');
}
}
}
5 changes: 3 additions & 2 deletions src/security/ClientSSLSecurity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var g = require('../globalize');
var fs = require('fs')
, https = require('https')
, _ = require('lodash')
@@ -25,7 +26,7 @@ class ClientSSLSecurity extends Security {
} else if (typeof key === 'string') {
this.key = fs.readFileSync(key);
} else {
throw new Error('key should be a buffer or a string!');
throw new Error(g.f('{{key}} should be a {{buffer}} or a {{string}}!'));
}
}

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

5 changes: 3 additions & 2 deletions src/security/ClientSSLSecurityPFX.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var g = require('../globalize');
var fs = require('fs')
, https = require('https')
, _ = require('lodash')
@@ -27,8 +28,8 @@ class ClientSSLSecurityPFX extends Security {
} else if (typeof pfx === 'string') {
this.pfx = fs.readFileSync(pfx);
} else {
throw new Error(
'supplied pfx file should be a buffer or a file location');
throw new Error(g.f(
'supplied {{pfx}} file should be a {{buffer}} or a file location'));
}
}

3 changes: 2 additions & 1 deletion src/security/WSSecurityCert.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var g = require('../globalize');
var optional = require('optional');
var ursa = optional('ursa');
var fs = require('fs');
@@ -42,7 +43,7 @@ class WSSecurityCert extends Security {
constructor(privatePEM, publicP12PEM, password, encoding) {
super();
if (!ursa) {
throw new Error('Module ursa must be installed to use WSSecurityCert');
throw new Error(g.f('Module {{ursa}} must be installed to use {{WSSecurityCert}}'));
}
this.privateKey = ursa.createPrivateKey(privatePEM, password, encoding);
this.publicP12PEM = publicP12PEM.toString()
9 changes: 5 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

'use strict';

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

if (typeof self.authenticate === 'function') {
if (!obj.Header || !obj.Header.Security) {
throw new Error('No security header');
throw new Error(g.f('No security header'));
}
if (!self.authenticate(obj.Header.Security)) {
throw new Error('Invalid username or password');
throw new Error(g.f('Invalid username or password'));
}
}

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

if (!binding) {
throw new Error('Failed to bind to WSDL');
throw new Error(g.f('Failed to bind to {{WSDL}}'));
}

try {
@@ -227,7 +228,7 @@ class Server extends Base {
}
}

console.log(' operationName: ' + operationName + ' outputName: ' + outputName);
g.log(' {{operationName}}: %s {{outputName}}: %s', operationName, outputName);
self.emit('request', obj, operationName);
if (headers)
self.emit('headers', headers, operationName);