Fault handling redirects in SOAPpy

Ivan R. Judson judson at mcs.anl.gov
Mon Mar 8 15:51:05 CST 2004



Looks cool; but I'm missing the motivation for it? Is something broken
without this?

--Ivan 

> -----Original Message-----
> From: owner-ag-dev at mcs.anl.gov 
> [mailto:owner-ag-dev at mcs.anl.gov] On Behalf Of Robert Olson
> Sent: Monday, March 08, 2004 2:55 PM
> To: ag-dev at mcs.anl.gov
> Subject: Fault handling redirects in SOAPpy
> 
> Try this on for size. In SOAPpy/CLient.py:
> 
> --- Client.py~  2004-02-17 22:05:59.000000000 -0600
> +++ Client.py   2004-03-08 14:45:21.000000000 -0600
> @@ -339,11 +339,46 @@
>               header = hd, methodattrs = ma, encoding = self.encoding,
>               config = self.config, noroot = self.noroot)
> 
> -        r, self.namespace = self.transport.call(self.proxy, 
> m, ns, sa,
> -                                                encoding = 
> self.encoding,
> -                                                http_proxy = 
> self.http_proxy,
> -                                                config = self.config)
> 
> +        call_retry = 0
> +        try:
> +
> +            r, self.namespace = 
> self.transport.call(self.proxy, m, ns, sa,
> +                                                    encoding 
> = self.encoding,
> +                                                    http_proxy =
> self.http_proxy,
> +                                                    config = 
> + self.config)
> +
> +        except Exception, ex:
> +            #
> +            # Call failed.
> +            #
> +            # See if we have a fault handling vector installed in our
> +            # config. If we do, invoke it. If it returns a 
> true value,
> +            # retry the call.
> +            #
> +            # In any circumstance other than the fault 
> handler returning
> +            # true, reraise the exception. This keeps the 
> semantics of this
> +            # code the same as without the fault_handler code.
> +            #
> +
> +            if hasattr(self.config, "fault_handler"):
> +                if callable(self.config.fault_handler):
> +                    call_retry = 
> self.config.fault_handler(self.proxy, ex)
> +                    if not call_retry:
> +                        raise
> +                else:
> +                    raise
> +            else:
> +                raise
> +
> +        if call_retry:
> +            r, self.namespace = 
> self.transport.call(self.proxy, m, ns, sa,
> +                                                    encoding 
> = self.encoding,
> +                                                    http_proxy =
> self.http_proxy,
> +                                                    config = 
> + self.config)
> +
> +
> +        print r
>           p, attrs = parseSOAPRPC(r, attrs = 1)
> 
>           try:
> 
> With this mod to hosting/SOAPpy/Client.py:
> 
> diff -u -r1.6 Client.py
> --- Client.py   2 Mar 2004 19:12:47 -0000       1.6
> +++ Client.py   8 Mar 2004 20:51:20 -0000
> @@ -29,7 +29,7 @@
>       A class that encapsulates a SOAP proxy.
>       """
>       def __init__(self, url, namespace = None, authCallback 
> = None, debug = 0,
> -                 config = None):
> +                 config = None, faultHandler = None):
>           """
>           @param url: the url to the service
>           @param namespace: the namespace for the service @@ 
> -46,6 +46,7 @@
>               self.config = config
> 
>           self.config.debug = debug
> +        self.config.fault_handler = faultHandler
>           self.url = url.replace("https", "httpg")
>           self.proxy = None
>           self.namespace = namespace
> 
> We can write:
> 
> def fh(proxy, ex):
>     print "Fault handler invoked! proxy=%s exception=%s" % (proxy, ex)
>     return 0
> 
> try:
>    self.profile.capabilities = Client.Handle( self.nodeServiceUri,
>                                    faultHandler = fh).
> 					GetProxy().GetCapabilities()
> 
> 
> A non-stub fault handler would do something like query the 
> local cert mgmt infrastructure, which can interact with the 
> user, to create the right flavor of proxy if possible, and 
> return 1 to have the soap level retry the call.
> 
> Thoughts?
> 
> --bob
> 
> 




More information about the ag-dev mailing list