Java: abstract RPC client

For interest sake only:

I wrote a small base client class to instantiate the RPC Server stub. The name of the required stub is passed as a parameter to the constructor. There is an accessor which returns the stub instance (as an RPCService).

In the client code, the call is done as follows:

public void callNatural() throws Exception {
// Call Natural subprogram TEST010N
try {
((StubName)this.getRpcServer()).test010n(_sin);
} catch (Exception e) {
_log.error(e.getMessage()); // log RPC errors
throw e; // pass exceptions on
}
// Check for application errors
_serr = ((StubName)this.getRpcServer()).getTest010nStd_error();
if (_serr.return_code != 0) {
throw new ExAppException(_serr.return_msg);
}
// Get the ouput fields
_sout = ((StubName)this.getRpcServer()).getTest010nServer_out();
}

Note how the RPCService is cast back to the Stub, to enable it’s methods.

We have a standard parameter naming convention (01 level fields in Natural; inner classes in Java)): Server_in for fields passed to the server; Server_out for fields returned by the server and Std_error which contains a return-code and message. Positive codes mean transport or environment problems, negative codes mean application errors.

If anyone is interested, I can post the actual code, and/or discuss further.

Nothing is foolproof to a sufficiently talented fool…