Apache XML-RPC teaching article + Demo program

Source: Internet
Author: User
Tags date object end interface reference string xml parser client
Apache|xml

[Main Topic]
Apache XML-RPC demo teaching (i.)

Objective
Try to create and share learning experiences

[Download Connections]
Http://ws.apache.org/xmlrpc/download.html

[Simple]
Apache XML-RPC is an XML-RPC suite that is written in Java, and the Apache XML-RPC is divided into two parts, the client side and the Server side, and it's a remote program that uses two sets of protocol--and HTTP--to actually do it. Call.

[Use of teaching-Client articles]
The Client side provides two main categories, which are described as follows:

1. Org.apache.xmlrpc.XmlRpcClient
This type uses the Java.net.URLConnection type as the standard HTTP Client.

2. Org.apache.xmlrpc.XmlRpcClientLite
This type of customization is a lightweight HTTP Client.

TIP:
If you need full HTTP protocol support (for example: Proxy server, reboot ...) etc. functions), please use the xmlrpcclient type. In other words, if your program does not require complete HTTP protocol support, and you need to consider the effectiveness problem, try these two types of Client: Xmlrpcclient and Xmlrpcclientlite. Because on some platforms xmlrpcclient may be faster, and on some platforms, Xmlrpcclientlite is more outstanding. Both of these provide the same interface, including synchronous and asynchronous calls. Therefore, use the method of Datong small differences, please do not worry about users.

Synchronous XML Remote Program call:
Apache XML-RPC is very intuitive and easy to use. Here are some examples of code, and you can also draw aloe.


Declaring a simple xmlrpcclient (using the standard J2SDK kit) xmlrpcclient client = new Xmlrpcclient ("Http://knight.fcu.edu.tw:8080/XML-RPC")  ;  params stores the parameters vector params = new vector () used in your method;  Params.addelement ("Your parameters"); The Execute method returns the legend string result = (string) Client.execute ("Method name", params);


TIP:
Please be aware that when you perform the Execute method, you may throw out xmlrpcexception and IOException, and you will have to declare the processing mode of the exception in your code.

Non-synchronized XML remote program call:
Apache XML-RPC supports asynchronous remote program calls. It is accomplished by the Eexecuteasync () method in XML-RPC Client. Using this method will activate another thread to perform the call to the method, and the Executeasync is immediately uploaded, rather than waiting for the processing to be done as the Execute method does. If you want to know the results of a remote end, or if you want to be notified when an exception occurs, you can spread into an object that actually org.apache.xmlrpc.AsyncCallback the interface. This interface defines two methods:

public void Handleresult (Object result, url url, String method);
public void HandleError (Exception Exception, url url, String method);

The two methods are viewed remotely and are not called.

[Using teaching Server articles]
On the server side, you can choose to bind the function library to the existing Server framework software or use the Mini HTTP server built in this suite. Let's take a look at how to use server-side dependencies and learn how to register the corresponding processing objects on the server.

XML-RPC Handler Objects
The Apache XML-RPC suite also provides two types on the Server side for your friends to use, which are described as follows:

1. Org.apache.xmlrpc.XmlRpcServer
This kind of standard server in Apache XML-RPC can be used to integrate with the server as it is now.
2. Org.apache.xmlrpc.WebServer
This type provides the Mini HTTP server I mentioned earlier.

The two servers above provide the following methods for you to register or to make a Java object that is called processing in XML.

AddHandler (String name, Object handler);
RemoveHandler (String name);

TIP:
Viewing the processing you provide to the Server, the following scenarios will appear:
If you pass any Java object to Xmlrpcserver, it will try to parse all incoming program calls through the object's introspection machine (object introspection). For example, by looking at the common methods in the process, find out the name of the method and the type of reference required by the caller. It is particularly noted that the reference form in the request for XML remote program calls must conform to the following specifications:

A.
XML-RPC data type: <i4> or <int>
XML Parser data type: Java.lang.Integer
Client-expected data type: int

B.
XML-RPC data type: <boolean>
XML Parser data type: Java.lang.Boolean
Client-Expected data type: Boolean

C.
XML-RPC data type: <string>
XML Parser data type: java.lang.String
Client-Expected data type: java.lang.String

D.
XML-RPC data type: <double>
XML Parser data type: java.lang.Double
Client-expected data type: double

F.
XML-RPC data type: <dateTime.iso8601>
XML Parser data type: java.util.Date
Client-Expected data type: java.util.Date

G.
XML-RPC data type: <struct>
XML Parser data type: java.util.Hashtable
Client-Expected data type: java.util.Hashtable

H.
XML-RPC data type: <array>
XML Parser data type: Java.util.Vector
Client-Expected data type: Java.util.Vector

G.
XML-RPC data type: <base64>
XML Parser-generated data type: byte[]
Client-Expected data type: byte[]

Otherwise the call will fail. In the same way, the back-end form must be supported by this XML remote program call kit. And if you are referring to a programming object that actually Org.apache.xmlrpc.XmlRpcHandler or Org.apache.xmlrpc.AuthenticatedXmlRpcHandler interface to Xmlrpcserver, The Execute () method is called every time the remote program calls. So you have complete control over how to handle XML remote program call requirements, and allow you to check and transfer the input and output parameters, as well as to make mistakes ... Wait a minute.

Not finished, please continue the article

Best regards,
Tzutolin



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.