Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problems with XML-RPC

843790Jan 26 2007 — edited Jan 26 2007
Hi everybody.
Sorry, I've got a french accent, then if you don't understand, dont' be worry ^^

I try using the apache's xmpl-rpc package, and I have got some problems with the xml-rpc client.

Here my source :

public interface ICalculator {
public int add(int i1, int i2);
public int subtract(int i1, int i2);
}

###########################################################

public class Calculator implements ICalculator {
public int add(int i1, int i2) {
return i1 + i2;
}
public int subtract(int i1, int i2) {
return i1 - i2;
}
}

###########################################################

import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;

public class Server {
private static final int port = 8080;

public static void main(String[] args) throws Exception {
WebServer webServer = new WebServer(port);

XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();

PropertyHandlerMapping phm = new PropertyHandlerMapping();
phm.addHandler(Calculator.class.getName(), Calculator.class);
phm.addHandler(ICalculator.class.getName(), ICalculator.class);

xmlRpcServer.setHandlerMapping(phm);

XmlRpcServerConfigImpl serverConfig =
(XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
serverConfig.setEnabledForExtensions(true);
serverConfig.setContentLengthOptional(false);

webServer.start();

System.out.println("Serveur XML-RPC is ready");
}
}

###########################################################

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
import org.apache.xmlrpc.client.util.ClientFactory;

public class Client {
public static void main(String[] args) throws Exception {
// create configuration
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:8080/xmlrpc"));
config.setEnabledForExtensions(true);
config.setConnectionTimeout(60 * 1000);
config.setReplyTimeout(60 * 1000);

XmlRpcClient client = new XmlRpcClient();
System.out.println("Connection");

// use Commons HttpClient as transport
client.setTransportFactory(
new XmlRpcCommonsTransportFactory(client));
// set configuration
client.setConfig(config);

ClientFactory factory = new ClientFactory(client);
ICalculator calc = (ICalculator)factory.newInstance(ICalculator.class); //Problems here !!!
System.out.println("Calculing");
System.out.println("Result : " + calc.add(2, 3));

}
}


And the error is:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpException
at org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory.getTransport(XmlRpcCommonsTransportFactory.java:31)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
at org.apache.xmlrpc.client.util.ClientFactory$1.invoke(ClientFactory.java:104)
at $Proxy0.add(Unknown Source)
at projet.Client.main(Client.java:45)


Can you help please ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2007
Added on Jan 26 2007
3 comments
1,174 views