Changeset bb3769a


Ignore:
Timestamp:
Jul 16, 2008 11:28:14 AM (16 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
Children:
0c0b13c
Parents:
0a47d52
Message:

parsing SOAP faults (finally)

Location:
fedd
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd.py

    r0a47d52 rbb3769a  
    123123                            fedid(cert=self.request.get_peer_cert()))
    124124                data = xmlrpclib.dumps((resp,), methodresponse=True)
    125             except Fault, f:
    126                 xf = xmlrpclib.Fault(f.code, f.string)
    127                 data = xmlrpclib.dumps(xf, methodresponse=True)
    128                 resp = None
     125            #except Fault, f:
     126        #       xf = xmlrpclib.Fault(f.code, f.string)
     127        #       data = xmlrpclib.dumps(xf, methodresponse=True)
     128        #       resp = None
    129129            except xmlrpclib.Fault, f:
    130130                data = xmlrpclib.dumps(f, methodresponse=True)
  • fedd/fedd_bindings.wsdl

    r0a47d52 rbb3769a  
    2222        <soap:operation soapAction=""/>
    2323        <input>
    24           <soap:body use="encoded" part="tns:RequestAccessRequestBody"
     24          <soap:body use="encoded" parts="tns:RequestAccessRequestBody"
    2525            namespace="http://www.isi.edu/faber/fedd.wsdl"
    2626            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
    2727        </input>
    2828        <output>
    29           <soap:body use="encoded" part="tns:RequestAccessResponseBody"
     29          <soap:body use="encoded" parts="tns:RequestAccessResponseBody"
    3030            namespace="http://www.isi.edu/faber/fedd.wsdl"
    3131            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  • fedd/fedd_client.py

    r0a47d52 rbb3769a  
    1313from xmlrpclib import ServerProxy, Error, dumps, loads
    1414from ZSI import SoapWriter
     15from ZSI.TC import QName, String, URI, AnyElement, UNBOUNDED, Any
     16from ZSI.wstools.Namespaces import SOAP
     17from ZSI.fault import FaultType, Detail
    1518
    1619import xmlrpclib
     
    2023
    2124from optparse import OptionParser, OptionValueError
     25
     26import parse_detail
    2227
    2328# Turn off the matching of hostname to certificate ID
     
    269274if opts.debug > 1: print >>sys.stderr, msg
    270275
     276print FaultType.typecode;
     277
    271278if opts.transport == "soap":
    272279    loc = feddServiceLocator();
     
    292299        sys.exit("Malformed response (XMLPRC?): %s" % e)
    293300    except ZSI.FaultException, e:
    294         sys.exit("Fault: %s" % e)
     301        print dir(e.fault.detail[0])
     302        print e.fault.detail[0].RequestAccessFaultBody.get_element_code()
     303        d = unpack_soap(e.fault.detail[0].get_element_RequestAccessFaultBody())
     304        f = unpack_soap(e.fault.detail[0])
     305        print "unpack ", d
     306        print "unpack ", f
     307        sys.exit("Fault: %s %s" % (str(e.fault.code), str(e.fault.string)))
    295308
    296309
  • fedd/fedd_messages.wsdl

    r0a47d52 rbb3769a  
    1515  </message>
    1616
     17  <message name="RequestAccessFaultMessage">
     18    <part name="RequestAccessFaultBody" type="xsd1:faultType"/>
     19  </message>
     20
    1721
    1822  <portType name="feddPortType">
     
    2428      <output message="tns:RequestAccessResponseMessage"/>
    2529      <fault name="RequestAccessFault"
    26         message="tns:RequestAccessResponseMessage"/>
     30        message="tns:RequestAccessFaultMessage"/>
    2731    </operation>
    2832  </portType>
  • fedd/fedd_proj.py

    r0a47d52 rbb3769a  
    2020from fedd_services import *
    2121from fedd_util import *
     22
     23if False:
     24    _RequestAccessFault_typecode = Struct(pname=("http://www.isi.edu/faber/fedd.wsdl", 'RequestAccessFault'), ofwhat=[ns0.faultType_Def( pname=("http://www.isi.edu/faber/fedd.wsdl", "RequestAccessFaultBody"), aname="_RequestAccessFaultBody", minoccurs=0, maxoccurs=1, nillable=True, encoded=None, typed=True)], pyclass=None)
     25    class RequestAccessFault:
     26        typecode = _RequestAccessFault_typecode
     27        __metaclass__ = pyclass_type
     28        def __init__(self, code=0, str="str"):
     29            self._RequestAccessFaultBody = None
     30    RequestAccessFault.typecode.pyclass=RequestAccessFault
    2231
    2332class fedd_proj:
     
    5766                return "access_proj('%s', [])" % self.name
    5867
    59 
    60     class parse_error(RuntimeError):
    61         """Raised if the configuration file is unparsable"""
    62         pass
     68    # These are used to make the error reporting independent of the transport.
     69    # The XMLRPC and SOAP dispatchers will convert them to transport-specific
     70    # errors
     71    class server_error(RuntimeError): pass
     72    class client_error(RuntimeError): pass
     73    # Error parsing config
     74    class parse_error(RuntimeError): pass
     75
    6376
    6477    def __init__(self, config=None):
     
    216229                    rc = subprocess.call(cmd)
    217230                except OSerror, e:
    218                     raise Fault(Fault.Server,
     231                    raise fedd_proj.server_error(
    219232                            "Dynamic project subprocess creation error "+ \
    220233                                    "[%s] (%s)" %  (cmd[1], e.strerror))
     
    223236
    224237            if rc != 0:
    225                 raise Fault(Fault.Server,
     238                raise fedd_proj.server_error(
    226239                        "Dynamic project subprocess error " +\
    227240                                "[%s] (%d)" % (cmd[1], rc))
     
    253266            ctx = fedd_ssl_context(self.cert_file, tc, password=self.cert_pwd)
    254267        except SSL.SSLError:
    255             raise Fault(Fault.Server, "Server certificates misconfigured")
     268            raise fedd_proj.server_error("Server certificates misconfigured")
    256269
    257270        # Of all the dumbass things.  The XMLRPC library in use here won't
     
    274287            resp, method = xmlrpclib.loads(resp)
    275288        except xmlrpclib.Error, e:
    276             raise Fault(Fault.Server, "Remote XMLRPC Fault: %s" % e)
     289            raise fedd_proj.server_error("Remote XMLRPC Fault: %s" % e)
    277290       
    278291        if resp[0].has_key('RequestAccessResponseBody'):
    279292            return resp[0]['RequestAccessResponseBody']
    280293        else:
    281             raise Fault(Fault.Server, "Bad proxy response")
     294            raise fedd_proj.server_error("Bad proxy response")
    282295
    283296    def proxy_request(self, dt, req):
     
    295308            ctx = fedd_ssl_context(self.cert_file, tc, password=self.cert_pwd)
    296309        except SSL.SSLError:
    297             raise Fault(Fault.Server, "Server certificates misconfigured")
     310            raise fedd_proj.server_error("Server certificates misconfigured")
    298311
    299312        loc = feddServiceLocator();
     
    309322            resp = port.RequestAccess(msg)
    310323        except ZSI.ParseException, e:
    311             raise Fault(Fault.Server, "Bad format message (XMLRPC??): %s" %
     324            raise fedd_proj.server_error("Bad format message (XMLRPC??): %s" %
    312325                    str(e))
    313326        except ZSI.FaultException, e:
     
    319332            return r['RequestAccessResponseBody']
    320333        else:
    321             raise Fault(Fault.Server, "Bad proxy response")
     334            raise fedd_proj.server_error("Bad proxy response")
    322335
    323336    def permute_wildcards(self, a, p):
     
    388401                fedids = [ u for u in user if isinstance(u, type(fid))]
    389402                if len(fedids) > 1:
    390                     raise Fault(Fault.Client,
     403                    raise fedd_proj.client_error(
    391404                            "User asserting multiple fedids")
    392405                elif len(fedids) == 1 and fedids[0] != fid:
    393                     raise Fault(Fault.Client,
     406                    raise fedd_proj.client_error(
    394407                            "User asserting different fedid")
    395408            project = None
     
    397410        elif principal_type == "project":
    398411            if isinstance(project, type(fid)) and fid != project:
    399                 raise Fault(Fault.Client,
     412                raise fedd_proj.client_error(
    400413                        "Project asserting different fedid")
    401414            tb = None
     
    406419        print "Found: ", found
    407420       
    408         if found == None: raise Fault(Fault.Server, "Access denied")
     421        if found == None: raise fedd_proj.server_error("Access denied")
    409422
    410423        # resolve <dynamic> and <same> in found
     
    416429                found[0].name = project
    417430            else :
    418                 raise Fault(Fault.Server,
     431                raise fedd_proj.server_error(
    419432                        "Project matched <same> when no project given")
    420433        elif found[0].name == "<dynamic>":
     
    425438            if user_match == "<any>":
    426439                if user != None: found = (found[0], user[0])
    427                 else: raise Fault(Fault.Server,
     440                else: raise fedd_proj.server_error(
    428441                        "Matched <same> on anonymous request")
    429442            else:
     
    474487            req = req['RequestAccessRequestBody']
    475488        else:
    476             raise Fault(Fault.Client, "No request!?")
     489            raise fedd_proj.client_error("No request!?")
    477490
    478491        if req.has_key('destinationTestbed'):
     
    492505                                                t not in found[0].node_types]
    493506                if len(inaccessible) > 0:
    494                     raise Fault(Fault.Server,
     507                    raise fedd_proj.server_error(
    495508                            "Access denied (nodetypes %s)" % \
    496509                            str(', ').join(inaccessible))
     
    503516                else: pass    # SSH key additions
    504517            else:
    505                 raise Fault(Fault.Client, "SSH access parameters required")
     518                raise fedd_proj.client_error("SSH access parameters required")
    506519
    507520            resp = self.build_response(req['allocID'], found, ssh)
     
    512525                # Proxy the request using SOAP
    513526                return self.proxy_request(dt, req)
    514             except Fault, f:
     527            except RuntimeError, f:
    515528                p_fault = f
    516529         
     
    519532            try:
    520533                return self.proxy_xmlrpc_request(dt, req)
    521             except Fault:
     534                print "here"
     535            except RuntimeError:
    522536                # Both failed, return the SOAP error.  If somehow that
    523537                # exception is gone, return the XMLRPC one
     
    529543
    530544        msg = self.RequestAccess(unpack_soap(req), fedid)
     545       
    531546        resp = RequestAccessResponseMessage()
    532 
    533547        resp.set_element_RequestAccessResponseBody(
    534548                pack_soap(resp, "RequestAccessResponseBody", msg))
     549
    535550        return resp
    536551
    537552    def xmlrpc_RequestAccess(self, params, fid):
    538553        msg = self.RequestAccess(params[0], fedid)
     554
    539555        if msg != None:
    540556            return xmlrpclib.dumps(({ "RequestAccessResponseBody": msg },))
     557        else:
     558            raise server_error("No response generated?!");
    541559
    542560    def read_trust(self, trust):
     
    709727    def soap_dispatch(self, method, req, fid):
    710728        if fedd_proj.soap_methods.has_key(method):
    711             return getattr(self, fedd_proj.soap_methods[method])(req, fid)
     729            try:
     730                return getattr(self, fedd_proj.soap_methods[method])(req, fid)
     731            except fedd_proj.server_error, e:
     732                de = ns0.faultType_Def((ns0.faultType_Def.schema,"RequestAccessFaultBody")).pyclass()
     733                de._code=100
     734                de._desc="temp"
     735                f = Fault(Fault.Server, "Server Test", detail=de)
     736                raise f
     737            except fedd_proj.client_error, e:
     738                raise Fault(Fault.Client, str(e))
    712739        else:
    713740            raise Fault(Fault.Client, "Unknown method: %s" % method)
     
    715742    def xmlrpc_dispatch(self, method, req, fid):
    716743        if fedd_proj.xmlrpc_methods.has_key(method):
    717             return getattr(self, fedd_proj.xmlrpc_methods[method])(req, fid)
     744            try:
     745                return getattr(self, fedd_proj.xmlrpc_methods[method])(req, fid)
     746            except fedd_proj.server_error, e:
     747                raise xmlrpclib.Fault("server", str(e))
     748            except fedd_proj.client_error, e:
     749                raise xmlrpclib.Fault("client", str(e))
    718750        else:
    719751            raise xmlrpclib.Fault(100, "Unknown method: %s" % method)
  • fedd/fedd_types.xsd

    r0a47d52 rbb3769a  
    183183  </xsd:complexType>
    184184
     185  <xsd:complexType name="faultType">
     186    <xsd:sequence>
     187      <xsd:element name="code" type="xsd:int"/>
     188      <xsd:element name="desc" type="xsd:string"/>
     189    </xsd:sequence>
     190  </xsd:complexType>
     191
    185192</xsd:schema>
Note: See TracChangeset for help on using the changeset viewer.