加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

【转】ZSI + mod_wsgi

发布时间:2020-12-17 00:14:00 所属栏目:安全 来源:网络整理
导读:ZSI in mod_wsgi Hello,I've been using the dispatch.AsCGI handler from ZSI behind an apache forquite a while. Now that the load is increasing on the server,the costof forking CGIs becomes a bottleneck. After making my handling processthread

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读