1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>LuaSOAP: SOAP interface to the Lua programming language</title>
<link rel="stylesheet" href="http://www.keplerproject.org/doc.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"><a href="http://www.keplerproject.org">
<img alt="LuaSOAP logo" src="luasoap.png"/>
</a></div>
<div id="product_name"><big><b>LuaSOAP</b></big></div>
<div id="product_description">SOAP interface for the Lua programming language</div>
</div> <!-- id="product" -->
<div id="main">
<div id="navigation">
<h1>LuaSOAP</h1>
<ul>
<li><a href="index.html">Home</a>
<ul>
<li><a href="index.html#overview">Overview</a></li>
<li><a href="index.html#status">Status</a></li>
<li><a href="index.html#download">Download</a></li>
<li><a href="index.html#history">History</a></li>
<li><a href="index.html#credits">Credits</a></li>
<li><a href="index.html#contact">Contact us</a></li>
</ul>
</li>
<li><strong>Manual</strong>
<ul>
<li><a href="manual.html#introduction">Introduction</a></li>
<li><a href="manual.html#installation">Installation</a></li>
<li><a href="manual.html#soap_elements">LuaSOAP elements</a></li>
<li><a href="manual.html#basic">Basic support</a>
<ul>
<li><a href="manual.html#encode">encode</a></li>
<li><a href="manual.html#decode">decode</a></li>
</ul>
</li>
<li><a href="manual.html#client">Client side</a>
<ul>
<li><a href="manual.html#call">call</a></li>
<li><a href="manual.html#https">HTTPS and ...</a></li>
</ul>
</li>
<li><a href="manual.html#references">References</a></li>
</ul>
</li>
<li><a href="examples.html">Examples</a>
<ul>
<li><a href="#soap_elements_example">SOAP elements</a></li>
<li><a href="#escape_example">Escaping example</a></li>
<li><a href="#client_example">Client example</a></li>
</ul>
</li>
<li><a href="license.html">License</a></li>
</ul>
</div> <!-- id="navigation" -->
<div id="content">
<h2><a name="introduction"></a>Introduction</h2>
<p>LuaSOAP is a <a href="http://www.lua.org">Lua</a> library to ease the use
of <a href="http://www.w3.org/TR/2003/REC-soap12-part0-20030624/">SOAP</a>.
It enables a Lua program to:</p>
<ul>
<li>Encode and decode SOAP messages without having to deal directly
with XML code </li>
<li>Invoke remote Web Services without having to deal directly with
SOAP messages </li>
</ul>
<p>LuaSOAP provides a very simple API and an abstraction layer over
XML avoiding manipulation of string representation of data
structures.</p>
<p>LuaSOAP is based on
<a href="http://matthewwild.co.uk/projects/luaexpat/">LuaExpat</a> and on
<a href="http://www.lua.org">Lua 5.1</a>.
The abstraction layer over HTTP depends on
<a href="http://w3.impa.br/~diego/software/luasocket/">LuaSocket 2.0</a>.
An optional layer over HTTPS depends on
<a href="http://www.inf.puc-rio.br/~brunoos/luasec/">LuaSec 0.4</a>.
</p>
<h2><a name="installation"></a>Installation</h2>
<p>LuaSOAP is a Lua library composed by a main module (<code>soap.lua</code>)
and some extensions: <code>client.lua</code> and <code>server.lua</code>.
The main module must be copied to your <code>package.path</code> and the
other two files to a <code>soap</code> directory in your
<code>package.path</code>.
<p>LuaSOAP can also be installed via <a href="http://luarocks.org">LuaRocks</a>
with the command <code>luarocks install luasoap</code>.
You can check the available rocks at <a href="http://luarocks.org/repositories/rocks/">LuaRocks' main repository</a>.</p>
<h2><a name="soap_elements"></a>LuaSOAP elements</h2>
<p>LuaSOAP elements are always represented by Lua tables except
strings. A LuaSOAP element is a table of the form defined by the <a
href="http://matthewwild.co.uk/projects/luaexpat/lom.html">Lua Object
Model</a> from the <a href=
"http://matthewwild.co.uk/projects/luaexpat/">LuaExpat</a> library. The
table has the following characteristics:</p>
<ul>
<li>a special field called <code>tag</code> with the element's
name;</li>
<li>a special optional field called <code>attr</code> with the
element's attributes (see next section);</li>
<li>the element's children are stored at the <em>array-part</em> of
the table. A child could be an ordinary string or a LuaSOAP element (a
Lua table following these same rules).</li>
</ul>
<h4>Attributes</h4>
<p>The special field <code>attr</code> is a Lua table that stores
the LuaSOAP element's attributes as pairs
<em><key>=<value></em>. To assure an order (if
necessary), the sequence of <em>key</em>s should be placed at the
<em>array-part</em> of that table.</p>
<p>This documentation provides a
<a href="examples.html#soap_elements_example">detailed example</a>
which shows some common use cases.</p>
<a name="escaping"></a>
<h4>Escaping and special characters</h4>
<p>
Since LuaSOAP 3.0, the library took the responsibility to escape data
inside LuaSOAP elements (<code>entries</code> field of soap envelope; see
function <a href="#encode">soap.encode</a> below).
Therefore, XML special characters such as <code><</code> and
<code>></code> are automatically converted to the corresponding XML
entities (<code>&lt;</code> and <code>&gt;</code>, respectively).
</p>
<p>This documentation provides <a href="examples.html#escape_example">examples</a>
which show some common use cases.</p>
<h2><a name="basic"></a>Basic support</h2>
<p>The module <code>soap</code> implements all basic support for
encoding and decoding SOAP messages. There are two functions:</p>
<ul>
<a name="encode"></a>
<li><b><code>encode(args) => envelope</code></b><br/>
Builds a SOAP document containing a <code>SOAP-Envelope</code> element.
It receives a table with the following fields:
<ul>
<li><b><code>namespace</code></b> a string with an URI indicating the namespace (<code>xmlns</code>) atribute of the request,</li>
<li><b><code>method</code></b> a string with the method's name,</li>
<li><b><code>entries</code></b> an array (a table with numeric keys) of <a href="#soap_elements">LuaSOAP elements</a>,</li>
<li><b><code>header</code></b> (<em>optional</em>) a table of headers (<code>soap:Header</code> element; a <a href="#soap_elements">LuaSOAP element</a> too),</li>
<li><b><code>soapversion</code></b> (<em>optional</em>; default = 1.1) a number with the SOAP version (currently supported versions are 1.1 and 1.2),</li>
<li><b><code>internal_namespace</code></b> (<em>optional</em>; default = "") a string with the `internal' namespace (<code>xmlns:<em>internal_namespace</em></code>)</li>
</ul>
The result is always a string containing the SOAP document.<br/>
The function can raise errors in case the <code>args</code> table is
mal formed.
</li>
<a name="decode"></a>
<li><b><code>decode (method_response) => namespace,
method_name, elements</code></b><br/>
Disassembles a SOAP document into Lua objects.
It receives a string containing the SOAP document.
The results are: the namespace (string),
the SOAP-element method's name (string) and
a table with the contents of the SOAP Body.
Each element of the <code>elements</code> table can be a
string or a <a href="#soap_elements">LuaSOAP element</a>.
</li>
</ul>
<h2><a name="client"></a>Client side</h2>
<p>The module <code>soap.client</code> implements a stand-alone client
which works over HTTP and is based on <a href=
"http://w3.impa.br/~diego/software/luasocket/">LuaSocket 2.0</a>.
The following function is provided:</p>
<ul>
<li style="list-style: none"><a name="call"></a></li>
<li><b><code>call (args) => namespace, method_name, elements</code></b><br/>
It encapsulates the call of <code>encode</code> and <code>decode</code>
over a connection to an HTTP server, thus the arguments are passed to the
<code>encode</code> function and the results received from the
<code>decode</code> function.
It receives a table with the following fields:
<ul>
<li><b><code>url</code></b> a string with the URL of the service (the protocol should be <code>http</code> or <code>https</code>, which requires the load of <a href="http://www.inf.puc-rio.br/~brunoos/luasec/">LuaSec</a>'s <code>ssl.https</code> module),</li>
<li><b><code>soapaction</code></b> a string with the value of the <code>SOAPAction</code> header,</li>
<li><b><code>encoding</code></b> (<em>optional</em>; default = "") a string with the text encoding (usually <code>"utf-8"</code> or <code>"iso-8859-1"</code>),</li>
<li><em>other arguments to the <code><a href="#encode">encode</a></code> function</em></li>
</ul>
The results are the same as the <code><a href="#decode">decode</a></code>
function: the namespace (string), the SOAP-element method's name (string) and
a table with the contents of the SOAP Body.</li>
</ul>
<h4><a name="https"></a>HTTPS and SOAP over other transport layers</h4>
<p>
LuaSOAP client module was designed to work over HTTP (via LuaSocket's
<code>socket.http</code> module) and HTTPS (via LuaSec's
<code>ssl.https</code> module).
In fact, it could be used over other protocols since they provide
LuaSocket's <code>socket.http.request</code> function.
</p>
<p>
The <code>soap.client.call</code> function inspects the URL to check
what protocol the SOAP message is supposed to be transfered upon.
Then, it looks for a function called <code>request</code> at the
<code>soap.client.<i>protocol</i></code> (where <i>protocol</i> is a
table which has an entry called <code>request</code> which is a
function with the same signature of
<a href="http://w3.impa.br/~diego/software/luasocket/http.html#request">LuaSocket's <code>socket.http.request</code></a>.
Thus, the support fot HTTPS can be enabled by a program with the following lines:
<pre class="example">
local soap_client = require"soap.client"
soap_client.https = require"ssl.https"
</pre>
<p>
By following this approach, one could extend LuaSOAP to use another protocol
by implementing a function equivalent to LuaSocket's <code>socket.http.request</code>
or LuaSec's <code>ssl.https.request</code>.</p>
<h2><a name="references"></a>References</h2>
Here is a list of related documentation:
<ul>
<li><a href=
"http://www.w3.org/XML/">http://www.w3.org/XML/</a></li>
</ul>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
<p><small>
$Id: manual.html,v 1.10 2009/08/10 19:04:40 tomas Exp $
</small></p>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
|