Commit c599f0d0 authored by Vincent Pelletier's avatar Vincent Pelletier

Cache parsed WSDL data, once per thread and for the duration of zope process life.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27221 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e3d05826
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
import SOAPpy import SOAPpy
from Products.AGProjects.patches import SOAPpy_WSDL as WSDL from Products.AGProjects.patches import SOAPpy_WSDL as WSDL
from AccessControl.SecurityInfo import allow_class, allow_module from AccessControl.SecurityInfo import allow_class, allow_module
import threading
# Exception class. # Exception class.
# This allows restricted python to handle exceptions without allowing direct # This allows restricted python to handle exceptions without allowing direct
...@@ -158,6 +159,10 @@ class MethodWrapper(object): ...@@ -158,6 +159,10 @@ class MethodWrapper(object):
except SOAPpy.Types.faultType, exception: except SOAPpy.Types.faultType, exception:
raise SOAPWSDLException(*exception()) raise SOAPWSDLException(*exception())
# SOAPpy says nothing about thread-safeness of parsed WSDL.
# Be on the safe side by using threading.local as a storage for it.
wsdl_cache = threading.local()
class SOAPWSDLConnection: class SOAPWSDLConnection:
""" """
Holds a SOAP connection described by a WSDL file. Holds a SOAP connection described by a WSDL file.
...@@ -191,8 +196,10 @@ class SOAPWSDLConnection: ...@@ -191,8 +196,10 @@ class SOAPWSDLConnection:
self._service = service self._service = service
def connect(self): def connect(self):
# TODO: caching of wsdl parsing try:
wsdl = SOAPpy.wstools.WSDLTools.WSDLReader().loadFromURL(self.url) wsdl = wsdl_cache.parsed
except AttributeError:
wsdl = wsdl_cache.parsed = SOAPpy.wstools.WSDLTools.WSDLReader().loadFromURL(self.url)
# TODO: transport (http) level authentication using self._user_name and # TODO: transport (http) level authentication using self._user_name and
# self._password # self._password
return WSDLConnection(wsdl, self._credentials, self._service) return WSDLConnection(wsdl, self._credentials, self._service)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment