예제 #1
0
def payload_from_request(cid, request, data_format, transport):
    """ Converts a raw request to a payload suitable for usage with SimpleIO.
    """
    if request is not None:
        if data_format == DATA_FORMAT.XML:
            if transport == 'soap':
                if isinstance(request, objectify.ObjectifiedElement):
                    soap = request
                else:
                    soap = objectify.fromstring(request)
                body = soap_body_xpath(soap)
                if not body:
                    raise ZatoException(
                        cid, 'Client did not send the [{}] element'.format(
                            soap_body_path))
                payload = get_body_payload(body)
            else:
                if isinstance(request, objectify.ObjectifiedElement):
                    payload = request
                else:
                    payload = objectify.fromstring(request)
        elif data_format in (DATA_FORMAT.DICT, DATA_FORMAT.JSON):
            if not request:
                return ''
            if isinstance(request,
                          basestring) and data_format == DATA_FORMAT.JSON:
                payload = loads(request)
            else:
                payload = request
        else:
            payload = request
    else:
        payload = request

    return payload
예제 #2
0
파일: util.py 프로젝트: m0rcq/zato
def payload_from_request(cid, request, data_format, transport):
    """ Converts a raw request to a payload suitable for usage with SimpleIO.
    """
    if request is not None:
        if data_format == DATA_FORMAT.XML:
            if transport == 'soap':
                if isinstance(request, objectify.ObjectifiedElement):
                    soap = request
                else:
                    soap = objectify.fromstring(request)
                body = soap_body_xpath(soap)
                if not body:
                    raise ZatoException(cid, 'Client did not send the [{}] element'.format(soap_body_path))
                payload = get_body_payload(body)
            else:
                if isinstance(request, objectify.ObjectifiedElement):
                    payload = request
                else:
                    payload = objectify.fromstring(request)
        elif data_format == DATA_FORMAT.JSON:
            if not request:
                return ''
            if isinstance(request, basestring):
                payload = loads(request)
            else:
                payload = request
        else:
            payload = request
    else:
        payload = request

    return payload
예제 #3
0
파일: test_util.py 프로젝트: Adniel/zato
    def test_zato_path(self):
        xml = etree.fromstring("""<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
         xmlns="https://zato.io/ns/20130518">
      <soap:Body>
            <zato_channel_amqp_edit_response xmlns="https://zato.io/ns/20130518">
               <zato_env>
                  <cid>K08984532360785332835581231451</cid>
                  <result>ZATO_OK</result>
               </zato_env>
               <item>
                  <id>1</id>
                  <name>crm.account</name>
               </item>
            </zato_channel_amqp_edit_response>
      </soap:Body>
   </soap:Envelope>""")

        request = soap_body_xpath(xml)[0].getchildren()[0]
        zato_path('item', True).get_from(request)
        
        path = uuid4().hex
        try:
            zato_path(path, True).get_from(request)
        except ParsingException:
            pass
        else:
            raise AssertionError('Expected an ParsingException with path:[{}]'.format(path))
예제 #4
0
    def test_zato_path(self):
        xml = etree.fromstring(
            """<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
         xmlns="https://zato.io/ns/20130518">
      <soap:Body>
            <zato_channel_amqp_edit_response xmlns="https://zato.io/ns/20130518">
               <zato_env>
                  <cid>K08984532360785332835581231451</cid>
                  <result>ZATO_OK</result>
               </zato_env>
               <item>
                  <id>1</id>
                  <name>crm.account</name>
               </item>
            </zato_channel_amqp_edit_response>
      </soap:Body>
   </soap:Envelope>""")

        request = soap_body_xpath(xml)[0].getchildren()[0]
        zato_path('item', True).get_from(request)

        path = uuid4().hex
        try:
            zato_path(path, True).get_from(request)
        except ParsingException:
            pass
        else:
            raise AssertionError(
                'Expected an ParsingException with path:[{}]'.format(path))
예제 #5
0
파일: http_soap.py 프로젝트: brtsz/zato
    def init(self, rid, task, request, headers, transport):
        logger.debug('[{0}] request:[{1}] headers:[{2}]'.format(rid, request, headers))

        if transport == 'soap':
            # HTTP headers are all uppercased at this point.
            soap_action = headers.get('SOAPACTION')
    
            if not soap_action:
                raise BadRequest(rid, 'Client did not send the SOAPAction header')
    
            # SOAP clients may send an empty header, i.e. SOAPAction: "",
            # as opposed to not sending the header at all.
            soap_action = soap_action.lstrip('"').rstrip('"')
    
            if not soap_action:
                raise BadRequest(rid, 'Client sent an empty SOAPAction header')
        else:
            soap_action = None

        _soap_actions = self.http_soap.getall(task.request_data.uri)
        for _soap_action_info in _soap_actions:
            if soap_action in _soap_action_info:
                _service_info = _soap_action_info[soap_action]
                break
        else:
            msg = '[{0}] Could not find the service config for URL:[{1}], SOAP action:[{2}]'.format(
                rid, task.request_data.uri, soap_action)
            logger.warn(msg)
            raise NotFound(rid, msg)

        logger.debug('[{0}] impl_name:[{1}]'.format(rid, _service_info.impl_name))

        logger.log(TRACE1, '[{0}] service_store.services:[{1}]'.format(rid, self.server.service_store.services))
        service_data = self.server.service_store.service_data(_service_info.impl_name)

        if transport == 'soap':
            soap = objectify.fromstring(request)
            body = soap_body_xpath(soap)
    
            if not body:
                raise BadRequest(rid, 'Client did not send the [{1}] element'.format(body_path))
            payload = get_body_payload(body)
        else:
            payload = request
        
        return payload, _service_info.impl_name, service_data
예제 #6
0
파일: util.py 프로젝트: dsuch/zato
def payload_from_request(request, data_format, transport):
    """ Converts a raw request to a payload suitable for usage with SimpleIO.
    """
    if request:
        if data_format == SIMPLE_IO.FORMAT.XML:
            if transport == 'soap':
                soap = objectify.fromstring(request)
                body = soap_body_xpath(soap)
                if not body:
                    raise ZatoException(cid, 'Client did not send the [{1}] element'.format(body_path))
                payload = get_body_payload(body)
            else:
                payload = objectify.fromstring(request)
        elif data_format == SIMPLE_IO.FORMAT.JSON:
            payload = loads(request)
        else:
            payload = request
    else:
        payload = request

    return payload