| Allegro CL version 8.1 Unrevised from 8.0 to 8.1. 8.0 version |
This document contains the following sections:
1.0 XML-RPC in Allegro CL introductionThe xml-rpc module implements classes and functions to support the XML-RPC protocol for remote function calls through HTTP connections. The protocol is described in detail on the XML-RPC Home Page at http://xmlrpc.com/. The XML-RPC Home Page also lists public XML-RPC servers and many community links.
The xml-rpc module was available in release 6.2. It was documented by a readme.txt and other files in the (now removed) xmlrpc/ directory. This document replaces that readme.txt file and associated files.
All symbols in this module are exported from the
net.xml-rpc
package. The module is named
xml-rpc
. It requires the AllegroServe
(aserve
) and the XML Utilities
(xmlutils
) modules. You load the
xml-rpc
module with a form like:
(require :xml-rpc)
This implementation of XML-RPC is separate and independent from the
Lisp RPC implememtation in the aclrpc
module (see
rpc.htm). The Lisp RPC module is more appropriate
for closely coupled applications on one processor or on a local area
network. XML-RPC is more appropriate for occasional contact between
applications separated by large distances and by firewalls.
The key features (both positive and negative) of the XML-RPC protocol are as follows. First the positive features:
Now the negative features:
The following variables, conditions, and methods are useful when using XML-RPC.
A list of three integers that describe the XML-RPC version.
Arguments: &optional stream
If stream is nil
, return
a string with a formatted version message.
If stream is a stream, write the formatted version message to the stream.
If stream is the keyword
:number
, return an integer of the form
aabbcc
where aa
,
bb
, and cc
are the version
number components.
Otherwise, return the value of *xml-rpc-version*
, a list of three
version numbers.
The superclass of conditions associated with xml-rpc.
A condition associated with xml-rpc.
A condition associated with xml-rpc.
A condition associated with xml-rpc.
A condition associated with xml-rpc.
Arguments: xml-rpc-fault
Accesses the code slot of an xml-rpc-fault
.
Arguments: xml-rpc-fault
Accesses the string slot of an xml-rpc-fault
.
Arguments: xml-rpc-error
Accesses the place slot of an xml-rpc-error
.
Arguments: xml-rpc-error
Accesses the data slot of an xml-rpc-error
.
The Client API allows a Lisp application to call any XML-RPC server.
In a client call:
Arguments: name &rest args
The purpose of this function is to encode a client call into a string ready to be transmitted to a server.
The name argument is a symbol or string that names a method available at the server.
The remaining arguments are Lisp values that are encoded into suitable protocol items. Default encoding rules are defined for many Lisp data types. Some arguments must be explicitly encoded by calling make-xml-rpc-encoding described later.
If the same call needs to be made several times, there is some efficiency gained in encoding the call once, and reusing the string.
The XML-RPC protocol requires that each http request includes a length and that the length is accurate.
Arguments: server name &rest args
The purpose of this function is to call the remote method and to decode the result.
The first argument is a list of keyword value pairs describing the desired XML-RPC server.
The second argument is the name of a remote method and the remaining arguments are arguments passed to the remote methods.
The value returned by the function is the decoded value returned by the remote method.
If the call results in an XML-RPC Fault, then a Lisp error of type
xml-rpc-fault
is signaled.
The keyword arguments that may appear in the server list are
:url
, :agent
, and
:host
.
The url argument specifies the URL of the remote
server. The default value is taken from the variable *xml-rpc-url*
.
The agent argument may be a string that is passed
to the server as the :user-agent header element. The default value is
:aserve
; this value sends the AllegroServe version
string.
The host argument may be a string that is passed
to the server as the :host
header element. When
this argument is nil
, the
:host
header element is omitted.
Arguments: encoded &key url agent host
The purpose of this function is to call the remote method and to decode the result.
The first argument is a string produced by the encode-xml-rpc-call function. It is the encoded version of the method name and argument values.
The value returned by the function is the decoded value returned by the remote method.
If the call results in an XML-RPC Fault, then a Lisp error of type
xml-rpc-fault
is signalled.
The url argument specifies the URL of the remote
server. The default value is taken from the variable *xml-rpc-url*
.
The agent argument may be a string that is passed
to the server as the :user-agent header element. The default value is
:aserve
; this value sends the AllegroServe version
string.
The host argument may be a string that is passed
to the server as the :host
header element. When
this argument is nil
, the
:host
header element is omitted.
The value of this variable is the default URL used to make a client call. If many calls to the same server are made in some context, the setting of this variable may be used to provide the correct default URL.
We provide classes and functions that give the programmer control over the encoding and decoding of Lisp values.
Lisp Data Type | Default Encoding | Default Decoding |
integer | <int> or <i4> | integer |
float | <double> | float |
string | <string> | string |
list | <array> | list |
xml-rpc-struct | <struct> | xml-rpc-struct |
xml-rpc-struct | <boolean> | t or nil |
xml-rpc-struct | <base64> | string |
Some XML-RPC data types must be explicitly created by the application since it is not possible to infer them from the Lisp data type.
The purpose of this class is to represent the XML-RPC <struct> data type.
Arguments: xml-rpc-struct
The default method returns a list of members defined in the
<struct>. Each item in the list is an instance of the xml-rpc-member
class.
The purpose of this class is to represent the members defined in a <struct>.
Arguments: xml-rpc-member
The deafult method returns a string that represents the name of the <struct> member.
Arguments: xml-rpc-member
The default method returns the Lisp value of the <struct> member.
The purpose of this class is to represent an explicit encoding of a Lisp value into an XML-RPC protocol value. Instances of this class are created when a default encoding cannot be used to create the desired encoding.
Arguments: xml-rpc-struct slot-name
The purpose of this function is to access the value of a member in a <struct> instance.
The slot-name argument is string or symbol that is string-equal to the desired member name.
The value returned is the current Lisp value of the member.
The setf of this generic function is called as follows:
((setf xml-rpc-slot-value) new-value xml-rpc-struct slot-name)
It may be used to store a new value as the Lisp value of the member.
Arguments: &rest name-value-sequence
This function creates an object from which an XML-RPC <struct> instance can be encoded. The arguments are an alternating sequence of name and value arguments. The name argument names a member of the <struct>, the value argument is a Lisp value to be encoded as the value component of the member.
Each name argument may be a string or symbol or a list. A name or
symbol specifies the name of the member and a default encoding for the
Lisp value. A list consists of a name for the member and a keyword
that specifies the desired XML-RPC encoding. All the encoding
keywords are described with the encode-xml-rpc-value function. A
third element in the list may be t
or nil
to specify whether the encoding for the Lisp
value should be cached in the member object.
Arguments: data &optional type &rest more
The purpose of this function is to make an explicit encoding of a Lisp value to create an encoded value that cannot be obtained from a default encoding.
If the type argument is omitted or nil
, then
the data argument value is encoded by default rules:
Lisp Data Type | Default Encoding |
integer | <i4> |
float | <double> |
string | <string> |
sequence | <array> |
xml-rpc-encoding | the encoding stored in the object |
xml-rpc-struct | <struct> |
The type argument may be a keyword to ensure a specific encoding:
:int
: The data argument is truncated to an
integer. Encoded value is <i4>.
:truncate
: The data argument is truncated to an
integer. Encoded value is <i4>.
:round
: The data argument is rounded to an
integer. Encoded value is <i4>.
:string
: The data argument is converted to a string
with a ~A format directive. Encoded value is <string>.
:double
: The data argument is coerced to a
double-float. Encoded value is <double>.
nil
(true). Encoded value is
<boolean>.
:date
: The data argument may be an integer treated
as a CL universal time number or a list of (second minute hour day
month year). In the second form, the year is treated literally - not
as in the CL definition, to allow dates before 1900. Encoded value is
<dateTime.iso8601>.
:base64
: The data argument is converted to a string
with a ~A format directive. The string is encoded as a base64
string. Encoded value is <base64>.
xml-rpc-struct
instance, then the data argument is encoded as in the default case.
Otherwise, the data argument is ignored and the more argument must be a list of items of the form (name value [type] ...) where name denotes a member name, value is the Lisp value of the member and the remainder of the list is used in a recursive call to encode the Lisp value.
This second form allows a <struct> argument to be encoded without creating an xml-rpc-struct instance.
Encoded value is a <struct>.
If an encoded value cannot be created, a Lisp error of type xml-rpc-argument-error
is signaled.
Arguments: data &optional type &rest more
This function is very similar to make-xml-rpc-encoding, but the value returned is a string that contains an XML-RPC value encoding. Since the resulting string must be stored in an xml-rpc-encoding instance to be recognized in an argument conversion, this function is only useful in some circumstances where creating the xml-rpc-encoding instance must be delayed. An instance is created with the form
(make-xml-rpc-encoding (encode-xml-rpc-value ...) :encoded)
The server API allows a Lisp application to act as an XML-RPC server on the internet. Other applications, possibly written in other languages such as Java and Perl, may then call the methods exported by the server.
Arguments: xml-rpc-server
The default method accesses the name of an xml-rpc-server
.
Arguments: &key start enable publish class name introspect
This function creates an instance of the xml-rpc-server
class to hold the definitions of a set of exported functions.
The publish argument defines how the server is
seen from the client side. It is the list of arguments passed to the
aserve:publish function. If the :path
argument is missing, the value "/RPC2" is supplied. If
:function
or :content-type
are
specified, an error is signaled.
If the start argument is non-nil
, then the function aserve:start is called.
If the start argument is a list, this list is
used as the argument list to aserve:start, otherwise
aserve:start is called with all default arguments.
If the enable argument is non-nil
, then the server is enabled. If the enable
argument is non-nil
, but the
start argument is nil
,
then AllegroServe must already be running when make-xml-rpc-server is called.
The name argument is returned to clients as the :server header entry. The default name is "AllegroServe/x.x.x(Allegro Common Lisp)".
The class argument can specify the name of a
sub-class of xml-rpc-server
. This feature allows
applications to add slots or methods to the server object. This
object is bound to *xml-rpc-server*
when an exported
function is called.
If the introspect argument is non-nil
, the standard introspection methods are exported
automatically (see export-standard-xml-rpc-methods).
Arguments: server &optional enable-exports
This function enables a server and optionally enables any exported methods.
A method is available to a client only if all three conditions are met:
If many methods need to be exported, the normal sequence of events is to make a disabled server, define and enable all the methods, and finally enable the server. In this way all the methods become available simultaneously.
Arguments: server
This function disables the server and makes all the methods unavailable.
Arguments: server name-spec result-spec &rest arg-specs
This function makes a method available to XML-RPC client applications.
The server argument must be an xml-rpc-server
instance.
The name-spec argument may be a symbol or a
list. When name-spec is a list, the first element
must be a string or symbol that names the exported method - this is
the name that a client uses to call the remote method. The second
element of the list is the name of the Lisp function that will be
called as the exported method. If the second element in the list is
omitted or nil
, then the first element must
be a symbol that is also the name of the Lisp function to be
called. The third element in the list is nil
or non-nil
; non-nil
specifies that the method is enabled immediately; if nil
is specified, then the method must be enabled
explicitly by calling enable-xml-rpc-method; if the third
element is omitted, t
is assumed and the
method is enabled. The fourth element in the list may be a string
containing a description of the method. When
name-spec is a symbol, it is equivalent to
(symbol nil t)
.
The result-spec argument must be one of the
keywords that represent XML-RPC data types. It is the type of the
result returned to the caller. The available keywords are
:int
, :double
,
:string
, :array
,
:struct
, and :base64
.
The remaining arguments are a list of XML-RPC data type keywords that describe the method signature.
Several methods, with different argument signatures, may be exported under the same method name.
The Lisp function is called with the decoded arguments of the remote call. The value returned by the Lisp function is encoded using the data type of the value and the result-spec. If the function returns an instance of the class xml-rpc-encoding then the result-spec is ignored and the encoding stored in the instance is used.
Arguments: server name
This function returns the help string associated with an exported method name. All the methods with one name share the same help string.
The setf of this generic function is called as follows:
((setf xml-rpc-method-help) new-string server name)
It may be used to store a new help string.
Arguments: server &optional enable
This function exports three introspection methods frequently provided
by XML-RPC servers. The enable argument may be
nil
to suppress automatic enabling of these
methods.
The methods are:
Arguments: server name &rest arg-specs
This function enables an individual exported method, or all the methods with the same name.
If the arg-specs argument is a list of the single
keyword :all
, then all the methods with the
specified name are enabled.
Otherwise, arg-specs must be a list of keywords that represent XML-RPC data types. The method with the matching argument signature is enabled.
Arguments: server name &rest arg-specs
This function disables an individual exported method, or all the methods with the same name.
If the arg-specs argument is a list of the single
keyword :all
, then all the methods with the
specified name are disabled.
Otherwise, arg-specs must be a list of keywords that represent XML-RPC data types. The method with the matching argument signature is disabled.
A simple client call:
(xml-rpc-call (encode-xml-rpc-call "currentTime.getCurrentTime") :url "http://time.xmlrpc.com:80/RPC2" )
A client call with an argument:
(xml-rpc-call (encode-xml-rpc-call "system.methodSignature" "meerkat.getCategories") :url "http://www.oreillynet.com/meerkat/xml-rpc/server.php" )
The validation server:
(defun make-validator1-server (&optional (port 8080)) (let ((s (make-xml-rpc-server :start nil :enable t :publish '(:path "/ACL-XML-RPC2")))) (export-xml-rpc-method s '("validator1.arrayOfStructsTest" validator1-array-of-struct) :int :array) (export-xml-rpc-method s '("validator1.countTheEntities" validator1-count) :struct :string) ... (start :port port) (enable-xml-rpc-server s) s))
and one of the validator functions:
(defun validator1-count (string) ;; validator1.countTheEntities -- returns :struct ;; ;; This handler takes a single parameter, a string, ;; that contains any number of predefined entities, ;; namely <, >, &, ' and ". ;; Your handler must return a struct that contains five fields, ;; all numbers: ctLeftAngleBrackets, ctRightAngleBrackets, ;; ctAmpersands, ctApostrophes, ctQuotes. (make-xml-rpc-struct "ctLeftAngleBrackets" (count #\< string) "ctRightAngleBrackets" (count #\> string) "ctAmpersands" (count #\& string) "ctApostrophes" (count #\' string) "ctQuotes" (count #\" string)))
xml-rpc-argument-error
xml-rpc-condition
xml-rpc-encoding
xml-rpc-error
xml-rpc-export
xml-rpc-fault
xml-rpc-member
xml-rpc-response-error
xml-rpc-server
*xml-rpc-server*
xml-rpc-struct
*xml-rpc-url*
*xml-rpc-version*
Copyright (c) 1998-2009, Franz Inc. Oakland, CA., USA. All rights reserved.
Documentation for Allegro CL version 8.1. This page was not revised from the 8.0 page.
Created 2009.7.29.
| Allegro CL version 8.1 Unrevised from 8.0 to 8.1. 8.0 version |