Package ndg :: Package soap :: Package server :: Package wsgi :: Module middleware
[hide private]

Source Code for Module ndg.soap.server.wsgi.middleware

 1  """NDG Security SOAP Service Middleware 
 2   
 3  NERC DataGrid Project 
 4   
 5  """ 
 6  __author__ = "P J Kershaw" 
 7  __date__ = "27/05/08" 
 8  __copyright__ = "(C) 2009 Science and Technology Facilities Council" 
 9  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
10  __license__ = "BSD - see LICENSE file in top-level directory" 
11  __revision__ = "$Id: $" 
12  import logging 
13  log = logging.getLogger(__name__) 
14 15 16 -class SOAPMiddlewareError(Exception):
17 """Base error handling exception class for the SOAP WSGI middleware module 18 """ 19 _log = log
20 - def __init__(self, *arg, **kw):
21 '''Extend to enable logging of errors''' 22 if len(arg) > 0: 23 self.__class__._log.error(arg[0]) 24 Exception.__init__(self, *arg, **kw)
25
26 27 -class SOAPMiddlewareReadError(SOAPMiddlewareError):
28 """SOAP Middleware read error"""
29
30 31 -class SOAPMiddlewareConfigError(SOAPMiddlewareError):
32 """SOAP Middleware configuration error"""
33
34 35 -class SOAPMiddleware(object):
36 """SOAP WSGI base class""" 37 SOAP_FAULT_SET_KEYNAME = 'ndg.security.server.wsgi.soap.soapFault' 38 SOAP_ACTION_ENVIRON_KEYNAME = 'HTTP_SOAPACTION' 39 40 _str2Bool = lambda str: str.lower() in ["yes", "true", "t", "1"] 41 str2Bool = staticmethod(_str2Bool) 42 43 @classmethod
44 - def isSOAPMessage(cls, environ):
45 '''Generic method to filter out non-soap messages 46 47 TODO: is HTTP_SOAPACTION only set for WSDL doc-literal wrapped style 48 generated content? - If so this test should be moved''' 49 return environ.get('REQUEST_METHOD', '') == 'POST' and \ 50 environ.get(cls.SOAP_ACTION_ENVIRON_KEYNAME) is not None
51 52 @classmethod
53 - def isSOAPFaultSet(cls, environ):
54 '''Check environment for SOAP fault flag set. This variable is set 55 from exception2SOAPFault''' 56 return environ.get(cls.SOAP_FAULT_SET_KEYNAME, False) == True
57 58 @classmethod
59 - def filter_app_factory(cls, app, global_conf, **app_conf):
60 """Set-up using a Paste app factory pattern. 61 62 @type app: callable following WSGI interface 63 @param app: next middleware application in the chain 64 @type global_conf: dict 65 @param global_conf: PasteDeploy global configuration dictionary 66 @type app_conf: dict 67 @param app_conf: PasteDeploy application specific configuration 68 dictionary 69 """ 70 app = cls(app) 71 app.initialise(global_conf, **app_conf) 72 73 return app
74
75 - def initialise(self, global_conf, **app_conf):
76 """Set attributes from keyword dictionaries global and or app_conf 77 @type global_conf: dict 78 @param global_conf: PasteDeploy global configuration dictionary 79 @type prefix: basestring 80 @param prefix: prefix for configuration items 81 @type app_conf: dict 82 @param app_conf: PasteDeploy application specific configuration 83 """ 84 raise NotImplementedError()
85