Cliento SOAP in lua

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Cliento SOAP in lua

José Francisco Luis Medina
Hello greetings to all members, I'm new to the language LUA, I have the
need to consume a web service from a page and I need to use a SOAP
client for this. What is the best and simplest?

Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

steve donovan
On Wed, Oct 10, 2012 at 3:04 PM, José Francisco Luis Medina
<[hidden email]> wrote:
> this. What is the best and simplest?

luasoap ? ;)  I see that it's in the LuaRocks repo.

Careful about LUA - we spell it Lua, since it's a very beautiful word ....

steve d.

Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

José Francisco Luis Medina
If I check that package, and I was testing it, they show an example of the client that is:

local client = require "soap.client"
local ns, meth, ent = client.call {
    url = "http://soap.4s4c.com/ssss4c/soap.asp",
    soapaction = "doubler",
    method = "http://simon.fell.com/calc",
    entries = { -- `tag' will be filled with `method' field
        {
            tag = "nums",
            attr = {
                ["xmlns:SOAP-ENC"] = "http://schemas.xmlsoap.org/soap/encoding/",
                ["SOAP-ENC:arrayType"] = "xsd:int[5]",
            },
            { tag = "number", 10 },
            { tag = "number", 20 },
            { tag = "number", 30 },
            { tag = "number", 50 },
            { tag = "number", 100 },
        },
    }
}
print("namespace = ", ns, "element name = ", meth)
for i, elem in ipairs (ent[1]) do
    print (elem[1])
end


but I have a problem because in table 'entries', the documentation says that is a table in LuaExpat's format. but I know that format and can not find documentation. If I rely on the example they show and my service only receives a parameter called 'date' and would stay that example? ofcourse knowing I have to place my namespace, my method and everything.


El 10/10/12 08:38, steve donovan escribió:
On Wed, Oct 10, 2012 at 3:04 PM, José Francisco Luis Medina
[hidden email] wrote:
this. What is the best and simplest?
luasoap ? ;)  I see that it's in the LuaRocks repo.

Careful about LUA - we spell it Lua, since it's a very beautiful word ....

steve d.



Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

steve donovan
On Wed, Oct 10, 2012 at 3:22 PM, José Francisco Luis Medina
<[hidden email]> wrote:
> but I have a problem because in table 'entries', the documentation says that
> is a table in LuaExpat's format. but I know that format and can not find
> documentation.

It's very simple, here's all there is to it:

http://matthewwild.co.uk/projects/luaexpat/lom.html

steve d.

Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

José Francisco Luis Medina
i'm try with

local client = require "soap.client"
local ns, meth, ent = client.call {
         url = "http://localhost:8080/Directorio/ServicioDirectorio",
         soapaction = "",
         method = "listarAlcaldia",

entries = {
         ["attr"] = {
         },
         [1] = "2010-01-01",
         ["tag"] = "fecha",
}
}

print("namespace = ", ns, "element name = ", meth)
for i, elem in ipairs (ent[1]) do
         print (elem[1])
end


and returns me:


<?xml version='1.0' encoding='UTF-8'?><S:Envelope
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><S:Fault
xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"><faultcode>S:Client</faultcode><faultstring>Cannot
find dispatch method for
{}listarAlcaldia</faultstring></S:Fault></S:Body></S:Envelope>
stack traceback:
     [C]: in function 'assert'
     /usr/share/lua/5.1/soap/client.lua:93: in function 'call'
     lua_client.lua:2: in main chunk
     [C]: ?




El 10/10/12 08:58, steve donovan escribió:

> On Wed, Oct 10, 2012 at 3:22 PM, José Francisco Luis Medina
> <[hidden email]> wrote:
>> but I have a problem because in table 'entries', the documentation says that
>> is a table in LuaExpat's format. but I know that format and can not find
>> documentation.
> It's very simple, here's all there is to it:
>
> http://matthewwild.co.uk/projects/luaexpat/lom.html
>
> steve d.
>



Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

Laurent FAILLIE
In reply to this post by José Francisco Luis Medina
I'm using LuaSOAP as well, but I created the following code to transform the response to an arrary, as PHP is doing, which is more easier to manage.

-[[
    Soap.lua

    Vigie's glue to query a web service using SOAP

    18/07/2012 LF - First version
    20/07/2012 LF - Make it more Lua oriented
--]]

local client = require "soap.client"

function Soap2Object(o) -- Convert LuaSoap's LMO to PHP like array
    local result
    local nbre = 0
    local nptag = {}
    for k,v in pairs(o) do
        if tonumber(k) ~= nil then      -- Ignore named field (tag, attr, ...)
            if type(v) == "table" then
                cont, tag = Soap2Object(v)
                if tag then             -- it's a sub object
                    if result == nil then   -- 1st result
                        result = {}
                        nbre = 1
                    elseif nbre == 1 then   -- contains already 1 object which is not a table
                        result = { result }
                        nbre = 2    -- we don't care about the real #, it has to be > 1
                    end
                    if result[tag] == nil then
                        result[tag] = cont
                        nptag[tag] = 1
                        nbre = 2    -- Even if we are the 1st element, we have created a table
                    else
                        if nptag[tag] == 1 then
                            result[tag] = { result[tag] }
                            nptag[tag] = 2
                        end
                        table.insert(result[tag], cont)
                    end
                end
            elseif v ~= "\n" then
                if result == nil then   -- 1st element
                    result = v
                    nbre = 1
                else
                    if type(result) == "string" then
                        result = { result }
                        nbre = 2
                    end
                    table.insert(result, v)
                end
            end
        end
    end
    return result, o.tag
end

function Query(soapparm)    -- Query the webserver
    assert(soapparm, "Soap parameters missing")

    local ok, error_msg, mt, resp = pcall(client.call, soapparm)
    if not ok then
        return error_msg or "Soap call failed"
    end

    return Soap2Object(resp)
end

function ExtractFromResponce( resp, fieldslist )    -- Extract requested info from the response
    for i=1, #fieldslist do
        if not resp or not resp[ fieldslist[i] ] then
            return false    -- Field not found == no error to report
        end
        resp = resp[ fieldslist[i] ]
    end
    return resp
end

return {    -- Expose public functions
    Query = Query,
    ExtractFromResponce = ExtractFromResponce
}


Part of a monitoring tool I'll release soon :)

 
The misspelling master is on the Web.
_________ 100 % Dictionnary Free !
/ /(
/ Dico / / Pleins d'autres fautes sur
/________/ /
(#######( / http://destroyedlolo.info
Quoi, des fautes d'orthographe! Pas possible ;-D.

From: José Francisco Luis Medina <[hidden email]>
To: [hidden email]
Sent: Wednesday, October 10, 2012 3:04 PM
Subject: Cliento SOAP in lua

Hello greetings to all members, I'm new to the language LUA, I have the need to consume a web service from a page and I need to use a SOAP client for this. What is the best and simplest?



Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

Tomás Guisasola-2
In reply to this post by José Francisco Luis Medina
  Hi José Francisco

On Wed, 10 Oct 2012, José Francisco Luis Medina wrote:

> local client = require "soap.client"
> local ns, meth, ent = client.call {
>         url = "http://localhost:8080/Directorio/ServicioDirectorio",
>         soapaction = "",
>         method = "listarAlcaldia",
>
> entries = {
>         ["attr"] = {
>         },
>         [1] = "2010-01-01",
>         ["tag"] = "fecha",
> }
> }
  Certainly you have to add another table inside entries.  Take a
look at the example.  Also, you shouldn't define soapaction as an empty
string; let it nil if you're using SOAP version 1.2.  In your case,
the code should look like that:

...
local ns, meth, ent = client.call {
  url = "http://localhost:8080/Directorio/ServicioDirectorio",
  --soapaction = "", -- don't do that!
  soapversion = 1.2, -- you should check that!
  method = "listarAlcaldia",
  entries = {
  { tag = "fecha", "2010-01-01", },
  }
}

  (I wrote the code succintly, but this is a matter of taste :-)
  Do you have a public URL?  I can check it for you...

> and returns me:
>
>
> <?xml version='1.0' encoding='UTF-8'?><S:Envelope
> xmlns: S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><S:Fault
> xmlns: ns4="http://www.w3.org/2003/05/soap-envelope"><faultcode>S:Client</faultcode><faultstring>Cannot
> find dispatch method for
> {}listarAlcaldia</faultstring></S:Fault></S:Body></S:Envelope>
> stack traceback:
>     [C]: in function 'assert'
>     /usr/share/lua/5.1/soap/client.lua:93: in function 'call'
>     lua_client.lua:2: in main chunk
>     [C]: ?
  The actual error message is "Cannot find dispatch method for
{}listarAlcaldia", which seems strange.  It could be a problem with the
SOAP version (version 1.1 had a mandatory SOAPAction header, but version
1.2 remove it).  Can you check that?

  Regards,
  Tomás
Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

José Francisco Luis Medina
local client = require "soap.client"
local ns, meth, ent = client.call {
      url =
"http://localhost:8080/Directorio/ServicioDirectorioEstadoVenezolano",
      method = "listarAlcaldia",
      namespace =
"http://www.cnti.gob.ve/servicio/ServicioDirectorioEstadoVenezolano",
      soapaction = "",
      entries = {
                 {
                 ["attr"] = {
                 },
                 [1] = "2010-01-01",
                 ["tag"] = "fecha",
         },
      },
}
print("namespace = ", ns, "element name = ", meth)

with this configuration th eservice response me:

ERROR: la sintaxis de entrada no es válida para tipo timestamp: « null »


seems that the value is not reaching 01/01/2010








El 10/10/12 12:46, Tomas Guisasola Gorham escribió:

>     Hi José Francisco
>
> On Wed, 10 Oct 2012, José Francisco Luis Medina wrote:
>> local client = require "soap.client"
>> local ns, meth, ent = client.call {
>>         url = "http://localhost:8080/Directorio/ServicioDirectorio",
>>         soapaction = "",
>>         method = "listarAlcaldia",
>>
>> entries = {
>>         ["attr"] = {
>>         },
>>         [1] = "2010-01-01",
>>         ["tag"] = "fecha",
>> } }
>     Certainly you have to add another table inside entries.  Take a
> look at the example.  Also, you shouldn't define soapaction as an empty
> string; let it nil if you're using SOAP version 1.2.  In your case,
> the code should look like that:
>
> ...
> local ns, meth, ent = client.call {
>     url = "http://localhost:8080/Directorio/ServicioDirectorio",
>     --soapaction = "", -- don't do that!
>     soapversion = 1.2, -- you should check that!
>     method = "listarAlcaldia",
>     entries = {
>         { tag = "fecha", "2010-01-01", },
>     } }
>
>     (I wrote the code succintly, but this is a matter of taste :-)
>     Do you have a public URL?  I can check it for you...
>
>> and returns me:
>>
>>
>> <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:
>> S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><S:Fault xmlns:
>> ns4="http://www.w3.org/2003/05/soap-envelope"><faultcode>S:Client</faultcode><faultstring>Cannot
>> find dispatch method for
>> {}listarAlcaldia</faultstring></S:Fault></S:Body></S:Envelope>
>> stack traceback:
>>     [C]: in function 'assert'
>>     /usr/share/lua/5.1/soap/client.lua:93: in function 'call'
>>     lua_client.lua:2: in main chunk
>>     [C]: ?
>     The actual error message is "Cannot find dispatch method for
> {}listarAlcaldia", which seems strange.  It could be a problem with the
> SOAP version (version 1.1 had a mandatory SOAPAction header, but version
> 1.2 remove it).  Can you check that?
>
>     Regards,
>         Tomás



Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

François Perrad
In reply to this post by steve donovan
2012/10/10 steve donovan <[hidden email]>:

> On Wed, Oct 10, 2012 at 3:22 PM, José Francisco Luis Medina
> <[hidden email]> wrote:
>> but I have a problem because in table 'entries', the documentation says that
>> is a table in LuaExpat's format. but I know that format and can not find
>> documentation.
>
> It's very simple, here's all there is to it:
>
> http://matthewwild.co.uk/projects/luaexpat/lom.html
>

In the context of Web Services (SOAP or ReST), a XML document never
uses a mixed content.
So, it's possible to use a more simpler representation than the Lua
Object Model.
See http://github.com/fperrad/lua-Spore/blob/master/src/Spore/XML.lua,
the module exports 2 functions : parse & dump.
(the idea comes from a Perl module, see
http://search.cpan.org/~grantm/XML-Simple/)

François

> steve d.
>

Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

Tomás Guisasola-2
In reply to this post by José Francisco Luis Medina
  Hi José Francisco

On Wed, 10 Oct 2012, José Francisco Luis Medina wrote:
> with this configuration th eservice response me:
>
> ERROR: la sintaxis de entrada no es válida para tipo timestamp: « null »
>
> seems that the value is not reaching 01/01/2010
  This is an internal message, produced by the implementation of
the service, not the SOAP machinery.  It does not help much, since we
can't say what is the name of the parameter.  Do you have access to the
WSDL page of the service?
  Did you check the SOAP version ?

  Regards,
  Tomás
Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

José Francisco Luis Medina
El 11/10/12 12:56, Tomas Guisasola Gorham escribió:
    Hi José Francisco

On Wed, 10 Oct 2012, José Francisco Luis Medina wrote:
with this configuration th eservice response me:

ERROR: la sintaxis de entrada no es válida para tipo timestamp: « null »

seems that the value is not reaching 01/01/2010
    This is an internal message, produced by the implementation of
the service, not the SOAP machinery.  It does not help much, since we
can't say what is the name of the parameter.  Do you have access to the
WSDL page of the service?
    Did you check the SOAP version ?

    Regards,
        Tomás

Hi Tomás! this is the WSDL http://pastebin.com/w6WGG9Mi

Reply | Threaded
Open this post in threaded view
|

Re: Cliento SOAP in lua

Tomás Guisasola-2
  Hi José Francisco

On Thu, 11 Oct 2012, José Francisco Luis Medina wrote:
>
> Hi Tomás! this is the WSDL http://pastebin.com/w6WGG9Mi
>
  Can you understand it? I can't find any type information about
the parameters.  It seems they are imported...

  Regards,
  Tomás