/**
 * Set a security processed result property to the message context
 * @env the environment 
 * @msg_ctx the message context in which data are stored/extracted
 * @return status of the operation
 */
AXIS2_EXTERN axis2_status_t AXIS2_CALL
rampart_set_security_processed_results_property(
    const axutil_env_t *env,
    axis2_msg_ctx_t *msg_ctx)
{
    axutil_hash_t *sec_processed_results = NULL;
    axutil_property_t *sec_processed_results_prop = NULL;

    sec_processed_results = axutil_hash_make(env);
    if(!sec_processed_results)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
            "[rampart]Security processed result hash container creation failed.");
        return AXIS2_FAILURE;
    }

    sec_processed_results_prop = axutil_property_create_with_args(
        env, AXIS2_SCOPE_REQUEST , AXIS2_TRUE, (void *)axutil_hash_free, sec_processed_results);
    if(!sec_processed_results_prop)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
            "[rampart]Security processed result property creation failed.");
        return AXIS2_FAILURE;
    }

    axis2_msg_ctx_set_property(
        msg_ctx, env, RAMPART_SECURITY_PROCESSED_RESULTS, sec_processed_results_prop);

    return AXIS2_SUCCESS;
}
axis2_status_t AXIS2_CALL
axis2_statistics_admin_global_request_count_handler_invoke(struct axis2_handler *handler, 
                        const axutil_env_t *env,
                        struct axis2_msg_ctx *msg_ctx)
{
    axis2_status_t status = AXIS2_SUCCESS;
    axis2_svc_t *svc = NULL;
    
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[adminservices] Start:axis2_statistics_admin_global_request_count_handler_invoke");
    AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);

    svc = axis2_msg_ctx_get_svc(msg_ctx, env);
    if(svc)
    {
        long *time_now = NULL;
        axutil_property_t *property = NULL;
       
        time_now = AXIS2_MALLOC(env->allocator, sizeof(long));
        *time_now = service_admin_util_get_current_time_in_millis(env);
        property = axutil_property_create_with_args(env, 0, 0, 0, time_now);
        axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_REQUEST_RECEIVED_TIME, property);
    }
    
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[adminservices] End:axis2_statistics_admin_global_request_count_handler_invoke");
    
    return status;
}
示例#3
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_client_close(
    axis2_svc_client_t * svc_client,
    const axutil_env_t * env)
{
    axis2_status_t status = AXIS2_FAILURE;
    axutil_property_t *property = NULL;
    axis2_endpoint_ref_t *replyto = NULL;

    property = axutil_property_create_with_args(env, 0, 0, 0, AXIS2_VALUE_TRUE);
    axis2_options_set_property(svc_client->options, env, AXIS2_SVC_CLIENT_CLOSED, property);
    replyto = axis2_options_get_reply_to(svc_client->options, env);
    if(replyto)
    {
        axiom_node_t *reply = NULL;

        reply = axis2_svc_client_send_receive(svc_client, env, NULL);
        if(reply)
        {
            status = AXIS2_SUCCESS;
        }
    }
    else
    {
        status = axis2_svc_client_send_robust(svc_client, env, NULL);
    }

    return status;
}
示例#4
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_amqp_receiver_init(
    axis2_transport_receiver_t* receiver,
    const axutil_env_t* env,
    axis2_conf_ctx_t* conf_ctx,
    axis2_transport_in_desc_t* in_desc)
{
    axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL;
    axutil_property_t* property = NULL;
    const axis2_char_t* broker_ip = NULL;
    int* broker_port = (int*)AXIS2_MALLOC(env->allocator, sizeof(int));
    *broker_port = AXIS2_QPID_NULL_CONF_INT;

    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);

    receiver_resource_pack = AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver);
    receiver_resource_pack->conf_ctx = conf_ctx;

    /* Set broker IP */
    broker_ip = axis2_amqp_util_get_in_desc_conf_value_string(in_desc, env,
        AXIS2_AMQP_CONF_QPID_BROKER_IP);
    if(!broker_ip)
    {
        broker_ip = AXIS2_QPID_DEFAULT_BROKER_IP;
    }
    property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0,
        (void*)broker_ip);
    axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx, env,
        AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP, property);

    /* Set broker port */
    *broker_port = axis2_amqp_util_get_in_desc_conf_value_int(in_desc, env,
        AXIS2_AMQP_CONF_QPID_BROKER_PORT);
    if(*broker_port == AXIS2_QPID_NULL_CONF_INT)
    {
        *broker_port = AXIS2_QPID_DEFAULT_BROKER_PORT;
    }
    property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0,
        (void*)broker_port);
    axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx, env,
        AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT, property);

    return AXIS2_SUCCESS;
}
static axutil_hash_t *
sct_provider_hash_map_get_sct_hash_store(
    const axutil_env_t *env, 
    axis2_msg_ctx_t* msg_ctx)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_ctx_t *ctx = NULL;
    axutil_property_t *property = NULL;
    axutil_hash_t *hash_store = NULL;
    
    /* Get the conf ctx */
    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
    if(!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log,AXIS2_LOG_SI, 
            "[rampart]Config context is NULL. Cannot get security context token hash store.");
        return NULL;
    }

    ctx = axis2_conf_ctx_get_base(conf_ctx,env);
    if(!ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "[rampart]Axis2 context is NULL. Cannot get security context token hash store.");
        return NULL;
    }

    /* Get the hash store property */
    property = axis2_ctx_get_property(ctx, env, RAMPART_SCT_PROVIDER_HASH_PROB);
    if(property)
    {
        /* Get the store */
        hash_store = (axutil_hash_t*)axutil_property_get_value(property, env);
    }
    else
    {
        axutil_property_t *hash_store_prop = NULL;

        hash_store = axutil_hash_make(env);
        hash_store_prop = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION,
               AXIS2_TRUE, (void *)sct_provider_hash_map_sct_hash_store_free, hash_store);
        axis2_ctx_set_property(ctx, env, RAMPART_SCT_PROVIDER_HASH_PROB, hash_store_prop);
    }

    return hash_store;
}
示例#6
0
int main(int argc, char** argv)
{
    const axutil_env_t *env = NULL;
    const axis2_char_t *address = NULL;
    const axis2_char_t *client_home = NULL;
    axis2_char_t *file_name = NULL;
    axis2_char_t *policy_file = NULL;
    axis2_endpoint_ref_t* endpoint_ref = NULL;
    axis2_options_t *options = NULL;
    axis2_svc_client_t* svc_client = NULL;
    axiom_node_t *payload = NULL;
    axiom_node_t *ret_node = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    neethi_policy_t *policy = NULL;
    rampart_config_t* client_config = NULL;
    axutil_property_t *property = NULL;
    rampart_saml_token_t *saml = NULL;
    axiom_node_t *assertion = NULL;
	/* Set up the environment */
    env = axutil_env_create_all("echo.log", AXIS2_LOG_LEVEL_TRACE);

    /* Set end-point-reference of echo service */
    address = "http://localhost:9090/axis2/services/echo";
    if (argc > 2)
    {
        address = argv[1];
        client_home = argv[2];
        printf("Using endpoint : %s\n", address);
        printf("Using client_home : %s\n", client_home);
    }

    if ((axutil_strcmp(argv[1], "-h") == 0) || (axutil_strcmp(argv[1], "--help") == 0))
    {
        printf("Usage : %s [endpoint_url] [client_home]\n", argv[0]);
        printf("use -h for help\n");
        return 0;
    }

    /* Create end-point-reference with given address */
    endpoint_ref = axis2_endpoint_ref_create(env, address);

    /* Setup options */
    options = axis2_options_create(env);
    axis2_options_set_to(options, env, endpoint_ref);
    axis2_options_set_action(options, env,
            "http://example.com/ws/2004/09/policy/Test/EchoRequest");
    /*axis2_options_set_action(options, env,
            "urn:echo");*/


    /*If the client home is not specified, use the AXIS2C_HOME*/
    if (!client_home)
    {
        client_home = AXIS2_GETENV("AXIS2C_HOME");
        printf("\nNo client_home specified. Using default %s", client_home);
    }

    /* Create service client */
    printf("client_home= %s", client_home);
    svc_client = axis2_svc_client_create(env, client_home);
    if (!svc_client)
    {
        printf("Error creating service client\n");
        return -1;
    }

    client_config = rampart_config_create(env);
    if(!client_config)
    {
        printf("Cannot create rampart config\n");
        return 0;
    }
    assertion = create_saml_assertion(env);
    saml = rampart_saml_token_create(env, assertion, RAMPART_ST_CONFIR_TYPE_SENDER_VOUCHES);
	rampart_saml_token_set_token_type(saml, env, RAMPART_ST_TYPE_SIGNED_SUPPORTING_TOKEN);
    rampart_config_add_saml_token(client_config, env, saml);

    property = axutil_property_create_with_args(env, AXIS2_SCOPE_REQUEST ,
        AXIS2_TRUE, (void *)rampart_config_free, client_config);
    axis2_options_set_property(options, env, RAMPART_CLIENT_CONFIGURATION, property);

    /* Set service client options */
    axis2_svc_client_set_options(svc_client, env, options);

    /*We need to specify the client's policy file location*/
    if(client_home)
    {
        file_name = axutil_stracat(env, client_home, AXIS2_PATH_SEP_STR);
        policy_file = axutil_stracat(env, file_name, "policy.xml" );
        AXIS2_FREE(env->allocator, file_name);
        file_name = NULL;        
    }else{
        printf("Client Home not Specified\n");
        printf("echo client invoke FAILED!\n");
        return 0;
    }
    /*Create the policy, from file*/   
    policy = neethi_util_create_policy_from_file(env, policy_file);
    if(!policy)
    {
        printf("\nPolicy creation failed from the file. %s\n", policy_file);
    }
	if(policy_file){
        AXIS2_FREE(env->allocator, policy_file);
        policy_file = NULL;
    }

    status = axis2_svc_client_set_policy(svc_client, env, policy);

    if(status == AXIS2_FAILURE)
    {
        printf("Policy setting failed\n");
    }
    
    /* Build the SOAP request message payload using OM API.*/
    payload = build_om_payload_for_echo_svc(env);
    
    /*If not engaged in the client's axis2.xml, uncomment this line*/
    axis2_svc_client_engage_module(svc_client, env, "rampart");
    
    /* Send request */
    ret_node = axis2_svc_client_send_receive(svc_client, env, payload);


    if (axis2_svc_client_get_last_response_has_fault(svc_client, env))
    {
        axiom_soap_envelope_t *soap_envelope = NULL;
        axiom_soap_body_t *soap_body = NULL;
        axiom_soap_fault_t *soap_fault = NULL;

        printf ("\nResponse has a SOAP fault\n");
        soap_envelope =
            axis2_svc_client_get_last_response_soap_envelope(svc_client, env);
        if (soap_envelope)
            soap_body = axiom_soap_envelope_get_body(soap_envelope, env);
        if (soap_body)
            soap_fault = axiom_soap_body_get_fault(soap_body, env);
        if (soap_fault)
        {
            printf("\nReturned SOAP fault: %s\n",
            axiom_node_to_string(axiom_soap_fault_get_base_node(soap_fault,env),
                env));
        }
            printf("echo client invoke FAILED!\n");
            return -1;
    }
    
    if (ret_node)
    {
        axis2_char_t *om_str = NULL;
        om_str = axiom_node_to_string(ret_node, env);
        if (om_str)
        {
            printf("\nReceived OM : %s\n", om_str);
        }
        printf("\necho client invoke SUCCESSFUL!\n");
        AXIS2_FREE(env->allocator, om_str);
        ret_node = NULL;
    }
    else
    {
        printf("echo client invoke FAILED!\n");
        return -1;
    }

    if (svc_client)
    {
        axis2_svc_client_free(svc_client, env);
        svc_client = NULL;
    }
    if (env)
    {
        axutil_env_free((axutil_env_t *) env);
        env = NULL;
    }
    
    return 0;
}
axis2_status_t
axis2_amqp_process_request(
    const axutil_env_t* env,
    axis2_amqp_request_processor_resource_pack_t* request_resource_pack)
{
    axiom_xml_reader_t* xml_reader = NULL;
    axiom_stax_builder_t* stax_builder = NULL;
    axiom_soap_builder_t* soap_builder = NULL;
    axis2_transport_out_desc_t* out_desc = NULL;
    axis2_transport_in_desc_t* in_desc = NULL;
    axis2_msg_ctx_t* msg_ctx = NULL;
    axiom_soap_envelope_t* soap_envelope = NULL;
    axis2_engine_t* engine = NULL;
    const axis2_char_t* soap_ns_uri = NULL;
    axis2_bool_t is_soap_11 = AXIS2_FALSE;
    axis2_char_t *soap_body_str = NULL;
    int soap_body_len = 0;
    axis2_bool_t is_mtom = AXIS2_FALSE;
    axis2_status_t status = AXIS2_FAILURE;
    axutil_hash_t *binary_data_map = NULL;
    axiom_soap_body_t *soap_body = NULL;
    axutil_property_t* reply_to_property = NULL;

    /* Create msg_ctx */
    if(!request_resource_pack->conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Conf Context not Available");
        return AXIS2_FAILURE;
    }

    out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(
        request_resource_pack->conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_AMQP);
    if(!out_desc)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport Out Descriptor not Found");
        return AXIS2_FAILURE;
    }

    in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(request_resource_pack->conf_ctx,
        env), env, AXIS2_TRANSPORT_ENUM_AMQP);
    if(!in_desc)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport In Descriptor not Found");
        return AXIS2_FAILURE;
    }

    /* Create msg_ctx */
    msg_ctx = axis2_msg_ctx_create(env, request_resource_pack->conf_ctx, in_desc, out_desc);

    axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE);

    /* Handle MTOM */
    if(strstr(request_resource_pack->content_type, AXIS2_AMQP_HEADER_ACCEPT_MULTIPART_RELATED))
    {
        axis2_char_t* mime_boundary = axis2_amqp_util_get_value_from_content_type(env,
            request_resource_pack->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);
                }
            }

            /* If this paramter is there mime_parser will cached the attachment 
             * using to the directory for large attachments. */
            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_MALLOC(env->allocator, sizeof(axis2_callback_info_t));

                stream = axutil_stream_create_basic(env);
                if(stream)
                {
                    axutil_stream_write(stream, env, request_resource_pack->request_content,
                        request_resource_pack->content_length);
                    callback_ctx->env = env;
                    callback_ctx->in_stream = stream;
                    callback_ctx->content_length = request_resource_pack->content_length;
                    callback_ctx->unread_len = request_resource_pack->content_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_str = axiom_mime_parser_get_soap_body_str(mime_parser, env);
                soap_body_len = axiom_mime_parser_get_soap_body_len(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 = request_resource_pack->request_content;
        soap_body_len = request_resource_pack->content_length;
    }

    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 AXIS2_FAILURE;
    }

    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 AXIS2_FAILURE;
    }

    soap_ns_uri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI;

    if(request_resource_pack->content_type)
    {
        if(strstr(request_resource_pack->content_type, AXIS2_AMQP_HEADER_ACCEPT_TEXT_XML))
        {
            is_soap_11 = AXIS2_TRUE;
            soap_ns_uri = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI;
        }
        /*if (strstr(request_resource_pack->content_type, AXIS2_AMQP_HEADER_ACCEPT_APPL_SOAP))
         {
         is_soap_11 = AXIS2_FALSE;
         soap_ns_uri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI;
         }
         else if (strstr(request_resource_pack->content_type, AXIS2_AMQP_HEADER_ACCEPT_TEXT_XML))
         {
         is_soap_11 = AXIS2_TRUE;
         soap_ns_uri = AXIOM_SOAP11_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 AXIS2_FAILURE;
    }

    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);
    axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_envelope);

    soap_body = axiom_soap_envelope_get_body(soap_envelope, env);

    if(!soap_body)
    {
        return AXIS2_FAILURE;
    }

    /* SOAPAction */
    if(request_resource_pack->soap_action)
    {
        axis2_msg_ctx_set_soap_action(msg_ctx, env, axutil_string_create(env,
            request_resource_pack->soap_action));
    }

    /* SOAP version */
    axis2_msg_ctx_set_is_soap_11(msg_ctx, env, is_soap_11);

    /* Set ReplyTo in the msg_ctx as a property. This is used by the server when
     * 1. WS-A is not in use
     * 2. ReplyTo is an anonymous EPR - Sandesha2/Dual-channel */
    reply_to_property = axutil_property_create_with_args(env, AXIS2_SCOPE_REQUEST, 0, 0,
        (void*)request_resource_pack->reply_to);
    axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_AMQP_MSG_CTX_PROPERTY_REPLY_TO,
        reply_to_property);

    engine = axis2_engine_create(env, request_resource_pack->conf_ctx);

    if(AXIS2_TRUE == axiom_soap_body_has_fault(soap_body, env))
    {
        status = axis2_engine_receive_fault(engine, env, msg_ctx);
    }
    else
    {
        status = axis2_engine_receive(engine, env, msg_ctx);
    }

    if(engine)
    {
        axis2_engine_free(engine, env);
    }

    if(soap_body_str && is_mtom)
    {
        AXIS2_FREE(env->allocator, soap_body_str);
    }

    return status;
}
示例#8
0
AXIS2_EXTERN axis2_transport_receiver_t* AXIS2_CALL
axis2_amqp_receiver_create(
    const axutil_env_t* env,
    const axis2_char_t* repo,
    const axis2_char_t* qpid_broker_ip,
    int qpid_broker_port)
{
    AXIS2_ENV_CHECK(env, NULL);

    axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL;

    receiver_resource_pack = (axis2_amqp_receiver_resource_pack_t*)AXIS2_MALLOC(env->allocator,
        sizeof(axis2_amqp_receiver_resource_pack_t));

    if(!receiver_resource_pack)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    receiver_resource_pack->receiver.ops = &amqp_receiver_ops;
    receiver_resource_pack->qpid_receiver = NULL;
    receiver_resource_pack->conf_ctx = NULL;
    receiver_resource_pack->conf_ctx_private = NULL;

    if(repo)
    {
        /**
         * 1. We first create a private conf ctx which is owned by this server
         * 	  we only free this private conf context. We should never free the
         *    receiver_impl->conf_ctx because it may be owned by any other object which
         *    may lead to double free.
         *
         * 2. The Qpid broker IP and port are set in conf_ctx at two different places.
         * 	  If the repo is specified, they are set here. Otherwise, they are set
         * 	  in axis2_amqp_receiver_init method.
         */
        axutil_property_t* property = NULL;
        const axis2_char_t* broker_ip = NULL;
        int* broker_port = (int*)AXIS2_MALLOC(env->allocator, sizeof(int));
        *broker_port = AXIS2_QPID_NULL_CONF_INT;

        receiver_resource_pack->conf_ctx_private = axis2_build_conf_ctx(env, repo);
        if(!receiver_resource_pack->conf_ctx_private)
        {
            axis2_amqp_receiver_free((axis2_transport_receiver_t *)receiver_resource_pack, env);
            return NULL;
        }

        /* Set broker IP */
        broker_ip = qpid_broker_ip ? qpid_broker_ip : AXIS2_QPID_DEFAULT_BROKER_IP;
        property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0,
            (void*)broker_ip);
        axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx_private, env,
            AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP, property);

        /* Set broker port */
        *broker_port = (qpid_broker_port != AXIS2_QPID_NULL_CONF_INT) ? qpid_broker_port
            : AXIS2_QPID_DEFAULT_BROKER_PORT;
        property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0,
            (void*)broker_port);
        axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx_private, env,
            AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT, property);

        receiver_resource_pack->conf_ctx = receiver_resource_pack->conf_ctx_private;
    }

    return &(receiver_resource_pack->receiver);
}
int main(int argc, char** argv)
{
    const axutil_env_t *env = NULL;
    const axis2_char_t *address = NULL;
    axis2_endpoint_ref_t* endpoint_ref = NULL;
    axis2_endpoint_ref_t* reply_to = NULL;
    axis2_options_t *options = NULL;
    const axis2_char_t *client_home = NULL;
    axis2_svc_client_t* svc_client = NULL;
    axiom_node_t *payload = NULL;
    axutil_property_t *property = NULL;
    axis2_listener_manager_t *listener_manager = NULL;
    axis2_char_t *offered_seq_id = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    axiom_node_t *result = NULL;
    neethi_policy_t *policy = NULL;
    
    /* Set up the environment */
    env = axutil_env_create_all("rm_echo_single_1_1_amqp.log", AXIS2_LOG_LEVEL_TRACE);
 

    /* Set end point reference of echo service */
    address = "amqp://127.0.0.1:5672/axis2/services/RM11SampleService";
    if (argc > 1)
    {
        if (axutil_strcmp(argv[1], "-h") == 0)
        {
            printf("Usage : %s [endpoint_url]\n", argv[0]);
            printf("use -h for help\n");
            return 0;
        }
        else
        {
            address = argv[1];
        }
    }
    printf ("Using endpoint : %s\n", address);
    
    /* Create EPR with given address */
    endpoint_ref = axis2_endpoint_ref_create(env, address);

    /* Setup options */
    options = axis2_options_create(env);
    axis2_options_set_to(options, env, endpoint_ref);
    
    /* Seperate listner needs addressing, hence addressing stuff in options */
    axis2_options_set_action(options, env,
        "http://127.0.0.1:8080/axis2/services/RM11SampleService/anonOutInOp");

    reply_to = axis2_endpoint_ref_create(env, AXIS2_WSA_ANONYMOUS_URL);
    axis2_options_set_reply_to(options, env, reply_to);

    /* Set up deploy folder. It is from the deploy folder, the configuration is 
     * picked up using the axis2.xml file.
     * In this sample client_home points to the Axis2/C default deploy folder. 
     * The client_home can be different from this folder on your system. For 
     * example, you may have a different folder (say, my_client_folder) with its 
     * own axis2.xml file. my_client_folder/modules will have the modules that 
     * the client uses
     */
    client_home = AXIS2_GETENV("AXIS2C_HOME");
    if (!client_home)
    {
        client_home = "../../..";
    }

    /* Create service client */
    svc_client = axis2_svc_client_create(env, client_home);
    if (!svc_client)
    {
        printf("Error creating service client\n");
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code:%d :: %s", 
                env->error->error_number, AXIS2_ERROR_GET_MESSAGE(env->error));

        return -1;
    }

    policy = neethi_util_create_policy_from_file(env, "../policy/rm11-policy.xml");
    if(!policy)
    {
        printf("\nPolicy creation failed from the file");
        return 0;
    }

    status = axis2_svc_client_set_policy(svc_client, env, policy);

    if(status == AXIS2_FAILURE)
    {
        printf("Policy setting failed\n");
    }


    /* Set service client options */
    axis2_svc_client_set_options(svc_client, env, options);    
    
    axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);  
    axis2_svc_client_engage_module(svc_client, env, "sandesha2");

    listener_manager = axis2_listener_manager_create(env);
    if (!listener_manager)
    {
        return AXIS2_FAILURE;
    }

    /* Offer sequence */
    offered_seq_id = axutil_uuid_gen(env);
    property = axutil_property_create(env);
    if(property)
    {
        axutil_property_set_value(property, env, axutil_strdup(env, offered_seq_id));
        axis2_options_set_property(options, env, SANDESHA2_CLIENT_OFFERED_SEQ_ID, property);
    }

    /* RM Version 1.1 */
    property = axutil_property_create_with_args(env, 3, 0, 0, SANDESHA2_SPEC_VERSION_1_1);
    if(property)
    {
        axis2_options_set_property(options, env, SANDESHA2_CLIENT_RM_SPEC_VERSION, property);
    }

    payload = build_om_payload_for_echo_svc(env, "echo1");
    /*status = axis2_svc_client_send_robust(svc_client, env, payload);
    if(status)
    {
        printf("\necho client single channel invoke SUCCESSFUL!\n");
    }
    payload = NULL;*/
    result = axis2_svc_client_send_receive(svc_client, env, payload);
    if(result)
    {
        axis2_char_t *om_str = NULL;
        om_str = axiom_node_to_string(result, env);
        if (om_str)
        {
            printf("\nReceived OM : %s\n", om_str);
            AXIS2_FREE(env->allocator, om_str);
        }
        printf("\necho client two way single channel invoke SUCCESSFUL!\n");
        result = NULL;
    }
    else
    {
        printf("\necho client two way single channel invoke FAILED!\n");
    }

    payload = build_om_payload_for_echo_svc(env, "echo2");
    /*status = axis2_svc_client_send_robust(svc_client, env, payload);
    if(status)
    {
        printf("\necho client single channel invoke SUCCESSFUL!\n");
    }
    payload = NULL;*/
    result = axis2_svc_client_send_receive(svc_client, env, payload);
    if(result)
    {
        axis2_char_t *om_str = NULL;
        om_str = axiom_node_to_string(result, env);
        if (om_str)
        {
            printf("\nReceived OM : %s\n", om_str);
            AXIS2_FREE(env->allocator, om_str);
        }
        printf("\necho client two way single channel invoke SUCCESSFUL!\n");
        result = NULL;
    }
    else
    {
        printf("\necho client two way single channel invoke FAILED!\n");
    }

    payload = build_om_payload_for_echo_svc(env, "echo3");
    /*status = axis2_svc_client_send_robust(svc_client, env, payload);
    if(status)
    {
        printf("\necho client single channel invoke SUCCESSFUL!\n");
    }
    payload = NULL;*/
    
    result = axis2_svc_client_send_receive(svc_client, env, payload);
    if(result)
    {
        axis2_char_t *om_str = NULL;
        om_str = axiom_node_to_string(result, env);
        if (om_str)
        {
            printf("\nReceived OM : %s\n", om_str);
            AXIS2_FREE(env->allocator, om_str);
        }
        printf("\necho client two way single channel invoke SUCCESSFUL!\n");
        result = NULL;
    }
    else
    {
        printf("\necho client two way single channel invoke FAILED!\n");
    }

    AXIS2_SLEEP(SANDESHA2_SLEEP); 

    sandesha2_client_terminate_seq_with_svc_client_and_seq_key(env, svc_client, NULL, NULL);

    AXIS2_SLEEP(6 * SANDESHA2_SLEEP);

    if (svc_client)
    {
        axis2_svc_client_free(svc_client, env);
        svc_client = NULL;
    }
    
    return 0;
}
/**
 * This function is invoked in RM 1.1 where client explicitly send the
 * terminate sequence message
 */
static axis2_status_t AXIS2_CALL
sandesha2_terminate_seq_msg_processor_process_out_msg(
    sandesha2_msg_processor_t *msg_processor,
    const axutil_env_t *env,
    sandesha2_msg_ctx_t *rm_msg_ctx)
{
    axis2_msg_ctx_t *msg_ctx = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    sandesha2_storage_mgr_t *storage_mgr = NULL;
    sandesha2_seq_property_mgr_t *seq_prop_mgr = NULL;
    sandesha2_create_seq_mgr_t *create_seq_mgr = NULL;
    sandesha2_sender_mgr_t *sender_mgr = NULL;
    axis2_char_t *to_address = NULL;
    axis2_char_t *seq_key = NULL;
    axis2_char_t *int_seq_id = NULL;
    axis2_char_t *out_seq_id = NULL;
    axutil_property_t *property = NULL;
    axis2_char_t *terminated = NULL;
    axis2_op_t *old_op = NULL;
    axis2_op_t *out_in_op = NULL;
    axutil_qname_t *qname = NULL;
    sandesha2_terminate_seq_t *term_seq_part = NULL;
    axis2_char_t *rm_version = NULL;
    axis2_char_t *transport_to = NULL;
    sandesha2_seq_property_bean_t *term_added = NULL;
    axis2_char_t *temp_action = NULL;
    axutil_string_t *soap_action = NULL;
    axis2_char_t *dbname = NULL;

    AXIS2_PARAM_CHECK(env->error, rm_msg_ctx, AXIS2_FAILURE);

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
                    "[sandesha2]Entry:sandesha2_terminate_seq_msg_processor_process_out_msg.");

    msg_ctx = sandesha2_msg_ctx_get_msg_ctx(rm_msg_ctx, env);
    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);

    dbname = sandesha2_util_get_dbname(env, conf_ctx);
    storage_mgr = sandesha2_utils_get_storage_mgr(env, dbname);
    if(!storage_mgr)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] Could not create storage manager.");
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_COULD_NOT_CREATE_STORAGE_MANAGER,
                        AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }
    seq_prop_mgr = sandesha2_permanent_seq_property_mgr_create(env, dbname);
    create_seq_mgr = sandesha2_permanent_create_seq_mgr_create(env, dbname);
    sender_mgr = sandesha2_permanent_sender_mgr_create(env, dbname);
    to_address = (axis2_char_t*)axis2_endpoint_ref_get_address(axis2_msg_ctx_get_to(msg_ctx, env),
                 env);

    property = axis2_msg_ctx_get_property(msg_ctx, env, SANDESHA2_CLIENT_SEQ_KEY);
    if(property)
    {
        seq_key = axutil_property_get_value(property, env);
    }

    int_seq_id = sandesha2_utils_get_client_internal_sequence_id(env, to_address, seq_key);
    out_seq_id = sandesha2_utils_get_seq_property(env, int_seq_id,
                 SANDESHA2_SEQUENCE_PROPERTY_OUTGOING_SEQUENCE_ID, seq_prop_mgr);

    if(!out_seq_id)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                        "[sandesha2]seq_id was not found. Cannot send the terminate message");

        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_CANNOT_FIND_SEQ_ID, AXIS2_FAILURE);
        if(seq_prop_mgr)
        {
            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
        }

        if(create_seq_mgr)
        {
            sandesha2_create_seq_mgr_free(create_seq_mgr, env);
        }

        if(sender_mgr)
        {
            sandesha2_sender_mgr_free(sender_mgr, env);
        }

        if(storage_mgr)
        {
            sandesha2_storage_mgr_free(storage_mgr, env);
        }

        return AXIS2_FAILURE;
    }

    terminated = sandesha2_utils_get_seq_property(env, int_seq_id,
                 SANDESHA2_SEQ_PROP_TERMINATE_ADDED, seq_prop_mgr);
    old_op = axis2_msg_ctx_get_op(msg_ctx, env);

    qname = axutil_qname_create(env, "temp", NULL, NULL);
    out_in_op = axis2_op_create_with_qname(env, qname);
    if(qname)
    {
        axutil_qname_free(qname, env);
    }

    axis2_op_set_msg_exchange_pattern(out_in_op, env, AXIS2_MEP_URI_OUT_IN);
    axis2_op_set_in_flow(out_in_op, env, axis2_op_get_in_flow(old_op, env));

    if(terminated && !axutil_strcmp(terminated, AXIS2_VALUE_TRUE))
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2] Terminate was added previously");
        if(terminated)
        {
            AXIS2_FREE(env->allocator, terminated);
        }

        if(out_seq_id)
        {
            AXIS2_FREE(env->allocator, out_seq_id);
        }

        if(seq_prop_mgr)
        {
            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
        }

        if(create_seq_mgr)
        {
            sandesha2_create_seq_mgr_free(create_seq_mgr, env);
        }

        if(sender_mgr)
        {
            sandesha2_sender_mgr_free(sender_mgr, env);
        }

        if(storage_mgr)
        {
            sandesha2_storage_mgr_free(storage_mgr, env);
        }

        return AXIS2_SUCCESS;
    }

    if(terminated)
    {
        AXIS2_FREE(env->allocator, terminated);
    }

    term_seq_part = sandesha2_msg_ctx_get_terminate_seq(rm_msg_ctx, env);
    sandesha2_identifier_set_identifier(sandesha2_terminate_seq_get_identifier(term_seq_part, env),
                                        env, out_seq_id);

    sandesha2_msg_ctx_set_flow(rm_msg_ctx, env, AXIS2_OUT_FLOW);
    property = axutil_property_create_with_args(env, 0, 0, 0, AXIS2_VALUE_TRUE);
    axis2_msg_ctx_set_property(msg_ctx, env, SANDESHA2_APPLICATION_PROCESSING_DONE, property);
    axis2_msg_ctx_set_to(msg_ctx, env, axis2_endpoint_ref_create(env, to_address));
    rm_version = sandesha2_utils_get_rm_version(env, msg_ctx);
    if(!rm_version)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                        "[sandesha2] Cant find the rm_version of the given message");

        if(out_seq_id)
        {
            AXIS2_FREE(env->allocator, out_seq_id);
        }

        if(seq_prop_mgr)
        {
            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
        }

        if(create_seq_mgr)
        {
            sandesha2_create_seq_mgr_free(create_seq_mgr, env);
        }

        if(sender_mgr)
        {
            sandesha2_sender_mgr_free(sender_mgr, env);
        }

        if(storage_mgr)
        {
            sandesha2_storage_mgr_free(storage_mgr, env);
        }

        return AXIS2_FAILURE;
    }

    axis2_msg_ctx_set_wsa_action(msg_ctx, env,
                                 sandesha2_spec_specific_consts_get_terminate_seq_action(env, rm_version));

    temp_action = sandesha2_spec_specific_consts_get_terminate_seq_soap_action(env, rm_version);

    soap_action = axutil_string_create(env, temp_action);
    axis2_msg_ctx_set_soap_action(msg_ctx, env, soap_action);
    transport_to = sandesha2_utils_get_seq_property(env, int_seq_id,
                   SANDESHA2_SEQ_PROP_TRANSPORT_TO, seq_prop_mgr);

    if(transport_to)
    {
        axis2_msg_ctx_set_transport_url(msg_ctx, env, transport_to);
        AXIS2_FREE(env->allocator, transport_to);
    }

    if(!sandesha2_util_is_ack_already_piggybacked(env, rm_msg_ctx))
    {
        sandesha2_ack_mgr_piggyback_acks_if_present(env, out_seq_id, rm_msg_ctx, storage_mgr,
                seq_prop_mgr, sender_mgr);
    }

    term_added = sandesha2_seq_property_bean_create(env);
    sandesha2_seq_property_bean_set_name(term_added, env, SANDESHA2_SEQ_PROP_TERMINATE_ADDED);
    sandesha2_seq_property_bean_set_seq_id(term_added, env, int_seq_id);
    if(out_seq_id)
    {
        AXIS2_FREE(env->allocator, out_seq_id);
    }

    sandesha2_seq_property_bean_set_value(term_added, env, AXIS2_VALUE_TRUE);
    sandesha2_seq_property_mgr_insert(seq_prop_mgr, env, term_added);

    if(seq_prop_mgr)
    {
        sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
    }

    if(create_seq_mgr)
    {
        sandesha2_create_seq_mgr_free(create_seq_mgr, env);
    }

    if(sender_mgr)
    {
        sandesha2_sender_mgr_free(sender_mgr, env);
    }

    if(storage_mgr)
    {
        sandesha2_storage_mgr_free(storage_mgr, env);
    }

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
                    "[sandesha2] Exit:sandesha2_terminate_seq_msg_processor_process_out_msg");

    return AXIS2_SUCCESS;
}
static axis2_status_t AXIS2_CALL
sandesha2_terminate_seq_msg_processor_add_terminate_seq_res(
    const axutil_env_t *env,
    sandesha2_msg_ctx_t *rm_msg_ctx,
    axis2_char_t *seq_id,
    sandesha2_seq_property_mgr_t *seq_prop_mgr)
{
    axis2_msg_ctx_t *msg_ctx = NULL;
    axis2_msg_ctx_t *out_msg_ctx = NULL;
    sandesha2_msg_ctx_t *out_rm_msg = NULL;
    sandesha2_msg_ctx_t *ack_rm_msg = NULL;
    sandesha2_seq_ack_t *seq_ack = NULL;
    axutil_property_t *property = NULL;
    axis2_engine_t *engine = NULL;
    axis2_op_ctx_t *op_ctx = NULL;
    axis2_endpoint_ref_t *to_epr = NULL;
    /*axis2_transport_out_desc_t *orig_trans_out = NULL;
    axis2_transport_out_desc_t *trans_out = NULL;
    sandesha2_sender_bean_t *term_res_bean = NULL;
    axis2_char_t *key = NULL;
    sandesha2_sender_mgr_t *retrans_mgr = NULL;*/

    AXIS2_PARAM_CHECK(env->error, rm_msg_ctx, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, seq_id, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, seq_prop_mgr, AXIS2_FAILURE);

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
                    "[sandesha2] Entry:sandesha2_terminate_seq_msg_processor_add_terminate_seq_res");

    msg_ctx = sandesha2_msg_ctx_get_msg_ctx(rm_msg_ctx, env);
    out_msg_ctx = sandesha2_utils_create_out_msg_ctx(env, msg_ctx);
    out_rm_msg = sandesha2_msg_creator_create_terminate_seq_res_msg(env, rm_msg_ctx, out_msg_ctx,
                 seq_prop_mgr);
    if(!out_rm_msg)
    {
        return AXIS2_FAILURE;
    }

    ack_rm_msg = sandesha2_ack_mgr_generate_ack_msg(env, rm_msg_ctx, seq_id, seq_prop_mgr);
    if(ack_rm_msg)
    {
        seq_ack = sandesha2_msg_ctx_get_seq_ack(ack_rm_msg, env);
        sandesha2_msg_ctx_set_seq_ack(out_rm_msg, env, seq_ack);
    }

    sandesha2_msg_ctx_add_soap_envelope(out_rm_msg, env);
    sandesha2_msg_ctx_set_flow(out_rm_msg, env, AXIS2_OUT_FLOW);

    property = axutil_property_create_with_args(env, 0, 0, 0, AXIS2_VALUE_TRUE);
    axis2_msg_ctx_set_property(out_msg_ctx, env, SANDESHA2_APPLICATION_PROCESSING_DONE, property);

    /* test code */
    /*
    to_epr = axis2_msg_ctx_get_to(out_msg_ctx, env);
    if(to_epr && !sandesha2_utils_is_anon_uri(env,
        axis2_endpoint_ref_get_address(to_epr, env)))
    {
        axis2_msg_ctx_t *tsr_msg_ctx = axis2_core_utils_create_out_msg_ctx(env, msg_ctx);
        orig_trans_out = axis2_msg_ctx_get_transport_out_desc(tsr_msg_ctx, env);
        property = axutil_property_create_with_args(env, 0, 0, 0, orig_trans_out);
        axis2_msg_ctx_set_property(tsr_msg_ctx, env, SANDESHA2_ORIGINAL_TRANSPORT_OUT_DESC, property);
        trans_out = sandesha2_utils_get_transport_out(env);
        axis2_msg_ctx_set_transport_out_desc(tsr_msg_ctx, env, trans_out);

        key = axutil_uuid_gen(env);
        term_res_bean = sandesha2_sender_bean_create(env);
        sandesha2_sender_bean_set_msg_ctx_ref_key(term_res_bean, env, key);
        property = axutil_property_create_with_args(env, 0, 0, 0, key);
        axis2_msg_ctx_set_property(tsr_msg_ctx, env, SANDESHA2_MESSAGE_STORE_KEY, property);
        sandesha2_storage_mgr_store_msg_ctx(storage_mgr, env, key, tsr_msg_ctx);
        */
    /* TODO: refine the terminate delay */
    /*
    sandesha2_sender_bean_set_time_to_send(term_res_bean, env,
        sandesha2_utils_get_current_time_in_millis(env) + SANDESHA2_TERMINATE_DELAY);
    sandesha2_sender_bean_set_msg_id(term_res_bean, env,
        (axis2_char_t *) axis2_msg_ctx_get_msg_id(tsr_msg_ctx, env));
    sandesha2_sender_bean_set_send(term_res_bean, env, AXIS2_TRUE);

    property = axutil_property_create_with_args(env, 0, 0, 0, AXIS2_VALUE_TRUE);
    axis2_msg_ctx_set_property(msg_ctx, env, SANDESHA2_QUALIFIED_FOR_SENDING, property);
    sandesha2_sender_bean_set_resend(term_res_bean, env, AXIS2_FALSE);
    retrans_mgr = sandesha2_storage_mgr_get_retrans_mgr(storage_mgr, env);
    sandesha2_sender_mgr_insert(retrans_mgr, env, term_res_bean);
    }*/
    /* end test code */

    engine = axis2_engine_create(env, axis2_msg_ctx_get_conf_ctx(msg_ctx, env));

    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2]axis2_engine_send");

    axis2_engine_send(engine, env, out_msg_ctx);
    op_ctx = axis2_msg_ctx_get_op_ctx(out_msg_ctx, env);
    if(to_epr)
    {
        if(sandesha2_utils_is_anon_uri(env, axis2_endpoint_ref_get_address(to_epr,
                                       env)))
        {
            axis2_op_ctx_set_response_written(op_ctx, env, AXIS2_TRUE);
        }
        else
        {
            axis2_op_ctx_set_response_written(op_ctx, env, AXIS2_FALSE);
        }
    }
    else
    {
        axis2_op_ctx_set_response_written(op_ctx, env, AXIS2_TRUE);
    }

    if(engine)
    {
        axis2_engine_free(engine, env);
    }

    if(out_rm_msg)
    {
        sandesha2_msg_ctx_free(out_rm_msg, env);
    }

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
                    "[sandesha2] Exit:sandesha2_terminate_seq_msg_processor_add_terminate_seq_res");

    return AXIS2_SUCCESS;
}
示例#12
0
文件: util.c 项目: kasungayan/commons
void
wsdl_util_manage_client_options(
    const axutil_env_t* env, 
    axis2_svc_client_t* svc_client,
    axutil_hash_t* svc_client_user_options, 
    axis2_options_t* client_options, 
    const axis2_char_t* operation_name,
    axiom_node_t* wsdl_axiom,
    axis2_bool_t is_version1_wsdl,
    axiom_node_t* sig_axiom, 
    axis2_char_t* service_name,
    axis2_char_t* port_name,
    axiom_node_t** operation_axiom,
    int* soap_version)
{
    axis2_char_t* endpoint_address = NULL;
    axis2_char_t* classmap = NULL;
    axis2_char_t* proxy_host = NULL;
    axis2_char_t* proxy_port = NULL;
    axis2_bool_t option_supported = AXIS2_TRUE;  /* ;-) */

    int string_malloc_length = -1;
    axis2_bool_t is_multiple_interfaces = AXIS2_FALSE; 
    axis2_bool_t multiple_ep = AXIS2_FALSE;
    axis2_endpoint_ref_t *to_epr = NULL;    
    axis2_char_t *soap_action = NULL;
    axis2_char_t *wsa_action = NULL;
    axis2_bool_t is_http_method_post = AXIS2_TRUE;
    axiom_node_t* binding_node = NULL;

    axis2_char_t *ssl_server_key_filename = NULL;
    axis2_char_t *ssl_client_key_filename = NULL;
    axis2_char_t *passphrase = NULL; 
    axutil_hash_t* wsdl_policy_hash = NULL;

    /* allocations */
    string_malloc_length = sizeof(axis2_char_t) * 256; 
    endpoint_address = (axis2_char_t *)AXIS2_MALLOC(env->allocator, string_malloc_length); 
    classmap = (axis2_char_t *)AXIS2_MALLOC(env->allocator, string_malloc_length); 
    soap_action = (axis2_char_t *)AXIS2_MALLOC(env->allocator, string_malloc_length); 
    wsa_action = (axis2_char_t *)AXIS2_MALLOC(env->allocator, string_malloc_length); 

    strcpy(soap_action, "");
    strcpy(wsa_action, "");

    if (svc_client_user_options)
    {
        if (axutil_hash_contains_key(svc_client_user_options, env, WSF_WSDL_ENDPOINT))
        {  
            strcpy(endpoint_address, (axis2_char_t*)axutil_hash_get(svc_client_user_options, WSF_WSDL_ENDPOINT, AXIS2_HASH_KEY_STRING)); 
        }
        else 
        {
            strcpy(endpoint_address, "");
        }

        if (axutil_hash_contains_key(svc_client_user_options, env, WSF_WSDL_CLASSMAP))
        {
            strcpy(classmap, (axis2_char_t*)axutil_hash_get(svc_client_user_options, WSF_WSDL_CLASSMAP, AXIS2_HASH_KEY_STRING)); 
        }
        else
        {
            strcpy(classmap, "");
        }
    
        if (axutil_hash_contains_key(svc_client_user_options, env, WSF_WSDL_USE_SOAP))
        {
            axis2_char_t* use_soap = (axis2_char_t*)axutil_hash_get(svc_client_user_options, WSF_WSDL_USE_SOAP, AXIS2_HASH_KEY_STRING);
            if (axutil_strcmp(use_soap, WSF_WSDL_SOAP_1_2) == 0)
            {
                *soap_version = 2;
                AXIS2_LOG_DEBUG_MSG(env->log, "soap version SOAP12");
            }
            else if (axutil_strcmp(use_soap, WSF_WSDL_SOAP_1_1) == 0)
            {
                *soap_version = 1;
                AXIS2_LOG_DEBUG_MSG(env->log, "soap version SOAP11"); 
            }
            else
            {
                 /* TODO: support REST */
            }
        }
        else
        {
            /* default to soap version 1.2 */
            *soap_version = 2;
            AXIS2_LOG_DEBUG_MSG(env->log, "default to soap version 1.2");
        }
        

        if (axutil_hash_contains_key(svc_client_user_options, env, WSF_WSDL_PROXY_HOST))
        {
            proxy_host = (axis2_char_t*)axutil_hash_get(svc_client_user_options, WSF_WSDL_PROXY_HOST, AXIS2_HASH_KEY_STRING);
        }

        if (axutil_hash_contains_key(svc_client_user_options, env, WSF_WSDL_PROXY_PORT))
        {
            proxy_port = (axis2_char_t*)axutil_hash_get(svc_client_user_options, WSF_WSDL_PROXY_PORT, AXIS2_HASH_KEY_STRING);
        }
        
        if (axutil_hash_contains_key(svc_client_user_options, env, WSF_WSDL_CLIENT_CERT))
        {
            ssl_server_key_filename = (axis2_char_t*)axutil_hash_get(svc_client_user_options, WSF_WSDL_CLIENT_CERT, AXIS2_HASH_KEY_STRING);
        }
        
        if (axutil_hash_contains_key(svc_client_user_options, env, WSF_WSDL_PASSPHRASE))
        {
            ssl_client_key_filename = (axis2_char_t*)axutil_hash_get(svc_client_user_options, WSF_WSDL_PASSPHRASE, AXIS2_HASH_KEY_STRING);
        }
        
        if (axutil_hash_contains_key(svc_client_user_options, env, WSF_WSDL_SERVER_CERT))
        {
            passphrase = (axis2_char_t*)axutil_hash_get(svc_client_user_options, WSF_WSDL_SERVER_CERT, AXIS2_HASH_KEY_STRING);
        }

        if (axutil_hash_contains_key(svc_client_user_options, env, WSF_WSDL_HTTP_METHOD))
        {
            if (axutil_strcasecmp((axis2_char_t*)axutil_hash_get(svc_client_user_options, WSF_WSDL_HTTP_METHOD, AXIS2_HASH_KEY_STRING), AXIS2_HTTP_GET) == 0)
            {
                is_http_method_post = AXIS2_FALSE;   
            }     
        }

    }
    else
    {
        strcpy(endpoint_address, "");
    }
    
    is_multiple_interfaces = AXIS2_FALSE;
    
    /* TODO: add support for multiple port/interface types */
    
    if (axutil_strcmp(endpoint_address, "") == 0)
    {
        axis2_char_t* sig_endpoint_address = NULL;
        if (wsdl_util_get_endpoint_address(sig_axiom, env, &sig_endpoint_address) == AXIS2_SUCCESS)
        {
            strcpy(endpoint_address, (char *)sig_endpoint_address);
        }
    }
    else
    {
        multiple_ep = 1;

        /* TODO: add suppor for multiple endpoints */ 
    }
    
    if (option_supported) /* get binding details */
    {
        axiom_node_t* op_axiom = NULL;
        int soap_ver = 2;
        axis2_char_t* wsa_action_binding_details = NULL;
        axis2_char_t* soap_action_binding_details = NULL;
    
        if (wsdl_util_find_operation(env,
                                     operation_name, endpoint_address,
                                     AXIS2_TRUE /* is_multiple */,
                                     sig_axiom,
                                     &op_axiom,
                                     &soap_ver) == AXIS2_SUCCESS)
        {
            *operation_axiom = op_axiom;
            *soap_version = soap_ver;
            if (wsdl_util_get_binding_details(env, 
                                              op_axiom,
                                              &wsa_action, &soap_action) == AXIS2_SUCCESS)
            {
                if (wsa_action_binding_details)
                    strcpy (wsa_action, wsa_action_binding_details);
                if (soap_action_binding_details)
                    strcpy (soap_action, soap_action_binding_details);

                /*TODO: check this condition */
                //if (wsa_action_binding_details || soap_action_binding_details) 
                //{
                //    soap_version = soap_version_binding_details; 
                //}
            }
        }
    }

    if (wsf_wsdl_util_get_binding_node(env,
                                       wsdl_axiom,
                                       is_version1_wsdl,
                                       service_name,
                                       port_name,
                                       &binding_node))
    {

        if (wsf_wsdl_util_get_all_policies_from_wsdl(env, 
                                                     wsdl_axiom,
                                                     is_version1_wsdl,
                                                     binding_node,
                                                     operation_name,
                                                     &wsdl_policy_hash))
        {
    
            wsf_wsdl_util_configure_security_for_svc_client(env,
                                                            svc_client_user_options,
                                                            wsdl_policy_hash,
                                                            svc_client);
        }
    }
                                                
    to_epr = axis2_endpoint_ref_create (env, endpoint_address);
    axis2_options_set_to (client_options, env, to_epr);
    
    /** enable ssl **/
    if (option_supported) /* wsf_client_enable_ssl */
    {
        axutil_property_t *ssl_server_key_prop = NULL;
        axutil_property_t *ssl_client_key_prop = NULL;
        axutil_property_t *passphrase_prop = NULL;

        ssl_server_key_prop =
            axutil_property_create_with_args (env, 0, AXIS2_TRUE, 0,
            axutil_strdup (env, ssl_server_key_filename));

        axis2_options_set_property (client_options, env, WSF_WSDL_SERVER_CERT, ssl_server_key_prop);

        ssl_client_key_prop = axutil_property_create_with_args (env, 0, AXIS2_TRUE, 0,
        axutil_strdup (env, ssl_client_key_filename));
        axis2_options_set_property (client_options, env, WSF_WSDL_KEY_FILE, ssl_client_key_prop);

        passphrase_prop = axutil_property_create_with_args (env, 0, AXIS2_TRUE, 0, axutil_strdup (env, passphrase));
        axis2_options_set_property (client_options, env, WSF_WSDL_SSL_PASSPHRASE, passphrase_prop);

        AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI,
                        "[wsf-client] setting ssh options %s -- %s -- %s ",
                        ssl_server_key_filename, ssl_client_key_filename, passphrase);
    }

    if (axutil_strcmp(soap_action, "") != 0){
        axutil_string_t *action_string = axutil_string_create (env, soap_action);
        axis2_options_set_soap_action (client_options, env, action_string);
        AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI,
                         "soap action present :- %s",
                         soap_action);
    }
    
    if (axutil_strcmp(wsa_action, "") != 0){
        axis2_options_set_action(client_options, env, wsa_action);
        AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI,
                         "addressing action present :- %s",
                         wsa_action);
        axis2_svc_client_engage_module (svc_client, env, WSF_WSDL_MODULE_ADDRESSING);
    }
    
    if (*soap_version)
    {
      axis2_options_set_soap_version (client_options, env,
                      *soap_version);
      AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI,
               "[wsf_wsdl]soap version in wsdl mode is %d",
               *soap_version);
    }

    /* 
    Add proxy options */
    if (proxy_host && proxy_port) 
    {
        axis2_svc_client_set_proxy (svc_client, env, proxy_host, proxy_port);
        AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI,
                         "[wsf_wsdl_client] setting proxy options %s -- %s -- ", proxy_host, 
                         proxy_port);
    }

    /* 
    Default header type is POST, so only setting the HTTP_METHOD if GET */
    if (is_http_method_post == AXIS2_FALSE)
    {
        axutil_property_t *property = axutil_property_create (env);
        axutil_property_set_value (property, env, axutil_strdup (env, AXIS2_HTTP_GET));

        axis2_options_set_property (client_options, env, AXIS2_HTTP_METHOD, property);

        AXIS2_LOG_DEBUG_MSG(env->log, "[wsf_client] setting http method get property");
    }
}
示例#13
0
int main(int argc, char** argv)
{
    const axutil_env_t *env = NULL;
    const axis2_char_t *address = NULL;
    axis2_endpoint_ref_t* endpoint_ref = NULL;
    axis2_endpoint_ref_t* reply_to = NULL;
    axis2_options_t *options = NULL;
    const axis2_char_t *client_home = NULL;
    axis2_svc_client_t* svc_client = NULL;
    axiom_node_t *payload = NULL;
    axis2_callback_t *callback = NULL;
    axis2_callback_t *callback2 = NULL;
    axis2_callback_t *callback3 = NULL;
    axutil_property_t *property = NULL;
    axis2_char_t *offered_seq_id = NULL;
    axis2_bool_t offer = AXIS2_TRUE;
    neethi_policy_t *policy = NULL;
    axis2_status_t status = AXIS2_FAILURE;
   
    /* Set up the environment */
    env = axutil_env_create_all("rm_echo_1_1_amqp.log", AXIS2_LOG_LEVEL_TRACE);

    /* Set end point reference of echo service */
    address = "amqp://127.0.0.1:5672/axis2/services/RM11SampleService";
    if (argc > 1)
    {
        if (axutil_strcmp(argv[1], "-h") == 0)
        {
            printf("Usage : %s [endpoint_url]\n", argv[0]);
            printf("use -h for help\n");
            return 0;
        }
        else
        {
            address = argv[1];
        }
    }
    printf ("Using endpoint : %s\n", address);
    
    /* Create EPR with given address */
    endpoint_ref = axis2_endpoint_ref_create(env, address);

    /* Setup options */
    options = axis2_options_create(env);
    axis2_options_set_to(options, env, endpoint_ref);
    axis2_options_set_use_separate_listener(options, env, AXIS2_TRUE);
    
    /* Seperate listner needs addressing, hence addressing stuff in options */
    /*axis2_options_set_action(options, env,
        "http://127.0.0.1:8080/axis2/services/RM11SampleService/anonOutInOp");*/
    axis2_options_set_action(options, env, "urn:wsrm:EchoString");
    reply_to = axis2_endpoint_ref_create(env, 
            "amqp://localhost:5672/axis2/services/__ANONYMOUS_SERVICE__");
    axis2_options_set_reply_to(options, env, reply_to);

	axis2_options_set_transport_in_protocol(options, env, AXIS2_TRANSPORT_ENUM_AMQP);

    /* Set up deploy folder. It is from the deploy folder, the configuration is 
     * picked up using the axis2.xml file.
     * In this sample client_home points to the Axis2/C default deploy folder. 
     * The client_home can be different from this folder on your system. For 
     * example, you may have a different folder (say, my_client_folder) with its 
     * own axis2.xml file. my_client_folder/modules will have the modules that 
     * the client uses
     */
    client_home = AXIS2_GETENV("AXIS2C_HOME");
    if (!client_home)
    {
        client_home = "../../..";
    }

    /* Create service client */
    svc_client = axis2_svc_client_create(env, client_home);
    if (!svc_client)
    {
        printf("Error creating service client\n");
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code: %d :: %s", 
                env->error->error_number, AXIS2_ERROR_GET_MESSAGE(env->error));
        return -1;
    }

    /*Create the policy, from file*/
    policy = neethi_util_create_policy_from_file(env, "../policy/rm11-policy.xml");
    if(!policy)
    {
        printf("\nPolicy creation failed from the file");
        return 0;
    }

    status = axis2_svc_client_set_policy(svc_client, env, policy);

    if(status == AXIS2_FAILURE)
    {
        printf("Policy setting failed\n");
    }


    /* Set service client options */
    axis2_svc_client_set_options(svc_client, env, options);    
    
    axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);  
    axis2_svc_client_engage_module(svc_client, env, "sandesha2");

    /* Offer sequence */
    if(offer)
    {
        offered_seq_id = axutil_uuid_gen(env);
        property = axutil_property_create(env);
        if(property)
        {
            axutil_property_set_value(property, env, axutil_strdup(env, offered_seq_id));
            axis2_options_set_property(options, env, SANDESHA2_CLIENT_OFFERED_SEQ_ID, property);
        }
    }

    /* RM Version 1.1 */
    property = axutil_property_create_with_args(env, 3, 0, 0, SANDESHA2_SPEC_VERSION_1_1);
    if(property)
    {
        axis2_options_set_property(options, env, SANDESHA2_CLIENT_RM_SPEC_VERSION, property);
    }
    
    payload = build_om_payload_for_echo_svc(env, "echo1");
    callback = axis2_callback_create(env);
    axis2_callback_set_on_complete(callback, rm_echo_callback_on_complete);
    axis2_callback_set_on_error(callback, rm_echo_callback_on_error);
    axis2_svc_client_send_receive_non_blocking(svc_client, env, payload, callback);
    wait_on_callback(env, callback);

    payload = build_om_payload_for_echo_svc(env, "echo2");
    callback2 = axis2_callback_create(env);
    axis2_callback_set_on_complete(callback2, rm_echo_callback_on_complete);
    axis2_callback_set_on_error(callback2, rm_echo_callback_on_error);
    axis2_svc_client_send_receive_non_blocking(svc_client, env, payload, callback2);
    wait_on_callback(env, callback2);

    AXIS2_SLEEP(SANDESHA2_MAX_COUNT); 
    callback3 = axis2_callback_create(env);
    axis2_callback_set_on_complete(callback3, rm_echo_callback_on_complete);
    axis2_callback_set_on_error(callback3, rm_echo_callback_on_error);
    sandesha2_client_terminate_seq_with_svc_client(env, svc_client, callback3);

    AXIS2_SLEEP(SANDESHA2_MAX_COUNT);

    if (svc_client)
    {
        axis2_svc_client_free(svc_client, env);
        svc_client = NULL;
    }
    
    return 0;
}
示例#14
0
int main(int argc, char** argv)
{
    const axutil_env_t *env = NULL;
    const axis2_char_t *address = NULL;
    axis2_endpoint_ref_t* endpoint_ref = NULL;
    axis2_options_t *options = NULL;
    const axis2_char_t *client_home = NULL;
    axis2_svc_client_t* svc_client = NULL;
    axiom_node_t *payload = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    axutil_property_t *property = NULL;
    axis2_char_t *seq_key = NULL;
    neethi_policy_t *policy = NULL;
    
    /* Set up the environment */
    env = axutil_env_create_all("rm_ping_1_0_amqp.log", AXIS2_LOG_LEVEL_TRACE);

    /* Set end point reference of echo service */
    address = "amqp://127.0.0.1:5672/axis2/services/RM10SampleService";
    if (argc > 1)
    {
        if (axutil_strcmp(argv[1], "-h") == 0)
        {
            printf("Usage : %s [endpoint_url]\n", argv[0]);
            printf("use -h for help\n");
            return 0;
        }
        else
        {
            address = argv[1];
        }
    }

    printf ("Using endpoint : %s\n", address);
    
    /* Create EPR with given address */
    endpoint_ref = axis2_endpoint_ref_create(env, address);

    /* Setup options */
    options = axis2_options_create(env);
    axis2_options_set_xml_parser_reset(options, env, AXIS2_FALSE);
    if(endpoint_ref)
    {
        axis2_options_set_to(options, env, endpoint_ref);
    }

    axis2_options_set_action(options, env, "urn:wsrm:Ping");

    /* Set up deploy folder. It is from the deploy folder, the configuration is 
     * picked up using the axis2.xml file.
     * In this sample client_home points to the Axis2/C default deploy folder. 
     * The client_home can be different from this folder on your system. For 
     * example, you may have a different folder (say, my_client_folder) with its 
     * own axis2.xml file. my_client_folder/modules will have the modules that 
     * the client uses
     */
    client_home = AXIS2_GETENV("AXIS2C_HOME");
    if (!client_home)
    {
        client_home = "../../..";
    }

    /* Create service client */
    svc_client = axis2_svc_client_create(env, client_home);
    if (!svc_client)
    {
        printf("Error creating service client\n");
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code: %d :: %s",
                env->error->error_number, AXIS2_ERROR_GET_MESSAGE(env->error));
    }

    /*Create the policy, from file*/
    policy = neethi_util_create_policy_from_file(env, "../policy/rm10-policy.xml");
    if(!policy)
    {
        printf("\nPolicy creation failed from the file");
        return 0;
    }

    status = axis2_svc_client_set_policy(svc_client, env, policy);

    if(status == AXIS2_FAILURE)
    {
        printf("Policy setting failed\n");
    }

    /* Set service client options */
    axis2_svc_client_set_options(svc_client, env, options);    
    
    /* Engage addressing module */
    axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);
    
    axis2_svc_client_engage_module(svc_client, env, "sandesha2");
    
    /* RM Version 1.0 */
    property = axutil_property_create_with_args(env, 0, 0, 0, SANDESHA2_SPEC_VERSION_1_0);
    if(property)
    {
        axis2_options_set_property(options, env, SANDESHA2_CLIENT_RM_SPEC_VERSION, property);
    }

    seq_key = axutil_uuid_gen(env);
    property = axutil_property_create_with_args(env, 0, 0, 0, seq_key);
    if(property)
    {
        axis2_options_set_property(options, env, SANDESHA2_CLIENT_SEQ_KEY, property);
    }
    
    /* Send request */
    payload = build_om_programatically(env, "ping1", seq_key);
    status = axis2_svc_client_send_robust(svc_client, env, payload);
    if(status)
    {
        printf("\nping client invoke SUCCESSFUL!\n");
    }
    payload = NULL;
    
    payload = build_om_programatically(env, "ping2", seq_key);
    status = axis2_svc_client_send_robust(svc_client, env, payload);
    if(status)
    {
        printf("\nping client invoke SUCCESSFUL!\n");
    }
    payload = NULL;

    property = axutil_property_create_with_args(env, 0, 0, 0, AXIS2_VALUE_TRUE);
    axis2_options_set_property(options, env, "Sandesha2LastMessage", property);
    payload = build_om_programatically(env, "ping3", seq_key);
    status = axis2_svc_client_send_robust(svc_client, env, payload);
    if(status)
    {
        printf("\nping client invoke SUCCESSFUL!\n");
    }
    
     /** Wait till callback is complete. Simply keep the parent thread running
       until our on_complete or on_error is invoked */

    /*This sleep is for wait the main thread until sandesha sends the terminatesequence 
     *messages. */

    AXIS2_SLEEP(SANDESHA2_SLEEP);
    AXIS2_FREE(env->allocator, seq_key);
   
    if (svc_client)
    {
        axis2_svc_client_free(svc_client, env);
        svc_client = NULL;
    }
    
    if (env)
    {
        axutil_env_free((axutil_env_t *) env);
        env = NULL;
    }

    return 0;
}
示例#15
0
文件: counter.c 项目: AdrianRys/wsf
int AXIS2_CALL
service_admin_counter_get_last_count (
    const axutil_env_t *env,
    axis2_msg_ctx_t *msg_ctx,
    axis2_char_t *svc_name,
    axis2_char_t *op_name)
{
    int *count = NULL;
    axutil_hash_t *last_counts = NULL;
    axutil_property_t *property = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;

    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
    if(svc_name && op_name)
    {
        axis2_char_t *key = NULL;
        key = axutil_strcat(env, svc_name, "-", op_name, NULL);
        property = axis2_conf_ctx_get_property(conf_ctx, env, SERVICE_ADMIN_COUNTER_LAST_OPERATION_COUNT);
        if(!property)
        {
            last_counts = axutil_hash_make(env);
            property = axutil_property_create_with_args(env, AXIS2_TRUE, AXIS2_SCOPE_APPLICATION, 
                    service_admin_counter_last_counts_free_void_arg, last_counts);
            axis2_conf_ctx_set_property(conf_ctx, env, SERVICE_ADMIN_COUNTER_LAST_OPERATION_COUNT, property);
        }
        else
        {
            last_counts = axutil_property_get_value(property, env);
        }
        count = axutil_hash_get(last_counts, key, AXIS2_HASH_KEY_STRING);
        if(count)
        {
            AXIS2_FREE(env->allocator, key);
        }
        else
        {
            count = AXIS2_MALLOC(env->allocator, sizeof(int));
            *count = 0;
            axutil_hash_set(last_counts, key, AXIS2_HASH_KEY_STRING, count);
        }
    }
    else if(svc_name)
    {
        property = axis2_conf_ctx_get_property(conf_ctx, env, SERVICE_ADMIN_COUNTER_LAST_SERVICE_COUNT);
        if(!property)
        {
            last_counts = axutil_hash_make(env);
            property = axutil_property_create_with_args(env, AXIS2_TRUE, AXIS2_SCOPE_APPLICATION,
                    service_admin_counter_last_counts_free_void_arg, last_counts);
            axis2_conf_ctx_set_property(conf_ctx, env, SERVICE_ADMIN_COUNTER_LAST_SERVICE_COUNT, property);
        }
        else
        {
            last_counts = axutil_property_get_value(property, env);
        }
        count = axutil_hash_get(last_counts, svc_name, AXIS2_HASH_KEY_STRING);
        if(!count)
        {
            count = AXIS2_MALLOC(env->allocator, sizeof(int));
            *count = 0;
            axutil_hash_set(last_counts, axutil_strdup(env, svc_name) , 
                    AXIS2_HASH_KEY_STRING, count);
        }
    }
    return *count;
}
示例#16
0
axis2_status_t AXIS2_CALL
sandesha2_out_handler_invoke(
    struct axis2_handler *handler, 
    const axutil_env_t *env,
    struct axis2_msg_ctx *msg_ctx)
{
    axutil_property_t *temp_prop = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_conf_t *conf = NULL;
    axis2_char_t *str_done = NULL;
    axis2_char_t *dummy_msg_str = NULL;
    axis2_bool_t dummy_msg = AXIS2_FALSE;
    axis2_svc_t *svc = NULL;
    axutil_qname_t *module_qname = NULL;
    sandesha2_msg_ctx_t *rm_msg_ctx = NULL;
    sandesha2_msg_processor_t *msg_processor = NULL;
    int msg_type = -1;

    AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[sandesha2] Entry:sandesha2_out_handler_invoke");
            
    temp_prop = axis2_msg_ctx_get_property(msg_ctx, env, SANDESHA2_SEQ_PROP_MAKE_CONNECTION_OUT_PATH);
    if (temp_prop)
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
            "[sandesha2] In make connection out path. So return here.");
        return AXIS2_SUCCESS;
        temp_prop = NULL;
    }

    if(sandesha2_util_is_rstr_msg(env, msg_ctx))
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
            "[sandesha2] A RSTR message. Sandesha don't process.");
        return AXIS2_SUCCESS;
    }

    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
    if(!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
            "[sandesha2] Configuration Context is NULL");
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_CONF_CTX_NULL, AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }
    svc = axis2_msg_ctx_get_svc(msg_ctx, env);
    if(!svc)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2]Axis2 Service is NULL");
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_SVC_NULL, AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }
    module_qname = axutil_qname_create(env, SANDESHA2_MODULE, NULL, NULL);
    if(!axis2_svc_is_module_engaged(svc, env, module_qname))
    {
        if(module_qname)
        {
            axutil_qname_free(module_qname, env);
        }

        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2]RM is not engaged. So return here");
        return AXIS2_SUCCESS;
    }

    if(module_qname)
    {
        axutil_qname_free(module_qname, env);
    }

    temp_prop = axis2_msg_ctx_get_property(msg_ctx, env, SANDESHA2_APPLICATION_PROCESSING_DONE);
    if(temp_prop)
    {
        str_done = (axis2_char_t *) axutil_property_get_value(temp_prop, env); 
    }

    if(str_done && 0 == axutil_strcmp(AXIS2_VALUE_TRUE, str_done))
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
            "[sandesha2]Application Processing Done. So return here.");
        return AXIS2_SUCCESS; 
    }

    temp_prop = axutil_property_create_with_args(env, 0, 0, 0, AXIS2_VALUE_TRUE);
    axis2_msg_ctx_set_property(msg_ctx, env, SANDESHA2_APPLICATION_PROCESSING_DONE, temp_prop);
    conf = axis2_conf_ctx_get_conf(conf_ctx, env);
    if(!sandesha2_permanent_storage_mgr_create_db(env, conf_ctx))
    {
        return AXIS2_FAILURE;
    }

    /* Getting rm message */ 
    rm_msg_ctx = sandesha2_msg_init_init_msg(env, msg_ctx);
    temp_prop = axis2_msg_ctx_get_property(msg_ctx, env, SANDESHA2_CLIENT_DUMMY_MESSAGE);
    if(NULL != temp_prop)
    {
        dummy_msg_str = (axis2_char_t *) axutil_property_get_value(temp_prop, env); 
    }

    if(dummy_msg_str && 0 == axutil_strcmp(AXIS2_VALUE_TRUE, dummy_msg_str))
    {
        dummy_msg = AXIS2_TRUE;
    }

    temp_prop = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_SVC_CLIENT_CLOSED);
    if(temp_prop)
    {
        axis2_char_t *spec_version = NULL;

        axis2_endpoint_ref_t *reply_to = axis2_msg_ctx_get_reply_to(msg_ctx, env);
        if(reply_to)
        {
            axis2_char_t *address = axis2_endpoint_ref_get_address(reply_to, env);
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "dam_reply_to_address:%s", address);
        }
        spec_version = sandesha2_utils_get_rm_version(env, msg_ctx);

        if(!axutil_strcmp(SANDESHA2_SPEC_VERSION_1_1, spec_version))
        {
            axis2_char_t *action = NULL;
            axutil_string_t *str_action = NULL;

            action = sandesha2_spec_specific_consts_get_terminate_seq_action(env, spec_version);
            str_action = axutil_string_create(env, action);
            axis2_msg_ctx_set_soap_action(msg_ctx, env, str_action);
            axutil_string_free(str_action, env);
            /*axis2_msg_ctx_set_reply_to(msg_ctx, env, NULL);*/
            msg_type = sandesha2_msg_ctx_set_msg_type(rm_msg_ctx, env, 
                SANDESHA2_MSG_TYPE_CLOSE_SEQ);
        }
        else if(!axutil_strcmp(SANDESHA2_SPEC_VERSION_1_0, spec_version))
        {
            axutil_property_t *property = NULL;
            axutil_string_t *str_action = NULL;
            
            /*axis2_msg_info_headers_set_action(axis2_msg_ctx_get_msg_info_headers(msg_ctx, env), 
             * env, SANDESHA2_SPEC_2005_02_SOAP_ACTION_LAST_MESSAGE); */
            str_action = axutil_string_create(env, SANDESHA2_SPEC_2005_02_SOAP_ACTION_LAST_MESSAGE);
            axis2_msg_ctx_set_soap_action(msg_ctx, env, str_action);
            axutil_string_free(str_action, env);
            property = axutil_property_create_with_args(env, 0, 0, 0, AXIS2_VALUE_TRUE);
            axis2_msg_ctx_set_property(msg_ctx, env, "Sandesha2LastMessage", property);
            /*axis2_msg_ctx_set_reply_to(msg_ctx, env, NULL);*/
        }
    }

    msg_type = sandesha2_msg_ctx_get_msg_type(rm_msg_ctx, env);
    if(msg_type == SANDESHA2_MSG_TYPE_UNKNOWN)
    {
        axis2_msg_ctx_t *req_msg_ctx = NULL;
        axis2_op_ctx_t *op_ctx = NULL;

        op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
        req_msg_ctx =  axis2_op_ctx_get_msg_ctx(op_ctx, env, AXIS2_WSDL_MESSAGE_LABEL_IN);
        if(req_msg_ctx) /* For the server side */
        {
            sandesha2_msg_ctx_t *req_rm_msg_ctx = NULL;
            sandesha2_seq_t *seq_part = NULL;

            req_rm_msg_ctx = sandesha2_msg_init_init_msg(env, req_msg_ctx);
            seq_part = sandesha2_msg_ctx_get_sequence(req_rm_msg_ctx, env);
            if(seq_part)
            {
                msg_processor = (sandesha2_msg_processor_t *) 
                sandesha2_app_msg_processor_create(env); /* rm intended msg */
            }
            if(req_rm_msg_ctx)
                sandesha2_msg_ctx_free(req_rm_msg_ctx, env);
        }
        else if(!axis2_msg_ctx_get_server_side(msg_ctx, env))
        {
            msg_processor = (sandesha2_msg_processor_t *) sandesha2_app_msg_processor_create(env);
        }
    }
    else
    {
        msg_processor = sandesha2_msg_processor_create_msg_processor(env, rm_msg_ctx);
    }
    if(msg_processor)
    {
        sandesha2_msg_processor_process_out_msg(msg_processor, env, rm_msg_ctx);
        sandesha2_msg_processor_free(msg_processor, env);
    }
    if(AXIS2_SUCCESS != AXIS2_ERROR_GET_STATUS_CODE(env->error))
    {
        /* Message should not be sent in an exception situation */

        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2] Pausing message context");
        axis2_msg_ctx_set_paused(msg_ctx, env, AXIS2_TRUE);
        if(rm_msg_ctx)
        {
            sandesha2_msg_ctx_free(rm_msg_ctx, env);
        }
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] Error in processing the message");
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_CANNOT_PROCESS_MSG, AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }
    
    temp_prop = axis2_msg_ctx_get_property(msg_ctx, env, SANDESHA2_APPLICATION_PROCESSING_DONE);
    if(temp_prop)
    {
        axutil_property_set_value(temp_prop, env, AXIS2_VALUE_FALSE);
    }

    if(rm_msg_ctx)
    {
        sandesha2_msg_ctx_free(rm_msg_ctx, env);
    }

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[sandesha2]Exit:sandesha2_out_handler_invoke");

    return AXIS2_SUCCESS;
}
static axis2_status_t AXIS2_CALL 
sandesha2_create_seq_msg_processor_process_in_msg (
    sandesha2_msg_processor_t *msg_processor,
    const axutil_env_t *env,
    sandesha2_msg_ctx_t *rm_msg_ctx)
{
    axis2_msg_ctx_t *create_seq_msg_ctx = NULL;
    sandesha2_create_seq_t *create_seq_part = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    sandesha2_msg_ctx_t *fault_rm_msg_ctx = NULL;
    axis2_msg_ctx_t *out_msg_ctx = NULL;
    sandesha2_seq_property_mgr_t *seq_prop_mgr = NULL;
    sandesha2_next_msg_mgr_t *next_msg_mgr = NULL;
    axutil_property_t *property = NULL;
    axis2_char_t *incoming_sequence_id = NULL;
    sandesha2_msg_ctx_t *rm_create_seq_res_msg_ctx = NULL;
    sandesha2_create_seq_res_t *create_seq_res_part = NULL;
    sandesha2_seq_offer_t *seq_offer = NULL;
    axis2_endpoint_ref_t *acks_to_epr = NULL;
    sandesha2_acks_to_t *acks_to = NULL;
    sandesha2_seq_property_bean_t *acks_to_bean = NULL;
    sandesha2_seq_property_bean_t *acks_to_ref_param_bean = NULL;
    axutil_array_list_t *ref_param_list = NULL;
    axis2_char_t *ref_param_list_str = NULL;
    sandesha2_seq_property_bean_t *to_bean = NULL;
    axis2_engine_t *engine = NULL;
    axis2_char_t *addr_ns_uri = NULL;
    axis2_char_t *anon_uri = NULL;
    axis2_char_t *to_addr = NULL;
    axis2_op_ctx_t *op_ctx = NULL;
    axis2_char_t *dbname = NULL;
    sandesha2_create_seq_mgr_t *create_seq_mgr = NULL;
    axis2_msg_ctx_t **msg_ctx_map = NULL;
     
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,  
        "[sandesha2] Start:sandesha2_create_seq_msg_processor_process_in_msg");
    
    AXIS2_PARAM_CHECK(env->error, rm_msg_ctx, AXIS2_FAILURE);
    
    create_seq_msg_ctx = sandesha2_msg_ctx_get_msg_ctx(rm_msg_ctx, env);
    
    op_ctx = axis2_msg_ctx_get_op_ctx(create_seq_msg_ctx, env);
    msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
    msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN] = create_seq_msg_ctx;

    create_seq_part = sandesha2_msg_ctx_get_create_seq(rm_msg_ctx, env);
    if(!create_seq_part)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] create_seq_part is NULL");
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_REQD_MSG_PART_MISSING, AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }

    conf_ctx = axis2_msg_ctx_get_conf_ctx(create_seq_msg_ctx, env);
    dbname = sandesha2_util_get_dbname(env, conf_ctx);
    seq_prop_mgr = sandesha2_permanent_seq_property_mgr_create(env, dbname);
    create_seq_mgr = sandesha2_permanent_create_seq_mgr_create(env, dbname);
    next_msg_mgr = sandesha2_permanent_next_msg_mgr_create(env, dbname);
    
    /*fault_rm_msg_ctx = sandesha2_fault_mgr_check_for_create_seq_refused(env, rm_msg_ctx, seq_prop_mgr);*/
    fault_rm_msg_ctx = sandesha2_fault_mgr_check_for_create_seq_refused(env, rm_msg_ctx, seq_prop_mgr);
    if(fault_rm_msg_ctx)
    {
        axis2_engine_t *engine = NULL;

        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] A fault occurred"); 

        engine = axis2_engine_create(env, conf_ctx);
        axis2_engine_send_fault(engine, env, sandesha2_msg_ctx_get_msg_ctx(fault_rm_msg_ctx, env));
        if(fault_rm_msg_ctx)
        {
            sandesha2_msg_ctx_free(fault_rm_msg_ctx, env);
        }

        if(engine)
        {
            axis2_engine_free(engine, env);
            engine = NULL;
        }

        axis2_msg_ctx_set_paused(create_seq_msg_ctx, env, AXIS2_TRUE);

        if(seq_prop_mgr)
        {
            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
        }
        if(create_seq_mgr)
        {
            sandesha2_create_seq_mgr_free(create_seq_mgr, env);
        }
        if(next_msg_mgr)
        {
            sandesha2_next_msg_mgr_free(next_msg_mgr, env);
        }

        return AXIS2_SUCCESS;
    }

    out_msg_ctx = sandesha2_utils_create_out_msg_ctx(env, create_seq_msg_ctx);

    incoming_sequence_id = sandesha2_seq_mgr_setup_new_incoming_sequence(env, rm_msg_ctx, 
            seq_prop_mgr, next_msg_mgr);

    rm_create_seq_res_msg_ctx = sandesha2_msg_creator_create_create_seq_res_msg(env, rm_msg_ctx, 
            out_msg_ctx, incoming_sequence_id, seq_prop_mgr);

    axis2_msg_ctx_set_flow(out_msg_ctx, env, AXIS2_OUT_FLOW);

    if(!rm_create_seq_res_msg_ctx)
    {
        if(incoming_sequence_id)
        {
            AXIS2_FREE(env->allocator, incoming_sequence_id);
        }

        if(seq_prop_mgr)
        {
            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
        }

        if(create_seq_mgr)
        {
            sandesha2_create_seq_mgr_free(create_seq_mgr, env);
        }

        if(next_msg_mgr)
        {
            sandesha2_next_msg_mgr_free(next_msg_mgr, env);
        }

        return AXIS2_FAILURE;
    }

    property = axutil_property_create_with_args(env, 0, 0, 0, AXIS2_VALUE_TRUE);

    /* For making sure that this won't be processed again */
    sandesha2_msg_ctx_set_property(rm_create_seq_res_msg_ctx, env, 
            SANDESHA2_APPLICATION_PROCESSING_DONE, property); 
    
    create_seq_res_part = sandesha2_msg_ctx_get_create_seq_res(rm_create_seq_res_msg_ctx, env);
    seq_offer = sandesha2_create_seq_get_seq_offer(create_seq_part, env);

    /* Offer processing */ 
    if(seq_offer)
    {
        sandesha2_accept_t *accept = NULL;
        axis2_char_t *outgoing_sequence_id = NULL;
        axis2_bool_t offer_accepted = AXIS2_FALSE;

        if(create_seq_res_part)
        {
            accept = sandesha2_create_seq_res_get_accept(create_seq_res_part, env);
        }
        if(!accept)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                    "[sandesha2] Accept part has not genereated for a message with offer");
            AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_REQD_MSG_PART_MISSING, AXIS2_FAILURE);

            if(rm_create_seq_res_msg_ctx)
            {
                sandesha2_msg_ctx_free(rm_create_seq_res_msg_ctx, env);
            }

            if(incoming_sequence_id)
            {
                AXIS2_FREE(env->allocator, incoming_sequence_id);
            }

            if(seq_prop_mgr)
            {
                sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
            }

            if(create_seq_mgr)
            {
                sandesha2_create_seq_mgr_free(create_seq_mgr, env);
            }

            if(next_msg_mgr)
            {
                sandesha2_next_msg_mgr_free(next_msg_mgr, env);
            }

            return AXIS2_FAILURE;
        }

        outgoing_sequence_id = sandesha2_identifier_get_identifier(sandesha2_seq_offer_get_identifier(
                    seq_offer, env), env);

        /* Check whether offered sequence id is valid or create sequence bean already created */
        offer_accepted = sandesha2_create_seq_msg_processor_offer_accepted(env, outgoing_sequence_id, 
                rm_msg_ctx, create_seq_mgr);

        if(offer_accepted)
        {
            /*sandesha2_create_seq_bean_t *create_seq_bean = NULL;*/
            axis2_char_t *outgoing_internal_sequence_id = NULL;
            sandesha2_seq_property_bean_t *outgoing_sequence_bean = NULL;
            sandesha2_seq_property_bean_t *outgoing_internal_sequence_bean = NULL;
    
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2] Offer Accepted"); 

            /*
             * If previously a create sequence message has arrived with an offer then there is
             * a create sequence bean already created in the database. Free it. Also free
             * outgoing_internal_sequence_bean, and outgoing_sequence_bean.
             */
            sandesha2_create_seq_msg_processor_create_seq_msg_already_received(env, 
                    outgoing_sequence_id, rm_msg_ctx, create_seq_mgr, seq_prop_mgr);
            /* Note that outgoing_internal_sequence_id is derived from incoming_sequence_id. This
             * is server side. So it should be noted that in server side 
             * incoming_internal_sequence_id and outgoing_internal_sequence_id are same
             */
            outgoing_internal_sequence_id = sandesha2_utils_get_internal_sequence_id(env, 
                    incoming_sequence_id);

            /*create_seq_bean = sandesha2_create_seq_bean_create(env);
            sandesha2_create_seq_bean_set_outgoing_sequence_id(create_seq_bean, env, 
                outgoing_sequence_id);
            sandesha2_create_seq_bean_set_internal_sequence_id(create_seq_bean, env, 
                    outgoing_internal_sequence_id);

            sandesha2_create_seq_bean_set_create_seq_msg_id(create_seq_bean, env, 
                    axutil_uuid_gen(env));

            sandesha2_create_seq_mgr_insert(create_seq_mgr, env, create_seq_bean);*/
            
            outgoing_sequence_bean = sandesha2_seq_property_bean_create(env);
            if(outgoing_sequence_bean)
            {
                sandesha2_seq_property_bean_set_name(outgoing_sequence_bean, env, 
                        SANDESHA2_SEQUENCE_PROPERTY_OUTGOING_SEQUENCE_ID);

                sandesha2_seq_property_bean_set_seq_id(outgoing_sequence_bean, env, 
                        outgoing_internal_sequence_id);
                sandesha2_seq_property_bean_set_value(outgoing_sequence_bean, env, 
                        outgoing_sequence_id);
                AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2] incoming_sequence_id:%s", 
                        incoming_sequence_id); 
                sandesha2_seq_property_mgr_insert(seq_prop_mgr, env, outgoing_sequence_bean);
                sandesha2_seq_property_bean_free(outgoing_sequence_bean, env);
            }

            outgoing_internal_sequence_bean = sandesha2_seq_property_bean_create(env);
            if(outgoing_internal_sequence_bean)
            {
                sandesha2_seq_property_bean_set_name(outgoing_internal_sequence_bean, env, 
                    SANDESHA2_SEQUENCE_PROPERTY_OUTGOING_INTERNAL_SEQUENCE_ID);

                sandesha2_seq_property_bean_set_seq_id(outgoing_internal_sequence_bean, env, 
                        outgoing_sequence_id);
                sandesha2_seq_property_bean_set_value(outgoing_internal_sequence_bean, env, 
                        outgoing_internal_sequence_id);
                sandesha2_seq_property_mgr_insert(seq_prop_mgr, env, outgoing_internal_sequence_bean);
                sandesha2_seq_property_bean_free(outgoing_internal_sequence_bean, env);
            }

            if(outgoing_internal_sequence_id)
            {
                AXIS2_FREE(env->allocator, outgoing_internal_sequence_id);
            }
        }
        else
        {
            sandesha2_msg_ctx_add_soap_envelope(rm_create_seq_res_msg_ctx, env);
        }
    }

    acks_to = sandesha2_create_seq_get_acks_to(create_seq_part, env);
    acks_to_epr = sandesha2_address_get_epr(sandesha2_acks_to_get_address(acks_to, env), env);

    if(!acks_to_epr || !axis2_endpoint_ref_get_address(acks_to_epr, env))
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2]Acks to is null");
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_INVALID_EPR, AXIS2_FAILURE);

        if(rm_create_seq_res_msg_ctx)
        {
            sandesha2_msg_ctx_free(rm_create_seq_res_msg_ctx, env);
        }

        if(incoming_sequence_id)
        {
            AXIS2_FREE(env->allocator, incoming_sequence_id);
        }

        if(seq_prop_mgr)
        {
            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
        }

        if(create_seq_mgr)
        {
            sandesha2_create_seq_mgr_free(create_seq_mgr, env);
        }

        if(next_msg_mgr)
        {
            sandesha2_next_msg_mgr_free(next_msg_mgr, env);
        }

        return AXIS2_FAILURE;
    }

    acks_to_bean = sandesha2_seq_property_bean_create_with_data(env, incoming_sequence_id, 
            SANDESHA2_SEQ_PROP_ACKS_TO_EPR, (axis2_char_t*)axis2_endpoint_ref_get_address(
                acks_to_epr, env));

    if(acks_to_bean)
    {
        sandesha2_seq_property_mgr_insert(seq_prop_mgr, env, acks_to_bean);
        sandesha2_seq_property_bean_free(acks_to_bean, env);
    }

    ref_param_list = sandesha2_acks_to_get_ref_param_list(acks_to, env);
    if(ref_param_list)
    {
        ref_param_list_str = sandesha2_util_get_string_from_node_list(env, ref_param_list);
        acks_to_ref_param_bean = sandesha2_seq_property_bean_create_with_data(env, 
                incoming_sequence_id, SANDESHA2_SEQ_PROP_ACKS_TO_REF_PARAM, ref_param_list_str);
        
        if(ref_param_list_str)
        {
            AXIS2_FREE(env->allocator, ref_param_list_str);
        }

        if(acks_to_ref_param_bean)
        {
            sandesha2_seq_property_mgr_insert(seq_prop_mgr, env, acks_to_ref_param_bean);
            sandesha2_seq_property_bean_free(acks_to_ref_param_bean, env);
        }
    }

    axis2_op_ctx_set_response_written(op_ctx, env, AXIS2_TRUE);
    sandesha2_seq_mgr_update_last_activated_time(env, incoming_sequence_id, seq_prop_mgr);

    engine = axis2_engine_create(env, conf_ctx);

    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2]axis2_engine_send");

    axis2_engine_send(engine, env, out_msg_ctx);
    if(engine)
    {
        axis2_engine_free(engine, env);
    }

    if(out_msg_ctx)
    {
        axis2_core_utils_reset_out_msg_ctx(env, out_msg_ctx);
        /*axis2_msg_ctx_reset_transport_out_stream(out_msg_ctx, env);*/
        axis2_msg_ctx_free(out_msg_ctx, env);
    }

    if(rm_create_seq_res_msg_ctx)
    {
        sandesha2_msg_ctx_free(rm_create_seq_res_msg_ctx, env);
    }

    to_bean = sandesha2_seq_property_mgr_retrieve(seq_prop_mgr, env, incoming_sequence_id, 
            SANDESHA2_SEQ_PROP_TO_EPR);
    if(!to_bean)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] wsa:To is not set");

        if(incoming_sequence_id)
        {
            AXIS2_FREE(env->allocator, incoming_sequence_id);
        }

        if(seq_prop_mgr)
        {
            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
        }

        if(create_seq_mgr)
        {
            sandesha2_create_seq_mgr_free(create_seq_mgr, env);
        }

        if(next_msg_mgr)
        {
            sandesha2_next_msg_mgr_free(next_msg_mgr, env);
        }

        return AXIS2_FAILURE;
    }

    to_addr = sandesha2_seq_property_bean_get_value(to_bean, env);
    addr_ns_uri = sandesha2_utils_get_seq_property(env, incoming_sequence_id, 
            SANDESHA2_SEQ_PROP_ADDRESSING_NAMESPACE_VALUE, seq_prop_mgr);

    anon_uri = sandesha2_spec_specific_consts_get_anon_uri(env, addr_ns_uri);
    if(addr_ns_uri)
    {
        AXIS2_FREE(env->allocator, addr_ns_uri);
    }
    
    if(sandesha2_utils_is_anon_uri(env, to_addr))
    {
        axis2_op_ctx_set_response_written(op_ctx, env, AXIS2_TRUE);
    }
    else
    {
        axis2_op_ctx_set_response_written(op_ctx, env, AXIS2_FALSE);
    }

    sandesha2_seq_property_bean_free(to_bean, env);
   
    /* Pausing the flow here so that it won't go to a message receiver which is not set for this flow */
    sandesha2_msg_ctx_set_paused(rm_msg_ctx, env, AXIS2_TRUE);

    if(incoming_sequence_id)
    {
        AXIS2_FREE(env->allocator, incoming_sequence_id);
    }

    if(seq_prop_mgr)
    {
        sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
    }

    if(create_seq_mgr)
    {
        sandesha2_create_seq_mgr_free(create_seq_mgr, env);
    }

    if(next_msg_mgr)
    {
        sandesha2_next_msg_mgr_free(next_msg_mgr, env);
    }

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,  
        "[sandesha2] Exit: sandesha2_create_seq_msg_processor_process_in_msg");

    return AXIS2_SUCCESS;
    
}
static axis2_status_t AXIS2_CALL 
sandesha2_ack_req_msg_processor_process_in_msg (
    sandesha2_msg_processor_t *msg_processor,
    const axutil_env_t *env,
    sandesha2_msg_ctx_t *rm_msg_ctx)
{
    sandesha2_ack_requested_t *ack_requested = NULL;
    axis2_msg_ctx_t *msg_ctx = NULL;
    axis2_char_t *seq_id = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    sandesha2_storage_mgr_t *storage_mgr = NULL;
    sandesha2_seq_property_mgr_t *seq_prop_mgr = NULL;
    sandesha2_seq_property_bean_t *acks_to_bean = NULL;
    axis2_endpoint_ref_t *acks_to = NULL;
    axis2_char_t *acks_to_str = NULL;
    axis2_op_t *ack_op = NULL;
    axis2_op_t *rm_msg_op = NULL;
    axis2_msg_ctx_t *ack_msg_ctx = NULL;
    axutil_property_t *property = NULL;
    sandesha2_msg_ctx_t *ack_rm_msg = NULL;
    axiom_soap_envelope_t *envelope = NULL;
    axis2_char_t *wsa_version = NULL;
    axis2_char_t *dbname = NULL;
    
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, 
        "[sandesha2]Entry:sandesha2_ack_req_msg_processor_process_in_msg");
    AXIS2_PARAM_CHECK(env->error, rm_msg_ctx, AXIS2_FAILURE);
    
    ack_requested = sandesha2_msg_ctx_get_ack_requested(rm_msg_ctx, env);
    if(!ack_requested)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
            "[sandesha2]Ack requested part is missing");
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_REQD_MSG_PART_MISSING,
            AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }
    sandesha2_ack_requested_set_must_understand(ack_requested, env, AXIS2_FALSE);
    sandesha2_msg_ctx_add_soap_envelope(rm_msg_ctx, env);
    
    msg_ctx = sandesha2_msg_ctx_get_msg_ctx(rm_msg_ctx, env);
    seq_id = sandesha2_identifier_get_identifier(
        sandesha2_ack_requested_get_identifier(ack_requested, env), env);
    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
    dbname = sandesha2_util_get_dbname(env, conf_ctx);
    storage_mgr = sandesha2_utils_get_storage_mgr(env, dbname);
    if(!storage_mgr)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] Could not create storage manager.");
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_COULD_NOT_CREATE_STORAGE_MANAGER, 
                AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }
    seq_prop_mgr = sandesha2_permanent_seq_property_mgr_create(env, dbname);
    acks_to_bean = sandesha2_seq_property_mgr_retrieve(seq_prop_mgr, env, seq_id,
        SANDESHA2_SEQ_PROP_ACKS_TO_EPR);
    acks_to_str = sandesha2_seq_property_bean_get_value(acks_to_bean, env);
    
    if(!acks_to_str)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2]acks_to_str"\
            " seqeunce property is not set correctly");
        if(seq_prop_mgr)
            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
        if(storage_mgr)
            sandesha2_storage_mgr_free(storage_mgr, env);
        return AXIS2_FAILURE;
    }
    acks_to = axis2_endpoint_ref_create(env, acks_to_str);
    ack_op = axis2_op_create(env);
    axis2_op_set_msg_exchange_pattern(ack_op, env, AXIS2_MEP_URI_IN_ONLY);
    rm_msg_op = axis2_msg_ctx_get_op(msg_ctx, env);
    if(rm_msg_op)
    {
        axutil_array_list_t *out_flow = NULL;
        axutil_array_list_t *new_out_flow = NULL;
        axutil_array_list_t *out_fault_flow = NULL;
        axutil_array_list_t *new_out_fault_flow = NULL;
        out_flow = axis2_op_get_out_flow(rm_msg_op, env);
        new_out_flow = axis2_phases_info_copy_flow(env, out_flow);
        out_fault_flow = axis2_op_get_out_flow(rm_msg_op, env);
        new_out_fault_flow = axis2_phases_info_copy_flow(env, out_fault_flow);
        if(new_out_flow)
            axis2_op_set_out_flow(ack_op, env, new_out_flow);
        if(new_out_fault_flow)
            axis2_op_set_fault_out_flow(ack_op, env, new_out_fault_flow);
    }

    ack_msg_ctx = sandesha2_utils_create_new_related_msg_ctx(env, rm_msg_ctx);

    property = axutil_property_create_with_args(env, 0, 0, 0, AXIS2_VALUE_TRUE);
    axis2_msg_ctx_set_property(ack_msg_ctx, env, 
        SANDESHA2_APPLICATION_PROCESSING_DONE, property);
    ack_rm_msg = sandesha2_msg_init_init_msg(env, ack_msg_ctx);
    sandesha2_msg_ctx_set_rm_ns_val(ack_rm_msg, env, 
        sandesha2_msg_ctx_get_rm_ns_val(rm_msg_ctx, env));
    axis2_msg_ctx_set_message_id(ack_msg_ctx, env, axutil_uuid_gen(env));
    
    envelope = axiom_soap_envelope_create_default_soap_envelope(env, 
        sandesha2_utils_get_soap_version(env, 
        axis2_msg_ctx_get_soap_envelope(msg_ctx, env)));
    axis2_msg_ctx_set_soap_envelope(ack_msg_ctx, env, envelope);
    axis2_msg_ctx_set_to(ack_msg_ctx, env, acks_to);
    axis2_msg_ctx_set_reply_to(ack_msg_ctx, env, axis2_msg_ctx_get_to(msg_ctx, 
        env));
    sandesha2_msg_creator_add_ack_msg(env, ack_rm_msg, seq_id, seq_prop_mgr);
    axis2_msg_ctx_set_server_side(ack_msg_ctx, env, AXIS2_TRUE);
    
    property = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_WSA_VERSION);
    if(property)
        wsa_version = axutil_property_get_value(property, env);
    
    property = axutil_property_create_with_args(env, 0, 0, 0, wsa_version);
    if(property)
    {
        axis2_msg_ctx_set_property(ack_msg_ctx, env, AXIS2_WSA_VERSION, property);
        property = NULL;
    }
    
    if(sandesha2_utils_is_anon_uri(env, acks_to_str))
    {
        axis2_engine_t *engine = NULL;
        axis2_op_ctx_t *op_ctx = NULL;
        
        if(!axis2_msg_ctx_get_op(msg_ctx, env))
        {
            axis2_op_t *operation = NULL;
            axis2_op_ctx_t *op_ctx = NULL;
            
            operation = axis2_op_create(env);
            axis2_op_set_msg_exchange_pattern(operation, env, 
                AXIS2_MEP_URI_IN_OUT);
            op_ctx = axis2_op_ctx_create(env, operation, NULL);
            axis2_msg_ctx_set_op(msg_ctx, env, operation);
            axis2_msg_ctx_set_op_ctx(msg_ctx, env, op_ctx);            
        }
        op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
        axis2_op_ctx_set_response_written(op_ctx, env, AXIS2_TRUE);
        
        property = axutil_property_create_with_args(env, 0, 0, 0, 
            AXIS2_VALUE_TRUE);
        axis2_msg_ctx_set_property(msg_ctx, env, SANDESHA2_ACK_WRITTEN, 
            property);
        
        engine = axis2_engine_create(env, conf_ctx);
        if(AXIS2_FAILURE == axis2_engine_send(engine, env, ack_msg_ctx))
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                "[sandesha2]ack sending failed");
            AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_SENDING_ACK, 
                AXIS2_FAILURE);
            if(engine)
            {
                axis2_engine_free(engine, env);
                engine = NULL;
            }
            if(seq_prop_mgr)
                sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
            if(storage_mgr)
                sandesha2_storage_mgr_free(storage_mgr, env);
            return AXIS2_FAILURE;
        }        
        if(engine)
        {
            axis2_engine_free(engine, env);
            engine = NULL;
        }
    }
    else
    {
        sandesha2_sender_mgr_t *sender_mgr = NULL;
        axis2_char_t *key = NULL;
        sandesha2_sender_bean_t *ack_bean = NULL;
        sandesha2_sender_bean_t *find_bean = NULL;
        sandesha2_property_bean_t *prop_bean = NULL;
        long ack_interval = 0;
        long time_to_send = 0;
        axutil_array_list_t *found_list = NULL;
        axis2_msg_ctx_t *msg_ctx = NULL;
        axis2_engine_t *engine = NULL;
        axis2_transport_out_desc_t *transport_out = NULL;
        axis2_svc_t *svc = NULL;
        
        sender_mgr = sandesha2_permanent_sender_mgr_create(env, dbname);
        key = axutil_uuid_gen(env);
        ack_bean = sandesha2_sender_bean_create(env);
        sandesha2_sender_bean_set_msg_ctx_ref_key(ack_bean, env, key);
        sandesha2_sender_bean_set_msg_id(ack_bean, env, 
            (axis2_char_t*)axis2_msg_ctx_get_msg_id(ack_msg_ctx, env));
        sandesha2_sender_bean_set_resend(ack_bean, env, AXIS2_FALSE);
        sandesha2_sender_bean_set_seq_id(ack_bean, env, seq_id);
        sandesha2_sender_bean_set_send(ack_bean, env, AXIS2_TRUE);
        sandesha2_sender_bean_set_msg_type(ack_bean, env, SANDESHA2_MSG_TYPE_ACK);
                        
        property = axutil_property_create_with_args(env, 0, 0, 0, 
            AXIS2_VALUE_FALSE);
        axis2_msg_ctx_set_property(ack_msg_ctx, env, 
            SANDESHA2_QUALIFIED_FOR_SENDING, property);
        
        /* Avoid retrieving property bean from operation until it is availbale */
        /*prop_bean = sandesha2_utils_get_property_bean_from_op(env, 
            axis2_msg_ctx_get_op(msg_ctx, env));*/
    
        svc = axis2_msg_ctx_get_svc(ack_msg_ctx, env);
        if(!svc)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                "[sandesha2][ack_req_msg_processor.c] service is NULL");
            return AXIS2_FAILURE;
        }

        prop_bean = sandesha2_utils_get_property_bean(env, svc);
        if(!prop_bean)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                "[sandesha2][ack_req_msg_processor.c] Property bean is NULL");
            return AXIS2_FAILURE;
        }

        /*prop_bean = sandesha2_utils_get_property_bean(env, 
            axis2_conf_ctx_get_conf(conf_ctx, env));*/
        prop_bean = sandesha2_utils_get_property_bean(env, svc);    
        ack_interval = sandesha2_property_bean_get_ack_interval(prop_bean, env);
        time_to_send = sandesha2_utils_get_current_time_in_millis(env) +
            ack_interval;
                        
        find_bean = sandesha2_sender_bean_create(env);
        sandesha2_sender_bean_set_resend(find_bean, env, AXIS2_FALSE);
        sandesha2_sender_bean_set_send(find_bean, env, AXIS2_TRUE);
        sandesha2_sender_bean_set_msg_type(find_bean, env, 
            SANDESHA2_MSG_TYPE_ACK);
                        
        found_list = sandesha2_sender_mgr_find_by_sender_bean(sender_mgr, env, 
            find_bean);
        if(find_bean)
            sandesha2_sender_bean_free(find_bean, env);
        if(found_list)
        {
            int i = 0;
            for(i = 0; i < axutil_array_list_size(found_list, env); i++)
            {
                axis2_char_t *msg_stored_key = NULL;
                sandesha2_sender_bean_t *old_ack_bean = NULL;
                old_ack_bean = axutil_array_list_get(found_list, env, i);
                time_to_send = sandesha2_sender_bean_get_time_to_send(
                    old_ack_bean, env);
                /*char *msg_id = sandesha2_sender_bean_get_msg_id(old_ack_bean, env);*/
                sandesha2_sender_mgr_remove(sender_mgr, env, 
                    sandesha2_sender_bean_get_msg_id(old_ack_bean, env));
                /* Removing the message from the storage */
                msg_stored_key = sandesha2_sender_bean_get_msg_ctx_ref_key(
                    old_ack_bean, env);
                sandesha2_storage_mgr_remove_msg_ctx(storage_mgr, env, 
                    msg_stored_key, conf_ctx, -1);
            }
        }
        sandesha2_sender_bean_set_time_to_send(ack_bean, env, time_to_send); 
        /*axis2_msg_ctx_set_keep_alive(ack_msg_ctx, env, AXIS2_TRUE);*/
        sandesha2_storage_mgr_store_msg_ctx(storage_mgr, env, key, ack_msg_ctx, AXIS2_FALSE);
        sandesha2_sender_mgr_insert(sender_mgr, env, ack_bean);
        
        transport_out = axis2_msg_ctx_get_transport_out_desc(ack_msg_ctx, env);
        property = axutil_property_create_with_args(env, 0, 0,
            axis2_transport_out_desc_free_void_arg, transport_out);
        axis2_msg_ctx_set_property(ack_msg_ctx, env, 
            SANDESHA2_ORIGINAL_TRANSPORT_OUT_DESC, property);
        
        property = axutil_property_create_with_args(env, 0, 0, 0, 
            AXIS2_VALUE_TRUE);
        axis2_msg_ctx_set_property(ack_msg_ctx, env, 
            SANDESHA2_SET_SEND_TO_TRUE, property);
        
        property = axutil_property_create_with_args(env, 0, 0, 0, key);
        axis2_msg_ctx_set_property(ack_msg_ctx, env, 
            SANDESHA2_MESSAGE_STORE_KEY, property);
                        
        axis2_msg_ctx_set_transport_out_desc(ack_msg_ctx, env, 
            sandesha2_utils_get_transport_out(env));
        engine = axis2_engine_create(env, conf_ctx);
        if(AXIS2_FAILURE == axis2_engine_send(engine, env, ack_msg_ctx))
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                "[sandesha2]ack sending failed");
            AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_SENDING_ACK, 
                AXIS2_FAILURE);
            if(engine)
                axis2_engine_free(engine, env);
            if(seq_prop_mgr)
                sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
            if(sender_mgr)
                sandesha2_sender_mgr_free(sender_mgr, env);
            if(storage_mgr)
                sandesha2_storage_mgr_free(storage_mgr, env);
            return AXIS2_FAILURE;
        }
        if(engine)
            axis2_engine_free(engine, env);
        sandesha2_utils_start_sender_for_seq(env, conf_ctx, seq_id, AXIS2_FALSE);
        axis2_msg_ctx_set_paused(msg_ctx, env, AXIS2_TRUE);
        if(sender_mgr)
            sandesha2_sender_mgr_free(sender_mgr, env);
    }
    if(seq_prop_mgr)
        sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
    if(storage_mgr)
        sandesha2_storage_mgr_free(storage_mgr, env);
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, 
        "[sandesha2]Exit:sandesha2_ack_req_msg_processor_process_in_msg");
    return AXIS2_SUCCESS;
}