SOAP Lua Service

Introduction

The SoapLuaService is a service for initiating Lua scripts running within the LogicApp.

The SoapLuaService receives messages from one or more instances of the SoapServerApp which is configured to receive SOAP/HTTP(S) Requests from an external client.

The SoapLuaService communicates with the SoapServerApp using the SOAP-S-… messages.

Configuring SoapLuaService

The SoapLuaService is configured within a LogicApp.

    <?xml version="1.0" encoding="utf-8"?>
    <n2svcd>
      ...
      <applications>
        ...
        <application name="Logic" module="LogicApp">
          <include>
            <lib>../apps/logic/lib</lib>
          </include>
          <parameters>
            ...
          </parameters>
          <config>
            <services>
              <service module="SoapServerApp::SoapLuaService" libs="../apps/soap_s/lib"/>
            </services>
            <agents>
              ...
            </agents>
          </config>
        </application>
        ...
      </application>
      ...
    </n2svcd>

Under normal installation, the following service attributes apply:

Parmeter Name Type XML Type Description
module String Attribute [Required] The module name containing the Lua Service code: SoapServerApp::SoapLuaService
libs String Element Location of the module for SoapLuaService.
(Default: ../apps/soap_s/lib)
script_subdir String Attribute An optional subdirectory for scripts used by this service.

Script Selection (SOAP Request)

Script selection is not configured. The script name is simply the SOAP message name received in the request.

e.g. an inbound request with message name OfferList will map to a script name of OfferList, which will be satisfied by a file named OfferList.lua in any of the directories configured as lua_script_dir in the LogicApp.

Refer to the LogicApp configuration for more information on directories, library paths, and script caching parameters.

Script Entry Parameters (SOAP Request)

The Lua script must be a Lua chunk which returns an n2svcd.handler, such as the following:

    local n2svcd = require "n2.n2svcd"

    local handler = function (soap)
        n2svcd.notice ("Echo Supplied SOAP Inputs:")
        n2svcd.notice_var (soap)

        return soap.args
    end

    return n2svcd.handler (handler)

The handler will be executed with a single soap entry parameter which is an object with the following attributes:

Field Type Description
.remote_host String The remote IP address from which the SOAP HTTP(S) request was sent.
.remote_port Integer The remote IP port from which the SOAP HTTP(S) request was sent.
.method String The HTTP Request method.
.uri String The URI for which the request was received.
Includes only path and query. No host/port/auth/user/fragment is present.
.path String The URI path.
.query String The URI query string (the part following "?" in the URI).
.query_args String or Object If the .query attribute contains & or = then this query_args contains a table of the name and values, decoded according to common web form conventions. If you wish to have full control of the decoding, then you should directly reference the undecoded .query.
.message_name String The name of the SOAP message (without namespace), being the name of the element contained within the SOAP body.
.args Object The args provided by the client into the SOAP request. This may be a complex, nested structure. The decoding and parsing of the args into an internal object representation differs slightly according the quirks_mode.
.message_namespace Object A container for the message namespace information.
.location message/envelope Location of the message namespace.
.alias String The alias for the message namespace, if one was used.
.url String The message namespace URL, if one was provided.
.standard_namespaces Object A container for the standard namespace information.
.encoding_alias String The alias for the standard encoding namespace, if present.
.envelope_alias String The alias for the standard envelope namespace, if present.
.schema_alias String The alias for the standard schema namespace, if present.
.schema_instance_alias String The alias for the standard schema instance namespace, if present.

Script Return Parameters (SOAP Response)

The Lua script is responsible for determing the SOAP Response which will be sent back in reply to the original SOAP Request.

The simplest way to do this is by the return value given back to the service at the end of script execution.

The script return value should be a response object with the following attributes:

Field Type Description
response Object Container for the SOAP response parameters we are to send.
.args Object The arguments which we will encode into XML for the SOAP response.
The quirks_mode for the SoapServerApp will control how this is done.
.message_name String Response message name to use.
(Default = Request name with Response appended)

Example (returning SOAP Response arguments):

    local n2svcd = require "n2.n2svcd"

    local handler = function (soap)
        return ({ ARG1 = "VALUE ONE", ARG2ARRAY = [ 'First Value', 'Second Value' ]})
    end

    return n2svcd.handler (handler)

The encoding of array elements will vary according to the quirks_mode configured for the SoapServerApp. For example, when SoapServerApp is configured to run in generic quirks mode, an array is encoded as:

    <ARG2ARRAY soapenc:arrayType="xsd:string[2]" xsi:type="soapenc:Array">
      <item xsi:type="xsd:string">First Value</item>
      <item xsi:type="xsd:string">Second Value</item>
    </ARG2ARRAY>

By comparison, in ncc_pi quirks mode, an array is simply a repeated element, e.g.:

    <ARG2ARRAY>First Value</pi:ARG2ARRAY>
    <ARG2ARRAY>Second Value</pi:ARG2ARRAY>

Alternatively, a script may return nil to return an empty SOAP response.

Example (returning a SOAP Response with no arguments):

    local n2svcd = require "n2.n2svcd"

    local handler = function (soap)
        return nil
    end

    return n2svcd.handler (handler)

The SoapLuaService API

The SOAP Server API can be loaded as follows.

    local soap_server_api = require "n2.n2svcd.soap_server"

It is not necessary to load the SOAP Server API if you are only using the simple response mechanism described above. It is only required if you wish to use any of the extended features described below.

.response

When a Lua Script needs to perform extended processing, it may wish to send an early SOAP response before the script completes. This can be done with the response method on the SOAP Server API. This method also allows the script to use a non-default response message name.

The response method takes the following parameters.

Parameter Type Description
response Object A Lua Table container for the following attributes.
.args Integer The SOAP arguments to be encoded into the response.
.message_name String Response message name to use.
(Default = Request name with Response appended)

The response method returns true.

[Fragment] Example (Early Response with overridden name):

    ...
    soap_server_api.response ({ num_updated = 3, new_ids = [ "1003", "3344"] }, "OfferSaveACK")
    ...
    [post-processing after SOAP transaction is concluded]
    ...