A Client For the XML-RPC Servlet
// will let you call the servlet in the snippet "An XML-RPC
// Servlet". Of course, since XML-RPC is pretty ubiquitous
// you can also use this code to call servers in dozens of
// other languages as well.
1 2 import java.util.Vector; 3 4 import org.apache.commons.logging.Log; 5 import org.apache.commons.logging.LogFactory; 6 import org.apache.xmlrpc.XmlRpcClient; 7 8 public class XMLRPCTestClient { 9 private static final String serverAddress = 10 "http://localhost:8080/lol/remoteapi"; 11 private static Log log = LogFactory.getLog(XMLRPCTestClient.class); 12 13 /** Creates a new instance of XMLRPCTestClient */ 14 public XMLRPCTestClient(String address) { 15 try { 16 XmlRpcClient xmlrpc = new XmlRpcClient(address); 17 18 Vector params = new Vector(); 19 params.addElement("Hello World! Hello!"); 20 21 try { 22 // this method returns a string 23 String result = (String) xmlrpc.execute("echo.echo", params); 24 System.out.println(result); 25 } catch (Exception e) { 26 log.error("The remote procedure call failed.", e); 27 } 28 } catch (java.net.MalformedURLException mue) { 29 log.error( 30 "The address given for the XML-RPC interface is bad: " + address); 31 } 32 } 33 34 /** 35 * @param args the command line arguments 36 */ 37 public static void main(String[] args) { 38 XMLRPCTestClient xmlRPCTestClient = new XMLRPCTestClient( 39 serverAddress); 40 } 41 }