2010-07-20

Making zOGI XML-RPC API calls from Jython

Using zOGI from CPython is simple - you just use the "xmlrpc" module.  However, that module relies on native [unmanaged] code so it doesn't work in Jython.  In order to make XML-RPC calls from Jython you need to use a Java XML-RPC assembly: for example, the Apache XML-RPC assembly (previously known as "Helma") from the Apache foundation.  Here is an example of making zOGI XML-RPC API calls from Jython:

import org.apache.xmlrpc.client as xmlrpc
from java.util import Vector
from java.util import Hashtable
import java.net

client = xmlrpc.XmlRpcClient()
config = xmlrpc.XmlRpcClientConfigImpl()
config.setServerURL(java.net.URL('http://***********/zidestore/so/***********/'))
config.basicUserName = '***********'
config.basicPassword = '***********'
client.setConfig(config)

qualifier = Hashtable()
qualifier['key'] = 'firstname'
qualifier['conjunction'] = 'AND'
qualifier['expression'] = 'LIKE'
qualifier['value'] = 'A%'
criteria = Vector()
criteria.add(qualifier)

params = Vector()
params.add('Contact')
params.add(criteria)
params.add(65535)

results = client.execute("zogi.searchForObjects", params)
for result in results:
    print 'ObjectId:%s %s, %s' % (
        result['objectId'], 
        result['lastName'],
        result['firstName'])

No comments:

Post a Comment