def request(self, message): to = None use_soap = None last_fault_e = None if self.service_client is None: WSFC.axis2_log_error(self.env, "[wsf-python] Service client is null.") return None client_options = WSFC.axis2_svc_client_get_options(self.service_client, \ self.env) # Get the end point address from client options. if self.options.has_key(WSFC.WSF_MP_TO): to = self.options[WSFC.WSF_MP_TO] if to is None: WSFC.axis2_log_error(self.env, "[wsf-python] End point not specified.") return None to_epr = WSFC.axis2_endpoint_ref_create(self.env, to) WSFC.axis2_options_set_to(client_options, self.env, to_epr) request_axiom = self.message_to_axiom(message) if request_axiom is None: WSFC.axis2_log_error(self.env, "[wsf-python] Failed to create AXIOM") return None WSFC.axis2_options_set_xml_parser_reset(client_options, self.env, WSFC.AXIS2_FALSE) if self.options.has_key(WSFC.WSF_CP_USE_SOAP): use_soap = self.options[WSFC.WSF_CP_USE_SOAP].upper() else: use_soap = 'TRUE' if use_soap != 'FALSE': if self.options.has_key(WSFC.WSF_MP_ACTION): action = self.options[WSFC.WSF_MP_ACTION] soap_action = WSFC.axutil_string_create(self.env, action) WSFC.axis2_options_set_soap_action(client_options, self.env,\ soap_action) response_axiom = WSFC.axis2_svc_client_send_receive(self.service_client,\ self.env, request_axiom) if WSFC.axis2_svc_client_get_last_response_has_fault(self.service_client,\ self.env) == WSFC.AXIS2_TRUE: last_fault_e = self.last_fault_exception() if last_fault_e is None: raise WSFault("SOAP-FAULT-ERROR", "Malformatted SOAP fault message") else: raise last_fault_e else: if response_axiom is None: raise WSFault("NULL-REPLY", "No response from the server") else: return self.axiom_to_str(response_axiom) pass
def __init__(self, options, log_file_name=WSFC.WSF_DEFAULT_LOG_FILE_NAME): self.service_client = None self.options = {} # Copy user options into options dictionary of WSClient. self.options = options.copy() # Get the log directory and log level from user options. # If user has not given these options defaults are used. if self.options.has_key(WSFC.WSF_CONF_LOG_DIR): log_dir = self.options[WSFC.WSF_CONF_LOG_DIR] else: log_dir = self.get_default_log_dir() if self.options.has_key(WSFC.WSF_CONF_LOG_LEVEL): log_level = int(self.options[WSFC.WSF_CONF_LOG_LEVEL]) else: log_level = 4 # Create the log file path using user options. log_file = os.path.join(log_dir, log_file_name) # Create a Logger object to use in WSClient. self.logger = Logger(log_file, log_level) # Create the axis2 environment. self.env = WSFC.axutil_env_create_all(log_file, log_level) if self.env is None: self.logger.log_critical("Failed to create WSFC environment....") return if self.options.has_key(WSFC.WSF_CONF_WSFC_HOME): wsfc_home = self.options[WSFC.WSF_CONF_WSFC_HOME] else: wsfc_home = WSFC.WSF_DEFAULT_WSF_HOME # Create the service client. self.service_client = WSFC.axis2_svc_client_create(self.env, wsfc_home) if self.service_client is None: WSFC.axis2_log_critical(self.env, "[wsf-python] Failed to create service client.") return # Set service client options. svc_client_options = WSFC.axis2_svc_client_get_options( \ self.service_client, self.env) if svc_client_options is None: svc_client_options = WSFC.axis2_options_create(self.env) WSFC.axis2_svc_client_set_options(self.service_client, \ self.env, svc_client_options) self.set_client_options(svc_client_options) pass