The JavaScript API

The JavaScript API provides a programmatic interface to MainView Middleware Administrator using the JavaScript programming language. Using the JavaScript API, a programmer can write JavaScript scripts to programmatically interact with a MainView Middleware Administrator server. The JavaScript API provides a scripting capability, allowing a programmer to create, read, modify and delete IBM WebSphere MQ objects (queues, channels, etc.), TIBCO EMS objects (queues, topics, durables, etc.) and MainView Middleware Administrator administrative objects (including projects, users, groups, connections, etc.).

Conventions

There are a number of conventions used to make using and remembering the JavaScript API easier.

  • All create, read, modify, and delete operations are prefixed with "create", "get", "modify", and "delete" respectively.
  • All operations contain the name of the type of object on which they operate. For instance, the method for getting a queue's attributes includes the word "Queue" in it.
  • All read operations that return the attributes for an object have the suffix "Attrs" while getting only the names of objects has no suffix.

For example, the set of operations on WebSphere MQ local queues are:

  • getLocalQueues() – return the names of the local queues for the specified connection
  • getLocalQueuesAttrs() – return all attributes for all local queues for the specified connection
  • createLocalQueue() – create a local queue
  • modifyLocalQueue() – modify a local queue
  • deleteLocalQueue() – delete a local queue

Note that there are some exceptions to this rule. For instance, starting and stopping a channel is "startChannel" and "stopChannel" respectively, they do not use the create, read, modify, get convention.

Running a JavaScript script

The JavaScript API distribution is available in the "api" directory under the installation directory and is named "javascript-api-[VERSION]-dist.[tar.gz | zip]. The JavaScript API distribution contains a shell script in the "bin" directory called runadmin.sh for use on Linux and runadmin.bat for use on Windows. To run a script, execute the runadmin script and provide the name of your JavaScript source file as the first argument.

Example:

$ bin/runadmin.sh Test.js

You can run the runadmin script from anywhere; you are not required to work in the scripting directory directly, and are discouraged from doing so in order to make it easy to update the scripting API in the future without having to move all of your scripts.

Getting an Administrative Object

Before you can call the programmatic methods for administering objects via the JavaScript API, you must invoke one of the Admin constructors for the various namespaces within MainView Middleware Administrator. There is one such constructor for each of "admin", "wmq", and "ems" and these constructors are "required" into your script module using the RequireJS "require" method.

"require" takes an array of required modules and a callback function that will be invoked when the required modules are all available. For instance, if you needed all three Admin constructors, you could use "require" like this:

require([
"bmm/admin/Admin",
"bmm/wmq/Admin",
"bmm/ems/Admin"
], function(BMMAdmin, WMQAdmin, EMSAdmin) { 
var baseUrl = "https://localhost:8443/bmmadmin"; 
var bmmAdmin = new BMMAdmin(baseUrl);
var wmqAdmin = new WMQAdmin(baseUrl, "MYQM");
var emsAdmin = new EMSAdmin(baseUrl, "MYSERVER"); 
bmmAdmin.login("admin", "admin");
bmmAdmin.logout();
bmmAdmin.close(); 
}

In the callback function for require, you can use whatever names you like, but it is recommended you use Admin if you only need one of the various Admin constructors and use a namespace prefixed Admin if you need more than one, as shown in the example above.

Environment

MainView Middleware Administrator JavaScript scripts are RequireJS modules ("http://requirejs.org") that run inside a Mozilla Rhino JavaScript runtime ("https://developer.mozilla.org/en-US/docs/Rhino"), which runs atop the Java runtime. So the act of writing a MainView Middleware Administrator JavaScript script is writing a requirejs module that "requires" its dependencies and then implements, within the requirejs module, the logic of the script.

Here is a boilerplate wrapper that can be used as a starting point for your scripts:

require([
"dojo/_base/json",
"dojo/_base/array",
"dojo/_base/lang",
"bmm/admin/Admin"
], function(json, array, lang, Admin) {
var i, args = []; 
for (i = 1; i < require.rawConfig.commandLineArgs.length; ++i) {
args.push(require.rawConfig.commandLineArgs[i]);
} 
var hostName = args[2] || "localhost";
var port = args[3] || 8443;
var baseUrl = "https://" + hostName + ":" + port + "/bmmadmin"; 
console.log("Connecting to BMM Admin server: " + baseUrl); 
var admin = new Admin(baseUrl);
admin.login("admin", "admin"); 
try { 
//
// YOUR CODE GOES HERE
//
} catch(e) {
if (e.rc && e.msg) {
console.error(e.msg + ", rc: " + e.rc);
} else {
console.error(e);
}
} 
admin.logout();
admin.close();
});

Note that the wrapper requires: "bmm/admin/Admin"

And in the function implementation for the module, it declares that module name as: Admin
And uses it like this:
var admin = new Admin(baseUrl);
admin.login("admin", "admin");

Was this page helpful? Yes No Submitting... Thank you

Comments