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*
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); } }
Client-side Proxy for Java
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); } }
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};
}
}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
Version 6.6 last modified by hritcu on 24/02/2008 at 19:18
Document data
Attachments:
No attachments for this document
Comments: 0