Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML-RPC The Quickest Way to Web Services. THE MOVES INSTITUTE XML-RPC XML-RPC is an attempt to implement conventional Remote Procedure Call (RPC) concepts.

Similar presentations


Presentation on theme: "XML-RPC The Quickest Way to Web Services. THE MOVES INSTITUTE XML-RPC XML-RPC is an attempt to implement conventional Remote Procedure Call (RPC) concepts."— Presentation transcript:

1 XML-RPC The Quickest Way to Web Services

2 THE MOVES INSTITUTE XML-RPC XML-RPC is an attempt to implement conventional Remote Procedure Call (RPC) concepts using XML to transmit the RPC information Traffic on wire in XML format

3 THE MOVES INSTITUTE XML-RPC You are specifying that a particular object method be called on a remote host with the arguments passed in, and a given return type. There may be several types of method calls: blocking, non-blocking, fire-and- forget, etc.

4 THE MOVES INSTITUTE Implementations There are several implementations out there (Userland, Sun, Apache). Some implementations have extensions that make your life easier, but are non-standard. http://ws.apache.org/xmlrpc/http://ws.apache.org/xmlrpc/ for the apache implementation; I used 3.x You’ll also need commons codec jar file in the classpath if building from scratch See https://movesinstitute.org/~mcgredo/WebServices/rpc Example.tar.gz for a pre-packaged example https://movesinstitute.org/~mcgredo/WebServices/rpc Example.tar.gz

5 THE MOVES INSTITUTE Example POST /RPC2 HTTP/1.0 User-Agent: Frontier/5.1.2 (WinNT) Host: betty.userland.com Content-Type: text/xml Content-length: 181 Calculator.add 41 17

6 THE MOVES INSTITUTE Apache XML-RPC On the client side the code is relatively straightforward: XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); XmlRpcClient client = new XmlRpcClient(); Object[] params = new Object[]{new Integer(1), new Integer(2)}; System.out.println("preparing execute"); Integer result = (Integer) client.execute("Calculator.add", params);

7 THE MOVES INSTITUTE Server Side The server side is trickier. There should be java object receiving messages, but how to do this? The apache implementation uses a properties file and a default implementation of a class called XmlRpcServlet to do this XmlRpcServlet handles decoding the XML and encoding the response back

8 THE MOVES INSTITUTE XmlRpcServlet XML Java Object Some Method Response XML Response XMLRpcServlet is responsible for handling the conversion from and to XML, and calling the Java object that actually implements the functionality

9 THE MOVES INSTITUTE XmlRpcServlet XmlRpcServlet accepts the HTTP, extracts the XML, and converts the XML into what is necessary to call the method on the local object. It accepts the return value from the object, converts it into XML-RPC, and places it into an HTTP response You don’t have to write any of this code

10 THE MOVES INSTITUTE XmlRpcServlet To specify the object, you need to modify the xmlrpc- server-3.0.jar file. Extract the contents of the jar file in a temporary directory: jar -xvf xmlrpc-server-3.0.jar Add a file called XmlRpcServlet.properties in org/apache/xmlrpc/webserver Contents are “objectName=fullyQualifiedClassName” Repackage the jar file: “jar -cvf xmlrpc-server-3.0.jar org” Replace the old jar file with the new one

11 THE MOVES INSTITUTE Set up servlet Deploying the servlet is a little tricky. The environment in which a servlet program lives is standardized AppName WEB-INF web.xml (config file) classes (your classes) lib (supporting jar files)

12 THE MOVES INSTITUTE Web.xml Contained inside of WEB-INF, describes the servlets, security, etc. The example web.xml file works. It includes a subclass of XmlRpcServlet that adds logging capability The ugly config stuff is done for you if you just use the example distribution

13 THE MOVES INSTITUTE Example The example distribution includes an Ant file that Generates a xmlRpcExample.war file in the dist directory Runs a client that connects to the servlet To deploy the servlet, remove the old copy from the Tomcat webapps directory, copy dist/xmlRpcExmaple.war it to the Tomcat /webapps directory, and restart Tomcat The war file will be automatically unpacked and the servlet started

14 THE MOVES INSTITUTE Data Types You can pass Integer, Boolean, String, Double, Date, byte[], Map and Arrays of these With enabledForExtensions switched on, you can pas Byte, Float, Long, XML DOM Node, Short, Serializable, BigDecimal, BigInteger, and Calendar objects

15 THE MOVES INSTITUTE Modifying To modify the example to do what you want: Unpack the xmlrpc-server-3.0.jar file Modify XmlRpcServlet.properties file with object name on the LHS and fully qualified class name on the RHS Repackage the jar file and replace the old jar file Implement the class with a no-args constructor and public methods that take only legal data types ant dist, copy war file to tomcat webapps directory, stop and restart tomcat


Download ppt "XML-RPC The Quickest Way to Web Services. THE MOVES INSTITUTE XML-RPC XML-RPC is an attempt to implement conventional Remote Procedure Call (RPC) concepts."

Similar presentations


Ads by Google