Beispiel #1
0
static axis2_status_t
savan_default_publisher_publish_to_subscriber(
    savan_publisher_t *publishermod,
    const axutil_env_t *env,
    axis2_svc_client_t *svc_client,
    savan_subscriber_t *subscriber,
    savan_filter_mod_t *filtermod,
    axiom_node_t *payload)
{
    axis2_options_t *options = NULL;
    axis2_status_t status = AXIS2_SUCCESS;
    axis2_endpoint_ref_t *to = NULL;
    const axis2_char_t *address = NULL;
    axis2_bool_t filter_apply = AXIS2_TRUE;
    axis2_endpoint_ref_t *notifyto = NULL;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[savan] Entry:savan_default_publisher_publish_to_subscriber");

    options = (axis2_options_t *) axis2_svc_client_get_options(svc_client, env);
    if(!options)
    {
        options = axis2_options_create(env);
        axis2_svc_client_set_options(svc_client, env, options);
    }
    axis2_options_set_action(options, env, "http://ws.apache.org/ws/2007/05/eventing-extended/Publish");
    axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);

    notifyto = savan_subscriber_get_notify_to(subscriber, env);
    if(notifyto)
    {
        address = axis2_endpoint_ref_get_address(notifyto, env);
        if(address)
        {
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[savan] Publishing to:%s", address);
            to = axis2_endpoint_ref_create(env, address);
            axis2_options_set_to(options, env, to);
        }
    }
    axis2_options_set_xml_parser_reset(options, env, AXIS2_FALSE);

#ifdef SAVAN_FILTERING
    /* If this is a filtering request and filter module is defined then filter the request.
     */
    {
        axis2_char_t *filter_dialect = NULL;
        filter_dialect = savan_subscriber_get_filter_dialect(subscriber, env);
        if(!axutil_strcmp(filter_dialect, SYNAPSE_FILTER_DIALECT))
        {
            /* Do nothing */
        }
        else if(filtermod && savan_subscriber_get_filter(subscriber, env))
        {
            /* Apply the filter, and check whether it evaluates to success */
            filter_apply = savan_filter_mod_apply(filtermod ,env, subscriber, payload);
            if(!filter_apply)
            {
                status = axutil_error_get_status_code(env->error);
                if(AXIS2_SUCCESS != status)
                {
                    axiom_node_detach(payload, env);
                    return status;
                }
            }
        }
        else
        {
            AXIS2_HANDLE_ERROR(env, SAVAN_ERROR_FILTER_MODULE_COULD_NOT_BE_RETRIEVED, 
                    AXIS2_FAILURE);
            return AXIS2_FAILURE;
        }
    }
#endif

    if(filter_apply)
    {
        axis2_svc_client_fire_and_forget(svc_client, env, payload);
    }

    axiom_node_detach(payload, env); /*insert this to prevent payload corruption in subsequent 
                                       "publish" calls with some payload.*/

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[savan] Exit:savan_default_publisher_publish_to_subscriber");

    return status;
}
Beispiel #2
0
WSF_WSDL_EXTERN axis2_bool_t WSF_WSDL_CALL 
wsf_wsdl_request(
    const axutil_env_t* env,
    axis2_char_t* wsdl_file_name,
    const axis2_char_t* operation_name,	
    wsf_wsdl_data_t* parameters,
    axis2_char_t* script_binding_home,
    axis2_svc_client_t* svc_client,
    axutil_hash_t* svc_client_user_options,
    axis2_char_t* service_name,
    axis2_char_t* port_name,
    wsf_wsdl_data_t** response)
{
    int soap_version = 2; 
    int has_fault = AXIS2_FALSE;
    int binding_style = WSDL_BINDING_STYLE_DOC_LIT_W;
    axis2_char_t* payload = NULL;	
    axiom_node_t* payload_node = NULL;
    axis2_char_t* request_buffer = NULL;	
    axiom_node_t* type_map = NULL;	
    axis2_char_t *res_text = NULL;	
    axiom_node_t* sig_axiom = NULL;	
    axiom_node_t *fault_node = NULL;	
    axiom_node_t* wsdl_axiom = NULL;	
    axiom_node_t* params_node = NULL;	
    axiom_node_t* returns_node = NULL;	
    axiom_soap_body_t *soap_body = NULL;	
    axiom_node_t *body_base_node = NULL;	
    /*axis2_char_t *wrapper_element = NULL;*/	
    axiom_node_t* operation_axiom = NULL;	
    axiom_soap_fault_t *soap_fault = NULL;	
    axis2_options_t *client_options = NULL;	
    /*axis2_char_t *wrapper_element_ns = NULL;*/	
    /*axiom_node_t *axiom_soap_base_node = NULL;	*/
    axiom_soap_envelope_t *response_envelope = NULL;	
    wsf_wsdl_data_template_t* input_template = NULL;	
    wsf_wsdl_data_template_t* output_template = NULL;	
    axis2_bool_t is_version1_wsdl = AXIS2_FALSE;
    axis2_char_t* xslt_location = NULL;
    axis2_char_t* type_map_file = NULL;

    AXIS2_LOG_TRACE_MSG(env->log, "Starting execution of wsf_wsdl_request..."); 

    xslt_location = axutil_strcat(env, script_binding_home, WSF_WSDL_XSLT_LOCATION_POSTFIX, NULL);
    type_map_file = axutil_strcat(env, script_binding_home, WSF_WSDL_TYPE_MAP_POSTFIX, NULL);

    client_options = (axis2_options_t *)axis2_svc_client_get_options(svc_client, env);

    axis2_options_set_xml_parser_reset(client_options, env, AXIS2_FALSE);

    if (!wsf_wsdl_parser_load_wsdl(env, wsdl_file_name, xslt_location, &wsdl_axiom, &sig_axiom, &is_version1_wsdl, AXIS2_FALSE))
        return AXIS2_FALSE;

    wsdl_util_create_type_map(env, type_map_file, &type_map);

    wsdl_util_manage_client_options(env, 
        svc_client, 
        svc_client_user_options, 
        client_options, 
        operation_name, 
        wsdl_axiom, 
        is_version1_wsdl, 
        sig_axiom, 
        service_name,
        port_name,
        &operation_axiom, 
        &soap_version);

    wsdl_util_identify_binding_style(env, operation_axiom, &binding_style);

    if (!operation_axiom)
    {
        AXIS2_LOG_ERROR_MSG(env->log, "Operation axiom is NULL");

        if (wsdl_axiom) 
            axiom_node_free_tree(wsdl_axiom, env);
        if (sig_axiom)
            axiom_node_free_tree(sig_axiom, env);
        if (type_map)
            axiom_node_free_tree(type_map, env);
        return AXIS2_FALSE;
    }

    wsdl_util_get_params_node(env, operation_axiom, &params_node);
    wsdl_util_get_returns_node(env, operation_axiom, &returns_node);

    wsdl_data_util_axiom_to_template(env, params_node, &input_template);
    wsdl_data_util_axiom_to_template(env, returns_node, &output_template);

#ifdef WSDL_DEBUG_MODE
    {
        axis2_char_t* buffer = NULL;
        wsdl_data_util_serialize_data(env, parameters, &buffer);
        AXIS2_LOG_DEBUG_MSG(env->log, buffer);
        AXIS2_FREE(env->allocator, buffer);
        wsdl_data_util_serialize_template(env, input_template, &buffer);
        AXIS2_LOG_DEBUG_MSG(env->log, buffer);
        AXIS2_FREE(env->allocator, buffer);
        buffer = NULL;
    }
#endif

    if (wsdl_data_util_validate_data(env, type_map, input_template, parameters, VALIDATION_CRITERIA_REQUEST_MODE_TYPE) == AXIS2_TRUE)
    {
        payload_node = wsdl_data_util_create_payload(env, parameters, binding_style);
        payload = payload_node? axiom_node_to_string(payload_node, env) : NULL;
        // axiom_node_free_tree(payload_node, env);
    }
    else
    {
        AXIS2_LOG_ERROR_MSG(env->log, "User data is not valid or not in proper format");

        if (input_template)
            wsdl_data_template_free(env, input_template);
        if (output_template)
            wsdl_data_template_free(env, output_template);

        if (wsdl_axiom) 
            axiom_node_free_tree(wsdl_axiom, env);
        if (sig_axiom)
            axiom_node_free_tree(sig_axiom, env);
        if (type_map)
            axiom_node_free_tree(type_map, env);
        return AXIS2_FALSE;
    }

    if (!payload_node)
    {
        AXIS2_LOG_ERROR_MSG(env->log, "Request payload is not found");

        if (input_template)
            wsdl_data_template_free(env, input_template);
        if (output_template)
            wsdl_data_template_free(env, output_template);

        if (wsdl_axiom) 
            axiom_node_free_tree(wsdl_axiom, env);
        if (sig_axiom)
            axiom_node_free_tree(sig_axiom, env);
        if (type_map)
            axiom_node_free_tree(type_map, env);
        return AXIS2_FALSE; 
    }

    request_buffer = (axis2_char_t*)wsdl_util_create_request_envelope(env, payload_node, soap_version);

    if (!request_buffer)
    {
        AXIS2_LOG_ERROR_MSG(env->log, "Error in creating request payload dom");

        if (input_template)
            wsdl_data_template_free(env, input_template);
        if (output_template)
            wsdl_data_template_free(env, output_template);

        if (wsdl_axiom) 
            axiom_node_free_tree(wsdl_axiom, env);
        if (sig_axiom)
            axiom_node_free_tree(sig_axiom, env);
        if (type_map)
            axiom_node_free_tree(type_map, env);

        return AXIS2_FALSE;
    }

    response_envelope = (axiom_soap_envelope_t*)wsdl_util_send_receive_soap_envelope_with_op_client(env, 
        svc_client, 
        client_options, 
        request_buffer);
    if (response_envelope) 
    {
        has_fault = AXIS2_TRUE;
        soap_body = axiom_soap_envelope_get_body (response_envelope, env);

        if (soap_body)
        {
            soap_fault = axiom_soap_body_get_fault (soap_body, env);
        }

        if (soap_fault) 
        {
            soap_version = axis2_options_get_soap_version(client_options, env);
            fault_node = axiom_soap_fault_get_base_node(soap_fault, env);
            if (fault_node)
            {
                res_text = axiom_node_to_string(fault_node, env);
                AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "Fault payload is %s", res_text);

                if (input_template)
                    wsdl_data_template_free(env, input_template);
                if (output_template)
                    wsdl_data_template_free(env, output_template);
                if (wsdl_axiom) 
                    axiom_node_free_tree(wsdl_axiom, env);
                if (sig_axiom)
                    axiom_node_free_tree(sig_axiom, env);
                if (type_map)
                    axiom_node_free_tree(type_map, env);

                return AXIS2_FALSE;
            }    
        }

        if (soap_body)
        {
            body_base_node = axiom_soap_body_get_base_node(soap_body, env);
        }

        if (body_base_node && !soap_fault)
        {
            axis2_char_t *response_buffer = NULL;	
            wsf_wsdl_data_t *response_data = NULL;

            response_buffer = axiom_node_to_string(body_base_node, env);
            AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI,
                "Response buffer is %s", response_buffer);

            AXIS2_FREE(env->allocator, response_buffer);

            wsdl_data_util_axiom_to_data(env, body_base_node, &response_data);

#ifdef WSDL_DEBUG_MODE
            {
                axis2_char_t* buffer = NULL;
                wsdl_data_util_serialize_data(env, response_data, &buffer);
                AXIS2_LOG_DEBUG_MSG(env->log, buffer);
                AXIS2_FREE(env->allocator, buffer);
                wsdl_data_util_serialize_template(env, output_template, &buffer);
                AXIS2_LOG_DEBUG_MSG(env->log, buffer);
                AXIS2_FREE(env->allocator, buffer);
                buffer = NULL;
            }
#endif

            if (wsdl_data_util_validate_data(env, type_map, output_template, response_data, VALIDATION_CRITERIA_RESPONSE_MODE) == AXIS2_TRUE)
            {
                AXIS2_LOG_DEBUG_MSG(env->log, "Valid response!!!");
                *response = response_data;

                if (input_template)
                    wsdl_data_template_free(env, input_template);
                if (output_template)
                    wsdl_data_template_free(env, output_template);
                if (wsdl_axiom) 
                    axiom_node_free_tree(wsdl_axiom, env);
                if (sig_axiom)
                    axiom_node_free_tree(sig_axiom, env);
                if (type_map)
                    axiom_node_free_tree(type_map, env);

                return AXIS2_TRUE;
            }
            else
            {
                AXIS2_LOG_ERROR_MSG(env->log, "Response data is not valid or not in proper format");

                if (input_template)
                    wsdl_data_template_free(env, input_template);
                if (output_template)
                    wsdl_data_template_free(env, output_template);
                if (wsdl_axiom) 
                    axiom_node_free_tree(wsdl_axiom, env);
                if (sig_axiom)
                    axiom_node_free_tree(sig_axiom, env);
                if (type_map)
                    axiom_node_free_tree(type_map, env);

                return AXIS2_FALSE;
            }
        }
    }
    else  /* response_envelope == NULL */
    {
        AXIS2_LOG_ERROR_MSG(env->log, "Response envelope not found");
    }

    if (input_template)
        wsdl_data_template_free(env, input_template);
    if (output_template)
        wsdl_data_template_free(env, output_template);

    if (wsdl_axiom) 
        axiom_node_free_tree(wsdl_axiom, env);
    if (sig_axiom)
        axiom_node_free_tree(sig_axiom, env);
    if (type_map)
        axiom_node_free_tree(type_map, env);

    return AXIS2_FALSE;
}
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;
}