日期:2014-05-16 浏览次数:20935 次
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcHttpClientConfig;
import org.apache.xmlrpc.client.XmlRpcLiteHttpTransportFactory;
import org.apache.xmlrpc.client.XmlRpcLocalTransportFactory;
import org.apache.xmlrpc.client.XmlRpcSunHttpTransportFactory;
public class HelloClient {
public static void main(String[] arg)throws MalformedURLException, XmlRpcException {
//XmlRpcHttpClientConfig clientConfig = XmlRpcHttpClientConfig();
XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
clientConfig.setServerURL(new URL("http://192.168.19.2:7777/xmlrpc"));
XmlRpcClient client = new XmlRpcClient();
client.setTransportFactory(new XmlRpcSunHttpTransportFactory(client));
client.setConfig(clientConfig);
Object[] params = new Object[] { "wly"};
String result = (String) client.execute("hello.sayHello", params);
System.out.println("Response from server is: " + result);
}
}
public class HelloHandler {
public String sayHello(String name){
return "hello11:"+name;
}
}
import java.io.IOException;
import org.apache.xmlrpc.XmlRpcException;
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 HelloServer {
public static final int PORT = 7777;
public static void main(String[] arg)throws XmlRpcException,IOException{
System.out.println("Start rpc Server Now...");
WebServer webServer = new WebServer(PORT
XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
PropertyHandlerMapping propertyHandlerMapping = new PropertyHandlerMapping();
propertyHandlerMapping.addHandler("hello", HelloHandler.class);
xmlRpcServer.setHandlerMapping(propertyHandlerMapping);
XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl)xmlRpcServer.getConfig();
serverConfig.setEnabledForExceptions(true);
serverConfig.setContentLengthOptional(false);
webServer.start();
System.out.println("Registered HelloHandler to \"hello\"");
System.out.println("Now Accepting Requests ...");
}
}
