durusmail: quixote-users: SOAP-support revisited
SOAP-support revisited
2004-09-22
2004-09-22
2004-09-23
2004-10-01
SOAP-support revisited
Toni Alatalo
2004-10-01
On Thu, 23 Sep 2004, Toni Alatalo wrote:

dunno if anyone is interested, but at least to document this to myself,
a little update on this follows:

> the nice thing for me about Quixote's XML-RPC support was that the handler
> could be added just like any URL handler (i put it to /rpc/), without any
> additional servers running or anything. once decided to do that, instead
(..)
> now if i indeed need SOAP, and create a separate server for it (like all
> the SOAPpy examples seem to do), there needs to be some mechanism for

it occurred that we indeed need SOAP, so had to add the support.
fortunately, at least so it seems so far *knocked-on-wood*, support for it
could in the end be added to the quixote app just like it was for xml-rpc.
i was unsure about that 'cause didn't know if SOAP was completely normal
HTTP POSTs, but so it seems..

i did it by using SOAPpy's SOAPpy.Parser.parseSOAP and
SOAPpy.SOAPBuilder.buildSOAP directly, instead of instanciating a
SOAPpy.Server.

here's the current attempt -- as you can see, the soap handler is using
the same rpc_process function that was there for xml-rpc, which i find
encouraging for the future where probably need to have both supported..

---begin---

(methods is a dictionary that maps rpc method name strings to functions
that wrap the actual methods on this server)

def _q_lookup (request, name):
    if name == "soap":
        return soap(request)

    else:
        return xmlrpc(request, rpc_process)

def rpc_process (meth, params):
    print "RPC:", meth, params

    if methods.has_key(meth):
        return methods[meth](params)

    else:
        raise RuntimeError, "Unknown XML-RPC method: %r" % meth

def soap (request): #after quixote.util.xmlrpc
    # Get contents of POST body
    if request.get_method() != 'POST':
        request.response.set_status(405, "Only the POST method is
                                    accepted")
        return "SOAP handlers only accept the POST method. or?"

    length = int(request.environ['CONTENT_LENGTH'])
    data = request.stdin.read(length)

    #print data

    body = SOAPpy.Parser.parseSOAP(data)
    body = SOAPpy.Types.simplify(body)

    print body

    meth, kwparams = body.items()[0]
    params = kwparams.values()
    if len(params) == 1:
        params = params[0]

    result = rpc_process(meth, params)

    return buildSOAP(result)

---end---

there are probably pitfalls in this approach too, but hopefully nothing
unmanageable

> ~Toni

same.


reply