def set_data(self): if self._set_data_details(): data = self.xpath(self.data) if not data: self.details = 'No {} in SOAP response'.format(self.path) else: if soap_fault_xpath(data[0]): self.details = data[0] else: self.data = data[0] self.ok = True return True
def init(self): response = objectify.fromstring(self.inner.text) soap_fault = soap_fault_xpath(response) if soap_fault: self.details = soap_fault[0] else: zato_data = zato_data_xpath(response) if not zato_data: msg = 'Server did not send a business payload ({} element is missing), soap_response:[{}]'.format( zato_data_path, self.inner.text) self.details = msg # We have a payload but hadn't there been any errors at the server's side? zato_result = zato_result_xpath(response) if zato_result[0] == ZATO_OK: self.ok = True self.data = zato_data[0] self.has_data = True else: self.details = zato_details_xpath(response)[0]
def invoke_admin_service(cluster, soap_action, soap_body="", headers={}, needs_config_key=False): """ Invokes a Zato server's administrative SOAP service. Returns an lxml's objectified response if no errors have been encountered. Raises a ZatoException if the response doesn't pass the formal validation. cluster - a cluster whose load balancer will be invoked soap_action - a SOAP action to invoke soap_body - an optional SOAP payload to pass to the admin service needs_config_key - whether the invoker should validate that a server's config crypto key has been returned in the response. Will raise a ZatoException if it hasn't and 'needs_config_key' is True. """ url = '' path = '' soap_response = '' try: url = 'http://{0}:{1}'.format(cluster.lb_host, cluster.lb_port) path = '/zato/soap' logger.log(TRACE1, 'About to invoke the admin service url:[{0}]'.format(url)) pool = SOAPPool(url) soap_response = pool.invoke(path, soap_action, soap_body, headers) try: logger.log(TRACE1, 'soap_response:[{0}]'.format(soap_response)) response = objectify.fromstring(soap_response) except Exception, e: msg = 'Could not parse the SOAP response:[{}]'.format( soap_response) raise Exception(msg) # Do we have a SOAP fault? if soap_fault_xpath(response): msg = "Server returned a SOAP fault, soap_response:[%s]" % soap_response logger.error(msg) raise ZatoException(msg=msg) # Did server send a business payload, i.e. a <data> elem in the Zato's namespace? zato_data = zato_data_xpath(response) if not zato_data: msg = 'Server did not send a business payload ({} element is missing), soap_response:[{}]'.format( zato_data_path, soap_response) logger.error(msg) raise ZatoException(msg=msg) zato_message = zato_data[0] logger.log(TRACE1, "zato_message:[%s]" % etree.tostring(zato_message)) # We have a payload but hadn't there been any errors at the server's side? zato_result = zato_result_path_xpath(response) if zato_result[0] != ZATO_OK: logger.log(TRACE1, "zato_result:[%s]" % zato_result) raise ZatoException(msg=soap_response) # Check whether the key has been received, if one has been requested. if needs_config_key: try: zato_message.envelope.config_pub_key except AttributeError, e: logger.error(e) msg = "A server's config crypto key has been requested but none has " \ "been received from the server, soap_response:[%s], traceback:[%s]" % (soap_response, format_exc()) logger.error(msg) raise ZatoException(msg=msg)
def invoke_admin_service(cluster, soap_action, soap_body="", headers={}, needs_config_key=False): """ Invokes a Zato server's administrative SOAP service. Returns an lxml's objectified response if no errors have been encountered. Raises a ZatoException if the response doesn't pass the formal validation. cluster - a cluster whose load balancer will be invoked soap_action - a SOAP action to invoke soap_body - an optional SOAP payload to pass to the admin service needs_config_key - whether the invoker should validate that a server's config crypto key has been returned in the response. Will raise a ZatoException if it hasn't and 'needs_config_key' is True. """ url = '' path = '' soap_response = '' try: url = 'http://{0}:{1}'.format(cluster.lb_host, cluster.lb_port) path = '/zato/soap' logger.log(TRACE1, 'About to invoke the admin service url:[{0}]'.format(url)) pool = SOAPPool(url) soap_response = pool.invoke(path, soap_action, soap_body, headers) try: logger.log(TRACE1, 'soap_response:[{0}]'.format(soap_response)) response = objectify.fromstring(soap_response) except Exception, e: msg = 'Could not parse the SOAP response:[{}]'.format(soap_response) raise Exception(msg) # Do we have a SOAP fault? if soap_fault_xpath(response): msg = "Server returned a SOAP fault, soap_response:[%s]" % soap_response logger.error(msg) raise ZatoException(msg=msg) # Did server send a business payload, i.e. a <data> elem in the Zato's namespace? zato_data = zato_data_xpath(response) if not zato_data: msg = 'Server did not send a business payload ({} element is missing), soap_response:[{}]'.format(zato_data_path, soap_response) logger.error(msg) raise ZatoException(msg=msg) zato_message = zato_data[0].getparent() logger.log(TRACE1, "zato_message:[%s]" % etree.tostring(zato_message)) # We have a payload but hadn't there been any errors at the server's side? zato_result = zato_result_path_xpath(response) if zato_result[0] != ZATO_OK: logger.log(TRACE1, "zato_result:[%s]" % zato_result) raise ZatoException(msg=soap_response) # Check whether the key has been received, if one has been requested. if needs_config_key: try: zato_message.envelope.config_pub_key except AttributeError, e: logger.error(e) msg = "A server's config crypto key has been requested but none has " \ "been received from the server, soap_response:[%s], traceback:[%s]" % (soap_response, format_exc()) logger.error(msg) raise ZatoException(msg=msg)