Using RMI from a Jython Script

The Remote Method Invocation (RMI) Interface of TPAE allows to connect from an external program to TPAE. Using RMI business objects can be red, written and updated by the control of a Jython script. To use RMI Scripting a current version of Jython has to be installed on the system where the script should be executed.

The script then connects to the RMI Port of TPAE which is by default Port 1099 (Maximo up to Version 6) or 13400 (Maximo 7 and higher). This port can be changed using the mxe.registry.port property. The following picture shows the concept:

RMI Base concept

Based on this knowledge we can develope our first RMI Script, which only connects to the MX Server and after that disconnects:

import psdi.util.MXSession as MXSession

session = MXSession.getSession()
session.setHost('192.168.158.135:13400/MXServer')
session.setUserName('maxadmin')
session.setPassword('maxadmin')
session.connect()

# ... Do your stuff here ...

session.disconnect()

One word to the Path “MXServer” in the setHost() function call. This has to be the name, which is provided in the Maximo Properties in the parameter mxe.name. This means, that you can have several RMI listeners for multiple Maximo installations on the same host (e.g. mx.name = MXTest, mx.name = MXProd).

In a second step the script can be extended to correctly handle error situations. To achive this you can utilize the Jython error handling functionality:

try:
# perform some task that may raise an exception

except Exception, value:
# perform some exception handling

finally:
# perform tasks that must always be completed (Will be performed before the exception is # raised.)

The new connection section of the script now looks as follows:

import psdi.util.MXSession as MXSession
from psdi.util import MXException

try:
    session = MXSession.getSession()
    session.setHost('192.168.158.135:13400/MXServer')
    session.setUserName('maxadmin')
    session.setPassword('maxadmin')
    session.connect()

except MXException, conex:
    print 'conex.getErrorGroup()     :',conex.getErrorGroup()
    print 'conex.getErrorKey()       :',conex.getErrorKey()
    print 'conex.getDetail()         :',conex.getDetail()
    print 'conex.getDisplayMessage() :',conex.getDisplayMessage()
    exit

# ... Do your stuff here ...

Leave a Reply

Your email address will not be published. Required fields are marked *