XML-RPC API

XWiki instances can be accessed remotely using the XML-RPC protocol.

Features

XWiki implements the most important part of the Confluence XML-RPC API.

  • Authenticated and anonymous access
  • Spaces: retrieval, creation and removal
  • Pages: retrieval, rendering, creation, history, update, search and removal
  • Attachments: retrieval(download), creation(upload)*, moving/renaming*, removal*
  • Comments: retrieval, creation* and removal*
* Available only in XWiki 1.2 or later

The list of functions from the Confluence API not yet supported by XWiki is given in the description of XWIKI-1559.

For more information about the Confluence XML-RPC API check out this documentation. In the future we plan to extend this API with XWiki-specific features - any extensions will be documented here.

XML-RPC Clients

There are XML-RPC libraries for most programming languages. For Java the most well-known one is Apache XML-RPC, which is also used in the implementation of XWiki (i.e. server-side). Here is an example which uses Apache XML-RPC directly in order to get the rendered content of a wiki page (for a much easier way to achieve the same result see the "Client-side Proxy for Java" section below).

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;


public class RawXmlRpc
{
    public static void main(String[] args)
        throws MalformedURLException, XmlRpcException
    {
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        URL url = new URL("http://127.0.0.1:8080/xwiki/xmlrpc");
        config.setServerURL(url);
        XmlRpcClient client = new XmlRpcClient();
        client.setConfig(config);
        
        String token = (String)client.execute("confluence1.login",
            new Object[] {"Admin", "admin"});
        
        Map page = (Map)client.execute("confluence1.getPage",
            new Object[] {token, "Main", "WebHome"});
        String pageId = (String)page.get("id");
        String content = (String)page.get("content");
        
        String renderedContent = (String)client.execute(
            "confluence1.renderContent",
            new Object[] {token, "Main", pageId, content});
        System.out.print(renderedContent);
        
    }
}

In order for this to work you need to have commons-logging-1.1.1.jar, ws-commons-util-1.0.1.jar, xmlrpc-common-3.0.jar, and xmlrpc-client-3.0.jar in your classpath (version numbers are irrelevant).

Client-side Proxy for Java

Warning: This section describes an unstable feature. It is still unclear whether the recommended way of using XWiki XML-RPC is through the proxy described in this section, or through Swizzle Confluence.

You can build Java applications that use XWiki through the XML-RPC interface easier by using the client-side proxy that is part of XWiki. This proxy is based on Swizzle Confluence and eliminates most of the plumbing needed to use XML-RPC directly. For instance the example above is much simpler when rewritten to use the proxy.

import com.xpn.xwiki.xmlrpc.client.SwizzleXWikiClient;
import com.xpn.xwiki.xmlrpc.client.XWikiClient;
import com.xpn.xwiki.xmlrpc.client.XWikiClientException;
import com.xpn.xwiki.xmlrpc.model.Page;


public class ProxyXmlRpc
{
    public static void main(String[] args) throws XWikiClientException
    {
        String url = "http://127.0.0.1:8080/xwiki/xmlrpc";
        XWikiClient rpc  = new SwizzleXWikiClient(url);
        Page page = rpc.getPage("Main", "WebHome");
        String rendered = rpc.renderContent(
            page.getSpace(), page.getId(), page.getContent());
        System.out.print(rendered);
    }
}

In order for this to work you need to have commons-logging-1.1.1.jar, ws-commons-util-1.0.1.jar, xmlrpc-common-3.0.jar, xmlrpc-client-3.0.jar, xwiki-core-1.3-SNAPSHOT.jar, and swizzle-confluence-1.1-20070908-xwiki.jar in your classpath (version numbers are for the most part irrelevant).

Warning: Starting with XWiki 1.2 the Apache XML-RPC dynamic proxies are no longer supported.

Examples

Simple Perl sample using XML::RPC:

#!/usr/bin/perl
use XML::RPC;
use strict;

my ($result, $token);
my $xmlrpc = XML::RPC->new('http://www.xwiki.org/xwiki/xmlrpc/confluence');
$token = $xmlrpc->call( 'confluence1.login', 
            ( 'username', 'password' ) );
$result = $xmlrpc->call( 'confluence1.getPages', 
            ( $token, 'UserGuide' ) );
foreach my $elem (@{$result}) {
    foreach my $key (keys( %{$elem})) {
        printf "%s->%s\n", $key, $elem->{$key};
    }
}

Simple Groovy sample:

import groovy.net.xmlrpc.*

def proxy = new XMLRPCServerProxy("http://www.xwiki.org/xwiki/xmlrpc/confluence") 
def token = proxy.confluence1.login("username","password")
def pages = proxy.confluence1.getPages(token, "UserGuide")
print pages
See also Stéphane's code in MediaWiki2XWiki
Version 6.6 last modified by hritcu on 24/02/2008 at 19:18

Comments 0

No comments for this document

Attachments 0

No attachments for this document

Creator: vmassol on 2006/12/12 23:25
This wiki is licensed under a Creative Commons license
1.4.1.10194