ZSI in mod_wsgi
Hello,I've been using the dispatch.AsCGI handler from ZSI behind an apache for quite a while. Now that the load is increasing on the server,the cost of forking CGIs becomes a bottleneck. After making my handling process thread safe,I've integrated it in mod_wsgi environment. While looking for this list,I stumbled upon http://sourceforge.net/mailarchive/message.php?msg_id=9982866 I haven't looked at the ZSI.ServiceContainer,but for the ZSI.dispatch,based on AsCGI,I've added the following,which works for me: --8<-- def _WsgiSendXML(text,code = "200 OK",**kw): response_headers = [('Content-type','text/xml; charset="%s"' %UNICODE_ENCODING),('Content-Length',str(len(text)))] kw['start_response'](code,response_headers) return [text] def _WSCGISendFault(f,**kw): return _WsgiSendXML(f.AsSOAP(),"500 Internal Server Error",**kw) def AsWsgi(environ,start_response,nsdict={},typesmodule=None,rpc=False,modules=None): '''dispatch within mod_wsgi ''' if environ.get('REQUEST_METHOD') != 'POST': return _WSCGISendFault(Fault(Fault.Client,'Must use POST'),start_response = start_response) ct = environ['CONTENT_TYPE'] try: if ct.startswith('multipart/'): cid = resolvers.MIMEResolver(ct,environ['wsgi.input']) xml = cid.GetSOAPPart() ps = ParsedSoap(xml,resolver=cid.Resolve) else: length = int(environ['CONTENT_LENGTH']) ps = ParsedSoap(environ['wsgi.input'].read(length)) except ParseException,e: return _WSCGISendFault(FaultFromZSIException(e),start_response = start_response) except ExpatError,start_response = start_response) return dispatch._dispatch(ps,modules,_WsgiSendXML,_WSCGISendFault,nsdict=nsdict,typesmodule=typesmodule,rpc=rpc,start_response = start_response) -- Note: in AsWsgi,the ExpatError exception is raised when an incorrectly formatted XML flow is received. But shouldn't it be trapped in ParsedSoad and raised as a ParseException? Then,my .wsgi script looks like: --8<-- from ZSI import dispatch import sessionManagement def application(environ,start_response): return dispatch.AsWsgi(environ,modules = (sessionManagement,)) -- Best Regards,
原始链接:
http://permalink.gmane.org/gmane.comp.python.pywebsvcs.general/3594
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。