How to build a Confluence SOAP client in 5 minutes
March 28th, 2010 by Micha KopsIn this tutorial we are going to build a SOAP client for the popular Confluence Wiki in about five minutes. The client is going to receive rendered HTML Markup from a specified Confluence Page.
Contents
Prerequisites
- A running Confluence Installation with SOAP API enabled – if you don’t already have one take a look at this article or if you’ve got the Atlassian Plugin SDK installed .. start a standalone instance using atlas-run-standalone ..
- Maven – never go without it ;)
- Five minutes of your life time ..
Project Setup / Dependencies
- Create a new Maven project:
mvn archetype:generate ...
- Edit the pom.xml and add the dependencies for the axistools plugin – I’m using an older version of axis here because of some Confluence SOAP dialect in some versions ;)
<dependencies> <dependency> <groupId>org.apache.axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>javax.xml</groupId> <artifactId>jaxrpc-api</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>commons-discovery</groupId> <artifactId>commons-discovery</artifactId> <version>0.4</version> </dependency> <dependency> <groupId>javax.xml.soap</groupId> <artifactId>saaj-api</artifactId> <version>1.3</version> </dependency> <dependency> <groupId>axis</groupId> <artifactId>axis-wsdl4j</artifactId> <version>1.5.1</version> </dependency> </dependencies>
Service Stub and SOAP Client
Now that we’ve got everything we need, we’re ready to create our soap client.
- Start your Confluence instance, ensure it is running ..
- Change to the Confluence administration console, click “General Configuration” > “Feature Settings” > “Remote API (XML-RPC & SOAP)” and activate this feature
- Now you should be able to view the WSDL for Confluence – point your browser to: http://localhost:8080/rpc/soap-axis/confluenceservice-v1?wsdl (newer Confluence versions use: http://localhost:8080/rpc/soap-axis/confluenceservice-v2?wsdl)
- Create a directory named wsdl in src/main in the project directory
- Save the wsdl file in the created wsdl directory – the axistool plugin searches for wsdl files at this location
- Run the following command to create the skeleton files:
mvn axistools:wsdl2java
- Now we got all we need in target/generated-classes
- We create a new package named com.hascode.confluence.rpc
- In this package we create a new class named PageReader:
package com.hascode.confluence.rpc; import javax.xml.rpc.ServiceException; import localhost.confluence.rpc.soap_axis.confluenceservice_v2.ConfluenceSoapService; import localhost.confluence.rpc.soap_axis.confluenceservice_v2.ConfluenceSoapServiceServiceLocator; import com.atlassian.confluence.rpc.AuthenticationFailedException; import com.atlassian.confluence.rpc.RemoteException; import com.atlassian.confluence.rpc.soap.beans.RemotePage; public class PageReader { public static void main(final String[] args) throws AuthenticationFailedException, RemoteException, java.rmi.RemoteException, ServiceException { final ConfluenceSoapService service; ConfluenceSoapServiceServiceLocator serviceLocator = new ConfluenceSoapServiceServiceLocator(); service = serviceLocator.getConfluenceserviceV2(); // insert your account data here String token = service.login("theuser", "thepassword"); // we are going to fetch a page from the pre-installed Demonstration // Space RemotePage page = service.getPage(token, "ds", "Tutorial"); String renderedOutput = service.renderContent(token, "ds", page.getId(), page.getContent()); System.out.println(renderedOutput); } }
- Now run the application and enjoy the rendered HTML content of the page “Tutorial” in the “Demonstration Space” ;)
Tutorial Sources
Please feel free to download the tutorial sources from my Bitbucket repository, fork it there or clone it using Git:
git clone https://bitbucket.org/hascode/confluence-soap-client-tutorial.git
Alternatives
There’s also a very nice Maven plugin using wsimport if you dont’t like the axis stuff … in this case, take a look at the jaxws-maven-plugin – there’s also a nice blog article from the Sun guys regarding this plugin.
*update* I just wrote an article about the jaxws-maven plugin – enjoy ! :)
*update* If you want to know how to write a SOAP component plugin for Confluence – take a look at this article of mine
Resources
- Maven Axis Tools Plugin
- Maven Axis Tools Usage Docs
- Confluence SOAP Provider Migration Information
- Confluence, Maven2 & SOAP
- Sun Blog: Using JAX-WS with Maven
- JAX-WS-Maven Plugin Homepage
- hasCode.com: How to create a Confluence SOAP Component in 5 Minutes
Tags: Axis, Axis2, Confluence, jax-ws, maven, rpc, soap, web service, wiki, ws, wsdl, wsimport
March 29th, 2010 at 3:41 pm
[...] This post was mentioned on Twitter by some code. some code said: New post: How to build a Confluence SOAP client in 5 minutes http://cli.gs/AqdNv [...]
April 20th, 2010 at 8:52 am
Thanks for the great examples!
April 20th, 2010 at 9:17 am
Good information here. Saved me some time!
May 24th, 2011 at 2:49 pm
hi,
i had a few issues to get it running. first i needed axis 1.2.1 to be compatible to the latest confluence (3.5). Using your dependencies ended it several ClassCastException and stuff with the classloader from felix vs. the classloader from tomcat. i’ve got it running with this setup to generate the stubs and not having any dependency inside the pom:
org.codehaus.mojo
axistools-maven-plugin
1.2-SNAPSHOT
axis
axis
1.2.1
axis
axis-jaxrpc
1.2.1-noqname
generate-sources
generate-sources
wsdl2java
de.netrapid
de.netrapid
false
regards
May 24th, 2011 at 3:48 pm
Hi,
thanks for your input though I was not able to reproduce your problem running the tutorial against my Confluence developer instance (3.5#1910).
January 3rd, 2013 at 8:56 pm
Hello Micha,
I’m using the Confluence SOAP/RPC method renderContent from a remote website and am successfully displaying the returned markup. My quandary is that the page stylesheets returned seem incomplete and as such, my content doesn’t render exactly as it renders from within Confluence. Our goal is to “deliver” the content from within our extranet so it would act as a proxy between the user and the content. (Our extranet governs a complex security structure based on products the customer has purchased so they only can access content for those products) We are transitioning our user documentation to Confluence and want to display it from within our extranet. How can I get the page to render more precisely to match how it renders in Confluence?
Any help would be greatly appreciated.
Cheers,
Rhys
January 4th, 2013 at 9:50 pm
Hm sorry .. my only idea atm is to create a custom SOAP endpoint that decorates the existing one and adds the stylesheets that you’re missing. The documentation for creating custom SOAP endpoints as a Confluence plugin can be found here or – as I’ve just remembered – I have also written a short tutorial “How to create a Confluence SOAP component in 5 minutes” :)
April 23rd, 2013 at 8:04 pm
Hi micha kops,
I’m working on creating a confluence client right now and I’m having trouble getting the import statements in the .java file to work. When I used the mvn axistools:wsdl2java command, instead of getting target/generated-classes I got target/generated-sources. I don’t really know why, but my .java file says stuff like “the import com.atlassian” cannot be resolved” etc.
Do you have any idea of what might be the cause?
Thank you in advance!
April 24th, 2013 at 6:55 pm
Hi Stephanie,
I’ve updated my article and I’ve put the tutorial sources on my bitbucket account – please feel free to reuse them for your project or your own custom SOAP client.
Cheers
Micha
May 8th, 2013 at 5:53 pm
Hi Micha – the tutorial helped me a lot. Thanks! :)
May 8th, 2013 at 6:13 pm
You’re welcome! I’m glad I could help :)