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;
}
Example #2
0
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;
}
Example #3
0
static axis2_status_t AXIS2_CALL
axis2_msg_recv_receive_impl(
    axis2_msg_recv_t * msg_recv,
    const axutil_env_t * env,
    axis2_msg_ctx_t * msg_ctx,
    void *callback_recv_param)
{
    axis2_msg_ctx_t *out_msg_ctx = NULL;
    axis2_engine_t *engine = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_op_ctx_t *op_ctx = NULL;
    axis2_svc_ctx_t *svc_ctx = NULL;
    axis2_status_t status = AXIS2_FAILURE;

    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[axis2]Entry:axis2_msg_recv_receive_impl");
    out_msg_ctx = axis2_core_utils_create_out_msg_ctx(env, msg_ctx);
    if(!out_msg_ctx)
    {
        return AXIS2_FAILURE;
    }
    op_ctx = axis2_msg_ctx_get_op_ctx(out_msg_ctx, env);
    if(!op_ctx)
    {
        axis2_core_utils_reset_out_msg_ctx(env, out_msg_ctx);
        axis2_msg_ctx_free(out_msg_ctx, env);
        return AXIS2_FAILURE;
    }

    status = axis2_op_ctx_add_msg_ctx(op_ctx, env, out_msg_ctx);
    if(!status)
    {
        axis2_core_utils_reset_out_msg_ctx(env, out_msg_ctx);
        axis2_msg_ctx_free(out_msg_ctx, env);
        return status;
    }
    status = axis2_op_ctx_add_msg_ctx(op_ctx, env, msg_ctx);

    if(!status)
    {
        return status;
    }

    status = axis2_msg_recv_invoke_business_logic(msg_recv, env, msg_ctx, out_msg_ctx);
    if(AXIS2_SUCCESS != status)
    {
        axis2_core_utils_reset_out_msg_ctx(env, out_msg_ctx);
        axis2_msg_ctx_free(out_msg_ctx, env);
        return status;
    }
    svc_ctx = axis2_op_ctx_get_parent(op_ctx, env);
    conf_ctx = axis2_svc_ctx_get_conf_ctx(svc_ctx, env);
    engine = axis2_engine_create(env, conf_ctx);
    if(!engine)
    {
        axis2_msg_ctx_free(out_msg_ctx, env);
        return AXIS2_FAILURE;
    }
    if(axis2_msg_ctx_get_soap_envelope(out_msg_ctx, env))
    {
        axiom_soap_envelope_t *soap_envelope = axis2_msg_ctx_get_soap_envelope(out_msg_ctx, env);
        if(soap_envelope)
        {
            axiom_soap_body_t *body = axiom_soap_envelope_get_body(soap_envelope, env);
            if(body)
            {
                /* in case of a SOAP fault, we got to return failure so that
                 transport gets to know that it should send 500 */
                if(axiom_soap_body_has_fault(body, env))
                {
                    status = AXIS2_FAILURE;
                    axis2_msg_ctx_set_fault_soap_envelope(msg_ctx, env, soap_envelope);
                    axis2_msg_ctx_set_soap_envelope(out_msg_ctx, env, NULL);
                }
                else
                {
                    /* if it is two way and not a fault then send through engine.
                     if it is one way we do not need to do an engine send */
                    status = axis2_engine_send(engine, env, out_msg_ctx);
                }
            }
        }
    }
    axis2_engine_free(engine, env);

    /* Reset the out message context to avoid double freeing at http worker. For example if this is
     * not done here both in and out message context will try to free the transport out stream 
     * which will result in memory corruption.
     */
    if(!axis2_msg_ctx_is_paused(out_msg_ctx, env) && !axis2_msg_ctx_is_keep_alive(out_msg_ctx, env))
    {
        axis2_core_utils_reset_out_msg_ctx(env, out_msg_ctx);
    }
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[axis2]Exit:axis2_msg_recv_receive_impl");
    return status;
    (void)callback_recv_param;
}
Example #4
0
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;
}