From: Gabriel T. <ga...@no...> - 2012-07-16 09:49:15
|
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, e: return _WSCGISendFault(FaultFromZSIException(e), 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, start_response, modules = (sessionManagement,)) -- Best Regards, -- G. Tourrand |