jabsorb
Java to JavaScript Object Request Broker

Differences between revisions 1 and 2

Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:

== "I can't get jabsorb to run on my webserver" ==

Make sure you have all the libraries on the classpath. Remember that jabsorb uses the slf4j logging libraries and that these need to included too.

Tips

Various tips and hints to help you use jabsorb are described here. Thanks to the users of jabsorb who came up with these!

"I can't get jabsorb to run on my webserver"

Make sure you have all the libraries on the classpath. Remember that jabsorb uses the slf4j logging libraries and that these need to included too.

Debugging

When debugging some memory leaks in ie6 it may be helpful to set the http_max_spare parameter to zero. This linearize the calls and look at one xmlrpc object at a time. Here's the line to change in the client (jsonrpc.js) to do this:

JSONRpcClient.http_max_spare = 0;  // changing the pool size to 0.

Handling Session Timeouts

This has been noted as a problem. One solution is to use the following exception handler:

JSONRpcClient.toplevel_ex_handler = function (ex) {
    if(ex instanceof JSONRpcClient.Exception)
    {
        // assuming this is because of a session timeout.  navigate to current location,
        // and the auth filter should let them log in and get back to whatever page we're on.
        if(ex.code == 550) //550 happens when the session has timed out
        {
            setTimeout(function () {navigate(document.location)}, 300);
            return;
        }
    }
    if(ex)
        throw ex.message.substring(ex.name.length + 2); //ideally this would throw a complex exception object
    else
        throw "Error making rpc request to server";
};

Preventing multiple client instances

You may find that you need an instance of the jabsorb client in many unrelated parts of a page. You probably don't want to have to instantiate separate JSONRpcClient objects and make a separate getMethods call back to the server for each template so use the js singleton pattern:

var RpcClient = function()
{
    var instance = null;

    return function()
    {
        if(instance == null)
            instance = new JSONRpcClient(CONTEXT_PATH + "/RPC", null, null, null);

        return instance;
    };
}(); //<---- The outer function gets evaluated here, so all new's refer to the same var instance.

Now we can just make new RpcClients where ever we like and they will always return the same instance:

var a = new RpcClient();
var b = new RpcClient();

if(a !== b) throw "Oh noes! Not same instance"

This code will run without a problem. Also, this has the nice side benefit of encapsulating our remote RPC URL inside the RpcClient constructor so it can be changed easily in one location.

Cleaning up

You can "free" the JSONRpcClient when the interface is destroyed.

    // 4) Clean up the JSONRpcClient
    if (typeof JSONRpcClient != 'undefined') {
      for (var i=0;i<JSONRpcClient.http_active.length;i++) {
        var http = JSONRpcClient.http_active[i];
        http.onreadystatechange = null_function;
        http.abort();
        delete JSONRpcClient.http_active[i];
      }
      for (var i=0;i<JSONRpcClient.http_spare.length;i++) {
        var http = JSONRpcClient.http_spare[i];
        http.onreadystatechange = null_function;
        http.abort();
        delete JSONRpcClient.http_spare[i];
      }

      for (var props in JSONRpcClient) {
        var p = JSONRpcClient[props];
        if (p == null) continue;
        if (p.constructor == Array) {
          p.length = 0;
        } else if (p.constructor == Object) {
          for (var props2 in p) {
            delete p[props2];
          }
        }
        delete JSONRpcClient[props];
      }
    }