wiki:XmlRpcPlugin

Version 61 (modified by lustin, 7 years ago) (diff)

added java alpha implementation (interface and client proxy)

Trac XML-RPC Plugin

Note about 0.11 compatibility

You can check out the tickets that users have created, there may be a solution to your problem. Especially #1075 states that it works out of the box with Eclipse-3.3 and Mylyn.

Description

This plugin allows Trac plugins to export select parts of their interface via XML-RPC.

It also includes some exported functions for manipulating tickets, with plans to include interfaces to other parts of Trac's API.

The browsable XML-RPC URI suffix is /xmlrpc, however most XML-RPC clients should use the authenticated URL suffix /login/xmlrpc as this is correctly authenticated by Trac.

Note: if you do want to use /xmlrpc and unauthenticated access, you must grant the XML_RPC permission to the 'anonymous' user.

WikiRPC API is complete, mostly thanks to mgood.

Ticket API is also complete, with the following types exported: component, version, milestone, type, status, resolution, priority and severity.

For example, for TracHacks the URIs are http://trac-hacks.org/xmlrpc and http://trac-hacks.org/login/xmlrpc (must be authenticated).

Todo

Outstanding tasks are roadmap, timeline, user management (e.g. get a (filtered) user list to assign a task in mylyn), plugin management (?)...plus probably more.

Installation

This plugin requires at least Trac 0.10. It will not work with Trac 0.9.x or earlier.

Install in the same manner as any other Trac plugin:

# python setup.py bdist_egg
# cp dist/*.egg /srv/trac/env/plugins

or if you want it to be installed for all Trac environments:

# easy_install /path/to/unpacked/xmlrpcplugin.zip/0.10

(You might want to use easy_install -Z so that it doesn't need to be unpacked when it's called.)

You will also probably need to enable the plugin in your environments trac.ini:

[components]
tracrpc.* = enabled

Bugs/Feature Requests

Existing bugs and feature requests for XmlRpcPlugin are here.

If you have any issues, create a new ticket.

Troubleshooting

Problems when AccountManagerPlugin is enabled

If you have the AccountManagerPlugin enabled and you followed their advise/example to disable the standard login module with

[components]
trac.web.auth.LoginModule = disabled

the /login/xmlrpc URL for authorized access will not work as expected. Every access will look like anonymous access.

You can use the HttpAuthPlugin to correct this.

Problems with Digest HTTP authentication

The xmlrpclib.ServerProxy client - as demonstrated in the following examples - will not work with a Digest-based HTTP authentication: you need to set up a Basic HTTP authentication on server side to make the examples work.

If you use the standalone Trac daemon, this means that you cannot use the tracd -a option (htdigest authentication file). Use trac --basic-auth (htpasswd authentication file) instead.

Problems with mod_python, Apache, python 2.4

XmlRpcPlugin might not work with Apache and python 2.4 as explained in TracInstall. Use python 2.5 if you want to run Trac with mod_python.

Download

Download the zipped source from here.

Source

You can check out the source for XmlRpcPlugin using Subversion from here or browse the source with Trac.

Example

Python End-User Usage

Obtain and print a list of XML-RPC exported functions available to my user:

import xmlrpclib

server = xmlrpclib.ServerProxy("http://athomas:password@localhost/trac-dev/login/xmlrpc")
for method in server.system.listMethods():
  print method
  print '\n'.join(['  ' + x for x in server.system.methodHelp(method).split('\n')])
  print
  print

The same example using system.multicall(). This reduces network and server load by compacting all of the system.methodHelp() calls into one HTTP POST.

import xmlrpclib

server = xmlrpclib.ServerProxy("http://athomas:password@localhost/trac/devel/login/xmlrpc")

multicall = xmlrpclib.MultiCall(server)
for method in server.system.listMethods():
    multicall.system.methodHelp(method)

for help in multicall():
    lines = help.splitlines()
    print lines[0]
    print '\n'.join(['  ' + x for x in lines[2:]])
    print

List all tickets that are owned by athomas, using the XML-RPC multicall system to issue multiple RPC calls with one HTTP request:

import xmlrpclib

server = xmlrpclib.ServerProxy("http://athomas:password@localhost/trac/devel/login/xmlrpc")

multicall = xmlrpclib.MultiCall(server)
for ticket in server.ticket.query("owner=athomas"):
    multicall.ticket.get(ticket)
print map(str, multicall())

Access the Wiki with WikiRPC

import xmlrpclib

server = xmlrpclib.ServerProxy("http://athomas:password@localhost/trac-dev/login/xmlrpc")

# print the content of WikiStart
print server.wiki.getPage("WikiStart")

# print WikiStart as HTML
print server.wiki.getPageHTML("WikiStart")

# write to the SandBox page from a text file
sandbox_content = file("sandbox.txt").read()
server.wiki.putPage("SandBox", sandbox_content, {"comment": "testing the WikiRPC interface"})

Add an attachment to WikiStart:

import xmlrpclib

server = xmlrpclib.ServerProxy("http://athomas:password@localhost:8080/trunk/login/xmlrpc")

server.wiki.putAttachment('WikiStart/t.py', xmlrpclib.Binary(open('t.py').read()))

Using from C#

See DotNet.

Using from Java

See http://trac-hacks.org/attachment/wiki/XmlRpcPlugin/trac_xml_rpc_example_java.zip?format=raw for example

API Usage

See the source for details.

Screenshot

If the HTTP request to this URI is not XML, the XmlRpcPlugin will list all exported functions that the current user has permission to use.

Change Log

[13776] by osimons on 2014-03-19 00:06:29
XmlRpcPlugin: Tweak [13728] fix again to let carriage return pass through. Closes #11050 again. Also closes #11635.
[13729] by osimons on 2014-03-07 09:55:24
XmlRpcPlugin: Tweak [13728] fix by not removing surrogate pairs. Closes #11050 again.

Thanks Jun.

[13728] by osimons on 2014-03-07 00:49:04
XmlRpcPlugin: Remove invalid XML characters from ouput. Closes #11050.

Thanks olemis.

[13710] by osimons on 2014-02-21 09:57:47
XmlRpcPlugin: Added a test for ticket.type.getAll.
[13637] by osimons on 2014-02-02 16:55:06
XmlRpcPlugin: Fixed missing mimetype when returning error for unknown faults. Closes #11321.

Thanks to mattinflection for report + patch, and to AllenB for verification.

Author/Contributors

Author: athomas
Contributors: mgood

TagIt(plugin,athomas,mgood,alpha,0.10)?

Attachments (2)

Download all attachments as: .zip