Search:
Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

Redstone - Simple and Compact Java XML-RPC library

March 7th, 2007 by Jon Moffet

Yesterday I had to look for a simple Java XML-RPC library in a simple proof of concept application.

Plainly speaking, I'm going to demonstrate XML-RPC concept to a bunch of friends who is unfamiliar with programming languages other than Java (but they are not 1337 programmers either!)

I'm looking for a simple library which isn't bloated with functionality and easy to use. After much surfing, I found Redstone XML-RPC Library.

Overall the library only size up to 44KB when zipped together and it can be use to either construct XML-RPC service or clients.

Compared to Apache XML-RPC, Redstone XML-RPC is much better suited for my use as a tool to introduce XML-RPC concept to a group of friend that never used it before.

To use it, you need to download XML-RPC library from Redstone project webpage first. Then mae appropriate adjustment to your CLASSPATH to include the Redstone library.

For this example, I use the XML-RPC API service which can be found at Foxrate.org: Currency Exchange website.

Here's the sample code that I use to demostrate XML-RPC to my friends :

JAVA:
  1. import redstone.xmlrpc.*;
  2. public class GetCurrency {
  3.     public static void main( String[] args ) throws Exception
  4.     {
  5.         new GetCurrency();
  6.     }
  7.  
  8.     public GetCurrency() throws Exception {
  9.             //declare RPC object
  10.             XmlRpcClient client = new XmlRpcClient("http://foxrate.org/rpc/",true );
  11.  
  12.                 //
  13.             // invoke RPC call (3 parameter, rujuk atas)
  14.             //
  15.             // please check http://foxrate.org/ for list of currencies
  16.             //
  17.             Object token = client.invoke( "foxrate.currencyConvert", new Object[] { new String("USD"),
  18.                     new String("MYR"), new Double(50.0) } );
  19.             XmlRpcStruct struct = (XmlRpcStruct)token;
  20.  
  21.  
  22.  
  23.             //output
  24.             System.out.println(new Double(struct.getDouble("amount")).toString());
  25.  
  26.  
  27.  
  28.  
  29.     }
  30.  
  31. }

The simple code will perform conversion of USD 50 to MYR (Malaysian Ringgit) through the use of XML-RPC api.

You can download the Foxrate XML-RPC sample code here.

Note that Redstone XML-RPC library and the sample code requires Java 5 (Java 1.5.x) to compile and run.

Tags: , , , , ,

Bookmark Post:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • NewsVine
  • Reddit
  • Netvouz
  • Spurl
  • Furl
  • digg
  • YahooMyWeb
  • del.icio.us

Posted in Uncategorized |

Related Posts

2 Responses

  1. xml-rpc, java, and eclipse | SpeakingX Says:

    Kramer auto Pingback[...] The Java code example here is based on http://phpcode.mypapit.net/redstone-simple-and-compact-java-xml-rpc-library/9/ [...]

  2. DeanteebesDef Says:

    steessobturse
    Bwog
    broadabrixkiz
    af5g

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.