Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous SOAP call with Tornado and SUDS

I am working with Tornado and SUDS. I would like to make an asynchronous call using Tornados AsyncHTTPClient. Here is my code

class RequestHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def post(self):
    data = tornado.escape.json_decode(self.request.body)
    uuid = data['id']
    suds_client = Client(wsdl_location, nosend=True) 
    context = suds_client.service.GetSubscriptions(uuid)        
    tornado_client = tornado.httpclient.AsyncHTTPClient()
    tornado_client.fetch(context.envelope,callback=self.on_response)

def on_response(self,response):
    print response
    #self.write(str(response))
    self.finish()

I set nosend = True in the above code based on the discussion from the post here

It says to set nosend = True and it builds an envelope and then use Tornado asynchronous http agent to fetch it.

When I execute the above code I don't get any response. How do I do it? Any help would be appreciated.Thanks.

like image 362
navin Avatar asked Jan 22 '26 14:01

navin


1 Answers

I solved it myself. I will be providing my code below for reference and understanding.

class RequestHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def post(self):
    data = tornado.escape.json_decode(self.request.body)
    uuid = data['id']
    suds_client = Client(wsdl_location, transport = trans_certs, nosend=True)
    context = suds_client.service.GetSubscriptions(uuid)
    tornado_client = tornado.httpclient.AsyncHTTPClient()
    url=context.client.location()
    tornado_client.fetch(url,body=str(context.envelope),method="POST",headers=context.client.headers(),callback=self.on_response)


def on_response(self,response):
    result=str(response.body)
    dom1 = parseString(result)
    for node in dom1.getElementsByTagName('subscriptionId'):
        self.write(str(node.toxml()))
    self.finish()
like image 126
navin Avatar answered Jan 25 '26 02:01

navin