-------------This article refer to Liu Yang, Wei Fei and other "proficient in JBoss---EJB and webservice development of the fine solution"
The essence of XML-RPC technology is to use XML to describe the remote calling method you need, and to transfer the XML data over HTTP
Apache XML-RPC Implementation tool: Can be downloaded to the following URL: http://download.csdn.net/detail/u013998070/8563005
One: Standalone installation and start-up:
1. Extract the downloaded Xmlrpc.zip file to your working directory and find the Xmlrpc-2.0.1.jar
2. Open the command line tool, adjust to Xmlrpc-2.0.1.jar, run the command line program, such as:
How the command line does not display any information, indicating that your XML-RPC server has started normally, this way is to use the Xmlrpc-2.0.1.jar in the built-in Web server to start the XML-RPC server
Second: The realization structure of XML-RPC
The XML-RPC server is implemented through Xmlrpchandler, and the Java class object used for the service in the server is encapsulated by Xmlrpchandler and is the method by which the Xmlrpchandler is responsible for executing the RPC call
Example: Invoking a server-side object with XML-RPC
A. Ways to use the built-in Web server
Package Com.liuyang.xmlrpc.server;import Org.apache.xmlrpc.webserver;import Com.liuyang.xmlrpc.handles.helloworldhandler;import Com.liuyang.xmlrpc.handles.inthandler;import com.liuyang.xmlrpc.handles.simplehandler;/* * 8080 Sets the webserver listening port, and also initializes its internal xmlrpcserver to initiate the XML-RPC request, Then add handler */public class Simpleserver {/** * @param args */public static void main (string[] args) for webserver { Webser Ver webserver=new webServer (8080); Launch the built-in Web server webserver.addhandler ("HelloWorldHandler", New HelloWorldHandler ()); Webserver.addhandler ("$default", New Simplehandler ()); Webserver.addhandler ("Inthandler", New Inthandler ()); System.out.println ("webserver start ()"); Webserver.start ();}}
1th handler:
Package Com.liuyang.xmlrpc.handles;public class HelloWorldHandler {public string SayHello (String message) { Return "SayHello to" +message; }}
2nd handler:
Package Com.liuyang.xmlrpc.handles;public class Inthandler {public int count; public int Add (int num) { count+=num; return count; }}
3rd handler:
Package Com.liuyang.xmlrpc.handles;import Java.util.vector;import Org.apache.xmlrpc.xmlrpchandler;public class Simplehandler implements Xmlrpchandler {@Overridepublic Object execute (String arg0, Vector arg1) throws Exception {return "This is Simplehandler";}}
After running Simpleserver, see such as:
The code for SimpleClient is as follows:
Package Com.liuyang.xmlrpc.client;import Java.io.ioexception;import Java.net.malformedurlexception;import Java.util.vector;import Org.apache.xmlrpc.xmlrpcclient;import Org.apache.xmlrpc.xmlrpcexception;public Class simplecient {/** * @param args * @throws ioexception * @throws xmlrpcexception */public static void Main (string[] args) throws Xmlrpcexception, IOException { xmlrpcclient xmlrpcclient=new xmlrpcclient ("localhost", 8080); Vector vector1=new vector (); Vector1.add ("Nini"); System.out.println (Xmlrpcclient.execute ("Helloworldhandler.sayhello", Vector1)); Vector vector2=new vector (); System.out.println (Xmlrpcclient.execute ("", Vector2)); Vector vector3=new vector (); Vector3.add (New Integer (1)); System.out.println (Xmlrpcclient.execute ("Inthandler.add", Vector3));} }
The above simple introduction of XML-RPC technology to use the built-in server to call the server object method, XML-RPC itself has some advantages, but there are great limitations, in the face of Web-service, there are a lot of shortcomings
XML-RPC Technology