1. What is xml rpc?
1.1. xml rpc Overview
Xml rpc uses HTTP as the RPC mechanism of the transmission protocol, and uses XML text to transmit commands and data.
An RPC system must include two parts: 1.rpc client, which is used to call a method to the RPC server and receive the returned data of the method; 2.rpc server, which is used to respond to the request and execution method of the RPC client, and return the method execution result.
1.2. Available versions of XML RPC
Xml rpc client and xml rpc server are implemented in many versions. Generally, a single implementation version implements both client and server. However, since the xml rpc specification is met, theoretically, the RPC client implementation of any version can be used together with any version of the RPC server.
Furthermore, xml rpc is transmitted over HTTP in the form of XML text, which is irrelevant to programming languages. For example, the implemented versions of the RPC client include Perl, PHP, Python, C/C ++, Java, and so on. The implementation languages of the RPC server include Perl, Java, and so on.
There are more than one version implemented by the same programming language. For example, Java version of the implementation of: marque XMLRPC implementation (http://xmlrpc.sourceforge.net/), Apache XMLRPC implementation (http://ws.apache.org/xmlrpc)
1.3.how XMLRPC works
Complete requirements refer to XMLRPC specifications (http://www.xmlrpc.com/spec)
Simple Description:
Rpcclient Working principle: rpcclient finds rpcserver Based on the URL-> constructs a command package, calls a method of a service on rpcserver-> receives the response from rpcserver, parses the response package, return the call result.
How rpcserver works: Start a webserver (when using the built-in webserver)-> Register each service that can be provided, and each Service corresponds to a handler class-> enter the service listening status.
1.4. XMLRPC Specification
The area is 6 pages and the lecture is very clear. I suggest you take a closer look. Http://www.xmlrpc.com/spec
2. Several examples of using xml rpc in Java
2. 0. Environment preparation: download the following package and set it to classpath.
Apache XMLRPC Software Package (http://ws.apache.org/xmlrpc)
Commons-httpclient-3.0-rc4.jar
Commons-codec-1.3.jar
2. 1. Use Apache Java XMLRPC to implement a simple addition/subtraction service. Refer to the test. xmlrpcclient class and test. assumerver class in the appendix.
2. Use the Java XMLRPC implementation version of Apache to test the ing between Java data types and XMLRPC data types. See test2.xmlrpcclient and test2.assumerver in the appendix.
Here is a brief description:
> The array type in XMLRPC corresponds to the vector type in Java.
For example, the declared type of the return value of a service method in the RPC server is string [], but the object received in the client is a vector object;
Otherwise, if the client transmits the previous call parameter as string [], but what is received in the RPC server will be a vector object
Of course, if we do not use string [], we can directly declare it as a vector.
> The struct type in XMLRPC corresponds to the hashtable type in Java.
> Other types, such as string, Int, double, Boolean, date, and so on, all correspond well. Note: In the RPC client, if you use the basic types int, double, or Boolean, You Need To encapsulate them into a corresponding object. For example: integer/Double/Boolean.
. Use Apache Java XMLRPC to implement version transfer of Custom Data
In this sample, assume that all transmitted objects have implemented the xmlrpcserializable interface. The purpose of this example is to simulate the command object in unionmon. If the transmitted data is an object [], this method can be used for transmission. Combined with the Code Generation Mechanism in unionmon, each VO serialization/deserialization method can be completed during code generation. Similarly, the serialization/deserialization methods of VOx must be handwritten.
Reference code: test3.xmlrpcserializable, test3.accountvo, test3.xmlrpcclient, test3.assumerver in the Appendix
. Disable the built-in webserver and enable tomcat to support RPC server.
Practice: 1. Implement a Servlet and configure it to Tomcat; 2. Ask the RPC client to directly find the servlet and obtain the service.
Note that the RPC client uses the http post method. Therefore, you only need to implement the dopost method in the servlet.
Process: Add the following configuration in Web. xml of Tomcat:
Sampleserviceservlet
Test4.servletxmlrpcserver
Sampleserviceservlet
/Sampleserviceservlet
Reference class: test4.sampleservice, test4.servletxmlrpcserver, and test4.xmlrpcclient in the attachment
3. todolist
. Whether the serialization/deserialization of custom VO can be completed automatically through introspect. Castor can complete the XML binding of the object. It seems that you can refer
3.2.the SOAP protocol is more complex and powerful than XMLRPC. Soap is unfamiliar. In addition, must soap be used with Web Services? Whether or not you can use web services, but use soap for RMI protocols.
4. Appendix
4. 1. Data Types supported by Appendix 1 XMLRPC (omitted)
4. Appendix 2 ing between XMLRPC data types and Java data types (omitted)
4. References
Implementation of XMLRPC for http://xmlrpc.sourceforge.net/-marque
Implementation of XMLRPC server on Apache in http://ws.apache.org/xmlrpc/
Http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto.html XMLRPC howto
Http://www.sentom.net/list.asp? Id = 80 XML-RPC instance
Http://www.xmlrpc.com/spec XMLRPC Specification