void axis2_addr_in_create_fault_envelope( const axutil_env_t * env, const axis2_char_t * header_name, const axis2_char_t * addr_ns_str, axis2_msg_ctx_t * msg_ctx) { axiom_soap_envelope_t *envelope = NULL; axutil_array_list_t *sub_codes = NULL; int soap_version = AXIOM_SOAP12; axiom_node_t *text_om_node = NULL; axiom_element_t *text_om_ele = NULL; axiom_namespace_t *ns1 = NULL; if (axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) { soap_version = AXIOM_SOAP11; } ns1 = axiom_namespace_create(env, addr_ns_str, AXIS2_WSA_DEFAULT_PREFIX); text_om_ele = axiom_element_create(env, NULL, "ProblemHeaderQName", ns1, &text_om_node); axiom_element_set_text(text_om_ele, env, header_name, text_om_node); sub_codes = axutil_array_list_create(env, 2); if (sub_codes) { axutil_array_list_add(sub_codes, env, "wsa:InvalidAddressingHeader"); axutil_array_list_add(sub_codes, env, "wsa:InvalidCardinality"); } envelope = axiom_soap_envelope_create_default_soap_fault_envelope(env, "soapenv:Sender", "A header representing a Message Addressing Property is not valid and the message cannot be processed", soap_version, sub_codes, text_om_node); axis2_msg_ctx_set_fault_soap_envelope(msg_ctx, env, envelope); axis2_msg_ctx_set_wsa_action(msg_ctx, env, "http://www.w3.org/2005/08/addressing/fault"); return; }
axis2_status_t AXIS2_CALL wsf_xml_msg_recv_invoke_business_logic_sync( axis2_msg_recv_t * msg_recv, const axutil_env_t * env, axis2_msg_ctx_t * in_msg_ctx, axis2_msg_ctx_t * out_msg_ctx) { axis2_op_ctx_t *op_ctx = NULL; axis2_op_t *op_desc = NULL; axiom_namespace_t *env_ns = NULL; int soap_version = AXIOM_SOAP12; axis2_status_t status = AXIS2_SUCCESS; axis2_bool_t skel_invoked = AXIS2_FALSE; const axis2_char_t *style = NULL; axis2_char_t *local_name = NULL; axis2_char_t *soap_ns = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; axis2_char_t *operation_name = NULL; char *classname = NULL; axutil_property_t *svc_info_prop = NULL; axutil_property_t *req_info_prop = NULL; wsf_svc_info_t *svc_info = NULL; wsf_request_info_t *req_info = NULL; /** store in_msg_ctx envelope */ axiom_soap_envelope_t *envelope = NULL; axiom_soap_body_t *body = NULL; axiom_node_t *in_body_node = NULL; /* store out_msg_ctx envelope */ axiom_soap_envelope_t *default_envelope = NULL; axiom_soap_body_t *out_body = NULL; axiom_soap_header_t *out_header = NULL; axiom_soap_fault_t *out_soap_fault = NULL; axiom_node_t *result_node = NULL; axiom_node_t *out_body_content_node = NULL; axiom_element_t *out_body_content_element = NULL; axiom_node_t *out_node = NULL; zval **output_headers_zval = NULL; TSRMLS_FETCH(); AXIS2_PARAM_CHECK(env->error, in_msg_ctx, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, out_msg_ctx, AXIS2_FAILURE); op_ctx = axis2_msg_ctx_get_op_ctx(in_msg_ctx, env); op_desc = axis2_op_ctx_get_op(op_ctx, env); style = axis2_op_get_style(op_desc, env); envelope = axis2_msg_ctx_get_soap_envelope(in_msg_ctx, env); body = axiom_soap_envelope_get_body(envelope, env); in_body_node = axiom_soap_body_get_base_node(body, env); if (0 == axutil_strcmp(AXIS2_STYLE_DOC, style)) { local_name = wsf_xml_msg_recv_get_method_name(in_msg_ctx, env); if (!local_name) { return AXIS2_FAILURE; } } else if (0 == axutil_strcmp(AXIS2_STYLE_RPC, style)) { axiom_node_t *op_node = NULL; axiom_element_t *op_element = NULL; op_node = axiom_node_get_first_child(in_body_node, env); if (!op_node) { return AXIS2_FAILURE; } op_element = axiom_node_get_data_element(op_node, env); if (!op_element) { return AXIS2_FAILURE; } local_name = axiom_element_get_localname(op_element, env); if (!local_name) { return AXIS2_FAILURE; } } /** set soap version and soap namespace to local variables */ if (in_msg_ctx && axis2_msg_ctx_get_is_soap_11(in_msg_ctx, env)) { soap_ns = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; /* default is 1.2 */ soap_version = AXIOM_SOAP11; } svc_info_prop = axis2_msg_ctx_get_property(in_msg_ctx, env, WSF_SVC_INFO); if (svc_info_prop) { svc_info = (wsf_svc_info_t *) axutil_property_get_value(svc_info_prop, env); if (svc_info) { operation_name = axutil_hash_get(svc_info->ops_to_functions, local_name, AXIS2_HASH_KEY_STRING); if (!operation_name) { return AXIS2_FAILURE; } } else { return AXIS2_FAILURE; } if (svc_info->ops_to_classes) { classname = axutil_hash_get(svc_info->ops_to_classes, local_name, AXIS2_HASH_KEY_STRING); } } req_info_prop = axis2_msg_ctx_get_property(in_msg_ctx, env, WSF_REQ_INFO); if (req_info_prop) { req_info = (wsf_request_info_t *) axutil_property_get_value(req_info_prop, env); if (axis2_msg_ctx_get_doing_rest(in_msg_ctx, env)) { axis2_op_t *op = NULL; axiom_node_t *body_child_node = NULL; axiom_element_t *body_child = NULL; int i = 0; body_child_node = axiom_node_get_first_child(in_body_node, env); if (!body_child_node) { op = axis2_msg_ctx_get_op(in_msg_ctx, env); if (op) { body_child = axiom_element_create_with_qname(env, NULL, axis2_op_get_qname(op, env), &body_child_node); axiom_soap_body_add_child(body, env, body_child_node); } } if (req_info->param_keys && req_info->param_values) { int i = 0; for (i = 0; i < axutil_array_list_size(req_info->param_keys, env); i++) { axiom_node_t *node = NULL; axiom_element_t *element = NULL; axis2_char_t *param_key = NULL; axis2_char_t *param_value = NULL; param_key = axutil_array_list_get(req_info->param_keys, env, i); param_value = axutil_array_list_get(req_info->param_values, env, i); element = axiom_element_create(env, NULL, param_key, NULL, &node); axiom_element_set_text(element, env, param_value, node); axiom_node_add_child(body_child_node, env, node); AXIS2_FREE(env->allocator, param_key); AXIS2_FREE(env->allocator, param_value); } axutil_array_list_free(req_info->param_keys, env); axutil_array_list_free(req_info->param_values, env); } } } if (svc_info->ht_op_params) { zval **tmp; char *function_type = NULL; if (zend_hash_find(svc_info->ht_op_params, operation_name, strlen(operation_name) + 1, (void **) & tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_STRING) { function_type = Z_STRVAL_PP(tmp); if (strcmp(function_type, WSF_MIXED) == 0) { result_node = wsf_xml_msg_recv_invoke_mixed(env, svc_info, in_msg_ctx, out_msg_ctx, operation_name, classname, &output_headers_zval TSRMLS_CC); } else if (strcmp(function_type, WSF_WSMESSAGE) == 0) { result_node = wsf_xml_msg_recv_invoke_wsmsg(env, operation_name, in_msg_ctx, out_msg_ctx, svc_info, classname, req_info->content_type TSRMLS_CC); } } } else { /* this is where the default value for opParam is set, If the wsdl option is set go for the MIXED mode by default */ if (svc_info->wsdl == NULL || svc_info->omit_wsdl) { result_node = wsf_xml_msg_recv_invoke_wsmsg(env, operation_name, in_msg_ctx, out_msg_ctx, svc_info, classname, req_info->content_type TSRMLS_CC); } else { result_node = wsf_xml_msg_recv_invoke_mixed(env, svc_info, in_msg_ctx, out_msg_ctx, operation_name, classname, &output_headers_zval TSRMLS_CC); } } if (!result_node) { status = AXIS2_ERROR_GET_STATUS_CODE(env->error); } else { AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "Response node is not null"); } if (result_node) { if (0 == axutil_strcmp(style, AXIS2_STYLE_RPC)) { axiom_namespace_t *ns = NULL; axis2_char_t *response_name = NULL; response_name = axutil_stracat(env, local_name, "Response"); ns = axiom_namespace_create(env, "http://soapenc/", "res"); if (!ns) { return AXIS2_FAILURE; } out_body_content_element = axiom_element_create(env, NULL, response_name, ns, &out_body_content_node); axiom_node_add_child(out_body_content_node, env, result_node); } else { out_body_content_node = result_node; } } if (axis2_msg_ctx_get_soap_envelope(out_msg_ctx, env)) { /* service implementation has set the envelope, useful when setting a SOAP fault. No need to further process */ AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "soap fault is set"); return AXIS2_SUCCESS; } /* create the soap envelope here */ env_ns = axiom_namespace_create(env, soap_ns, AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX); if (!env_ns) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] error seting the namespces for the " AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX); return AXIS2_FAILURE; } default_envelope = axiom_soap_envelope_create(env, env_ns); if (!default_envelope) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "failed in creating the response soap envelope"); return AXIS2_FAILURE; } out_body = axiom_soap_body_create_with_parent(env, default_envelope); if (!out_body) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] failed in creating the response soap body"); return AXIS2_FAILURE; } out_header = axiom_soap_header_create_with_parent(env, default_envelope); if (!out_header) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "failed in creating the response soap headers"); return AXIS2_FAILURE; } if (output_headers_zval) { axiom_node_t *header_base_node = NULL; HashPosition pos; zval **param; char *header_str; axiom_node_t *header_node; for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(output_headers_zval), &pos); zend_hash_get_current_data_ex(Z_ARRVAL_PP(output_headers_zval), (void **) & param, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_PP(output_headers_zval), &pos)) { if (Z_TYPE_PP(param) == IS_STRING) { header_base_node = axiom_soap_header_get_base_node(out_header, env); if (header_base_node) { header_str = Z_STRVAL_PP(param); header_node = wsf_util_deserialize_buffer(env, header_str); axiom_node_add_child(header_base_node, env, header_node); } else { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] failed in retrieving the response soap headers node"); return AXIS2_FAILURE; } } } } out_node = axiom_soap_body_get_base_node(out_body, env); if (!out_node) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] failed in retrieving the response soap body node"); return AXIS2_FAILURE; } if (status != AXIS2_SUCCESS) { /* something went wrong, set a SOAP Fault */ axis2_char_t *fault_value_str = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" AXIOM_SOAP12_SOAP_FAULT_VALUE_SENDER; axis2_char_t *fault_reason_str = NULL; axis2_char_t *err_msg = NULL; if (!skel_invoked) fault_value_str = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" AXIOM_SOAP12_SOAP_FAULT_VALUE_RECEIVER; ; err_msg = (char *) AXIS2_ERROR_GET_MESSAGE(env->error); if (err_msg) { fault_reason_str = err_msg; } else { fault_reason_str = "Error occurred while processing SOAP message"; } out_soap_fault = axiom_soap_fault_create_default_fault(env, out_body, fault_value_str, fault_reason_str, soap_version); } if (out_body_content_node) { axiom_node_add_child(out_node, env, out_body_content_node); status = axis2_msg_ctx_set_soap_envelope(out_msg_ctx, env, default_envelope); } else if (out_soap_fault) { axis2_msg_ctx_set_soap_envelope(out_msg_ctx, env, default_envelope); status = AXIS2_FAILURE; /* if there is a failure we have to return a failure code */ } else { /* we should free the memory as the envelope is not used, one way case */ axiom_soap_envelope_free(default_envelope, env); default_envelope = NULL; } return AXIS2_SUCCESS; }
axis2_status_t AXIS2_CALL axis2_libcurl_send( axis2_libcurl_t *data, axiom_output_t * om_output, const axutil_env_t * env, axis2_msg_ctx_t * msg_ctx, axiom_soap_envelope_t * out, const axis2_char_t * str_url, const axis2_char_t * soap_action) { struct curl_slist *headers = NULL; axiom_soap_body_t *soap_body; axis2_bool_t is_soap = AXIS2_TRUE; axis2_bool_t send_via_get = AXIS2_FALSE; axis2_bool_t send_via_head = AXIS2_FALSE; axis2_bool_t send_via_put = AXIS2_FALSE; axis2_bool_t send_via_delete = AXIS2_FALSE; axis2_bool_t doing_mtom = AXIS2_FALSE; axiom_node_t *body_node = NULL; axiom_node_t *data_out = NULL; axutil_property_t *method = NULL; axis2_char_t *method_value = NULL; axiom_xml_writer_t *xml_writer = NULL; axis2_char_t *buffer = NULL; unsigned int buffer_size = 0; int content_length = -1; axis2_char_t *content_type = NULL; /*axis2_char_t *content_len = AXIS2_HTTP_HEADER_CONTENT_LENGTH_; */ const axis2_char_t *char_set_enc = NULL; axis2_char_t *content = AXIS2_HTTP_HEADER_CONTENT_TYPE_; axis2_char_t *soap_action_header = AXIS2_HTTP_HEADER_SOAP_ACTION_; axutil_stream_t *in_stream; axutil_property_t *trans_in_property; axutil_string_t *char_set_enc_str; axis2_byte_t *output_stream = NULL; int output_stream_size = 0; CURL *handler; axis2_conf_ctx_t *conf_ctx = NULL; axis2_conf_t *conf = NULL; axis2_transport_out_desc_t *trans_desc = NULL; axutil_param_t *write_xml_declaration_param = NULL; axutil_hash_t *transport_attrs = NULL; axis2_bool_t write_xml_declaration = AXIS2_FALSE; axutil_property_t *property; int *response_length = NULL; axis2_http_status_line_t *status_line = NULL; axis2_char_t *status_line_str = NULL; axis2_char_t *tmp_strcat = NULL; int status_code = 0; AXIS2_PARAM_CHECK(env->error, data, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, data->handler, AXIS2_FAILURE); handler = data->handler; curl_easy_reset(handler); curl_easy_setopt(handler, CURLOPT_ERRORBUFFER, data->errorbuffer); headers = curl_slist_append(headers, AXIS2_HTTP_HEADER_USER_AGENT_AXIS2C); headers = curl_slist_append(headers, AXIS2_HTTP_HEADER_ACCEPT_); headers = curl_slist_append(headers, AXIS2_HTTP_HEADER_EXPECT_); if(AXIS2_FAILURE == axis2_libcurl_set_options(handler, env, msg_ctx)) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[axis2libcurl]Setting options in Libcurl failed"); return AXIS2_FAILURE; } if (AXIS2_TRUE == axis2_msg_ctx_get_doing_rest(msg_ctx, env)) { is_soap = AXIS2_FALSE; } else { is_soap = AXIS2_TRUE; } if (!is_soap) { soap_body = axiom_soap_envelope_get_body(out, env); if (!soap_body) { AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL, AXIS2_FAILURE); return AXIS2_FAILURE; } body_node = axiom_soap_body_get_base_node(soap_body, env); if (!body_node) { AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL, AXIS2_FAILURE); return AXIS2_FAILURE; } data_out = axiom_node_get_first_element(body_node, env); method = (axutil_property_t *) axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_HTTP_METHOD); if (method) { method_value = (axis2_char_t *) axutil_property_get_value(method, env); } /* The default is POST */ if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_GET)) { send_via_get = AXIS2_TRUE; } else if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_HEAD)) { send_via_head = AXIS2_TRUE; } else if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_PUT)) { send_via_put = AXIS2_TRUE; } else if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_DELETE)) { send_via_delete = AXIS2_TRUE; } } conf_ctx = axis2_msg_ctx_get_conf_ctx (msg_ctx, env); if (conf_ctx) { conf = axis2_conf_ctx_get_conf (conf_ctx, env); } if (conf) { trans_desc = axis2_conf_get_transport_out (conf, env, AXIS2_TRANSPORT_ENUM_HTTP); } if (trans_desc) { write_xml_declaration_param = axutil_param_container_get_param (axis2_transport_out_desc_param_container (trans_desc, env), env, AXIS2_XML_DECLARATION); } if (write_xml_declaration_param) { transport_attrs = axutil_param_get_attributes (write_xml_declaration_param, env); if (transport_attrs) { axutil_generic_obj_t *obj = NULL; axiom_attribute_t *write_xml_declaration_attr = NULL; axis2_char_t *write_xml_declaration_attr_value = NULL; obj = axutil_hash_get (transport_attrs, AXIS2_ADD_XML_DECLARATION, AXIS2_HASH_KEY_STRING); if (obj) { write_xml_declaration_attr = (axiom_attribute_t *) axutil_generic_obj_get_value (obj, env); } if (write_xml_declaration_attr) { write_xml_declaration_attr_value = axiom_attribute_get_value (write_xml_declaration_attr, env); } if (write_xml_declaration_attr_value && 0 == axutil_strcasecmp (write_xml_declaration_attr_value, AXIS2_VALUE_TRUE)) { write_xml_declaration = AXIS2_TRUE; } } } if (write_xml_declaration) { axiom_output_write_xml_version_encoding (om_output, env); } if (!send_via_get && !send_via_head && !send_via_delete) { xml_writer = axiom_output_get_xml_writer(om_output, env); char_set_enc_str = axis2_msg_ctx_get_charset_encoding(msg_ctx, env); if (!char_set_enc_str) { char_set_enc = AXIS2_DEFAULT_CHAR_SET_ENCODING; } else { char_set_enc = axutil_string_get_buffer(char_set_enc_str, env); } if (!send_via_put && is_soap) { doing_mtom = axis2_msg_ctx_get_doing_mtom(msg_ctx, env); axiom_output_set_do_optimize(om_output, env, doing_mtom); axiom_soap_envelope_serialize(out, env, om_output, AXIS2_FALSE); if (AXIS2_TRUE == axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) { if (AXIS2_ESC_DOUBLE_QUOTE != *soap_action) { axis2_char_t *tmp_soap_action = NULL; tmp_soap_action = AXIS2_MALLOC(env->allocator, (axutil_strlen(soap_action) + 5) * sizeof(axis2_char_t)); sprintf(tmp_soap_action, "\"%s\"", soap_action); tmp_strcat = axutil_stracat(env, soap_action_header,tmp_soap_action); headers = curl_slist_append(headers, tmp_strcat); AXIS2_FREE(env->allocator, tmp_strcat); AXIS2_FREE(env->allocator, tmp_soap_action); } else { tmp_strcat = axutil_stracat(env, soap_action_header, soap_action); headers = curl_slist_append(headers, tmp_strcat ); AXIS2_FREE(env->allocator, tmp_strcat); } } if (doing_mtom) { /*axiom_output_flush(om_output, env, &output_stream, &output_stream_size);*/ axiom_output_flush(om_output, env); content_type = (axis2_char_t *) axiom_output_get_content_type(om_output, env); if (AXIS2_TRUE != axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) { if (axutil_strcmp(soap_action, "")) { /* handle SOAP action for SOAP 1.2 case */ axis2_char_t *temp_content_type = NULL; temp_content_type = axutil_stracat (env, content_type, AXIS2_CONTENT_TYPE_ACTION); content_type = temp_content_type; temp_content_type = axutil_stracat (env, content_type, soap_action); AXIS2_FREE (env->allocator, content_type); content_type = temp_content_type; temp_content_type = axutil_stracat (env, content_type, AXIS2_ESC_DOUBLE_QUOTE_STR); AXIS2_FREE (env->allocator, content_type); content_type = temp_content_type; } } } else if (AXIS2_TRUE == axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) { axis2_char_t *temp_content_type = NULL; content_type = (axis2_char_t *) AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML; content_type = axutil_stracat(env, content_type, AXIS2_CONTENT_TYPE_CHARSET); temp_content_type = axutil_stracat(env, content_type, char_set_enc); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; } else { axis2_char_t *temp_content_type = NULL; content_type = (axis2_char_t *) AXIS2_HTTP_HEADER_ACCEPT_APPL_SOAP; content_type = axutil_stracat(env, content_type, AXIS2_CONTENT_TYPE_CHARSET); temp_content_type = axutil_stracat(env, content_type, char_set_enc); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; if (axutil_strcmp(soap_action, "")) { temp_content_type = axutil_stracat(env, content_type, AXIS2_CONTENT_TYPE_ACTION); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; temp_content_type = axutil_stracat(env, content_type, soap_action); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; } temp_content_type = axutil_stracat(env, content_type, AXIS2_SEMI_COLON_STR); AXIS2_FREE(env->allocator, content_type); content_type = temp_content_type; } } else if (is_soap) { AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Attempt to send SOAP" "message using HTTP PUT failed"); return AXIS2_FAILURE; } else { axutil_property_t *content_type_property = NULL; axutil_hash_t *content_type_hash = NULL; axis2_char_t *content_type_value = NULL; axiom_node_serialize(data_out, env, om_output); content_type_property = (axutil_property_t *) axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_USER_DEFINED_HTTP_HEADER_CONTENT_TYPE); if (content_type_property) { content_type_hash = (axutil_hash_t *) axutil_property_get_value(content_type_property, env); if (content_type_hash) { content_type_value = (char *) axutil_hash_get(content_type_hash, AXIS2_HTTP_HEADER_CONTENT_TYPE, AXIS2_HASH_KEY_STRING); } } if (content_type_value) { content_type = content_type_value; } else { content_type = axutil_strdup(env,AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML); } } buffer = axiom_xml_writer_get_xml(xml_writer, env); if (!doing_mtom) { buffer_size = axiom_xml_writer_get_xml_size(xml_writer, env); } else buffer_size = output_stream_size; { /* * Curl calculates the content-length automatically. * This commented section is not only unnecessary, * it interferes with authentication. * * NTLM, for example, will send an empty request * first (no body) to get the auth challenge * before resending with actual content. */ /*char tmp_buf[10]; sprintf(tmp_buf, "%d", buffer_size); tmp_strcat = axutil_stracat(env, content_len, tmp_buf); headers = curl_slist_append(headers, tmp_strcat); AXIS2_FREE(env->allocator, tmp_strcat); tmp_strcat = NULL;*/ tmp_strcat = axutil_stracat(env, content, content_type); headers = curl_slist_append(headers, tmp_strcat); AXIS2_FREE(env->allocator, tmp_strcat); tmp_strcat = NULL; } if (!doing_mtom) { curl_easy_setopt(handler, CURLOPT_POSTFIELDSIZE, buffer_size); curl_easy_setopt(handler, CURLOPT_POSTFIELDS, buffer); } else { curl_easy_setopt(handler, CURLOPT_POSTFIELDSIZE, output_stream_size); curl_easy_setopt(handler, CURLOPT_POSTFIELDS, output_stream); } if (send_via_put) { curl_easy_setopt(handler, CURLOPT_CUSTOMREQUEST, AXIS2_HTTP_PUT); } curl_easy_setopt(handler, CURLOPT_URL, str_url); } else { axis2_char_t *request_param; axis2_char_t *url_encode; request_param = (axis2_char_t *) axis2_http_sender_get_param_string(NULL, env, msg_ctx); url_encode = axutil_strcat(env, str_url, AXIS2_Q_MARK_STR, request_param, NULL); if (send_via_get) { curl_easy_setopt(handler, CURLOPT_HTTPGET, 1); } else if (send_via_head) { curl_easy_setopt(handler, CURLOPT_NOBODY, 1); } else if (send_via_delete) { curl_easy_setopt(handler, CURLOPT_CUSTOMREQUEST, AXIS2_HTTP_DELETE); } curl_easy_setopt(handler, CURLOPT_URL, url_encode); } { axis2_bool_t manage_session; manage_session = axis2_msg_ctx_get_manage_session(msg_ctx, env); if (manage_session == AXIS2_TRUE) { if (data->cookies == AXIS2_FALSE) { /* Ensure cookies enabled to manage session */ /* Pass empty cookie string to enable cookies */ curl_easy_setopt(handler, CURLOPT_COOKIEFILE, " "); data->cookies = AXIS2_TRUE; } } else if (data->cookies == AXIS2_TRUE) { /* Pass special string ALL to reset cookies if any have been enabled. */ /* If cookies have ever been enabled, we reset every time as long as manage_session is false, as there is no clear curl option to turn off the cookie engine once enabled. */ curl_easy_setopt(handler, CURLOPT_COOKIELIST, AXIS2_ALL); } } curl_easy_setopt(handler, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(handler, CURLOPT_WRITEFUNCTION, axis2_libcurl_write_memory_callback); curl_easy_setopt(handler, CURLOPT_WRITEDATA, data); curl_easy_setopt (handler, CURLOPT_HEADERFUNCTION, axis2_libcurl_header_callback); curl_easy_setopt (handler, CURLOPT_WRITEHEADER, data); /* Free response data from previous request */ if( data->size ) { if (data->memory) { AXIS2_FREE(data->env->allocator, data->memory); } data->size = 0; } if (curl_easy_perform(handler)) { AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "%s", &data->errorbuffer); AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_HTTP_CLIENT_TRANSPORT_ERROR, AXIS2_FAILURE); return AXIS2_FAILURE; } in_stream = axutil_stream_create_libcurl(env, data->memory, data->size); trans_in_property = axutil_property_create(env); axutil_property_set_scope(trans_in_property, env, AXIS2_SCOPE_REQUEST); axutil_property_set_free_func(trans_in_property, env, libcurl_stream_free); axutil_property_set_value(trans_in_property, env, in_stream); axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_TRANSPORT_IN, trans_in_property); if (axutil_array_list_size(data->alist, env) > 0) { status_line_str = axutil_array_list_get(data->alist, env, 0); if (status_line_str) { status_line = axis2_http_status_line_create(env, status_line_str); } } if (status_line) { status_code = axis2_http_status_line_get_status_code(status_line, env); } axis2_msg_ctx_set_status_code (msg_ctx, env, status_code); AXIS2_FREE(data->env->allocator, content_type); content_type = axis2_libcurl_get_content_type(data, env); if (content_type) { if (strstr (content_type, AXIS2_HTTP_HEADER_ACCEPT_MULTIPART_RELATED) && strstr (content_type, AXIS2_HTTP_HEADER_ACCEPT_XOP_XML)) { axis2_ctx_t *axis_ctx = axis2_op_ctx_get_base (axis2_msg_ctx_get_op_ctx (msg_ctx, env), env); property = axutil_property_create (env); axutil_property_set_scope (property, env, AXIS2_SCOPE_REQUEST); axutil_property_set_value (property, env, axutil_strdup (env, content_type)); axis2_ctx_set_property (axis_ctx, env, MTOM_RECIVED_CONTENT_TYPE, property); } } content_length = axis2_libcurl_get_content_length(data, env); if (content_length >= 0) { response_length = AXIS2_MALLOC (env->allocator, sizeof (int)); memcpy (response_length, &content_length, sizeof (int)); property = axutil_property_create (env); axutil_property_set_scope (property, env, AXIS2_SCOPE_REQUEST); axutil_property_set_value (property, env, response_length); axis2_msg_ctx_set_property (msg_ctx, env, AXIS2_HTTP_HEADER_CONTENT_LENGTH, property); } curl_slist_free_all (headers); /* release the read http headers. */ /* (commenting out the call below is a clever way to force a premature EOF condition in subsequent messages, as they will be read using the content-length of the first message.) */ axis2_libcurl_free_headers(data, env); AXIS2_FREE(data->env->allocator, content_type); axis2_http_status_line_free( status_line, env); return AXIS2_SUCCESS; }
static axis2_status_t AXIS2_CALL axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync( axis2_msg_recv_t * msg_recv, const axutil_env_t * env, axis2_msg_ctx_t * msg_ctx, axis2_msg_ctx_t * new_msg_ctx) { axis2_svc_skeleton_t *svc_obj = NULL; axis2_op_ctx_t *op_ctx = NULL; axis2_op_t *op_desc = NULL; const axis2_char_t *style = NULL; axiom_node_t *om_node = NULL; axiom_element_t *om_element = NULL; axis2_char_t *local_name = NULL; axiom_node_t *result_node = NULL; axiom_node_t *body_content_node = NULL; axiom_element_t *body_content_element = NULL; axiom_soap_envelope_t *default_envelope = NULL; axiom_soap_body_t *out_body = NULL; axiom_soap_header_t *out_header = NULL; axiom_soap_fault_t *soap_fault = NULL; axiom_node_t *out_node = NULL; axis2_status_t status = AXIS2_SUCCESS; axis2_bool_t skel_invoked = AXIS2_FALSE; const axis2_char_t *soap_ns = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; int soap_version = AXIOM_SOAP12; axiom_namespace_t *env_ns = NULL; axiom_node_t *fault_node = NULL; axiom_soap_fault_detail_t *fault_detail; axis2_bool_t is_fault = AXIS2_FALSE; AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, new_msg_ctx, AXIS2_FAILURE); AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[axis2]Entry:axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync"); /* get the implementation class for the Web Service */ svc_obj = axis2_msg_recv_make_new_svc_obj(msg_recv, env, msg_ctx); if(!svc_obj) { const axis2_char_t *svc_name = NULL; axis2_svc_t *svc = axis2_msg_ctx_get_svc(msg_ctx, env); if(svc) { svc_name = axis2_svc_get_name(svc, env); } else { svc_name = "unknown"; } AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Impl object for service '%s' not set in message receiver. %d :: %s", svc_name, env->error->error_number, AXIS2_ERROR_GET_MESSAGE(env->error)); status = AXIS2_FAILURE; } else { op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env); op_desc = axis2_op_ctx_get_op(op_ctx, env); style = axis2_op_get_style(op_desc, env); if(0 == axutil_strcmp(AXIS2_STYLE_DOC, style)) { axiom_soap_envelope_t *envelope = NULL; axiom_soap_body_t *body = NULL; envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env); body = axiom_soap_envelope_get_body(envelope, env); om_node = axiom_soap_body_get_base_node(body, env); om_element = axiom_node_get_data_element(om_node, env); om_node = axiom_node_get_first_element(om_node, env); } else if(0 == axutil_strcmp(AXIS2_STYLE_RPC, style)) { axiom_soap_envelope_t *envelope = NULL; axiom_soap_body_t *body = NULL; axiom_node_t *op_node = NULL; axiom_element_t *op_element = NULL; envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env); body = axiom_soap_envelope_get_body(envelope, env); op_node = axiom_soap_body_get_base_node(body, env); op_element = axiom_node_get_data_element(op_node, env); if(op_element) { local_name = axiom_element_get_localname(op_element, env); if(local_name) { axutil_array_list_t *function_arr = NULL; int i = 0; int size = 0; axis2_bool_t matches = AXIS2_FALSE; function_arr = svc_obj->func_array; if(function_arr) { size = axutil_array_list_size(function_arr, env); } for(i = 0; i < size; i++) { axis2_char_t *function_name = NULL; function_name = (axis2_char_t *)axutil_array_list_get(function_arr, env, i); if(!axutil_strcmp(function_name, local_name)) { matches = AXIS2_TRUE; } } if(matches) { om_node = axiom_node_get_first_child(op_node, env); om_element = axiom_node_get_data_element(om_node, env); } else { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OM_ELEMENT_MISMATCH, AXIS2_FAILURE); status = AXIS2_FAILURE; } } else { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OM_ELEMENT_INVALID_STATE, AXIS2_FAILURE); status = AXIS2_FAILURE; } } else { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_RPC_NEED_MATCHING_CHILD, AXIS2_FAILURE); status = AXIS2_FAILURE; } } else { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_UNKNOWN_STYLE, AXIS2_FAILURE); status = AXIS2_FAILURE; } if(status == AXIS2_SUCCESS) { skel_invoked = AXIS2_TRUE; result_node = AXIS2_SVC_SKELETON_INVOKE(svc_obj, env, om_node, new_msg_ctx); } if(result_node) { if(0 == axutil_strcmp(style, AXIS2_STYLE_RPC)) { axiom_namespace_t *ns = NULL; axis2_char_t *res_name = NULL; res_name = axutil_stracat(env, local_name, "Response"); ns = axiom_namespace_create(env, "http://soapenc/", "res"); if(!ns) { status = AXIS2_FAILURE; } else { body_content_element = axiom_element_create(env, NULL, res_name, ns, &body_content_node); axiom_node_add_child(body_content_node, env, result_node); } } else { body_content_node = result_node; } } else { axis2_char_t *mep = (axis2_char_t *)axis2_op_get_msg_exchange_pattern(op_desc, env); if(axutil_strcmp(mep, AXIS2_MEP_URI_IN_ONLY) && axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY) && axutil_strcmp(mep, AXIS2_MEP_URI_IN_ONLY_WSDL2) && axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY_WSDL2)) { status = AXIS2_ERROR_GET_STATUS_CODE(env->error); if(status == AXIS2_SUCCESS) { axis2_msg_ctx_set_no_content(new_msg_ctx, env, AXIS2_TRUE); } else { axis2_msg_ctx_set_status_code(msg_ctx, env, axis2_msg_ctx_get_status_code( new_msg_ctx, env)); } /* The new_msg_ctx is passed to the service. The status code must * be taken from here and set to the old message context which is * used by the worker when the request processing fails. */ if(svc_obj->ops->on_fault) { fault_node = AXIS2_SVC_SKELETON_ON_FAULT(svc_obj, env, om_node); } is_fault = AXIS2_TRUE; } else { /* If we have a in only message result node is NULL. We create fault only if * an error is set */ status = AXIS2_ERROR_GET_STATUS_CODE(env->error); if(status == AXIS2_SUCCESS) { axis2_msg_ctx_set_no_content(new_msg_ctx, env, AXIS2_TRUE); } else { axis2_msg_ctx_set_status_code(msg_ctx, env, axis2_msg_ctx_get_status_code( new_msg_ctx, env)); if((!axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY)) || (!axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY_WSDL2))) { /* The new_msg_ctx is passed to the service. The status code must * be taken from here and set to the old message context which is * used by the worker when the request processing fails. */ if(svc_obj->ops->on_fault) { fault_node = AXIS2_SVC_SKELETON_ON_FAULT(svc_obj, env, om_node); } is_fault = AXIS2_TRUE; } } } } } if(msg_ctx && axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) { soap_ns = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; /* default is 1.2 */ soap_version = AXIOM_SOAP11; } if(axis2_msg_ctx_get_soap_envelope(new_msg_ctx, env)) { /* service implementation has set the envelope, useful when setting a SOAP fault. No need to further process */ return AXIS2_SUCCESS; } /* create the soap envelope here */ env_ns = axiom_namespace_create(env, soap_ns, "soapenv"); if(!env_ns) { return AXIS2_FAILURE; } default_envelope = axiom_soap_envelope_create(env, env_ns); axiom_namespace_free(env_ns, env); if(!default_envelope) { return AXIS2_FAILURE; } out_header = axiom_soap_header_create_with_parent(env, default_envelope); if(!out_header) { return AXIS2_FAILURE; } out_body = axiom_soap_body_create_with_parent(env, default_envelope); if(!out_body) { return AXIS2_FAILURE; } out_node = axiom_soap_body_get_base_node(out_body, env); if(!out_node) { return AXIS2_FAILURE; } if(status != AXIS2_SUCCESS || is_fault) { /* something went wrong. set a SOAP Fault */ const axis2_char_t *fault_value_str = "soapenv:Sender"; const axis2_char_t *fault_reason_str = NULL; const axis2_char_t *err_msg = NULL; if(!skel_invoked) { if(axis2_msg_ctx_get_is_soap_11(msg_ctx, env)) { fault_value_str = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" AXIOM_SOAP11_FAULT_CODE_RECEIVER; } else { fault_value_str = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" AXIOM_SOAP12_SOAP_FAULT_VALUE_RECEIVER; } } err_msg = AXIS2_ERROR_GET_MESSAGE(env->error); if (err_msg && axutil_strcmp(err_msg, "")) { if(!axutil_strcmp(err_msg, "No Error")) { fault_reason_str = "An error has occurred, but could not determine exact details"; } else { fault_reason_str = err_msg; } } else { fault_reason_str = "An error has occurred, but could not determine exact details"; } soap_fault = axiom_soap_fault_create_default_fault(env, out_body, fault_value_str, fault_reason_str, soap_version); if (fault_node) { axiom_node_t *fault_detail_node = NULL; axis2_char_t *om_str = NULL; fault_detail = axiom_soap_fault_detail_create_with_parent(env, soap_fault); fault_detail_node = axiom_soap_fault_detail_get_base_node(fault_detail, env); om_str = axiom_node_to_string(fault_detail_node, env); if (om_str) { AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "fault_detail:%s", om_str); AXIS2_FREE(env->allocator, om_str); } axiom_soap_fault_detail_add_detail_entry(fault_detail, env, fault_node); } } if (body_content_node) { axiom_node_add_child(out_node, env, body_content_node); status = axis2_msg_ctx_set_soap_envelope(new_msg_ctx, env, default_envelope); } else if (soap_fault) { axis2_msg_ctx_set_soap_envelope(new_msg_ctx, env, default_envelope); status = AXIS2_SUCCESS; } else { /* we should free the memory as the envelope is not used, one way case */ axiom_soap_envelope_free(default_envelope, env); default_envelope = NULL; } AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[axis2]Exit:axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync"); return status; }
AXIS2_EXTERN axiom_soap_envelope_t* AXIS2_CALL axis2_amqp_util_get_soap_envelope( axis2_amqp_response_t* response, const axutil_env_t* env, axis2_msg_ctx_t* msg_ctx) { axiom_xml_reader_t* xml_reader = NULL; axiom_stax_builder_t* stax_builder = NULL; axiom_soap_builder_t* soap_builder = NULL; axiom_soap_envelope_t* soap_envelope = NULL; const axis2_char_t* soap_ns_uri = NULL; axis2_char_t *soap_body_str = NULL; int soap_body_len = 0; axis2_bool_t is_mtom = AXIS2_FALSE; axutil_hash_t *binary_data_map = NULL; axis2_bool_t is_soap_11 = AXIS2_FALSE; if(!response || !response->data || !response->content_type) { return NULL; } is_soap_11 = axis2_msg_ctx_get_is_soap_11(msg_ctx, env); /* Handle MTOM */ if(strstr(response->content_type, AXIS2_AMQP_HEADER_ACCEPT_MULTIPART_RELATED)) { axis2_char_t* mime_boundary = axis2_amqp_util_get_value_from_content_type(env, response->content_type, AXIS2_AMQP_HEADER_CONTENT_TYPE_MIME_BOUNDARY); if(mime_boundary) { axiom_mime_parser_t *mime_parser = NULL; int soap_body_len = 0; axutil_param_t *buffer_size_param = NULL; axutil_param_t *max_buffers_param = NULL; axutil_param_t *attachment_dir_param = NULL; axis2_char_t *value_size = NULL; axis2_char_t *value_num = NULL; axis2_char_t *value_dir = NULL; int size = 0; int num = 0; mime_parser = axiom_mime_parser_create(env); buffer_size_param = axis2_msg_ctx_get_parameter(msg_ctx, env, AXIS2_MTOM_BUFFER_SIZE); if(buffer_size_param) { value_size = (axis2_char_t *)axutil_param_get_value(buffer_size_param, env); if(value_size) { size = atoi(value_size); axiom_mime_parser_set_buffer_size(mime_parser, env, size); } } max_buffers_param = axis2_msg_ctx_get_parameter(msg_ctx, env, AXIS2_MTOM_MAX_BUFFERS); if(max_buffers_param) { value_num = (axis2_char_t*)axutil_param_get_value(max_buffers_param, env); if(value_num) { num = atoi(value_num); axiom_mime_parser_set_max_buffers(mime_parser, env, num); } } attachment_dir_param = axis2_msg_ctx_get_parameter(msg_ctx, env, AXIS2_ATTACHMENT_DIR); if(attachment_dir_param) { value_dir = (axis2_char_t*)axutil_param_get_value(attachment_dir_param, env); if(value_dir) { axiom_mime_parser_set_attachment_dir(mime_parser, env, value_dir); } } if(mime_parser) { axis2_callback_info_t* callback_ctx = NULL; axutil_stream_t* stream = NULL; callback_ctx = (axis2_callback_info_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_callback_info_t)); stream = axutil_stream_create_basic(env); if(stream) { axutil_stream_write(stream, env, response->data, response->length); callback_ctx->env = env; callback_ctx->in_stream = stream; callback_ctx->content_length = response->length; callback_ctx->unread_len = response->length; callback_ctx->chunked_stream = NULL; } /*binary_data_map = axiom_mime_parser_parse(mime_parser, env, axis2_amqp_util_on_data_request, (void*)callback_ctx, mime_boundary);*/ if(!binary_data_map) { return AXIS2_FAILURE; } soap_body_len = axiom_mime_parser_get_soap_body_len(mime_parser, env); soap_body_str = axiom_mime_parser_get_soap_body_str(mime_parser, env); axutil_stream_free(stream, env); AXIS2_FREE(env->allocator, callback_ctx); axiom_mime_parser_free(mime_parser, env); } AXIS2_FREE(env->allocator, mime_boundary); } is_mtom = AXIS2_TRUE; } else { soap_body_str = response->data; soap_body_len = axutil_strlen(response->data); } soap_body_len = axutil_strlen(soap_body_str); xml_reader = axiom_xml_reader_create_for_memory(env, soap_body_str, soap_body_len, NULL, AXIS2_XML_PARSER_TYPE_BUFFER); if(!xml_reader) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create XML Reader"); return NULL; } stax_builder = axiom_stax_builder_create(env, xml_reader); if(!stax_builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create StAX Builder"); return NULL; } soap_ns_uri = is_soap_11 ? AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI : AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI; soap_builder = axiom_soap_builder_create(env, stax_builder, soap_ns_uri); if(!soap_builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to Create SOAP Builder"); return NULL; } if(binary_data_map) { axiom_soap_builder_set_mime_body_parts(soap_builder, env, binary_data_map); } soap_envelope = axiom_soap_builder_get_soap_envelope(soap_builder, env); return soap_envelope; }
axis2_status_t axis2_engine_check_must_understand_headers( const axutil_env_t * env, axis2_msg_ctx_t * msg_ctx) { axiom_soap_envelope_t *soap_envelope = NULL; axiom_soap_header_t *soap_header = NULL; axutil_hash_t *header_block_ht = NULL; axutil_hash_index_t *hash_index = NULL; AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE); soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env); if(!soap_envelope) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Soap envelope not found in message context"); return AXIS2_FAILURE; } soap_header = axiom_soap_envelope_get_header(soap_envelope, env); if(!soap_header) return AXIS2_SUCCESS; header_block_ht = axiom_soap_header_get_all_header_blocks(soap_header, env); if(!header_block_ht) return AXIS2_SUCCESS; for(hash_index = axutil_hash_first(header_block_ht, env); hash_index; hash_index = axutil_hash_next(env, hash_index)) { void *hb = NULL; axiom_soap_header_block_t *header_block = NULL; axis2_char_t *role = NULL; axutil_hash_this(hash_index, NULL, NULL, &hb); header_block = (axiom_soap_header_block_t *)hb; if(header_block) { if(axiom_soap_header_block_is_processed(header_block, env) || !axiom_soap_header_block_get_must_understand(header_block, env)) { continue; } /* If this header block is not targeted to me then its not my problem. Currently this code only supports the "next" role; we need to fix this to allow the engine/service to be in one or more additional roles and then to check that any headers targeted for that role too have been dealt with. */ role = axiom_soap_header_block_get_role(header_block, env); if(axis2_msg_ctx_get_is_soap_11(msg_ctx, env) != AXIS2_TRUE) { /* SOAP 1.2 */ if(!role || axutil_strcmp(role, AXIOM_SOAP12_SOAP_ROLE_NEXT) != 0) { axiom_soap_envelope_t *temp_env = axiom_soap_envelope_create_default_soap_fault_envelope(env, "soapenv:MustUnderstand", "Header not understood", AXIOM_SOAP12, NULL, NULL); axis2_msg_ctx_set_fault_soap_envelope(msg_ctx, env, temp_env); axis2_msg_ctx_set_wsa_action(msg_ctx, env, "http://www.w3.org/2005/08/addressing/fault"); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Must understand soap fault occured"); return AXIS2_FAILURE; } } else { /* SOAP 1.1 */ if(!role || axutil_strcmp(role, AXIOM_SOAP11_SOAP_ACTOR_NEXT) != 0) { axiom_soap_envelope_t *temp_env = axiom_soap_envelope_create_default_soap_fault_envelope(env, "soapenv:MustUnderstand", "Header not understood", AXIOM_SOAP11, NULL, NULL); axis2_msg_ctx_set_fault_soap_envelope(msg_ctx, env, temp_env); axis2_msg_ctx_set_wsa_action(msg_ctx, env, "http://www.w3.org/2005/08/addressing/fault"); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Must understand soap fault occured"); return AXIS2_FAILURE; } } } } return AXIS2_SUCCESS; }
AXIS2_EXTERN axis2_msg_ctx_t * AXIS2_CALL axis2_engine_create_fault_msg_ctx( axis2_engine_t * engine, const axutil_env_t * env, axis2_msg_ctx_t * processing_context, const axis2_char_t * code_value, const axis2_char_t * reason_text) { axis2_msg_ctx_t *fault_ctx = NULL; axis2_endpoint_ref_t *fault_to = NULL; axis2_endpoint_ref_t *reply_to = NULL; axutil_stream_t *stream = NULL; axiom_soap_envelope_t *envelope = NULL; const axis2_char_t *wsa_action = NULL; const axis2_char_t *msg_id = NULL; axis2_relates_to_t *relates_to = NULL; axis2_char_t *msg_uuid = NULL; axis2_msg_info_headers_t *msg_info_headers = NULL; axis2_bool_t doing_rest = AXIS2_FALSE; AXIS2_PARAM_CHECK(env->error, processing_context, NULL); if(axis2_msg_ctx_get_process_fault(processing_context, env)) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_PROCESSING_FAULT_ALREADY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating fault message contex failed"); return NULL; } fault_ctx = axis2_msg_ctx_create(env, engine->conf_ctx, axis2_msg_ctx_get_transport_in_desc( processing_context, env), axis2_msg_ctx_get_transport_out_desc(processing_context, env)); axis2_msg_ctx_set_process_fault(fault_ctx, env, AXIS2_TRUE); fault_to = axis2_msg_ctx_get_fault_to(processing_context, env); if(fault_to) { const axis2_char_t *address = axis2_endpoint_ref_get_address(fault_to, env); if(!address) { fault_to = NULL; } else if(axutil_strcmp(AXIS2_WSA_NONE_URL, address) == 0 || axutil_strcmp( AXIS2_WSA_NONE_URL_SUBMISSION, address) == 0) { reply_to = axis2_msg_ctx_get_reply_to(processing_context, env); if(reply_to) { axis2_msg_ctx_set_fault_to(fault_ctx, env, reply_to); } else { axis2_msg_ctx_set_fault_to(fault_ctx, env, fault_to); } } else { axis2_msg_ctx_set_fault_to(fault_ctx, env, fault_to); } } stream = axis2_msg_ctx_get_transport_out_stream(processing_context, env); if(stream) { axis2_msg_ctx_set_transport_out_stream(fault_ctx, env, stream); axis2_msg_ctx_reset_transport_out_stream(processing_context, env); } if(!fault_to && !stream) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NOWHERE_TO_SEND_FAULT, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Soap fault target destination not found"); return NULL; } /* Set WSA action */ msg_info_headers = axis2_msg_ctx_get_msg_info_headers(processing_context, env); if(msg_info_headers) { wsa_action = axis2_msg_info_headers_get_action(msg_info_headers, env); if(wsa_action) { /* We have to use the action set by user, cannot use the default always. wsa_action = "http://www.w3.org/2005/08/addressing/fault"; */ axis2_msg_ctx_set_wsa_action(fault_ctx, env, wsa_action); } } /* Set relates to */ msg_id = axis2_msg_ctx_get_msg_id(processing_context, env); /* we can create with default Relates to namespace. Actual namespace based on addressing version will be created in addressing out handler */ relates_to = axis2_relates_to_create(env, msg_id, AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE); axis2_msg_ctx_set_relates_to(fault_ctx, env, relates_to); /* Set msg id */ msg_uuid = axutil_uuid_gen(env); axis2_msg_ctx_set_message_id(fault_ctx, env, msg_uuid); if(msg_uuid) { AXIS2_FREE(env->allocator, msg_uuid); msg_uuid = NULL; } /** Copy the property map from the current message context to the newly created fault message context. */ { axis2_ctx_t *ctx = axis2_msg_ctx_get_base(processing_context, env); axis2_ctx_t *fault_base_ctx = axis2_msg_ctx_get_base(fault_ctx, env); if(ctx && fault_ctx) { axis2_ctx_set_property_map(fault_base_ctx, env, axis2_ctx_get_property_map(ctx, env)); } } axis2_msg_ctx_set_op_ctx(fault_ctx, env, axis2_msg_ctx_get_op_ctx(processing_context, env)); axis2_msg_ctx_set_process_fault(fault_ctx, env, AXIS2_TRUE); axis2_msg_ctx_set_server_side(fault_ctx, env, AXIS2_TRUE); envelope = axis2_msg_ctx_get_fault_soap_envelope(processing_context, env); if(!envelope) { if(axis2_msg_ctx_get_is_soap_11(processing_context, env)) { envelope = axiom_soap_envelope_create_default_soap_fault_envelope(env, code_value, reason_text, AXIOM_SOAP11, NULL, NULL); } else { envelope = axiom_soap_envelope_create_default_soap_fault_envelope(env, code_value, reason_text, AXIOM_SOAP12, NULL, NULL); } if(!envelope) { AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Creating default soap envelope failed"); return NULL; } } else { axis2_msg_ctx_set_fault_soap_envelope(processing_context, env, NULL); } doing_rest = axis2_msg_ctx_get_doing_rest(processing_context, env); axis2_msg_ctx_set_doing_rest(fault_ctx, env, doing_rest); axis2_msg_ctx_set_soap_envelope(fault_ctx, env, envelope); axis2_msg_ctx_set_out_transport_info(fault_ctx, env, axis2_msg_ctx_get_out_transport_info( processing_context, env)); axis2_msg_ctx_reset_out_transport_info(processing_context, env); return fault_ctx; }
axis2_status_t AXIS2_CALL sandesha2_msg_ctx_add_soap_envelope( sandesha2_msg_ctx_t *rm_msg_ctx, const axutil_env_t *env) { int soap_ver = AXIOM_SOAP11; axiom_soap_envelope_t *soap_envelope = NULL; if(!axis2_msg_ctx_get_is_soap_11(rm_msg_ctx->msg_ctx, env)) { soap_ver = AXIOM_SOAP12; } soap_envelope = axis2_msg_ctx_get_soap_envelope(rm_msg_ctx->msg_ctx, env); if(!soap_envelope) { soap_envelope = axiom_soap_envelope_create_default_soap_envelope(env, soap_ver); axis2_msg_ctx_set_soap_envelope(rm_msg_ctx->msg_ctx, env, soap_envelope); } if(rm_msg_ctx->close_seq) { sandesha2_close_seq_to_soap_envelope(rm_msg_ctx->close_seq, env, soap_envelope); } if(rm_msg_ctx->close_seq_res) { sandesha2_close_seq_res_to_soap_envelope(rm_msg_ctx->close_seq_res, env, soap_envelope); } if(rm_msg_ctx->create_seq) { sandesha2_create_seq_to_soap_envelope(rm_msg_ctx->create_seq, env, soap_envelope); } if(rm_msg_ctx->create_seq_res) { sandesha2_create_seq_res_to_soap_envelope(rm_msg_ctx->create_seq_res, env, soap_envelope); } if(rm_msg_ctx->make_connection) { sandesha2_make_connection_to_soap_envelope(rm_msg_ctx->make_connection, env, soap_envelope); } if(rm_msg_ctx->msg_pending) { sandesha2_msg_pending_to_soap_envelope(rm_msg_ctx->msg_pending, env, soap_envelope); } if(rm_msg_ctx->seq_ack) { sandesha2_seq_ack_to_soap_envelope(rm_msg_ctx->seq_ack, env, soap_envelope); } if(rm_msg_ctx->seq) { sandesha2_seq_to_soap_envelope(rm_msg_ctx->seq, env, soap_envelope); } if(rm_msg_ctx->terminate_seq) { sandesha2_terminate_seq_to_soap_envelope(rm_msg_ctx->terminate_seq, env, soap_envelope); } if(rm_msg_ctx->terminate_seq_res) { sandesha2_terminate_seq_res_to_soap_envelope(rm_msg_ctx->terminate_seq_res, env, soap_envelope); } return AXIS2_SUCCESS; }