How to Call a REST Service with Apache XML-RPC

import static java.lang.System.out;

import java.util.HashMap;
import java.util.Map;

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

@SuppressWarnings({"rawtypes", "unchecked"})
public final class ApacheXmlRpcSample {

  public static void main(final String[] args) throws Exception {
    final XmlRpcClient client = new XmlRpcClient();

    final XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();

    config.setServerURL(new URL("http://localhost/sample"));


    final Map paramMap = new HashMap();

    if (args[0] != null)
      paramMap.put("param1", args[0]);

    final Map result = (Map) client.execute("sample", new Object[] { paramMap });

    for (final Object key : result.keySet())
      out.println(key + " = " + result.get(key));



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s