You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by Vrihad Shoonya <vr...@gmail.com> on 2007/01/25 12:59:33 UTC

Sample code needed for XMLRPC 3.0

Dear pals,

Please provide the URL containing the tutorial for using XMLRPC 3.0. I have
searched the Net and found none for the version 3.0 so far. I have tried to
build a sample server and client but it throws XmlRpcException saying that
no handler exists. Following is the server code:

<code>
import org.apache.xmlrpc.webserver.WebServer;
import org.apache.xmlrpc.server.*;
import java.util.*;

public class Trade {
    Tread t;

    private final int port = 8200;
    private final String propertyFile = "server.properties";


    public static void main(String args[]) throws ClassNotFoundException {
        //System.out.println("testing ");
        try {
            Trade t = new Trade();
        } catch (java.io.IOException e) {
            System.out.println("Caught IOException\n");
            e.printStackTrace();
        } catch (org.apache.xmlrpc.XmlRpcException e) {
            System.out.println("Caught IOException\n");
            e.printStackTrace();
        }
    }

    public Trade() throws java.io.IOException,
org.apache.xmlrpc.XmlRpcException, ClassNotFoundException {
        PropertyHandlerMapping mapping = new PropertyHandlerMapping();
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        mapping.load(cl, propertyFile);
        mapping.addHandler("calculate", Class.forName("Trade"));
        WebServer ws = new WebServer(port);
        XmlRpcServerConfigImpl config = new XmlRpcServerConfigImpl();
        XmlRpcServer server = ws.getXmlRpcServer();
        server.setConfig(config);
        server.setHandlerMapping(mapping);
        ws.start();
    }

    public String calculate(String n1, String n2){
        int ans = Integer.parseInt(n1)+Integer.parseInt(n2);
        return String.valueOf(ans);
    }
}
</code>

Empty file server.properties exists in the classpath.

Following is the client code:

<code>
import org.apache.xmlrpc.client.*;
import org.apache.commons.httpclient.*;
import org.apache.xmlrpc.XmlRpcException;
import java.util.*;
import java.net.*;

//import org.apache.xmlrpc.webserver.WebServer;

public class TradeClient {

    public static void main(String args[]) {
            TradeClient t = new TradeClient();
    }

    public TradeClient() {
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        try {
            config.setServerURL(new URL("http://127.0.0.1:8200/"));
        } catch (java.net.MalformedURLException e) {
            System.out.println("Caught MalformedURLException\n");
            e.printStackTrace();
        }
        try {
            XmlRpcClient client = new XmlRpcClient();
            client.setTransportFactory(new
XmlRpcCommonsTransportFactory(client));
            client.setConfig(config);
            Object[] params = new Object[]{new Integer(33), new Integer(9)};
            Integer result = (Integer) client.execute("calculate", params);
        } catch (XmlRpcException e) {
            System.out.println("Caught XmlRpcException\n");
            e.printStackTrace();
        }
    }
}
</code>

If tutorial is not available for version 3.0 of XMLRPC, then post your
own sample
code for working client and server parts which can be studied by others.

Thanks in advance.

VS

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org