XMLRPC a lightweight data communication protocol - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

XMLRPC a lightweight data communication protocol

Description:

A free XML-RPC library. http://xmlrpc.helma.org ... http://xmlrpc-c.sourceforge.net/sample-code.php. 11/11/09. 28. References (Cont.) Book ... – PowerPoint PPT presentation

Number of Views:88
Avg rating:3.0/5.0
Slides: 30
Provided by: csCol6
Category:

less

Transcript and Presenter's Notes

Title: XMLRPC a lightweight data communication protocol


1
XML-RPCa lightweight data communication protocol
  • Jing Deng
  • Computer Science Department
  • University of Colorado at Boulder
  • 26 September 2001

2
Overview
  • Introduction
  • XML-RPC protocol
  • How it works
  • Data format
  • How to use XML-RPC (Java example)
  • References

3
Introduction
  • What is XML-RPC
  • Remote process calling protocol with XML format
  • What can it do
  • allow software running on disparate operating
    systems, running in different environments to
    make procedure calls over the Internet.
  • History
  • Created by UserLand Software in April 1998, for
    its Frontier software communication

4
Fundamentals
  • XML
  • A very powerful meta-language for description
    data. XML-RPC just uses a little bit of XML
  • RPC
  • A mechanism which allows a program running on one
    computer to execute a function that is actually
    running on another computer
  • HTTP
  • Most data on Internet are transferred under HTTP
    protocol
  • Not very efficient, but easy to use
  • Make XML-RPC more convenient to be used in web
    applications

5
Definition
  • XML-RPC is a remote procedure calling protocol
    that works over the Internet.
  • XML-RPC is composed by an HTTP-POST request and a
    HTTP reply.
  • The body of the request and the value returned
    from server is formatted by XML.

6
XML-RPC Overview
  • XML-RPC call is conducted between two parties
  • A client to send RPC request
  • A server to process RPC request and send back the
    return value to the client
  • Servers address is in a standard URL
  • http//example.org8080/rpcserver/
  • The data is composed by a HTTP header and a XML
    body

7
XML-RPC Overview (Cont.)
  • A XML-RPC request and a XML-RPC response
  • Both of them are composed by a HTTP header and a
    XML body
  • Request should indicate a method name and its
    parameters
  • Response should contain a function return value
    and indicates if it is a successful return or a
    error message
  • There is a data type set for parameters and
    return value

8
How does XML-RPC work
client
Web server
Client program
procedure
XML-RPC listener
9
Request Example
  • POST /RPC2 HTTP/1.0
  • User-Agent Frontier/5.1.2
  • Host xml.colorado.edu
  • Content-Type text/xml
  • Content-length 181
  • lt?xml version1.0?gt
  • ltmethodCallgt
  • ltmethodNamegtexamples.getStateNamelt/methodNamegt
  • ltparamsgt ltparamgt
  • ltvaluegtlti4gt41lt/i4gtlt/valuegt
  • lt/paramgtlt/paramsgt
  • lt/methodCallgt

10
Request Format
  • A single ltmethodCallgt structure, which contains
  • A single ltmethodNamegt. It contains the calling
    methods name
  • A single ltparamsgt, which can contain any number
    of
  • ltparamgts. Each ltparamgt has a
  • ltvaluegt

11
Data Type Scalar ltvaluegts
  • lti4gt or ltintgt four-byte signed integer
    -12
  • ltbooleangt 0 (false) or 1 (true)
    1
  • ltstringgt ASCII string
    Hi!
  • ltdoublegt double-precision
    3.1415
  • ltdateTime.iso8601gt date/time
    19980717T140855
  • ltbase64gt base64-encoded binary
    eW91IGNhbid
  • (default type is string)

12
Data Type (Cont.) - ltstructgt
  • ltstructgt contains ltmembergts, each ltmembergt
    contains a ltnamegt and a ltvaluegt
  • ltstructgt
  • ltmembergt
  • ltnamegtlowerBoundlt/namegt ltvaluegtlti4gt18lt/i4gtlt
    /valuegt
  • lt/membergt
  • ltmembergt
  • ltnamegtupperBoundlt/namegt ltvaluegtlti4gt122lt/i4gt
    lt/valuegt
  • lt/membergt
  • lt/structgt

13
Data Type (Cont.) - ltarraygt
  • An ltarraygt contains a single ltdatagt element,
    which can contain any number of ltvaluegts
  • ltarraygt
  • ltdatagt
  • ltvaluegtlti4gt12lt/i4gtlt/valuegt
  • ltvaluegtltstringgtEgyptlt/ltstringgtlt/valuegt
  • ltvaluegtltbooleangt0lt/booleangtlt/valuegt
  • ltvaluegtlti4gt-31lt/i4gtlt/valuegt
  • lt/datagt
  • lt/arraygt

14
Response Example
  • HTTP/1.1 200 OK
  • Connection close
  • Content-Length 158
  • Content-Type text/xml
  • Date Wed, 26 Sep 2001 101028 GMT
  • Server UserLand Frontier/5.1.2-WinNT
  • lt?xml version1.0?gt
  • ltmethodResponsegt
  • ltparamsgt ltparamgt
  • ltvaluegtltstringgtSouth Dakotalt/stringgtlt/valuegt
  • lt/paramgtlt/paramsgt
  • lt/methodResponsegt

15
Response Format
  • One ltmethodResponsegt, it may contains either
  • A single ltparamsgt -- a successful procedure
    return
  • It contains a single ltparamgt which contains a
    single ltvaluegt
  • A ltfaultgt -- a failure procedure return
  • It contains a ltvaluegt which is a ltstructgt that
    contains two members ltfaultCodegt and ltintgt,
    ltfaultStringgt and ltstringgt

16
Example - XML-RPC in Java
  • Many XML-RPC applications encapsulate the details
    of XML-RPC protocol
  • They provides an interface for users to send
    remote procedure call, and retrieve return value
  • A XML-RPC Java library helma.xmlrpc

17
Helma.xmlprc
  • A free XML-RPC library
  • http//xmlrpc.helma.org/
  • Contains source code, documentations, and
    examples
  • Has a jar file as a library xmlrpc.jar, which
    contains a OpenXML parser as well
  • Easy to install

18
XML-RPC Client
  • Send XML-RPC to server, and get the return value
  • Interface (encapsulate most protocol details
    HTTP, XML)
  • XmlRpcClient class
  • XmlRpcClient(String URL)
  • public Object execute(String procedure_name,
  • Vector params)

19
XML-RPC Server
  • Process XML-RPC request, call the procedure that
    request wants to call, and send back the return
    value
  • Two kinds of server
  • A mini web server, only process XML-RPC
  • WebServer class
  • (See its interface later)
  • XML-RPC listener which cooperates with a web
    server
  • XmlRpcServer class
  • Input is a XML stream, and output is a XML stream
    also
  • execute() method to process RPC

20
XML-RPC Handler
  • Contains the procedures client wants to call
  • We need to register handler to server
  • Automatic registration
  • Explicit registration
  • Implement XmlRpcHanlder interface
  • Use Xml.RpcHandler.execute() to process input
    parameter
  • Interface
  • WebServer.addHandler(String handler_name, Object
    handler)

21
Example - Handler
  • public class AreaHandler
  • public Double rectArea(double length, double
    width)
  • return new Double(length width)
  • public Double circleArea(double radious)
  • double value (radious radious Math.PI)
  • return new Double (value)

22
Example - Server
  • import java.io.IOException
  • import helma.xmlrpc.WebServer
  • import helma.xmlrpc.XmlRpc
  • public class AreaServer
  • public static void main(String args)
  • try
  • WebServer server new WebServer(Integer.p
    arseInt(args0))
  • server.addHandler("area", new
    AreaHandler())
  • catch (IOException e)
  • System.out.println("Could not start
    server " e.getMessage())

23
Example - Client
  • import java.io.IOException
  • import java.util.Vector
  • import helma.xmlrpc.XmlRpc
  • import helma.xmlrpc.XmlRpcClient
  • import helma.xmlrpc.XmlRpcException
  • public class AreaClient
  • public static void main(String args)
  • try
  • XmlRpcClient client
  • new XmlRpcClient("http//localhost889
    9")
  • // continue.

24
Example Client (Cont.)
  • // continue from last slide..
  • Vector params new Vector()
  • params.addElement(new Double(args0))
  • Object result client.execute("area.circl
    eArea", params)
  • System.out.println(result.toString())
  • catch (IOException e)
  • System.out.println("IO Exception "
    e.getMessage())
  • catch (XmlRpcException e)
  • System.out.println("Exception within
    XML-RPC " e.getMessage())

25
Discussions
  • Characters of XML-RPC
  • Platform independent because it is a protocol
  • Very simple, very easy to implement, very ease to
    use
  • Too simple for some applications
  • Implemented with many languages Java, C/C,
    Perl, Python, etc
  • Other important issues I didnt mention
  • Security
  • Apply XML-RPC in web applications

26
Discussions (Cont.)
  • Comparisons
  • Differences between XML-RPC and web page
  • Differences between XML-RPC and RMI, Corba
  • Differences between XML-RPC and SOAP
  • Beyond XML-RPC
  • SOAP, UDDI, WSDL, BXXP

27
References
  • XML-RPC documents
  • http//www.xmlrpc.com
  • http//www.xmlrpc.com/spec
  • http//xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlr
    pc-howto.html
  • XML-RPC in Java
  • http//xmlrpc.helma.org
  • XML-RPC in C and C
  • http//xmlrpc-c.sourceforge.net/sample-code.php

28
References (Cont.)
  • Book
  • Simon St.Laurent, Joe Johnston, Edd Dumbill,
    programming web services with XML-RPC, OReilly,
    2001
  • Others
  • http//www.w3.org/2000/xp/
  • http//www.google.com

29
Thanks!
Write a Comment
User Comments (0)
About PowerShow.com