Question

I am trying to implement a sample XML-RPC code from here using apache.xmlrpc.

import org.apache.xmlrpc.*;
import java.net.URL;
import java.util.Hashtable;
import java.util.Vector;

public class JavaServer {    
    public Integer sum(int x, int y) {
        return new Integer(x + y);
    }

    public static void main(String[] args) {
        try {   System.out.println("Attempting to start XML-RPC Server...");
            WebServer server = new WebServer(80);
            server.addHandler("sample", new JavaServer());
            server.start();
            System.out.println("Started successfully.");
            System.out.println("Accepting requests. (Halt program to stop.)");
        } catch (Exception exception) {
            System.err.println("JavaServer: " + exception);
        }
    }
}

But on this line: server.addHandler("sample", new JavaServer()); of the above code I am getting the following error.

The method addHandler(String, Rpc Server) is undefined for the type WebServer.

I have imported a jar from the newest XML-RPC from apache apache-xmlrpc-3.1.3-bin.zip.

Does anybody have any idea why I get this error?

Was it helpful?

Solution

Seems like the method does not exist in versions 3. The problem was that many examples existing on the net today about XML-RPC use older versions. Hence, I got xmlrpc-helma-1.0.jar from this link.

Apache XML-RPC writes in its website

"If you have code using the Helma library, all you should have to do is change the import statements in your code from helma.xmlrpc.* to org.apache.xmlrpc.*. "

But it does not work. There is no helma.xmlrpc.WebServer.addHandler method in version 3. I do not know what new method replaces in newer versions. But using the older API, the error is resolved for now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top