Exemple #1
0
def make_soap_fault(faultString, faultCode = 'Server', detail = None, 
    header_elements = None):
    '''
    This method populates a soap fault message with the provided 
    fault string and details.  
    @param faultString the short description of the error
    @param detail the details of the exception, such as a stack trace
    @param faultCode defaults to 'Server', but can be overridden
    @param header_elements A list of XML elements to add to the fault header.
    @returns the element corresponding to the fault message
    '''
    
    nsmap = NamespaceLookup()
    envelope = create_xml_element(nsmap.get('SOAP-ENV') + 'Envelope', nsmap)
    
    if header_elements:
        header = create_xml_subelement(
            envelope, nsmap.get('SOAP-ENV') + 'Header')
        for element in header_elements:
            header.append(element)
    
    body = create_xml_subelement(envelope, nsmap.get('SOAP-ENV') + 'Body')

    f = Fault(faultCode,faultString,detail)
    body.append(Fault.to_xml(f, nsmap.get('SOAP-ENV') + "Fault", nsmap))

    return envelope
Exemple #2
0
def make_soap_fault(faultString, faultCode='Server', detail=None):
    '''
    This method populates a soap fault message with the provided fault string and 
    details.  
    @param faultString the short description of the error
    @param detail the details of the exception, such as a stack trace
    @param faultCode defaults to 'Server', but can be overridden
    @returns the element corresponding to the fault message
    '''
    envelope = ElementTree.Element('SOAP-ENV:Envelope')
    envelope.set('xmlns:SOAP-ENV','http://schemas.xmlsoap.org/soap/envelope/')

    body = ElementTree.SubElement(envelope,'SOAP-ENV:Body')
    
    f = Fault(faultCode,faultString,detail)
    body.append(Fault.to_xml(f))

    return envelope
     def __call__(self,*args,**kwargs):
         # copied & simplified from soaplib.client.SimpleSoapClient
        if len(args) != len(self.descriptor.inMessage.params):
            argstring = '\r\n'.join([ '    ' + str(arg) for arg in args ])
            paramstring = '\r\n'.join([ '    ' + str(p[0]) for p in self.descriptor.inMessage.params ])
            err_msg = _err_format % (argstring, paramstring)
            raise Exception(err_msg)

        msg = self.descriptor.inMessage.to_xml(*args)

        # grab the soap headers passed into this call
        headers = kwargs.get('headers', [])
        msgid = kwargs.get('msgid')
        if msgid:
            # special case for the msgid field as a convenience
            # when dealing with async callback methods
            headers.append(create_relates_to_header(msgid))

        envelope = make_soap_envelope(msg, header_elements=headers)

        body = ElementTree.tostring(envelope)
        # removed http header logic - not needed for django test client

        # use django.test.client to send request
        client = Client()
        response = client.post(self.path, body, content_type="text/xml")
        data = response.content        
        
        if str(response.status_code) not in ('200', '202'):
            # consider everything NOT 200 or 202 as an error response
            
            if str(response.status_code) == '500': 
                fault = None
                try:
                    payload, headers = from_soap(data)
                    fault = Fault.from_xml(payload)
                except:
                    trace = StringIO()
                    import traceback
                    traceback.print_exc(file=trace)
                    
                    fault = Exception('Unable to read response \n  %s %s \n %s \n %s' % \
                            (response.status, response.reason, trace.getvalue(), data))
                raise fault
            else:
                raise Exception('%s %s' % (response.status,response.reason,))

        if not self.descriptor.outMessage.params:            
            return

        payload, headers = from_soap(data)        
        
        results = self.descriptor.outMessage.from_xml(payload)        
        return results[0]
Exemple #4
0
def make_soap_fault(faultString,
                    faultCode='Server',
                    detail=None,
                    header_elements=None):
    '''
    This method populates a soap fault message with the provided
    fault string and details.
    @param faultString the short description of the error
    @param detail the details of the exception, such as a stack trace
    @param faultCode defaults to 'Server', but can be overridden
    @param header_elements A list of XML elements to add to the fault header.
    @returns the element corresponding to the fault message
    '''
    nsmap = NamespaceLookup()
    envelope = create_xml_element(nsmap.get('SOAP-ENV') + 'Envelope', nsmap)
    if header_elements:
        header = create_xml_subelement(envelope,
                                       nsmap.get('SOAP-ENV') + 'Header')
        for element in header_elements:
            header.append(element)
    body = create_xml_subelement(envelope, nsmap.get('SOAP-ENV') + 'Body')
    f = Fault(faultCode, faultString, detail)
    body.append(Fault.to_xml(f, nsmap.get('SOAP-ENV') + "Fault", nsmap))
    return envelope
Exemple #5
0
def make_soap_fault(faultString, faultCode='Server', detail=None):
    '''
    This method populates a soap fault message with the provided fault string and 
    details.  
    @param faultString the short description of the error
    @param detail the details of the exception, such as a stack trace
    @param faultCode defaults to 'Server', but can be overridden
    @returns the element corresponding to the fault message
    '''
    envelope = ElementTree.Element('SOAP-ENV:Envelope')
    envelope.set('xmlns:SOAP-ENV','http://schemas.xmlsoap.org/soap/envelope/')

    body = ElementTree.SubElement(envelope,'SOAP-ENV:Body')
    
    f = Fault(faultCode,faultString,detail)
    body.append(Fault.to_xml(f))

    return envelope
Exemple #6
0
 def __init__(self, dberr):
     Fault.__init__(self, faultcode="ElbeDBError", faultstring=str(dberr))
Exemple #7
0
 def __init__(self):
     Fault.__init__(self, faultcode="ElbeInvalidState", faultstring="Project is Busy ! Operation Invalid")
Exemple #8
0
 def __init__(self):
     Fault.__init__(self,
                    faultcode="ElbeAuthenticationFailed",
                    faultstring="Authentication Failed")
Exemple #9
0
 def __init__(self):
     Fault.__init__(self, faultcode="ElbeNotAuthorized", faultstring="Not Authorized ! Cant let you perform this command.")
Exemple #10
0
 def __init__(self, exc):
     Fault.__init__(self, faultcode="ElbeValidationError", faultstring=exc.__repr__())
Exemple #11
0
 def __init__(self, err):
     Fault.__init__(self,
                    faultcode="ElbeProjectError",
                    faultstring=str(err))
Exemple #12
0
 def __init__(self):
     Fault.__init__(self, faultcode="ElbeNotLoggedIn", faultstring="Not authenticated ! Cant let you perform this command.")
Exemple #13
0
    def __call__(self, *args, **kwargs):
        '''
        This method executes the http request to the remote web service.  With
        the exception of 'headers', 'msgid', and 'mtom'; all keyword arguments
        to this method are put in the http header.  The 'headers' keyword is to
        denote a list of elements to be included in the soap header, 'msgid'
        is a convenience keyword used in async web services which creates a
        WS-Addressing messageid header to be included in the soap headers, and
        'mtom' enables the Message Transmission Optimization Mechanism.

        @param the arguments to the remote method
        @param the keyword arguments
        '''
        if len(args) != len(self.descriptor.inMessage.params):
            argstring = '\r\n'.join(['    ' + str(arg) for arg in args])
            paramstring = '\r\n'.join(
                ['    ' + str(p[0]) for p in self.descriptor.inMessage.params])
            err_msg = _err_format % (argstring, paramstring)
            raise Exception(err_msg)

        msg = self.descriptor.inMessage.to_xml(*args)

        # grab the soap headers passed into this call
        headers = kwargs.get('headers', [])
        mtom = kwargs.get('mtom', False)
        msgid = kwargs.get('msgid')
        if msgid:
            # special case for the msgid field as a convenience
            # when dealing with async callback methods
            headers.append(create_relates_to_header(msgid))

        tns = self.descriptor.inMessage.ns
        envelope = make_soap_envelope(msg, tns, header_elements=headers)

        body = ElementTree.tostring(envelope)
        methodName = '\"%s\"' % self.descriptor.soapAction
        httpHeaders = {
            'Content-Length':
            len(body),
            'Content-type':
            'text/xml; charset="UTF-8"',
            'Accept': ('application/soap+xml, application/dime, '
                       'multipart/related, text/*'),
            'User-Agent':
            'Soaplib/1.0',
            'SOAPAction':
            methodName,
        }

        for k, v in kwargs.items():
            # add all the other keywords to the http headers
            if k not in ('headers', 'msgid', 'mtom'):
                httpHeaders[k] = v

        if mtom:
            httpHeaders, body = apply_mtom(httpHeaders, body,
                                           self.descriptor.inMessage.params,
                                           args)

        dump(self.host, self.path, httpHeaders, body)

        if self.scheme == "http":
            conn = httplib.HTTPConnection(self.host)
        elif self.scheme == "https":
            conn = httplib.HTTPSConnection(self.host)
        else:
            raise RuntimeError("Unsupported URI connection scheme: %s" %
                               self.scheme)

        conn.request("POST", self.path, body=body, headers=httpHeaders)
        response = conn.getresponse()
        data = response.read()

        dump(self.host, self.path, dict(response.getheaders()), data)

        contenttype = response.getheader('Content-Type')
        data = collapse_swa(contenttype, data)

        conn.close()
        if str(response.status) not in ['200', '202']:
            # consider everything NOT 200 or 202 as an error response

            if str(response.status) == '500':
                fault = None
                try:
                    payload, headers = from_soap(data)
                    fault = Fault.from_xml(payload)
                except:
                    trace = StringIO()
                    import traceback
                    traceback.print_exc(file=trace)

                    fault = Exception("Unable to read response \n"
                                      "%s %s \n %s \n %s" %
                                      (response.status, response.reason,
                                       trace.getvalue(), data))
                raise fault
            else:
                raise Exception("%s %s" % (response.status, response.reason))

        if not self.descriptor.outMessage.params:
            return

        payload, headers = from_soap(data)
        results = self.descriptor.outMessage.from_xml(payload)
        #TODO: consider supporting multiple return types in a better manner
        if len(results) > 1:
            return results
        return results[0]
Exemple #14
0
 def __init__(self):
     Fault.__init__(
         self,
         faultcode="ElbeNotLoggedIn",
         faultstring="Not authenticated ! Cant let you perform this command."
     )
Exemple #15
0
 def __init__(self):
     Fault.__init__(
         self,
         faultcode="ElbeNotAuthorized",
         faultstring="Not Authorized ! Cant let you perform this command.")
Exemple #16
0
 def __init__(self):
     Fault.__init__(self,
                    faultcode="ElbeInvalidState",
                    faultstring="Project is Busy ! Operation Invalid")
Exemple #17
0
 def __init__(self, exc):
     Fault.__init__(self,
                    faultcode="ElbeValidationError",
                    faultstring=exc.__repr__())
Exemple #18
0
 def __init__(self, err):
     Fault.__init__(self, faultcode="ElbeProjectError", faultstring=str(err))
Exemple #19
0
 def __init__(self):
     Fault.__init__(self, faultcode="ElbeAuthenticationFailed", faultstring="Authentication Failed")
Exemple #20
0
    def __call__(self, *args, **kwargs):
        '''
        This method executes the http request to the remote web service.  With
        the exception of 'headers', 'msgid', and 'mtom'; all keyword arguments
        to this method are put in the http header.  The 'headers' keyword is to
        denote a list of elements to be included in the soap header, 'msgid'
        is a convenience keyword used in async web services which creates a
        WS-Addressing messageid header to be included in the soap headers, and
        'mtom' enables the Message Transmission Optimization Mechanism.

        @param the arguments to the remote method
        @param the keyword arguments
        '''
        if len(args) != len(self.descriptor.inMessage.params):
            argstring = '\r\n'.join(['    ' + str(arg) for arg in args])
            paramstring = '\r\n'.join(['    ' + str(p[0])
                for p in self.descriptor.inMessage.params])
            err_msg = _err_format % (argstring, paramstring)
            raise Exception(err_msg)

        msg = self.descriptor.inMessage.to_xml(*args)

        # grab the soap headers passed into this call
        headers = kwargs.get('headers', [])
        mtom = kwargs.get('mtom', False)
        msgid = kwargs.get('msgid')
        if msgid:
            # special case for the msgid field as a convenience
            # when dealing with async callback methods
            headers.append(create_relates_to_header(msgid))

        tns = self.descriptor.inMessage.ns
        envelope = make_soap_envelope(msg, tns, header_elements=headers)

        body = ElementTree.tostring(envelope)
        methodName = '\"%s\"' % self.descriptor.soapAction
        httpHeaders = {'Content-Length': len(body),
                      'Content-type': 'text/xml; charset="UTF-8"',
                      'Accept': ('application/soap+xml, application/dime, '
                                'multipart/related, text/*'),
                      'User-Agent': 'Soaplib/1.0',
                      'SOAPAction': methodName,
                      }

        for k, v in kwargs.items():
            # add all the other keywords to the http headers
            if k not in ('headers', 'msgid', 'mtom'):
                httpHeaders[k] = v

        if mtom:
            httpHeaders, body = apply_mtom(httpHeaders, body,
                self.descriptor.inMessage.params, args)

        dump(self.host, self.path, httpHeaders, body)

        if self.scheme == "http":
            conn = httplib.HTTPConnection(self.host)
        elif self.scheme == "https":
            conn = httplib.HTTPSConnection(self.host)
        else:
            raise RuntimeError("Unsupported URI connection scheme: %s" %
                self.scheme)

        conn.request("POST", self.path, body=body, headers=httpHeaders)
        response = conn.getresponse()
        data = response.read()

        dump(self.host, self.path, dict(response.getheaders()), data)

        contenttype = response.getheader('Content-Type')
        data = collapse_swa(contenttype, data)

        conn.close()
        if str(response.status) not in['200', '202']:
            # consider everything NOT 200 or 202 as an error response

            if str(response.status) == '500':
                fault = None
                try:
                    payload, headers = from_soap(data)
                    fault = Fault.from_xml(payload)
                except:
                    trace = StringIO()
                    import traceback
                    traceback.print_exc(file=trace)

                    fault = Exception("Unable to read response \n"
                        "%s %s \n %s \n %s" %
                        (response.status, response.reason, trace.getvalue(),
                         data))
                raise fault
            else:
                raise Exception("%s %s" % (response.status, response.reason))

        if not self.descriptor.outMessage.params:
            return

        payload, headers = from_soap(data)
        results = self.descriptor.outMessage.from_xml(payload)
        return results[0]
Exemple #21
0
 def __init__(self, dberr):
     Fault.__init__(self, faultcode="ElbeDBError", faultstring=str(dberr))