archiva-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James William Dumay <ja...@atlassian.com>
Subject Re: MRM-124 - XML RPC Web Services
Date Thu, 04 Sep 2008 05:02:24 GMT
Oh I also forgot - the API docs for the Binder project are available
from this page:

http://docs.atlassian.com/atlassian-xmlrpc-binder/0.7/apidocs/

Cheers
James

On Thu, 2008-09-04 at 14:55 +1000, James William Dumay wrote:
> Hey guys,
> I created a branch for MRM-124 - support for web services using XML-RPC
> - which I am proposing to merge into trunk.
> 
> https://svn.apache.org/repos/asf/archiva/branches/MRM-124
> 
> It introduces two new modules - Archiva XML-RPC API and Archiva XML-RPC
> Services. These two modules use the library I wrote at Atlassian
> imaginatively called "Atlassian XML-RPC Binder" which is a companion
> library to the Apache XML-RPC client and servlet which makes XML-RPC
> using Java easy and type safe. It is licensed under the Apache 2
> license.
> 
> So, let me explain how it works :)
> 
> Here is a example application that uses the "test" XML-RPC service
> included on the branch.
> 
> package com.mycompany.testservicething;
> 
> import com.atlassian.xmlrpc.Binder;
> import com.atlassian.xmlrpc.DefaultBinder;
> import java.net.URL;
> import org.apache.maven.archiva.web.xmlrpc.api.TestService;
> 
> public class App
> {
>     public static void main( String[] args ) throws Exception
>     {
>         URL url = new URL("http://localhost:8080/archiva/xmlrpc");
> 
>         Binder binder = new DefaultBinder();
> 
>         TestService service = binder.bind(TestService.class, url);
>         System.out.println(service.ping()); //will output "pong"
>     }
> }
> 
> When bind() is called, we pass an interface class type that represents
> the remote service and the URL of the xmlrpc servlet and it then returns
> a dynamic proxy object of that interface.
> 
> The object returned is a type safe instance of the remote service - so
> when ping() is called we are actually calling ping on the xmlrpc
> service.
> 
> The interface looks a like this:
> 
> import com.atlassian.xmlrpc.ServiceObject;
> 
> @ServiceObject("Test")
> public interface TestService
> {
>     public String ping();
> }
> 
> The ServiceObject annotation denotes that this is a xmlrpc service with
> the object name of "test".
> 
> The server side object looks like this:
> 
> import org.apache.maven.archiva.web.xmlrpc.api.TestService;
> 
> public class PingServiceImpl implements TestService
> {
>     public String ping()
>     {
>         return "pong";
>     }
> }
> 
> As you can see, the interface for accessing the service and implementing
> the server side service are the same (yay for interfaces).
> 
> The best part about this is that anyone using the XML-RPC service to
> talk to Archiva using java will be type safe the entire time they are
> using it. 
> 
> Services are easily registered with the servlet by appending bean
> references to the applicationContext.xml "xmlrpcServicesList" list bean
> - when the servlet initialises it looks for this list in the spring
> ApplicationContext and allows clients to start accessing the services
> defined. There is no need for a servlet subclass.
> 
> If you wondering how to return POJO's (or lists of them) take a look at
> the following test case:
> https://svn.atlassian.com/svn/public/atlassian/xmlrpcbinder/trunk/binder/src/test/java/com/atlassian/xmlrpc/BeanServiceTest.java
> 
> 
> Anyway, would love to hear your thoughts, questions and complaints :)
> 
> Cheers
> James
> 


Mime
View raw message