axis2_status_t axis2_addr_in_extract_addr_params( const axutil_env_t * env, axiom_soap_header_t * soap_header, axis2_msg_info_headers_t ** msg_info_headers_p, axutil_array_list_t * addr_headers, const axis2_char_t * addr_ns_str, axis2_msg_ctx_t * msg_ctx) { axutil_hash_t *header_block_ht = NULL; axutil_hash_index_t *hash_index = NULL; axis2_msg_info_headers_t *msg_info_headers = *(msg_info_headers_p); axis2_status_t status = AXIS2_SUCCESS; axis2_bool_t to_found = AXIS2_FALSE; axis2_bool_t reply_to_found = AXIS2_FALSE; axis2_bool_t fault_to_found = AXIS2_FALSE; axis2_bool_t action_found = AXIS2_FALSE; axis2_bool_t msg_id_found = AXIS2_FALSE; AXIS2_PARAM_CHECK(env->error, soap_header, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, msg_info_headers_p, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, addr_headers, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, addr_ns_str, AXIS2_FAILURE); if (!msg_info_headers) { AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No messgae info header. Creating new"); msg_info_headers = axis2_msg_info_headers_create(env, NULL, NULL); if (!msg_info_headers) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MSG_INFO_HEADERS, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No message information headers available"); return AXIS2_FAILURE; } } header_block_ht = axiom_soap_header_get_all_header_blocks(soap_header, env); if (!header_block_ht) { return AXIS2_FAILURE; } /* Iterate thru header blocks */ 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; axiom_node_t *header_block_node = NULL; axiom_element_t *header_block_ele = NULL; axis2_char_t *ele_localname = NULL; axis2_endpoint_ref_t *epr = NULL; axis2_char_t *role = NULL; axutil_hash_this(hash_index, NULL, NULL, &hb); header_block = (axiom_soap_header_block_t *) hb; header_block_node = axiom_soap_header_block_get_base_node(header_block, env); header_block_ele = (axiom_element_t *) axiom_node_get_data_element(header_block_node, env); ele_localname = axiom_element_get_localname(header_block_ele, env); role = axiom_soap_header_block_get_role(header_block, env); if (role && !axutil_strcmp(role, AXIOM_SOAP12_SOAP_ROLE_NONE)) { /* Role is none, no need of processing */ continue; } if (!axutil_strcmp(ele_localname, AXIS2_WSA_TO)) { /* Here the addressing epr overidde what ever already there in the message context */ epr = axis2_endpoint_ref_create(env, axiom_element_get_text (header_block_ele, env, header_block_node)); if (AXIS2_TRUE == to_found) { /* Duplicate To */ axis2_addr_in_create_fault_envelope(env, AXIS2_WSA_PREFIX_TO, addr_ns_str, msg_ctx); status = AXIS2_FAILURE; continue; } axis2_msg_info_headers_set_to(msg_info_headers, env, epr); axis2_addr_in_extract_to_epr_ref_params(env, epr, soap_header, addr_ns_str); axiom_soap_header_block_set_processed(header_block, env); to_found = AXIS2_TRUE; } else if (!axutil_strcmp(ele_localname, AXIS2_WSA_FROM)) { epr = axis2_msg_info_headers_get_from(msg_info_headers, env); if (!epr) { /* The address is not known now. Pass the empty string and fill this once the element under this is processed. */ epr = axis2_endpoint_ref_create(env, ""); axis2_msg_info_headers_set_from(msg_info_headers, env, epr); } axis2_addr_in_extract_epr_information(env, header_block, epr, addr_ns_str); axiom_soap_header_block_set_processed(header_block, env); } else if (!axutil_strcmp(ele_localname, AXIS2_WSA_REPLY_TO)) { epr = axis2_msg_info_headers_get_reply_to(msg_info_headers, env); if (reply_to_found == AXIS2_TRUE) { /* Duplicate Reply To */ axis2_addr_in_create_fault_envelope(env, AXIS2_WSA_PREFIX_REPLY_TO, addr_ns_str, msg_ctx); status = AXIS2_FAILURE; continue; } if (!epr) { epr = axis2_endpoint_ref_create(env, ""); axis2_msg_info_headers_set_reply_to(msg_info_headers, env, epr); } axis2_addr_in_extract_epr_information(env, header_block, epr, addr_ns_str); axiom_soap_header_block_set_processed(header_block, env); reply_to_found = AXIS2_TRUE; } else if (!axutil_strcmp(ele_localname, AXIS2_WSA_FAULT_TO)) { epr = axis2_msg_info_headers_get_fault_to(msg_info_headers, env); if (fault_to_found == AXIS2_TRUE) { /* Duplicate Fault To */ axis2_addr_in_create_fault_envelope(env, AXIS2_WSA_PREFIX_FAULT_TO, addr_ns_str, msg_ctx); status = AXIS2_FAILURE; axis2_msg_info_headers_set_fault_to(msg_info_headers, env, NULL); continue; } if (!epr) { epr = axis2_endpoint_ref_create(env, ""); axis2_msg_info_headers_set_fault_to(msg_info_headers, env, epr); } axis2_addr_in_extract_epr_information(env, header_block, epr, addr_ns_str); axiom_soap_header_block_set_processed(header_block, env); fault_to_found = AXIS2_TRUE; } else if (!axutil_strcmp(ele_localname, AXIS2_WSA_MESSAGE_ID)) { axis2_char_t *text = NULL; if (msg_id_found == AXIS2_TRUE) { /* Duplicate Message ID */ axis2_addr_in_create_fault_envelope(env, AXIS2_WSA_PREFIX_MESSAGE_ID, addr_ns_str, msg_ctx); status = AXIS2_FAILURE; continue; } text = axiom_element_get_text(header_block_ele, env, header_block_node); axis2_msg_info_headers_set_in_message_id(msg_info_headers, env, text); axiom_soap_header_block_set_processed(header_block, env); msg_id_found = AXIS2_TRUE; } else if (!axutil_strcmp(ele_localname, AXIS2_WSA_ACTION)) { axis2_char_t *text = NULL; if (action_found == AXIS2_TRUE) { /* Duplicate Action */ axis2_addr_in_create_fault_envelope(env, AXIS2_WSA_PREFIX_ACTION, addr_ns_str, msg_ctx); status = AXIS2_FAILURE; continue; } text = axiom_element_get_text(header_block_ele, env, header_block_node); axis2_msg_info_headers_set_action(msg_info_headers, env, text); axiom_soap_header_block_set_processed(header_block, env); action_found = AXIS2_TRUE; } else if (!axutil_strcmp(ele_localname, AXIS2_WSA_RELATES_TO)) { axis2_char_t *address = NULL; axutil_qname_t *rqn = NULL; axiom_attribute_t *relationship_type = NULL; const axis2_char_t *relationship_type_default_value = NULL; const axis2_char_t *relationship_type_value = NULL; axis2_relates_to_t *relates_to = NULL; if (!axutil_strcmp(AXIS2_WSA_NAMESPACE_SUBMISSION, addr_ns_str)) { relationship_type_default_value = AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE_SUBMISSION; } else { relationship_type_default_value = AXIS2_WSA_ANONYMOUS_URL_SUBMISSION; } rqn = axutil_qname_create(env, AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE, NULL, NULL); relationship_type = axiom_element_get_attribute(header_block_ele, env, rqn); if (!relationship_type) { relationship_type_value = AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE_SUBMISSION; } else { relationship_type_value = axiom_attribute_get_value(relationship_type, env); } address = axiom_element_get_text(header_block_ele, env, header_block_node); relates_to = axis2_relates_to_create(env, address, relationship_type_value); axis2_msg_info_headers_set_relates_to(msg_info_headers, env, relates_to); axiom_soap_header_block_set_processed(header_block, env); axutil_qname_free(rqn, env); } } /* If an action is not found, it's a false*/ if (action_found == AXIS2_FALSE) { axis2_addr_in_create_fault_envelope(env, AXIS2_WSA_PREFIX_ACTION, addr_ns_str, msg_ctx); status = AXIS2_FAILURE; } return status; }
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; }