The ServiceRegistry is responsible for managing Service definitions and their instances.
Typical usage involves several steps:
The service is defined in the Business Manager and configured with necessary credentials.
The service callback is configured once during cartridge initialization:
1ServiceRegistry.configure("MyFTPService", { mockExec : function(svc:FTPService, params) { return [ { "name": "file1", "timestamp": new Date(2011, 02, 21)}, { "name": "file2", "timestamp": new Date(2012, 02, 21)}, { "name": "file3", "timestamp": new Date(2013, 02, 21)} ]; }, createRequest: function(svc:FTPService, params) { svc.setOperation("list", "/"); }, parseResponse : function(svc:FTPService, listOutput) { var x : Array = []; var resp : Array = listOutput; for(var i = 0; i <resp.length; i++) { var f = resp[i]; x.push( { "name": f['name'], "timestamp": f['timestamp'] } ); } return x; }});
A new service instance is created and called in order to perform the operation:
1var result : Result = ServiceRegistry.get("MyFTPService").call();if(result.status == 'OK') { // The result.object is the object returned by the 'after' callback.} else { // Handle the error. See result.error for more information.}
See ServiceCallback for all the callback options, and individual ServiceDefinition
classes for customization specific to a service type.