With Groovy and the XML-RPC library (groovy.codehaus.org/XMLRPC) the access to Trac gets extremely easy. The older version 0.4 and 0.5 of the library could not handle basic authorization but thanks to Tim fixing the missing feature and some other xml format error, you can now access any Trac Wikipage with as little as 3 lines of Groovy code.
def serverProxy
= new XMLRPCServerProxy
("https://user:password@sometracserver.com/login/xmlrpc") // or
// def serverProxy = new XMLRPCServerProxy("http://sometracserver.com/login/xmlrpc")
serverProxy.setBasicAuth("user","password")
println serverProxy.
wiki.
getPage("TracBackup")
Remark:
At the time of this entry version 0.6 is not released yet. Check for availability at repository.codehaus.org/org/codehaus/groovy/groovy-xmlrpc/ for the new version or update your svn copy and build by yourself (see blog entry)
Update 2010-02-01: The new version was released as 0.5.1 (link)
The Groovy XML-RPC library 0.5 allows me to do perform basic authorization, but my Trac Server now throws a error code 500 at me (stating XML declaration not well-formed). Since I dont know how to check the XML request the library posts, I choose to dissect the messages at the network level using Wireshark. Luckily I have a Python library that works fine, so I can compare the working version of the XML-RPC request. (Remark: Dont forget to start wireshark as root user/sudo)
2010-01-07 09:03:03,095 Trac[main] DEBUG: Dispatching <Request "POST u'/login/xmlrpc'">
2010-01-07 09:03:03,117 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
File "/usr/local/Python-2.5.2/lib/python2.5/site-packages/trac/web/main.py", line 441, in _dispatch_request
dispatcher.dispatch(req)
File "/usr/local/Python-2.5.2/lib/python2.5/site-packages/trac/web/main.py", line 205, in dispatch
resp = chosen_handler.process_request(req)
File "/usr/local/Python-2.5.2/lib/python2.5/site-packages/TracXMLRPC-1.0.6-py2.5.egg/tracrpc/web_ui.py", line 163, in process_request
self.process_xml_request(req, content_type)
File "/usr/local/Python-2.5.2/lib/python2.5/site-packages/TracXMLRPC-1.0.6-py2.5.egg/tracrpc/web_ui.py", line 167, in process_xml_request
args, method = xmlrpclib.loads(req.read(int(req.get_header('Content-Length'))))
File "/usr/local/Python-2.5.2/lib/python2.5/xmlrpclib.py", line 1130, in loads
p.feed(data)
File "/usr/local/Python-2.5.2/lib/python2.5/xmlrpclib.py", line 547, in feed
self._parser.Parse(data, 0)
ExpatError: XML declaration not well-formed: line 1, column 30
2010-01-07 09:03:03,121 Trac[chrome] DEBUG: Prepare chrome data for request
Python Library/Call
import xmlrpclib
server = xmlrpclib.ServerProxy("http://user:password@sometracserver.com/login/xmlrpc")
print server.wiki.getPage("WikiStart")
Result in Wireshark

Wireshark
Groovy Call
def serverProxy
= new XMLRPCServerProxy
("http://sometracserver.com/project/login/xmlrpc") serverProxy.setBasicAuth("user","password")
serverProxy.wiki.getPage("WikiStart")
Result in Wireshark

Wireshark
There is the problem: encoding=”+ENCODING+”
The Trac XML reader most likely will throw up the complete call because of this. Actually the comparison was not really required because the error is very obvious.
Comments Off