예제 #1
0
AXIS2_EXTERN axiom_node_t *AXIS2_CALL
axiom_soap_header_get_base_node(
    axiom_soap_header_t * soap_header,
    const axutil_env_t * env)
{
    if(!soap_header->om_ele_node)
    {
        axiom_node_t *parent_node = NULL;
        axiom_element_t *parent_ele = NULL;
        axiom_namespace_t *parent_ns = NULL;
        axiom_element_t *this_ele = NULL;
        axiom_node_t *this_node = NULL;
        axiom_soap_body_t *soap_body = NULL;
        axiom_node_t *body_node = NULL;

        parent_node = axiom_soap_envelope_get_base_node(soap_header->soap_envelope, env);

        if(!parent_node || axiom_node_get_node_type(parent_node, env) != AXIOM_ELEMENT)
        {
            axiom_soap_header_free(soap_header, env);
            return NULL;
        }

        parent_ele = (axiom_element_t *)axiom_node_get_data_element(parent_node, env);
        if(!parent_ele)
        {
            axiom_soap_header_free(soap_header, env);
            return NULL;
        }

        parent_ns = axiom_element_get_namespace(parent_ele, env, parent_node);
        this_ele = axiom_element_create(env, NULL, AXIOM_SOAP_HEADER_LOCAL_NAME, parent_ns,
            &this_node);
        if(!this_ele)
        {
            axiom_soap_header_free(soap_header, env);
            return NULL;
        }

        soap_body = axiom_soap_envelope_get_body(soap_header->soap_envelope, env);
        if(soap_body)
        {
            body_node = axiom_soap_body_get_base_node(soap_body, env);
            axiom_node_insert_sibling_before(body_node, env, this_node);
        }
        else
        {
            axiom_node_add_child(parent_node, env, this_node);
        }
        soap_header->om_ele_node = this_node;
    }

    return soap_header->om_ele_node;
}
예제 #2
0
static axis2_status_t AXIS2_CALL
axis2_msg_recv_receive_impl(
    axis2_msg_recv_t * msg_recv,
    const axutil_env_t * env,
    axis2_msg_ctx_t * msg_ctx,
    void *callback_recv_param)
{
    axis2_msg_ctx_t *out_msg_ctx = NULL;
    axis2_engine_t *engine = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_op_ctx_t *op_ctx = NULL;
    axis2_svc_ctx_t *svc_ctx = NULL;
    axis2_status_t status = AXIS2_FAILURE;

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

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

    if(!status)
    {
        return status;
    }

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

    /* Reset the out message context to avoid double freeing at http worker. For example if this is
     * not done here both in and out message context will try to free the transport out stream 
     * which will result in memory corruption.
     */
    if(!axis2_msg_ctx_is_paused(out_msg_ctx, env) && !axis2_msg_ctx_is_keep_alive(out_msg_ctx, env))
    {
        axis2_core_utils_reset_out_msg_ctx(env, out_msg_ctx);
    }
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[axis2]Exit:axis2_msg_recv_receive_impl");
    return status;
    (void)callback_recv_param;
}
예제 #3
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axiom_soap11_builder_helper_handle_event(
    axiom_soap11_builder_helper_t * builder_helper,
    const axutil_env_t * env,
    axiom_node_t * om_element_node,
    int element_level)
{
    axiom_element_t *om_ele = NULL;
    axis2_char_t *ele_localname = NULL;
    axiom_soap_envelope_t *soap_envelope = NULL;
    axiom_soap_body_t *soap_body = NULL;
    axiom_soap_fault_t *soap_fault = NULL;

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

    om_ele = (axiom_element_t *)axiom_node_get_data_element(om_element_node, env);

    ele_localname = axiom_element_get_localname(om_ele, env);
    if(!ele_localname)
    {
        return AXIS2_FAILURE;
    }

    soap_envelope = axiom_soap_builder_get_soap_envelope(builder_helper->soap_builder, env);

    if(!soap_envelope)
    {
        return AXIS2_FAILURE;
    }

    soap_body = axiom_soap_envelope_get_body(soap_envelope, env);
    if(!soap_body)
    {
        return AXIS2_FAILURE;
    }

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

    if(element_level == 4)
    {
        axiom_soap_fault_code_t *fault_code = NULL;
        axiom_soap_fault_value_t *fault_value = NULL;
        axiom_node_t *fault_value_node = NULL;
        axiom_element_t *fault_value_ele = NULL;

        if(axutil_strcmp(ele_localname, AXIOM_SOAP11_SOAP_FAULT_CODE_LOCAL_NAME) == 0)
        {
            axis2_status_t status = AXIS2_SUCCESS;

            if(builder_helper->fault_string_present)
            {
                axiom_soap_builder_set_bool_processing_mandatory_fault_elements(
                    builder_helper->soap_builder, env, AXIS2_FALSE);
            }

            fault_code = axiom_soap_fault_code_create(env);
            if(!fault_code)
            {
                return AXIS2_FAILURE;
            }
            axiom_soap_fault_code_set_base_node(fault_code, env, om_element_node);

            axiom_soap_fault_set_code(soap_fault, env, fault_code);

            axiom_soap_fault_code_set_builder(fault_code, env, builder_helper->soap_builder);

            axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME);

            fault_value = axiom_soap_fault_value_create_with_code(env, fault_code);
            if(!fault_value)
            {
                return AXIS2_FAILURE;
            }
            fault_value_node = axiom_soap_fault_value_get_base_node(fault_value, env);
            if(!fault_value_node)
            {
                return AXIS2_FAILURE;
            }
            fault_value_ele = (axiom_element_t *)axiom_node_get_data_element(fault_value_node, env);

            axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, fault_value_node);

            status = axiom_soap11_builder_helper_process_text(builder_helper, env);
            if(status == AXIS2_FAILURE)
            {
                return AXIS2_FAILURE;
            }
            axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, om_element_node);
            axiom_node_set_complete(om_element_node, env, AXIS2_TRUE);

            axiom_stax_builder_set_element_level(builder_helper->om_builder, env, (element_level
                - 1));
            builder_helper->fault_code_present = AXIS2_TRUE;
        }
        else if(axutil_strcmp(AXIOM_SOAP11_SOAP_FAULT_STRING_LOCAL_NAME, ele_localname) == 0)
        {

            axiom_soap_fault_reason_t *fault_reason = NULL;
            axiom_soap_fault_text_t *fault_text = NULL;
            axiom_node_t *fault_text_node = NULL;
            int status = AXIS2_SUCCESS;
            if(builder_helper->fault_code_present)
            {
                axiom_soap_builder_set_bool_processing_mandatory_fault_elements(
                    builder_helper->soap_builder, env, AXIS2_FALSE);
            }

            axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME);

            fault_reason = axiom_soap_fault_reason_create(env);
            if(!fault_reason)
            {
                return AXIS2_FAILURE;
            }
            axiom_soap_fault_reason_set_base_node(fault_reason, env, om_element_node);

            axiom_soap_fault_set_reason(soap_fault, env, fault_reason);

            fault_text = axiom_soap_fault_text_create_with_parent(env, fault_reason);
            if(!fault_text)
            {
                return AXIS2_FAILURE;
            }
            fault_text_node = axiom_soap_fault_text_get_base_node(fault_text, env);
            if(!fault_text_node)
            {
                return AXIS2_FAILURE;
            }
            axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, fault_text_node);

            status = axiom_soap11_builder_helper_process_text(builder_helper, env);
            if(status == AXIS2_FAILURE)
            {
                return AXIS2_FAILURE;
            }
            axiom_stax_builder_set_lastnode(builder_helper->om_builder, env, om_element_node);

            axiom_node_set_complete(om_element_node, env, AXIS2_TRUE);

            axiom_stax_builder_set_element_level(builder_helper->om_builder, env, (element_level
                - 1));

            builder_helper->fault_string_present = AXIS2_TRUE;

        }
        else if(axutil_strcmp(AXIOM_SOAP11_SOAP_FAULT_ACTOR_LOCAL_NAME, ele_localname) == 0)
        {
            axiom_soap_fault_role_t *fault_role = NULL;
            fault_role = axiom_soap_fault_role_create(env);
            if(!fault_role)
            {
                return AXIS2_FAILURE;
            }
            axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME);

            axiom_soap_fault_role_set_base_node(fault_role, env, om_element_node);

            axiom_soap_fault_set_role(soap_fault, env, fault_role);
            /*
             Role element may not have a namespace associated, hence commented, else it segfaults here - Samisa
             status = axiom_soap_builder_process_namespace_data(
             builder_helper->soap_builder, env, om_element_node, AXIS2_TRUE);
             if(status == AXIS2_FAILURE)
             return AXIS2_FAILURE; */
        }
        else if(axutil_strcmp(AXIOM_SOAP11_SOAP_FAULT_DETAIL_LOCAL_NAME, ele_localname) == 0)
        {
            axiom_soap_fault_detail_t *fault_detail = NULL;
            fault_detail = axiom_soap_fault_detail_create(env);
            if(!fault_detail)
            {
                return AXIS2_FAILURE;
            }
            axiom_element_set_localname(om_ele, env, AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME);

            axiom_soap_fault_detail_set_base_node(fault_detail, env, om_element_node);

            axiom_soap_fault_set_detail(soap_fault, env, fault_detail);
        }
        else
        {
            return AXIS2_SUCCESS;
        }
    }
    else if(element_level == 5)
    {
        axiom_node_t *parent_node = NULL;
        axiom_element_t *parent_element = NULL;
        axis2_char_t *parent_localname = NULL;

        parent_node = axiom_node_get_parent(om_element_node, env);
        if(!parent_node)
        {
            return AXIS2_FAILURE;
        }
        parent_element = (axiom_element_t *)axiom_node_get_data_element(om_element_node, env);
        parent_localname = axiom_element_get_localname(parent_element, env);

        if(!parent_localname)
        {
            return AXIS2_FAILURE;
        }
        if(axutil_strcmp(parent_localname, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME) == 0)
        {
            AXIS2_ERROR_SET(env->error,
                AXIS2_ERROR_SOAP11_FAULT_ACTOR_SHOULD_NOT_HAVE_CHILD_ELEMENTS, AXIS2_FAILURE);
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "SOAP 1.1 Actor should not have child elements");
            return AXIS2_FAILURE;
        }
    }
    return AXIS2_SUCCESS;
}
예제 #4
0
AXIS2_EXTERN void AXIS2_CALL
savan_default_publisher_publish(
    savan_publisher_t *publishermod,
    const axutil_env_t *env,
    void *msg_ctx,
    savan_subs_mgr_t *subs_mgr)
{
    savan_default_publisher_t *publishermodimpl = NULL;
    axutil_array_list_t *subs_store = NULL;
    int i = 0, size = 0;
    savan_filter_mod_t *filtermod = NULL;
    const axis2_char_t *path = NULL;
    axiom_node_t *payload = NULL;
    axiom_soap_envelope_t *envelope = NULL;
    axiom_soap_body_t *body = NULL;
    axiom_node_t *body_node = NULL;
    const axis2_char_t *filter = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    axutil_property_t *topic_property = NULL;

    publishermodimpl = SAVAN_INTF_TO_IMPL(publishermod);

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

    topic_property = axis2_msg_ctx_get_property(msg_ctx, env, ELEM_NAME_TOPIC);
    if(topic_property)
    {
        filter = axutil_property_get_value(topic_property, env);
    }
    axutil_allocator_switch_to_global_pool(env->allocator);
    if(subs_mgr)
    {
        subs_store = savan_subs_mgr_retrieve_all_subscribers(subs_mgr, env, filter);
    }

    if (!subs_store)
    {
        axutil_allocator_switch_to_local_pool(env->allocator);
        AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "[savan] Subscriber store is NULL"); 
    }

    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
    path = axis2_conf_ctx_get_root_dir(conf_ctx, env);
    if(!path)
    {
        path = AXIS2_GETENV("AXIS2C_HOME");
    }

    envelope =  axis2_msg_ctx_get_soap_envelope((axis2_msg_ctx_t *) msg_ctx, env);
    if (!envelope)
    {
        axutil_allocator_switch_to_local_pool(env->allocator);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to extract the soap envelop");
    }
    
    body = axiom_soap_envelope_get_body(envelope, env);
    if (!body)
    {
        axutil_allocator_switch_to_local_pool(env->allocator);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to extract the soap body"); 
    }
    
    body_node = axiom_soap_body_get_base_node(body, env);

    payload = axiom_node_get_first_child(body_node, env);
    size = axutil_array_list_size(subs_store, env);
    for(i = 0; i < size; i++)
    {
        axis2_svc_client_t *svc_client = NULL;
        savan_subscriber_t *sub = NULL;

        sub = (savan_subscriber_t *)axutil_array_list_get(subs_store, env, i);
        if (sub)
        {
            axis2_char_t *id = savan_subscriber_get_id(sub, env);
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[savan] Publishing to:%s", id);

            svc_client = axis2_svc_client_create(env, path);
            filtermod = savan_util_get_filter_module(env, publishermodimpl->conf);
            /* Ideally publishing to each subscriber should happen within a thread for each 
             * subscriber. However until Axis2/C provide a good thread pool to handle
             * such tasks I use this sequential publishing to subscribers.
             */
            if(!savan_default_publisher_publish_to_subscriber(publishermod, env, svc_client, sub, 
                        filtermod, payload))
            {
                axis2_endpoint_ref_t *notifyto = savan_subscriber_get_notify_to(sub, env);
                const axis2_char_t *address = NULL;

                if(notifyto)
                {
                    address = axis2_endpoint_ref_get_address(notifyto, env);
                }

                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                        "Publishing to the Data Sink:%s proviced by subscriber:%s Failed. Check "\
                        "whether the Data Sink url is correct", address, id);
            }
            if(svc_client)
            {
                axis2_svc_client_free(svc_client, env);
            }
        }
    }

    axutil_allocator_switch_to_local_pool(env->allocator);

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[savan] Exit:savan_default_publisher_publish");
}
예제 #5
0
axis2_status_t AXIS2_CALL
axis2_libcurl_send(
    axis2_libcurl_t *data,
    axiom_output_t * om_output,
    const axutil_env_t * env,
    axis2_msg_ctx_t * msg_ctx,
    axiom_soap_envelope_t * out,
    const axis2_char_t * str_url,
    const axis2_char_t * soap_action)
{
    struct curl_slist *headers = NULL;
    axiom_soap_body_t *soap_body;
    axis2_bool_t is_soap = AXIS2_TRUE;
    axis2_bool_t send_via_get = AXIS2_FALSE;
    axis2_bool_t send_via_head = AXIS2_FALSE;
    axis2_bool_t send_via_put = AXIS2_FALSE;
    axis2_bool_t send_via_delete = AXIS2_FALSE;
    axis2_bool_t doing_mtom = AXIS2_FALSE;
    axiom_node_t *body_node = NULL;
    axiom_node_t *data_out = NULL;
    axutil_property_t *method = NULL;
    axis2_char_t *method_value = NULL;
    axiom_xml_writer_t *xml_writer = NULL;
    axis2_char_t *buffer = NULL;
    unsigned int buffer_size = 0;
    int content_length = -1;
    axis2_char_t *content_type = NULL;
    /*axis2_char_t *content_len = AXIS2_HTTP_HEADER_CONTENT_LENGTH_; */
    const axis2_char_t *char_set_enc = NULL;
    axis2_char_t *content = AXIS2_HTTP_HEADER_CONTENT_TYPE_;
    axis2_char_t *soap_action_header = AXIS2_HTTP_HEADER_SOAP_ACTION_;
    axutil_stream_t *in_stream;
    axutil_property_t *trans_in_property;
    axutil_string_t *char_set_enc_str;
    axis2_byte_t *output_stream = NULL;
    int output_stream_size = 0;
    CURL *handler;
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_conf_t *conf = NULL;
    axis2_transport_out_desc_t *trans_desc = NULL;
    axutil_param_t *write_xml_declaration_param = NULL;
    axutil_hash_t *transport_attrs = NULL;
    axis2_bool_t write_xml_declaration = AXIS2_FALSE;
    axutil_property_t *property;
    int *response_length = NULL;
    axis2_http_status_line_t *status_line = NULL;
    axis2_char_t *status_line_str = NULL;
    axis2_char_t *tmp_strcat = NULL;
    int status_code = 0;

    AXIS2_PARAM_CHECK(env->error, data, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, data->handler, AXIS2_FAILURE);

    handler = data->handler;
    curl_easy_reset(handler);
    curl_easy_setopt(handler, CURLOPT_ERRORBUFFER, data->errorbuffer);
    headers = curl_slist_append(headers, AXIS2_HTTP_HEADER_USER_AGENT_AXIS2C);
    headers = curl_slist_append(headers, AXIS2_HTTP_HEADER_ACCEPT_);
    headers = curl_slist_append(headers, AXIS2_HTTP_HEADER_EXPECT_);

    if(AXIS2_FAILURE == axis2_libcurl_set_options(handler, env, msg_ctx))
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[axis2libcurl]Setting options in Libcurl failed");
        return AXIS2_FAILURE;
    }

    if (AXIS2_TRUE == axis2_msg_ctx_get_doing_rest(msg_ctx, env))
    {
        is_soap = AXIS2_FALSE;
    }
    else
    {
        is_soap = AXIS2_TRUE;
    }

    if (!is_soap)
    {
        soap_body = axiom_soap_envelope_get_body(out, env);
        if (!soap_body)
        {
            AXIS2_HANDLE_ERROR(env,
                AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL,
                AXIS2_FAILURE);
            return AXIS2_FAILURE;
        }

        body_node = axiom_soap_body_get_base_node(soap_body, env);
        if (!body_node)
        {
            AXIS2_HANDLE_ERROR(env,
                AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL,
                AXIS2_FAILURE);

            return AXIS2_FAILURE;
        }
        data_out = axiom_node_get_first_element(body_node, env);

        method = (axutil_property_t *) axis2_msg_ctx_get_property(msg_ctx, env,
            AXIS2_HTTP_METHOD);

        if (method)
        {
            method_value =
            (axis2_char_t *) axutil_property_get_value(method, env);
        }

        /* The default is POST */
        if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_GET))
        {
            send_via_get = AXIS2_TRUE;
        }
        else if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_HEAD))
        {
            send_via_head = AXIS2_TRUE;
        }
        else if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_PUT))
        {
            send_via_put = AXIS2_TRUE;
        }
        else if (method_value && 0 == axutil_strcmp(method_value, AXIS2_HTTP_DELETE))
        {
            send_via_delete = AXIS2_TRUE;
        }
    }

    conf_ctx = axis2_msg_ctx_get_conf_ctx (msg_ctx, env);
    if (conf_ctx)
    {
        conf = axis2_conf_ctx_get_conf (conf_ctx, env);
    }

    if (conf)
    {
        trans_desc = axis2_conf_get_transport_out (conf,
            env, AXIS2_TRANSPORT_ENUM_HTTP);
    }

    if (trans_desc)
    {
        write_xml_declaration_param =
        axutil_param_container_get_param
        (axis2_transport_out_desc_param_container (trans_desc, env), env,
            AXIS2_XML_DECLARATION);
    }

    if (write_xml_declaration_param)
    {
        transport_attrs =
        axutil_param_get_attributes (write_xml_declaration_param, env);
        if (transport_attrs)
        {
            axutil_generic_obj_t *obj = NULL;
            axiom_attribute_t *write_xml_declaration_attr = NULL;
            axis2_char_t *write_xml_declaration_attr_value = NULL;

            obj = axutil_hash_get (transport_attrs, AXIS2_ADD_XML_DECLARATION,
                AXIS2_HASH_KEY_STRING);
            if (obj)
            {
                write_xml_declaration_attr = (axiom_attribute_t *)
                axutil_generic_obj_get_value (obj,
                    env);
            }
            if (write_xml_declaration_attr)
            {
                write_xml_declaration_attr_value =
                axiom_attribute_get_value (write_xml_declaration_attr, env);
            }
            if (write_xml_declaration_attr_value &&
                0 == axutil_strcasecmp (write_xml_declaration_attr_value,
                    AXIS2_VALUE_TRUE))
            {
                write_xml_declaration = AXIS2_TRUE;
            }
        }
    }

    if (write_xml_declaration)
    {
        axiom_output_write_xml_version_encoding (om_output, env);
    }

    if (!send_via_get && !send_via_head && !send_via_delete)
    {
        xml_writer = axiom_output_get_xml_writer(om_output, env);

        char_set_enc_str = axis2_msg_ctx_get_charset_encoding(msg_ctx, env);

        if (!char_set_enc_str)
        {
            char_set_enc = AXIS2_DEFAULT_CHAR_SET_ENCODING;
        }
        else
        {
            char_set_enc = axutil_string_get_buffer(char_set_enc_str, env);
        }

        if (!send_via_put && is_soap)
        {
            doing_mtom = axis2_msg_ctx_get_doing_mtom(msg_ctx, env);

            axiom_output_set_do_optimize(om_output, env, doing_mtom);
            axiom_soap_envelope_serialize(out, env, om_output, AXIS2_FALSE);
            if (AXIS2_TRUE == axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
            {
                if (AXIS2_ESC_DOUBLE_QUOTE != *soap_action)
                {
                    axis2_char_t *tmp_soap_action = NULL;
                    tmp_soap_action =
                    AXIS2_MALLOC(env->allocator,
                        (axutil_strlen(soap_action) +
                            5) * sizeof(axis2_char_t));
                    sprintf(tmp_soap_action, "\"%s\"", soap_action);
                    tmp_strcat = axutil_stracat(env, soap_action_header,tmp_soap_action);
                    headers = curl_slist_append(headers, tmp_strcat);
                    AXIS2_FREE(env->allocator, tmp_strcat);
                    AXIS2_FREE(env->allocator, tmp_soap_action);
                }
                else
                {
                    tmp_strcat = axutil_stracat(env, soap_action_header, soap_action);
                    headers = curl_slist_append(headers, tmp_strcat );
                    AXIS2_FREE(env->allocator, tmp_strcat);
                }
            }

            if (doing_mtom)
            {
                /*axiom_output_flush(om_output, env, &output_stream,
                 &output_stream_size);*/
                axiom_output_flush(om_output, env);
                content_type =
                (axis2_char_t *) axiom_output_get_content_type(om_output,
                    env);
                if (AXIS2_TRUE != axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
                {
                    if (axutil_strcmp(soap_action, ""))
                    {
                        /* handle SOAP action for SOAP 1.2 case */
                        axis2_char_t *temp_content_type = NULL;
                        temp_content_type = axutil_stracat (env,
                            content_type,
                            AXIS2_CONTENT_TYPE_ACTION);
                        content_type = temp_content_type;
                        temp_content_type = axutil_stracat (env,
                            content_type,
                            soap_action);
                        AXIS2_FREE (env->allocator, content_type);
                        content_type = temp_content_type;
                        temp_content_type =
                        axutil_stracat (env, content_type,
                            AXIS2_ESC_DOUBLE_QUOTE_STR);
                        AXIS2_FREE (env->allocator, content_type);
                        content_type = temp_content_type;
                    }
                }
            }
            else if (AXIS2_TRUE == axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
            {
                axis2_char_t *temp_content_type = NULL;
                content_type =
                (axis2_char_t *) AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML;
                content_type = axutil_stracat(env, content_type,
                    AXIS2_CONTENT_TYPE_CHARSET);
                temp_content_type =
                axutil_stracat(env, content_type, char_set_enc);
                AXIS2_FREE(env->allocator, content_type);
                content_type = temp_content_type;
            }
            else
            {
                axis2_char_t *temp_content_type = NULL;
                content_type =
                (axis2_char_t *) AXIS2_HTTP_HEADER_ACCEPT_APPL_SOAP;
                content_type = axutil_stracat(env, content_type,
                    AXIS2_CONTENT_TYPE_CHARSET);
                temp_content_type =
                axutil_stracat(env, content_type, char_set_enc);
                AXIS2_FREE(env->allocator, content_type);
                content_type = temp_content_type;
                if (axutil_strcmp(soap_action, ""))
                {
                    temp_content_type =
                    axutil_stracat(env, content_type,
                        AXIS2_CONTENT_TYPE_ACTION);
                    AXIS2_FREE(env->allocator, content_type);
                    content_type = temp_content_type;
                    temp_content_type =
                    axutil_stracat(env, content_type, soap_action);
                    AXIS2_FREE(env->allocator, content_type);
                    content_type = temp_content_type;
                }
                temp_content_type = axutil_stracat(env, content_type,
                    AXIS2_SEMI_COLON_STR);
                AXIS2_FREE(env->allocator, content_type);
                content_type = temp_content_type;
            }
        }
        else if (is_soap)
        {
            AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Attempt to send SOAP"
                "message using HTTP PUT failed");
            return AXIS2_FAILURE;
        }
        else
        {
            axutil_property_t *content_type_property = NULL;
            axutil_hash_t *content_type_hash = NULL;
            axis2_char_t *content_type_value = NULL;

            axiom_node_serialize(data_out, env, om_output);
            content_type_property =
            (axutil_property_t *)
            axis2_msg_ctx_get_property(msg_ctx, env,
                AXIS2_USER_DEFINED_HTTP_HEADER_CONTENT_TYPE);

            if (content_type_property)
            {
                content_type_hash =
                (axutil_hash_t *)
                axutil_property_get_value(content_type_property, env);

                if (content_type_hash)
                {
                    content_type_value =
                    (char *) axutil_hash_get(content_type_hash,
                        AXIS2_HTTP_HEADER_CONTENT_TYPE,
                        AXIS2_HASH_KEY_STRING);
                }
            }

            if (content_type_value)
            {
                content_type = content_type_value;
            }
            else
            {
                content_type = axutil_strdup(env,AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML);
            }

        }

        buffer = axiom_xml_writer_get_xml(xml_writer, env);
        if (!doing_mtom)
        {
            buffer_size = axiom_xml_writer_get_xml_size(xml_writer, env);
        }
        else
        buffer_size = output_stream_size;
        {
            /*
             * Curl calculates the content-length automatically.
             * This commented section is not only unnecessary,
             * it interferes with authentication.
             *
             * NTLM, for example, will send an empty request
             * first (no body) to get the auth challenge
             * before resending with actual content.
             */
            /*char tmp_buf[10];
            sprintf(tmp_buf, "%d", buffer_size);
            tmp_strcat = axutil_stracat(env, content_len, tmp_buf);
            headers = curl_slist_append(headers, tmp_strcat);
            AXIS2_FREE(env->allocator, tmp_strcat);
            tmp_strcat = NULL;*/

            tmp_strcat = axutil_stracat(env, content, content_type);
            headers = curl_slist_append(headers, tmp_strcat);
            AXIS2_FREE(env->allocator, tmp_strcat);
            tmp_strcat = NULL;
        }

        if (!doing_mtom)
        {
            curl_easy_setopt(handler, CURLOPT_POSTFIELDSIZE, buffer_size);
            curl_easy_setopt(handler, CURLOPT_POSTFIELDS, buffer);
        }
        else
        {
            curl_easy_setopt(handler, CURLOPT_POSTFIELDSIZE,
                output_stream_size);
            curl_easy_setopt(handler, CURLOPT_POSTFIELDS, output_stream);
        }

        if (send_via_put)
        {
            curl_easy_setopt(handler, CURLOPT_CUSTOMREQUEST, AXIS2_HTTP_PUT);
        }
        curl_easy_setopt(handler, CURLOPT_URL, str_url);
    }
    else
    {
        axis2_char_t *request_param;
        axis2_char_t *url_encode;
        request_param =
        (axis2_char_t *) axis2_http_sender_get_param_string(NULL, env,
            msg_ctx);
        url_encode = axutil_strcat(env, str_url, AXIS2_Q_MARK_STR,
            request_param, NULL);
        if (send_via_get)
        {
            curl_easy_setopt(handler, CURLOPT_HTTPGET, 1);
        }
        else if (send_via_head)
        {
            curl_easy_setopt(handler, CURLOPT_NOBODY, 1);
        }
        else if (send_via_delete)
        {
            curl_easy_setopt(handler, CURLOPT_CUSTOMREQUEST, AXIS2_HTTP_DELETE);
        }
        curl_easy_setopt(handler, CURLOPT_URL, url_encode);
    }

    {
        axis2_bool_t manage_session;
        manage_session = axis2_msg_ctx_get_manage_session(msg_ctx, env);
        if (manage_session == AXIS2_TRUE)
        {
            if (data->cookies == AXIS2_FALSE)
            {
                /* Ensure cookies enabled to manage session */
                /* Pass empty cookie string to enable cookies */
                curl_easy_setopt(handler, CURLOPT_COOKIEFILE, " ");
                data->cookies = AXIS2_TRUE;
            }
        }
        else if (data->cookies == AXIS2_TRUE)
        {
            /* Pass special string ALL to reset cookies if any have been enabled. */
            /* If cookies have ever been enabled, we reset every time as long as 
             manage_session is false, as there is no clear curl option to
             turn off the cookie engine once enabled. */
            curl_easy_setopt(handler, CURLOPT_COOKIELIST, AXIS2_ALL);
        }
    }

    curl_easy_setopt(handler, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(handler, CURLOPT_WRITEFUNCTION,
        axis2_libcurl_write_memory_callback);
    curl_easy_setopt(handler, CURLOPT_WRITEDATA, data);

    curl_easy_setopt (handler, CURLOPT_HEADERFUNCTION, axis2_libcurl_header_callback);

    curl_easy_setopt (handler, CURLOPT_WRITEHEADER, data);

    /* Free response data from previous request */
    if( data->size )
    {
        if (data->memory)
        {
            AXIS2_FREE(data->env->allocator, data->memory);
        }
        data->size = 0;
    }

    if (curl_easy_perform(handler))
    {
        AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "%s", &data->errorbuffer);
        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_HTTP_CLIENT_TRANSPORT_ERROR,
            AXIS2_FAILURE);
        return AXIS2_FAILURE;
    }

    in_stream = axutil_stream_create_libcurl(env, data->memory, data->size);
    trans_in_property = axutil_property_create(env);
    axutil_property_set_scope(trans_in_property, env, AXIS2_SCOPE_REQUEST);
    axutil_property_set_free_func(trans_in_property, env,
        libcurl_stream_free);
    axutil_property_set_value(trans_in_property, env, in_stream);
    axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_TRANSPORT_IN,
        trans_in_property);

    if (axutil_array_list_size(data->alist, env) > 0)
    {
        status_line_str = axutil_array_list_get(data->alist, env, 0);
        if (status_line_str)
        {
            status_line = axis2_http_status_line_create(env, status_line_str);
        }
    }

    if (status_line)
    {
        status_code = axis2_http_status_line_get_status_code(status_line, env);
    }

    axis2_msg_ctx_set_status_code (msg_ctx, env, status_code);
    AXIS2_FREE(data->env->allocator, content_type);
    content_type = axis2_libcurl_get_content_type(data, env);

    if (content_type)
    {
        if (strstr (content_type, AXIS2_HTTP_HEADER_ACCEPT_MULTIPART_RELATED)
            && strstr (content_type, AXIS2_HTTP_HEADER_ACCEPT_XOP_XML))
        {
            axis2_ctx_t *axis_ctx =
            axis2_op_ctx_get_base (axis2_msg_ctx_get_op_ctx (msg_ctx, env),
                env);
            property = axutil_property_create (env);
            axutil_property_set_scope (property, env, AXIS2_SCOPE_REQUEST);
            axutil_property_set_value (property,
                env, axutil_strdup (env, content_type));
            axis2_ctx_set_property (axis_ctx,
                env, MTOM_RECIVED_CONTENT_TYPE, property);
        }
    }

    content_length = axis2_libcurl_get_content_length(data, env);
    if (content_length >= 0)
    {
        response_length = AXIS2_MALLOC (env->allocator, sizeof (int));
        memcpy (response_length, &content_length, sizeof (int));
        property = axutil_property_create (env);
        axutil_property_set_scope (property, env, AXIS2_SCOPE_REQUEST);
        axutil_property_set_value (property, env, response_length);
        axis2_msg_ctx_set_property (msg_ctx, env,
            AXIS2_HTTP_HEADER_CONTENT_LENGTH, property);
    }

    curl_slist_free_all (headers);
    /* release the read http headers. */
    /* (commenting out the call below is a clever way to force a premature EOF 
     condition in subsequent messages, as they will be read using the content-length
     of the first message.) */
    axis2_libcurl_free_headers(data, env);
    AXIS2_FREE(data->env->allocator, content_type);
    axis2_http_status_line_free( status_line, env);

    return AXIS2_SUCCESS;
}
예제 #6
0
AXIS2_EXTERN axiom_node_t *AXIS2_CALL
axis2_svc_client_send_receive_with_op_qname(
    axis2_svc_client_t * svc_client,
    const axutil_env_t * env,
    const axutil_qname_t * op_qname,
    const axiom_node_t * payload)
{
    axiom_soap_envelope_t *soap_envelope = NULL;
    axiom_soap_body_t *soap_body = NULL;
    axiom_node_t *soap_node = NULL;
    axis2_op_t *op = NULL;
    axutil_param_t *param = NULL;
    axutil_uri_t *action_uri = NULL;
    axis2_char_t *action_str = NULL;
    axis2_bool_t qname_free_flag = AXIS2_FALSE;

    axis2_msg_ctx_t *res_msg_ctx = NULL;
    axis2_msg_ctx_t *msg_ctx = NULL;

    AXIS2_PARAM_CHECK(env->error, svc_client, NULL);

    svc_client->last_response_soap_envelope = NULL;
    svc_client->last_response_has_fault = AXIS2_FALSE;
    svc_client->auth_failed = AXIS2_FALSE;
    svc_client->required_auth_is_http = AXIS2_FALSE;
    if(svc_client->auth_type)
    {
        AXIS2_FREE(env->allocator, svc_client->auth_type);
    }
    svc_client->auth_type = NULL;

    op = axis2_svc_get_op_with_qname(svc_client->svc, env, op_qname);
    if(op)
    {
        param = axis2_op_get_param(op, env, AXIS2_SOAP_ACTION);
        if(param)
        {
            action_uri = (axutil_uri_t *)axutil_param_get_value(param, env);
            action_str = axutil_uri_to_string(action_uri, env, AXIS2_URI_UNP_OMITUSERINFO);
            axis2_options_set_action(svc_client->options, env, action_str);
        }
    }

    if(!op_qname)
    {
        op_qname = axutil_qname_create(env, AXIS2_ANON_OUT_IN_OP, NULL, NULL);
        if(!op_qname)
            return NULL;

        qname_free_flag = AXIS2_TRUE;
    }

    /* If dual channel blocking. We come to this block if the client indicate to use
     * a separate listener but don't provide a callback function to acted upon when
     * response is received in the listener thread. What we do here is we create a callback
     * and call axis2_svc_client_send_receive_non_blocking_with_op_qname with it. */
    if(axis2_options_get_use_separate_listener(svc_client->options, env))
    {
        axis2_callback_t *callback = NULL;
        axis2_msg_ctx_t *msg_ctx = NULL;
        long index = 0;

        /* This means doing a Request-Response invocation using two channels.
         If the transport is a two way transport (e.g. http), only one channel is used
         (e.g. in http cases 202 OK is sent to say no response available).
         Axis2 gets blocked and return when the response is available. */

        callback = axis2_callback_create(env);
        if(!callback)
        {
            return NULL;
        }

        /* Call two channel non blocking invoke to do the work and wait on the callback. We don't 
         * set a callback function for the callback. That functionality is handled here. 
         */
        axis2_svc_client_send_receive_non_blocking_with_op_qname(svc_client, env, op_qname,
            payload, callback);

        index = axis2_options_get_timeout_in_milli_seconds(svc_client->options, env) / 10;

        while(!axis2_callback_get_complete(callback, env))
        {
            if(index-- >= 0)
            {
                AXIS2_USLEEP(10000);
            }
            else
            {
                AXIS2_ERROR_SET(env->error, AXIS2_ERROR_RESPONSE_TIMED_OUT, AXIS2_FAILURE);
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Response time out.");
                return NULL;
            }
        }

        soap_envelope = axis2_callback_get_envelope(callback, env);
        msg_ctx = axis2_callback_get_msg_ctx(callback, env);
        axis2_op_client_add_in_msg_ctx(svc_client->op_client, env, msg_ctx);

        /* start of hack to get rid of memory leak */
        /*msg_ctx = axis2_msg_ctx_create(env, axis2_svc_ctx_get_conf_ctx(svc_client-> svc_ctx, env),
            NULL, NULL);
        if(!msg_ctx)
            return NULL;

        axis2_op_client_add_in_msg_ctx(svc_client->op_client, env, msg_ctx);

        axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_envelope);*/
        /* end of hack to get rid of memory leak */

        /* process the result of the invocation */
        if(!soap_envelope)
        {
            if(axis2_callback_get_error(callback, env) != AXIS2_ERROR_NONE)
            {
                AXIS2_ERROR_SET(env->error, axis2_callback_get_error(callback, env), AXIS2_FAILURE);
                return NULL;
            }
        }
    }
    else
    {
        msg_ctx = axis2_msg_ctx_create(env, axis2_svc_ctx_get_conf_ctx(svc_client->svc_ctx, env),
            NULL, NULL);
        if(!msg_ctx)
            return NULL;

        if(!axis2_svc_client_fill_soap_envelope(env, svc_client, msg_ctx, payload))
        {
            return NULL;
        }

        if(!axis2_svc_client_create_op_client(svc_client, env, op_qname))
        {
            return NULL;
        }

        axis2_op_client_add_msg_ctx(svc_client->op_client, env, msg_ctx);
        axis2_op_client_execute(svc_client->op_client, env, AXIS2_TRUE);
        axis2_svc_client_set_http_info(svc_client, env, msg_ctx);
        svc_client->auth_failed = axis2_msg_ctx_get_auth_failed(msg_ctx, env);
        svc_client->required_auth_is_http = axis2_msg_ctx_get_required_auth_is_http(msg_ctx, env);
        if(axis2_msg_ctx_get_auth_type(msg_ctx, env))
        {
            svc_client->auth_type = axutil_strdup(env, axis2_msg_ctx_get_auth_type(msg_ctx, env));
        }
        res_msg_ctx = (axis2_msg_ctx_t *)axis2_op_client_get_msg_ctx(svc_client-> op_client, env,
            AXIS2_WSDL_MESSAGE_LABEL_IN);

        if(res_msg_ctx)
        {
            soap_envelope = axis2_msg_ctx_get_soap_envelope(res_msg_ctx, env);
        }
        else
        {
            axis2_op_client_add_msg_ctx(svc_client->op_client, env, res_msg_ctx);
            /* set in msg_ctx to be NULL to reset */
        }
    }

    if(qname_free_flag)
    {
        axutil_qname_free((axutil_qname_t *)op_qname, env);
    }

    if(!soap_envelope)
    {
        return NULL;
    }
    svc_client->last_response_soap_envelope = soap_envelope;

    soap_body = axiom_soap_envelope_get_body(soap_envelope, env);

    if(!soap_body)
    {
        axiom_node_t *node = axiom_soap_envelope_get_base_node(soap_envelope, env);
        if(node)
        {
            axiom_element_t *envelope_element = (axiom_element_t *)axiom_node_get_data_element(
                node, env);
            axiom_util_get_first_child_element_with_localname(envelope_element, env, node,
                AXIOM_SOAP_BODY_LOCAL_NAME, &soap_node);
            if(soap_node)
            {
                return axiom_node_get_first_element(soap_node, env);
            }
        }
        return NULL;
    }

    if(axis2_msg_ctx_get_doing_rest(res_msg_ctx, env))
    {
        /* All HTTP 4xx and 5xx status codes are treated as errors */
        if(axis2_msg_ctx_get_status_code(res_msg_ctx, env) >= 400)
        {
            svc_client->last_response_has_fault = AXIS2_TRUE;
        }
        else
        {
            svc_client->last_response_has_fault = AXIS2_FALSE;
        }
    }
    else
    {
        svc_client->last_response_has_fault = axiom_soap_body_has_fault(soap_body, env);
    }

    if(AXIOM_SOAP11 == axiom_soap_envelope_get_soap_version(soap_envelope, env))
    {
        axiom_soap_body_convert_fault_to_soap11(soap_body, env);
    }

    soap_node = axiom_soap_body_get_base_node(soap_body, env);
    if(!soap_node)
    {
        return NULL;
    }
    return axiom_node_get_first_element(soap_node, env);
}
        axis2_status_t AXIS2_CALL axis2_stub_on_complete_IIp2Location_get(axis2_callback_t *callback, const axutil_env_t *env)
        {
            axis2_status_t ( AXIS2_CALL *on_complete ) (const axutil_env_t *, adb_getResponse_t* _getResponse, void *data);
            struct axis2_stub_IIp2Location_get_callback_data* callback_data = NULL;
            void *user_data = NULL;
            axis2_status_t status = AXIS2_SUCCESS;
            adb_getResponse_t* ret_val;
            

            axiom_node_t *ret_node = NULL;
            axiom_soap_envelope_t *soap_envelope = NULL;

            

            callback_data = (struct axis2_stub_IIp2Location_get_callback_data*)axis2_callback_get_data(callback);

            
            soap_envelope = axis2_callback_get_envelope(callback, env);
            if(soap_envelope)
            {
                axiom_soap_body_t *soap_body;
                soap_body = axiom_soap_envelope_get_body(soap_envelope, env);
                if(soap_body)
                {
                    axiom_soap_fault_t *soap_fault = NULL;
                    axiom_node_t *body_node = axiom_soap_body_get_base_node(soap_body, env);

                      if(body_node)
                    {
                        ret_node = axiom_node_get_first_child(body_node, env);
                    }
                }
                
                
            }

            user_data = callback_data->data;
            on_complete = callback_data->on_complete;

            
                    if(ret_node != NULL)
                    {
                        ret_val = adb_getResponse_create(env);
     
                        if(adb_getResponse_deserialize(ret_val, env, &ret_node, NULL, AXIS2_FALSE ) == AXIS2_FAILURE)
                        {
                            AXIS2_LOG_ERROR( env->log, AXIS2_LOG_SI, "NULL returnted from the LendResponse_deserialize: "
                                                                    "This should be due to an invalid XML");
                            adb_getResponse_free(ret_val, env);
                            ret_val = NULL;
                        }
                     }
                     else
                     {
                         ret_val = NULL; 
                     }

                     
                         status = on_complete(env, ret_val, user_data);
                         
 
            if(callback_data)
            {
                AXIS2_FREE(env->allocator, callback_data);
            }
            return status;
        }
예제 #8
0
axis2_status_t AXIS2_CALL 
sandesha2_rm_elements_from_soap_envelope(
    sandesha2_rm_elements_t *rm_elements,
    const axutil_env_t *env,
    axiom_soap_envelope_t *soap_envelope,
    axis2_char_t *action)
{
    axiom_soap_header_t *soap_header = NULL;
    axiom_soap_body_t *soap_body = NULL;
    axiom_node_t *header_node = NULL;
    axiom_element_t *body_element = NULL;
    axiom_node_t *body_node = NULL;
    axiom_element_t *header_element = NULL;
    axiom_node_t *seq_node = NULL;
    axiom_element_t *seq_ack_element = NULL;
    axiom_node_t *seq_ack_node = NULL;
    axiom_node_t *create_seq_node = NULL;
    axiom_node_t *create_seq_res_node = NULL;
    axiom_node_t *terminate_seq_node = NULL;
    axiom_node_t *terminate_seq_res_node = NULL;
    axiom_node_t *close_seq_node = NULL;
    axiom_node_t *close_seq_res_node = NULL;
    axiom_node_t *ack_requested_node = NULL;
    axiom_node_t *make_conn_node = NULL;
    axiom_node_t *msg_pending_node = NULL;
    axutil_qname_t *qname = NULL;
    axis2_char_t *rm_ns_val = NULL;
    axis2_char_t *addr_ns_val = NULL;
    
    AXIS2_PARAM_CHECK(env->error, soap_envelope, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, action, AXIS2_FAILURE);
    
    rm_ns_val = sandesha2_rm_elements_get_rm_ns_val(env, soap_envelope, action);
    if(!rm_ns_val)
        return AXIS2_SUCCESS;
    addr_ns_val =  sandesha2_rm_elements_get_addr_ns_val_from_env(env, 
        soap_envelope, action);
    if(!addr_ns_val)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
            "[sandesha2]Cannot find the addressing version");
        return AXIS2_FAILURE;
    }
    soap_header = axiom_soap_envelope_get_header(soap_envelope, env);    
    header_node = axiom_soap_header_get_base_node(soap_header, env);
    header_element = axiom_node_get_data_element(header_node, env);
    
    soap_body = axiom_soap_envelope_get_body(soap_envelope, env);
    body_node = axiom_soap_body_get_base_node(soap_body, env);
    body_element = axiom_node_get_data_element(body_node, env);
                        
    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_SEQ, rm_ns_val, NULL);
    axiom_element_get_first_child_with_qname(header_element, env,
                        qname, header_node, &seq_node);
    if(qname)
        axutil_qname_free(qname, env);
    if(seq_node)
    {
        rm_elements->seq = sandesha2_seq_create(env, rm_ns_val);
        sandesha2_seq_from_om_node(
            rm_elements->seq, env, seq_node);
    }
    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_SEQ_ACK, rm_ns_val, 
                        NULL);
    seq_ack_element = axiom_element_get_first_child_with_qname(header_element,
                        env, qname, header_node, &seq_ack_node);
    if(qname)
        axutil_qname_free(qname, env);
    if(seq_ack_element)
    {
        rm_elements->seq_ack = sandesha2_seq_ack_create(env, rm_ns_val);
        sandesha2_seq_ack_from_om_node(
            rm_elements->seq_ack, env, seq_ack_node);
    }
    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_CREATE_SEQ, rm_ns_val,
                        NULL);
    axiom_element_get_first_child_with_qname(body_element,
                        env, qname, body_node, &create_seq_node);
    if(qname)
        axutil_qname_free(qname, env);
    if(create_seq_node)
    {
        rm_elements->create_seq = sandesha2_create_seq_create(env,
                        addr_ns_val, rm_ns_val);
        sandesha2_create_seq_from_om_node(
            rm_elements->create_seq, env, create_seq_node);
    }
    
    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_CREATE_SEQ_RESPONSE, rm_ns_val, NULL);
    axiom_element_get_first_child_with_qname(body_element, env, qname, 
            body_node, &create_seq_res_node);

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

    if(create_seq_res_node)
    {
        rm_elements->create_seq_res = sandesha2_create_seq_res_create(env, rm_ns_val, addr_ns_val);
        sandesha2_create_seq_res_from_om_node(rm_elements->create_seq_res, env, create_seq_res_node);
    }
    
    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_TERMINATE_SEQ, rm_ns_val, NULL);
    axiom_element_get_first_child_with_qname(body_element, env, qname, 
            body_node, &terminate_seq_node);

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

    if(terminate_seq_node)
    {
        rm_elements->terminate_seq = sandesha2_terminate_seq_create(env, rm_ns_val);
        sandesha2_terminate_seq_from_om_node(rm_elements->terminate_seq, env, terminate_seq_node);
    }

    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_TERMINATE_SEQ_RESPONSE, rm_ns_val, NULL);
    axiom_element_get_first_child_with_qname(body_element, env, qname, 
            body_node, &terminate_seq_res_node);

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

    if(terminate_seq_res_node)
    {
        rm_elements->terminate_seq_res = sandesha2_terminate_seq_res_create(env, rm_ns_val);
        sandesha2_terminate_seq_res_from_om_node(rm_elements->terminate_seq_res, env, 
                terminate_seq_res_node);
    }

    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_CLOSE_SEQ, rm_ns_val, NULL);
    axiom_element_get_first_child_with_qname(body_element, env, qname, 
            body_node, &close_seq_node);

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

    if(close_seq_node)
    {
        rm_elements->close_seq = sandesha2_close_seq_create(env, rm_ns_val);
        sandesha2_close_seq_from_om_node(rm_elements->close_seq, env, close_seq_node);
    }

    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_CLOSE_SEQ_RESPONSE, rm_ns_val, NULL);
    axiom_element_get_first_child_with_qname(body_element, env, qname, 
            body_node, &close_seq_res_node);

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

    if(close_seq_res_node)
    {
        rm_elements->close_seq_res = sandesha2_close_seq_res_create(env, rm_ns_val);
        sandesha2_close_seq_res_from_om_node(rm_elements->close_seq_res, env, close_seq_res_node);
    }

    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_MAKE_CONNECTION, rm_ns_val, NULL);
    axiom_element_get_first_child_with_qname(body_element, env, qname, 
            body_node, &make_conn_node);

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

    if(make_conn_node)
    {
        rm_elements->make_connection = sandesha2_make_connection_create(env, rm_ns_val);
        sandesha2_make_connection_from_om_node(rm_elements->make_connection, env, make_conn_node);
    }

    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_ACK_REQUESTED, rm_ns_val, NULL);
    axiom_element_get_first_child_with_qname(header_element, env, qname, header_node, &ack_requested_node);
    if(qname)
        axutil_qname_free(qname, env);
    if(ack_requested_node)
    {
        rm_elements->ack_requested = sandesha2_ack_requested_create(env, 
            rm_ns_val);
        sandesha2_ack_requested_from_om_node(
            rm_elements->ack_requested, env, ack_requested_node);
    }
    qname = axutil_qname_create(env, SANDESHA2_WSRM_COMMON_MESSAGE_PENDING, 
        rm_ns_val, NULL);
    axiom_element_get_first_child_with_qname(header_element, env, qname, header_node, &msg_pending_node);
    if(qname)
        axutil_qname_free(qname, env);
    if(msg_pending_node)
    {
        rm_elements->msg_pending = sandesha2_msg_pending_create(env, 
                        rm_ns_val);
        sandesha2_msg_pending_from_om_node(
            rm_elements->msg_pending, env, msg_pending_node);
    }
    return AXIS2_SUCCESS;
}
예제 #9
0
/**
 * Create a new create_seq_response message.
 * @param env axis2 environment struct
 * @param create_seq_msg
 * @param out_msg
 * @param new_seq_id
 * @param seq_prop_mgr
 * @return sandesha2_msg_ctx_t
 */
sandesha2_msg_ctx_t *
sandesha2_msg_creator_create_create_seq_res_msg(
    const axutil_env_t *env,
    sandesha2_msg_ctx_t *create_seq_msg,
    axis2_msg_ctx_t *out_msg,
    axis2_char_t *new_seq_id,
    sandesha2_seq_property_mgr_t *seq_prop_mgr)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_msg_ctx_t *temp_msg_ctx = NULL;
    axis2_char_t *rm_version = NULL;
    axis2_char_t *rm_ns_value = NULL;
    axis2_char_t *addressing_ns_value = NULL;
    axis2_char_t *new_msg_id = NULL;
    axis2_char_t *temp_action = NULL;
    axutil_string_t *soap_action = NULL;
    axiom_soap_envelope_t *envelope = NULL;
    axiom_soap_envelope_t *temp_envelope = NULL;
    axiom_soap_body_t *temp_soap_body = NULL;
    axiom_node_t *temp_om_node = NULL;
    sandesha2_create_seq_res_t *create_seq_res = NULL;
    sandesha2_identifier_t *identifier = NULL;
    sandesha2_seq_offer_t *offer = NULL;
    sandesha2_msg_ctx_t *create_seq_res_rm_msg_ctx = NULL;
    sandesha2_create_seq_t *cs = NULL;
    int soap_version = -1;

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

    temp_msg_ctx = sandesha2_msg_ctx_get_msg_ctx(create_seq_msg, env);
    conf_ctx = axis2_msg_ctx_get_conf_ctx(temp_msg_ctx, env);
    cs = sandesha2_msg_ctx_get_create_seq(create_seq_msg, env);
    rm_version = sandesha2_utils_get_rm_version(env, temp_msg_ctx);

    if(!rm_version)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] Cannot find rm version of given message");
        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_CANNOT_FIND_RM_VERSION_OF_GIVEN_MSG, 
                AXIS2_FAILURE);
        return NULL;
    }

    rm_ns_value = sandesha2_spec_specific_consts_get_rm_ns_val(env, rm_version);
    addressing_ns_value = sandesha2_utils_get_seq_property(env, new_seq_id, 
        SANDESHA2_SEQ_PROP_ADDRESSING_NAMESPACE_VALUE, seq_prop_mgr);
    if(!addressing_ns_value)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] Cannot find addressing namespace value");
        return NULL;
    }

    create_seq_res = sandesha2_create_seq_res_create(env, rm_ns_value, addressing_ns_value);
    identifier = sandesha2_identifier_create(env, rm_ns_value);
    sandesha2_identifier_set_identifier(identifier, env, new_seq_id);
    sandesha2_create_seq_res_set_identifier(create_seq_res, env, identifier);
    offer = sandesha2_create_seq_get_seq_offer(cs, env);

    if(offer)
    {
        axis2_char_t *out_seq_id = NULL;
        sandesha2_identifier_t *temp_identifier = NULL;
        
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2] Offer present");

        temp_identifier = sandesha2_seq_offer_get_identifier(offer, env);
        out_seq_id = sandesha2_identifier_get_identifier(temp_identifier, env);
        if(out_seq_id && axutil_strcmp("", out_seq_id))
        {
            sandesha2_accept_t *accept = NULL;
            axis2_endpoint_ref_t *acks_to_epr = NULL;
            sandesha2_acks_to_t *acks_to = NULL;
            sandesha2_address_t *address = NULL;

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

            accept = sandesha2_accept_create(env, rm_ns_value, addressing_ns_value);
            if(accept)
            {
                axis2_endpoint_ref_t *temp_to_epr = NULL;

                acks_to_epr = sandesha2_msg_ctx_get_to(create_seq_msg, env);
                if(acks_to_epr)
                {
                    temp_to_epr = sandesha2_util_endpoint_ref_clone(env, acks_to_epr);
                }

                address = sandesha2_address_create(env, addressing_ns_value, temp_to_epr);
                acks_to = sandesha2_acks_to_create(env, address, rm_ns_value, addressing_ns_value);
                sandesha2_accept_set_acks_to(accept, env, acks_to);
                sandesha2_create_seq_res_set_accept(create_seq_res, env, accept);
            }
            else
            {
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[sandesha2] Could not create accept element");
                return NULL;
            }
        }
    }

    temp_envelope = sandesha2_msg_ctx_get_soap_envelope(create_seq_msg, env); 
    soap_version = sandesha2_utils_get_soap_version(env, temp_envelope);
    envelope = axiom_soap_envelope_create_default_soap_envelope(env, soap_version);
    temp_soap_body = axiom_soap_envelope_get_body(envelope, env);
    temp_om_node = axiom_soap_body_get_base_node(temp_soap_body, env);
    sandesha2_create_seq_res_to_om_node(create_seq_res, env, temp_om_node);
    temp_action = sandesha2_spec_specific_consts_get_create_seq_res_action(env, rm_version);

    axis2_msg_ctx_set_wsa_action(out_msg, env, temp_action);

    soap_action = axutil_string_create(env, temp_action);
    /*if(soap_action)
    {
        axis2_msg_ctx_set_soap_action(out_msg, env, soap_action);
        axutil_string_free(soap_action, env);
    }*/

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

    new_msg_id = axutil_uuid_gen(env);
    if(new_msg_id)
    {
        axis2_msg_ctx_set_message_id(out_msg, env, new_msg_id);
        AXIS2_FREE(env->allocator, new_msg_id);
    }

    axis2_msg_ctx_set_soap_envelope(out_msg, env, envelope);
    temp_msg_ctx = sandesha2_msg_ctx_get_msg_ctx(create_seq_msg, env);
    sandesha2_msg_creator_init_creation(env, temp_msg_ctx, out_msg);
    create_seq_res_rm_msg_ctx = sandesha2_msg_init_init_msg(env, out_msg);
    sandesha2_msg_ctx_set_create_seq_res(create_seq_res_rm_msg_ctx, env, create_seq_res);
    temp_msg_ctx = sandesha2_msg_ctx_get_msg_ctx(create_seq_msg, env);
    sandesha2_msg_creator_finalize_creation(env, temp_msg_ctx, out_msg);
    axis2_msg_ctx_set_server_side(temp_msg_ctx, env, AXIS2_TRUE);

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

    return create_seq_res_rm_msg_ctx;
}
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;
}
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axiom_soap12_builder_helper_handle_event(
    axiom_soap12_builder_helper_t * builder_helper,
    const axutil_env_t * env,
    axiom_node_t * om_ele_node,
    int element_level)
{
    axis2_char_t *ele_localname = NULL;
    axiom_element_t *om_ele = NULL;

    axiom_soap_body_t *soap_body = NULL;
    axiom_soap_fault_t *soap_fault = NULL;
    axiom_soap_envelope_t *soap_envelope = NULL;

    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, om_ele_node, AXIS2_FAILURE);

    om_ele = (axiom_element_t *) axiom_node_get_data_element(om_ele_node, env);
    if (!om_ele)
    {
        return AXIS2_FAILURE;
    }

    ele_localname = axiom_element_get_localname(om_ele, env);
    if (!ele_localname)
    {
        return AXIS2_FAILURE;
    }

    soap_envelope =
        axiom_soap_builder_get_soap_envelope(builder_helper->soap_builder, env);
    if (!soap_envelope)
    {
        return AXIS2_FAILURE;
    }

    soap_body = axiom_soap_envelope_get_body(soap_envelope, env);
    if (!soap_body)
    {
        return AXIS2_FAILURE;
    }

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

    if (element_level == 4)
    {
        if (axutil_strcmp
            (AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME, ele_localname) == 0)
        {
            if (builder_helper->code_present)
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_MULTIPLE_CODE_ELEMENTS_ENCOUNTERED,
                                AXIS2_FAILURE);
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                       "Multiple  fault code elements encountered in SOAP fault");
                return AXIS2_FAILURE;
            }
            else
            {
                axiom_soap_fault_code_t *soap_fault_code = NULL;
                soap_fault_code = axiom_soap_fault_code_create(env);
                if (!soap_fault_code)
                {
                    return AXIS2_FAILURE;
                }
                axiom_soap_fault_code_set_base_node(soap_fault_code, env,
                                                    om_ele_node);

                axiom_soap_fault_code_set_builder(soap_fault_code, env,
                                                  builder_helper->soap_builder);

                axiom_soap_fault_set_code(soap_fault, env, soap_fault_code);

                builder_helper->code_present = AXIS2_TRUE;
                builder_helper->code_processing = AXIS2_TRUE;
            }
        }
        else if (axutil_strcmp
                 (AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME,
                  ele_localname) == 0)
        {
            if (!(builder_helper->code_processing) &&
                !(builder_helper->sub_code_processing))
            {
                if (builder_helper->code_present)
                {
                    if (builder_helper->reason_present)
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_REASON_ELEMENTS_ENCOUNTERED,
                                        AXIS2_FAILURE);
                        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                            "Multiple fault reason elements encountered in SOAP fault");

                        return AXIS2_FAILURE;
                    }
                    else
                    {
                        axiom_soap_fault_reason_t *fault_reason = NULL;
                        fault_reason = axiom_soap_fault_reason_create(env);
                        if (!fault_reason)
                        {
                            return AXIS2_FAILURE;
                        }

                        axiom_soap_fault_reason_set_base_node(fault_reason, env,
                                                              om_ele_node);

                        axiom_soap_fault_set_reason(soap_fault, env,
                                                    fault_reason);

                        axiom_soap_fault_reason_set_builder(fault_reason, env,
                                                            builder_helper->
                                                            soap_builder);

                        builder_helper->reason_present = AXIS2_TRUE;
                        builder_helper->reason_processing = AXIS2_TRUE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
            else
            {
                if (builder_helper->code_processing)
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_SOAP_FAULT_CODE_DOES_NOT_HAVE_A_VALUE,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_SOAP_FAULT_CODE_DOES_NOT_HAVE_A_VALUE,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
        }
        else if (axutil_strcmp
                 (ele_localname, AXIOM_SOAP12_SOAP_FAULT_NODE_LOCAL_NAME) == 0)
        {
            if (!(builder_helper->reason_processing))
            {
                if (builder_helper->reason_present &&
                    !(builder_helper->role_present) &&
                    !(builder_helper->detail_present))
                {
                    if (builder_helper->node_present)
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_NODE_ELEMENTS_ENCOUNTERED,
                                        AXIS2_FAILURE);
                        return AXIS2_FAILURE;
                    }
                    else
                    {
                        axiom_soap_fault_node_t *soap_fault_node = NULL;
                        soap_fault_node = axiom_soap_fault_node_create(env);
                        if (!soap_fault_node)
                        {
                            return AXIS2_FAILURE;
                        }

                        axiom_soap_fault_node_set_base_node(soap_fault_node,
                                                            env, om_ele_node);

                        axiom_soap_fault_set_node(soap_fault, env,
                                                  soap_fault_node);

                        builder_helper->node_present = AXIS2_TRUE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED,
                                    AXIS2_FALSE);

                    return AXIS2_FAILURE;
                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_SOAP_FAULT_REASON_ELEMENT_SHOULD_HAVE_A_TEXT,
                                AXIS2_FALSE);
                return AXIS2_FAILURE;
            }

        }
        else if (axutil_strcmp
                 (ele_localname, AXIOM_SOAP12_SOAP_FAULT_ROLE_LOCAL_NAME) == 0)
        {
            if (!(builder_helper->reason_processing))
            {
                if (builder_helper->reason_present &&
                    !(builder_helper->detail_present))
                {
                    if (builder_helper->role_present)
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_ROLE_ELEMENTS_ENCOUNTERED,
                                        AXIS2_FAILURE);

                        return AXIS2_FAILURE;
                    }
                    else
                    {
                        axiom_soap_fault_role_t *soap_fault_role = NULL;
                        soap_fault_role = axiom_soap_fault_role_create(env);
                        if (!soap_fault_role)
                            return AXIS2_FAILURE;

                        axiom_soap_fault_role_set_base_node(soap_fault_role,
                                                            env, om_ele_node);

                        axiom_soap_fault_set_role(soap_fault, env,
                                                  soap_fault_role);
                        builder_helper->role_present = AXIS2_TRUE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
            else
            {

                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_SOAP_FAULT_ROLE_ELEMENT_SHOULD_HAVE_A_TEXT,
                                AXIS2_FAILURE);
                return AXIS2_FAILURE;
            }
        }
        else if (axutil_strcmp
                 (ele_localname,
                  AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME) == 0)
        {
            if (!(builder_helper->reason_processing))
            {
                if (builder_helper->reason_present)
                {
                    if (builder_helper->detail_present)
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_DETAIL_ELEMENTS_ENCOUNTERED,
                                        AXIS2_FAILURE);
                        return AXIS2_FAILURE;
                    }
                    else
                    {

                        axiom_soap_fault_detail_t *soap_fault_detail = NULL;
                        soap_fault_detail = axiom_soap_fault_detail_create(env);
                        if (!soap_fault_detail)
                            return AXIS2_FAILURE;

                        axiom_soap_fault_detail_set_base_node(soap_fault_detail,
                                                              env, om_ele_node);

                        axiom_soap_fault_set_detail(soap_fault, env,
                                                    soap_fault_detail);
                        builder_helper->detail_present = AXIS2_TRUE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED,
                                    AXIS2_FAILURE);

                    return AXIS2_FAILURE;

                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_SOAP_FAULT_REASON_ELEMENT_SHOULD_HAVE_A_TEXT,
                                AXIS2_FAILURE);
                return AXIS2_FAILURE;
            }

        }
        else
        {
            AXIS2_ERROR_SET(env->error,
                            AXIS2_ERROR_UNSUPPORTED_ELEMENT_IN_SOAP_FAULT_ELEMENT,
                            AXIS2_FAILURE);
            return AXIS2_FAILURE;
        }
    }
    else if (element_level == 5)
    {
        axiom_node_t *parent_node = NULL;
        axiom_element_t *parent_ele = NULL;
        axis2_char_t *parent_localname = NULL;
        parent_node = axiom_node_get_parent(om_ele_node, env);
        if (!parent_node)
        {
            return AXIS2_FAILURE;
        }
        parent_ele =
            (axiom_element_t *) axiom_node_get_data_element(parent_node, env);
        if (!parent_ele)
        {
            return AXIS2_FAILURE;
        }
        parent_localname = axiom_element_get_localname(parent_ele, env);
        if (!parent_localname)
        {
            return AXIS2_FAILURE;
        }

        if (axutil_strcmp(parent_localname,
                          AXIOM_SOAP12_SOAP_FAULT_CODE_LOCAL_NAME) == 0)
        {
            if (axutil_strcmp
                (ele_localname, AXIOM_SOAP12_SOAP_FAULT_VALUE_LOCAL_NAME) == 0)
            {
                if (!(builder_helper->value_present))
                {
                    axiom_soap_fault_value_t *soap_fault_value = NULL;
                    axiom_soap_fault_code_t *parent_fcode = NULL;

                    soap_fault_value = axiom_soap_fault_value_create(env);
                    if (!soap_fault_value)
                    {
                        return AXIS2_FAILURE;
                    }
                    axiom_soap_fault_value_set_base_node(soap_fault_value, env,
                                                         om_ele_node);

                    parent_fcode = axiom_soap_fault_get_code(soap_fault, env);
                    if (!parent_fcode)
                    {
                        return AXIS2_FAILURE;
                    }
                    axiom_soap_fault_code_set_value(parent_fcode, env,
                                                    soap_fault_value);

                    builder_helper->value_present = AXIS2_TRUE;
                    builder_helper->code_processing = AXIS2_FALSE;

                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_MULTIPLE_VALUE_ENCOUNTERED_IN_CODE_ELEMENT,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
            else if (axutil_strcmp(ele_localname,
                                   AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME)
                     == 0)
            {
                if (!(builder_helper->sub_code_present))
                {
                    if (builder_helper->value_present)
                    {

                        axiom_soap_fault_sub_code_t *fault_subcode = NULL;
                        axiom_soap_fault_code_t *fault_code = NULL;

                        fault_subcode = axiom_soap_fault_sub_code_create(env);
                        if (!fault_subcode)
                        {
                            return AXIS2_FAILURE;
                        }
                        axiom_soap_fault_sub_code_set_base_node(fault_subcode,
                                                                env,
                                                                om_ele_node);

                        fault_code = axiom_soap_fault_get_code(soap_fault, env);
                        if (!fault_code)
                        {
                            return AXIS2_FAILURE;
                        }
                        axiom_soap_fault_code_set_sub_code(fault_code, env,
                                                           fault_subcode);

                        axiom_soap_fault_sub_code_set_builder(fault_subcode,
                                                              env,
                                                              builder_helper->
                                                              soap_builder);

                        builder_helper->sub_code_present = AXIS2_TRUE;
                        builder_helper->sub_code_processing = AXIS2_TRUE;
                    }
                    else
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_SOAP_FAULT_VALUE_SHOULD_BE_PRESENT_BEFORE_SUB_CODE,
                                        AXIS2_FAILURE);
                        return AXIS2_FAILURE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_THIS_LOCALNAME_NOT_SUPPORTED_INSIDE_THE_CODE_ELEMENT,
                                AXIS2_FAILURE);
                return AXIS2_FAILURE;
            }
        }
        else if (axutil_strcmp
                 (parent_localname,
                  AXIOM_SOAP12_SOAP_FAULT_REASON_LOCAL_NAME) == 0)
        {
            if (axutil_strcmp
                (ele_localname, AXIOM_SOAP12_SOAP_FAULT_TEXT_LOCAL_NAME) == 0)
            {
                axiom_soap_fault_text_t *soap_fault_text = NULL;
                axiom_soap_fault_reason_t *fault_reason = NULL;

                soap_fault_text = axiom_soap_fault_text_create(env);
                if (!soap_fault_text)
                {
                    return AXIS2_FAILURE;
                }
                axiom_soap_fault_text_set_base_node(soap_fault_text, env,
                                                    om_ele_node);

                fault_reason = axiom_soap_fault_get_reason(soap_fault, env);
                if (!fault_reason)
                {
                    return AXIS2_FAILURE;
                }

                axiom_soap_fault_reason_add_soap_fault_text(fault_reason, env,
                                                            soap_fault_text);
                builder_helper->reason_processing = AXIS2_FALSE;

                axiom_soap_builder_set_bool_processing_mandatory_fault_elements
                    (builder_helper->soap_builder, env, AXIS2_FALSE);

            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_REASON_ELEMENT,
                                AXIS2_FAILURE);
                return AXIS2_FAILURE;
            }

        }
        else if (axutil_strcmp
                 (parent_localname,
                  AXIOM_SOAP12_SOAP_FAULT_DETAIL_LOCAL_NAME) == 0)
        {
            axiom_soap_builder_set_processing_detail_elements(builder_helper->
                                                              soap_builder, env,
                                                              AXIS2_TRUE);

            if (!(builder_helper->detail_element_names))
            {
                builder_helper->detail_element_names =
                    axutil_array_list_create(env, 20);
            }

            axutil_array_list_add(builder_helper->detail_element_names, env,
                                  ele_localname);

        }
        else
        {

            return AXIS2_FAILURE;
        }

    }
    else if (element_level > 5)
    {
        axiom_node_t *parent_node = NULL;
        axiom_element_t *parent_ele = NULL;
        axis2_char_t *parent_localname = NULL;

        parent_node = axiom_node_get_parent(om_ele_node, env);
        if (!parent_node)
        {
            return AXIS2_FAILURE;
        }
        parent_ele =
            (axiom_element_t *) axiom_node_get_data_element(parent_node, env);
        if (!parent_ele)
        {
            return AXIS2_FAILURE;
        }

        parent_localname = axiom_element_get_localname(parent_ele, env);
        if (!parent_localname)
        {
            return AXIS2_FAILURE;
        }
        if (axutil_strcmp
            (parent_localname,
             AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME) == 0)
        {
            if (axutil_strcmp
                (ele_localname, AXIOM_SOAP12_SOAP_FAULT_VALUE_LOCAL_NAME) == 0)
            {
                if (builder_helper->subcode_value_present)
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED,
                                    AXIS2_FAILURE);
                    return AXIS2_FAILURE;
                }
                else
                {

                    axiom_soap_fault_sub_code_t *sub_code = NULL;
                    axiom_soap_fault_code_t *code = NULL;
                    axiom_soap_fault_value_t *value = NULL;
                    code = axiom_soap_fault_get_code(soap_fault, env);

                    if (!code)
                    {
                        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                                        "fault code null when it should not be null");
                        return AXIS2_FAILURE;
                    }

                    sub_code = axiom_soap_fault_code_get_sub_code(code, env);
                    if (!sub_code)
                    {
                        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                                        "fault subcode null when it should not be null");
                        return AXIS2_FAILURE;
                    }
                    value = axiom_soap_fault_value_create(env);
                    if (!value)
                    {
                        return AXIS2_FAILURE;
                    }

                    axiom_soap_fault_value_set_base_node(value, env,
                                                         om_ele_node);

                    axiom_soap_fault_sub_code_set_value(sub_code, env, value);

                    builder_helper->subcode_value_present = AXIS2_TRUE;
                    builder_helper->sub_sub_code_present = AXIS2_FALSE;
                    builder_helper->sub_code_processing = AXIS2_FALSE;
                }
            }
            else if (axutil_strcmp
                     (ele_localname,
                      AXIOM_SOAP12_SOAP_FAULT_SUB_CODE_LOCAL_NAME) == 0)
            {
                if (builder_helper->subcode_value_present)
                {
                    if (!(builder_helper->sub_sub_code_present))
                    {
                        axiom_soap_fault_code_t *fault_code = NULL;
                        axiom_soap_fault_sub_code_t *parent_subcode = NULL;
                        axiom_soap_fault_sub_code_t *subcode = NULL;

                        subcode = axiom_soap_fault_sub_code_create(env);
                        if (!subcode)
                        {
                            return AXIS2_FAILURE;
                        }

                        axiom_soap_fault_sub_code_set_base_node(subcode, env,
                                                                om_ele_node);

                        fault_code = axiom_soap_fault_get_code(soap_fault, env);
                        if (!fault_code)
                        {
                            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                                            "fault code null when it should not be null");
                            return AXIS2_FAILURE;
                        }
                        parent_subcode =
                            axiom_soap_fault_code_get_sub_code(fault_code, env);
                        if (!parent_subcode)
                        {
                            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
                                            "fault subcode null when it should not be null");
                            return AXIS2_FAILURE;
                        }

                        axiom_soap_fault_sub_code_set_sub_code(parent_subcode,
                                                               env, subcode);

                        builder_helper->subcode_value_present = AXIS2_FALSE;
                        builder_helper->sub_sub_code_present = AXIS2_TRUE;
                        builder_helper->sub_code_processing = AXIS2_TRUE;
                    }
                    else
                    {
                        AXIS2_ERROR_SET(env->error,
                                        AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED,
                                        AXIS2_FAILURE);

                        return AXIS2_FAILURE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error,
                                    AXIS2_ERROR_SOAP_FAULT_VALUE_SHOULD_BE_PRESENT_BEFORE_SUB_CODE,
                                    AXIS2_FAILURE);

                    return AXIS2_FAILURE;

                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error,
                                AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_SUB_CODE_ELEMENT,
                                AXIS2_FAILURE);

                return AXIS2_FAILURE;
            }
        }
        else if (axiom_soap_builder_is_processing_detail_elements
                 (builder_helper->soap_builder, env))
        {

            int detail_element_level = 0;
            axis2_bool_t local_name_exists = AXIS2_FALSE;
            int i = 0;
            if (!(builder_helper->detail_element_names))
            {
                return AXIS2_FAILURE;
            }

            for (i = 0;
                 i <
                 axutil_array_list_size(builder_helper->detail_element_names,
                                        env); i++)
            {
                if (axutil_strcmp
                    (parent_localname,
                     axutil_array_list_get(builder_helper->detail_element_names,
                                           env, i)) == 0)
                {
                    local_name_exists = AXIS2_TRUE;
                    detail_element_level = i + 1;
                }
            }
            if (local_name_exists)
            {
                axutil_array_list_add(builder_helper->detail_element_names, env,
                                      ele_localname);
            }
            else
            {
                return AXIS2_FAILURE;
            }
        }
    }
    return AXIS2_SUCCESS;
}
예제 #12
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;
    /*axutil_property_t *property  = NULL;
     int i = 0;*/

    /* Set up the environment */
    env = axutil_env_create_all("echo.log", AXIS2_LOG_LEVEL_TRACE);

    /*if (argc == 4)
     AXIS2_SLEEP(10); */

    /* 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,
     "http://xmlsoap.org/Ping");*/
    /*axis2_options_set_action(options, env,
     "urn:echoString");*/

    /*axis2_options_set_soap_action(options, env, axutil_string_create(env, "http://xmlsoap.org/Ping"));
     axis2_options_set_soap_version(options, env, AXIOM_SOAP11);*/
    axis2_options_set_soap_version(options, env, AXIOM_SOAP12);

    /*If the client home is not specified, use the WSFC_HOME*/
    if(!client_home)
    {
        client_home = AXIS2_GETENV("WSFC_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;
    }

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

    /* 
     property = axutil_property_create(env);
     axutil_property_set_scope(property, env, AXIS2_SCOPE_APPLICATION);
     axutil_property_set_value(property, env, AXIS2_WSA_NAMESPACE_SUBMISSION);
     axis2_options_set_property(options, env, AXIS2_WSA_VERSION, property);
     */

    /*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_file)
    {
        AXIS2_FREE(env->allocator, policy_file);
        policy_file = NULL;
    }
    if(!policy)
    {
        printf("\nPolicy creation failed from the file. %s\n", policy_file);
    }

    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);
    /*axis2_options_set_enable_mtom(options, env, AXIS2_TRUE);*/

    /*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;
}
예제 #13
0
axis2_status_t AXIS2_CALL
axis2_addr_out_handler_invoke(
    struct axis2_handler * handler,
    const axutil_env_t * env,
    axis2_msg_ctx_t * msg_ctx)
{
    axis2_char_t *addr_ver_from_msg_ctx = NULL;
    const axis2_char_t *addr_ns = NULL;
    axis2_msg_info_headers_t *msg_info_headers = NULL;
    axis2_ctx_t *ctx = NULL;
    axiom_soap_envelope_t *soap_envelope = NULL;
    axiom_soap_header_t *soap_header = NULL;
    axiom_node_t *soap_header_node = NULL;
    axiom_element_t *soap_header_ele = NULL;
    axis2_endpoint_ref_t *epr_to = NULL;
    axis2_endpoint_ref_t *epr_reply_to = NULL;
    axis2_endpoint_ref_t *epr_from = NULL;
    axis2_endpoint_ref_t *epr_fault_to = NULL;
    axutil_property_t *property = NULL;
    const axis2_char_t *wsa_action = NULL;
	axis2_bool_t set_must_understand = AXIS2_FALSE;
	axutil_property_t *must_understand_prop;

    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);

    AXIS2_LOG_INFO(env->log, "Starting addressing out handler");

    soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
    if(!soap_envelope)
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No SOAP envelope. Stop processing addressing");
        return AXIS2_SUCCESS; /* Can happen in case of ONE-WAY services/clients */
    }

    msg_info_headers = axis2_msg_ctx_get_msg_info_headers(msg_ctx, env);

    if(msg_info_headers)
    {
        wsa_action = axis2_msg_info_headers_get_action(msg_info_headers, env);
    }
    else
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No addressing in use");
        return AXIS2_SUCCESS; /* No addressing in use */
    }

    if(!wsa_action || !*wsa_action)
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No action present. Stop processing addressing");
        return AXIS2_SUCCESS; /* If no action present, assume no addressing in use */
    }


    ctx = axis2_msg_ctx_get_base(msg_ctx, env);
    property = axis2_ctx_get_property(ctx, env, AXIS2_WSA_VERSION);

    if(property)
    {
        addr_ver_from_msg_ctx = axutil_property_get_value(property, env);
        property = NULL;
    }

	must_understand_prop = axis2_msg_ctx_get_property(msg_ctx, env, AXIS2_ADDR_ADD_MUST_UNDERSTAND_TO_ADDR_HEADERS);
	if(must_understand_prop)
	{
		axis2_char_t *value = axutil_property_get_value(must_understand_prop, env);
		if(axutil_strcmp(value, AXIS2_VALUE_TRUE) == 0)
			set_must_understand = AXIS2_TRUE;
	}

    /* Setting version 1.0 as the default addressing namespace */
    addr_ns = AXIS2_WSA_NAMESPACE;

    if(addr_ver_from_msg_ctx)
    {
        if(!axutil_strcmp(AXIS2_WSA_NAMESPACE_SUBMISSION, addr_ver_from_msg_ctx))
        {
            addr_ns = AXIS2_WSA_NAMESPACE_SUBMISSION;
        }
    }
    else if(axis2_msg_ctx_get_op_ctx(msg_ctx, env))
    {
        axis2_op_ctx_t *op_ctx = NULL;
        axis2_msg_ctx_t *in_msg_ctx = NULL;
        op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);

        if(op_ctx)
        {
            in_msg_ctx = axis2_op_ctx_get_msg_ctx(op_ctx, env, AXIS2_WSDL_MESSAGE_LABEL_IN);
        }

        if(in_msg_ctx)
        {
            axis2_ctx_t *in_ctx = NULL;
            in_ctx = axis2_msg_ctx_get_base(in_msg_ctx, env);

            property = axis2_ctx_get_property(in_ctx, env, AXIS2_WSA_VERSION);
            if(property)
            {
                addr_ns = axutil_property_get_value(property, env);
                property = NULL;
            }

            if(!addr_ns || !*addr_ns)
            {
                addr_ns = AXIS2_WSA_NAMESPACE;
            }
        }
    }

    soap_header = axiom_soap_envelope_get_header(soap_envelope, env);
    if(!soap_header)
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No SOAP header. Stop processing addressing");
        return AXIS2_SUCCESS; /* No SOAP header, so no point proceeding */
    }
    else
    {
        /* By this time, we definitely have some addressing information to be sent. This is because,
         * we have tested at the start of this whether msg_info_headers are null or not.
         * So rather than declaring addressing namespace in each and every addressing header, lets
         * define that in the Header itself.
         */
        const axis2_char_t *action = NULL;
        const axis2_char_t *address = NULL;
        const axis2_char_t *svc_group_context_id = NULL;
        const axis2_char_t *message_id = NULL;
        axis2_relates_to_t *relates_to = NULL;
        axiom_node_t *relates_to_header_node = NULL;
        axiom_element_t *relates_to_header_ele = NULL;
        axiom_namespace_t *addressing_namespace = NULL;

        soap_header_node = axiom_soap_header_get_base_node(soap_header, env);
        soap_header_ele = (axiom_element_t *)axiom_node_get_data_element(soap_header_node, env);

        addressing_namespace = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);

        axiom_element_declare_namespace(soap_header_ele, env, soap_header_node,
            addressing_namespace);

        epr_to = axis2_msg_info_headers_get_to(msg_info_headers, env);

        if(epr_to)
        {
            axiom_soap_body_t *body = axiom_soap_envelope_get_body(soap_envelope, env);

            if(body)
            {
                /* In case of a SOAP fault, we got to send the response to
                 the adress specified by FaultTo */
                if(axiom_soap_body_has_fault(body, env))
                {
                    axis2_endpoint_ref_t *epr_fault_to = axis2_msg_info_headers_get_fault_to(
                        msg_info_headers, env);
                    if(epr_fault_to)
                    {
                        const axis2_char_t *fault_to_address = axis2_endpoint_ref_get_address(
                            epr_fault_to, env);
                        if(fault_to_address)
                        {
                            if(axutil_strcmp(AXIS2_WSA_NONE_URL, fault_to_address)
                                && axutil_strcmp(AXIS2_WSA_NONE_URL_SUBMISSION, fault_to_address))
                            {
                                axis2_endpoint_ref_set_address(epr_to, env, fault_to_address);
                            }
                        }
                    }
                }
            }

            address = axis2_endpoint_ref_get_address(epr_to, env);
            if(address && *address)
            {
                axiom_node_t *to_header_block_node = NULL;
                axiom_soap_header_block_t *to_header_block = NULL;
                axutil_array_list_t *ref_param_list = NULL;
                int size = 0;

                to_header_block = axiom_soap_header_add_header_block(soap_header, env,
                    AXIS2_WSA_TO, addressing_namespace);
				if(set_must_understand == AXIS2_TRUE)
				{
					axiom_soap_header_block_set_must_understand_with_bool(to_header_block, env, AXIS2_TRUE);
				}
				to_header_block_node = axiom_soap_header_block_get_base_node(to_header_block, env);
                if(to_header_block_node)
                {
                    axiom_element_t *to_header_block_element = NULL;
                    to_header_block_element = (axiom_element_t *)axiom_node_get_data_element(
                        to_header_block_node, env);
                    if(to_header_block_element)
                    {
                        axiom_element_set_text(to_header_block_element, env, address,
                            to_header_block_node);
                    }
                }

                ref_param_list = axis2_endpoint_ref_get_ref_param_list(epr_to, env);

                size = axutil_array_list_size(ref_param_list, env);
                if(ref_param_list && size > 0)
                {
                    axiom_soap_header_block_t *reference_header_block = NULL;
                    axiom_node_t *reference_node = NULL;
                    int i = 0;

                    for(i = 0; i < size; i++)
                    {
                        axiom_node_t *temp_node = NULL;

                        temp_node = (axiom_node_t *)axutil_array_list_get(ref_param_list, env, i);
                        if(temp_node)
                        {
                            axiom_element_t *temp_ele = NULL;

                            temp_ele = axiom_node_get_data_element(temp_node, env);
                            if(temp_ele)
                            {
                                reference_header_block = axiom_soap_header_add_header_block(
                                    soap_header, env, axiom_element_get_localname(temp_ele, env),
                                    axiom_element_get_namespace(temp_ele, env, temp_node));
								if(set_must_understand)
								{
									axiom_soap_header_block_set_must_understand_with_bool(reference_header_block, env, AXIS2_TRUE);
								}

                                reference_node = axiom_soap_header_block_get_base_node(
                                    reference_header_block, env);
                                if(reference_node)
                                {
                                    axiom_element_t *reference_ele = NULL;
                                    reference_ele = (axiom_element_t *)axiom_node_get_data_element(
                                        reference_node, env);

                                    if(reference_ele)
                                    {
                                        axiom_namespace_t *addr_ns_obj = NULL;
                                        axiom_attribute_t *reference_attr = NULL;

                                        addr_ns_obj = axiom_namespace_create(env, addr_ns,
                                            AXIS2_WSA_DEFAULT_PREFIX);
                                        reference_attr = axiom_attribute_create(env,
                                        /*"isReferenceParameter"*/
                                        AXIS2_WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE, "true",
                                            addr_ns_obj);
                                        axiom_element_add_attribute(reference_ele, env,
                                            reference_attr, reference_node);
                                        axiom_element_set_text(reference_ele, env,
                                            axiom_element_get_text(temp_ele, env, temp_node),
                                            reference_node);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }/* if(epr_to) */

		axiom_namespace_free(addressing_namespace, env);

        action = axis2_msg_info_headers_get_action(msg_info_headers, env);
        if(action && *action)
        {
            axis2_addr_out_handler_process_string_info(env, action, AXIS2_WSA_ACTION, &soap_header,
				addr_ns, set_must_understand);
        }

        epr_reply_to = axis2_msg_info_headers_get_reply_to(msg_info_headers, env);
        if(!epr_reply_to)
        {
            const axis2_char_t *anonymous_uri = NULL;
            axis2_bool_t anonymous = axis2_msg_info_headers_get_reply_to_anonymous(
                msg_info_headers, env);
            axis2_bool_t none = axis2_msg_info_headers_get_reply_to_none(msg_info_headers, env);
            if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION))
            {
                if(none)
                {
                    anonymous_uri = AXIS2_WSA_NONE_URL_SUBMISSION;
                }
                else if(anonymous)
                {
                    anonymous_uri = AXIS2_WSA_ANONYMOUS_URL_SUBMISSION;
                }
            }
            else
            {
                if(none)
                {
                    anonymous_uri = AXIS2_WSA_NONE_URL;
                }
                else if(anonymous)
                {
                    anonymous_uri = AXIS2_WSA_ANONYMOUS_URL;
                }
            }

            if(anonymous_uri)
            {
                epr_reply_to = axis2_endpoint_ref_create(env, anonymous_uri);
            }

            if(epr_reply_to)
            {
                axis2_msg_info_headers_set_reply_to(msg_info_headers, env, epr_reply_to);
            }
        }

        /* add the service group id as a reference parameter */
        svc_group_context_id = axutil_string_get_buffer(axis2_msg_ctx_get_svc_grp_ctx_id(msg_ctx,
            env), env);

        axis2_addr_out_handler_add_to_soap_header(env, epr_reply_to, AXIS2_WSA_REPLY_TO,
            soap_header, addr_ns);

        epr_from = axis2_msg_info_headers_get_from(msg_info_headers, env);

        if(epr_from)
        {
            axis2_addr_out_handler_add_to_soap_header(env, epr_from, AXIS2_WSA_FROM, soap_header,
                addr_ns);

        }

        epr_fault_to = axis2_msg_info_headers_get_fault_to(msg_info_headers, env);
        if(!epr_fault_to)
        {
            const axis2_char_t *anonymous_uri = NULL;
            axis2_bool_t anonymous = axis2_msg_info_headers_get_fault_to_anonymous(
                msg_info_headers, env);
            axis2_bool_t none = axis2_msg_info_headers_get_fault_to_none(msg_info_headers, env);
            if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION))
            {
                if(none)
                {
                    anonymous_uri = AXIS2_WSA_NONE_URL_SUBMISSION;
                }
                else if(anonymous)
                {
                    anonymous_uri = AXIS2_WSA_ANONYMOUS_URL_SUBMISSION;
                }
            }
            else
            {
                if(none)
                    anonymous_uri = AXIS2_WSA_NONE_URL;
                else if(anonymous)
                    anonymous_uri = AXIS2_WSA_ANONYMOUS_URL;
            }

            if(anonymous_uri)
            {
                epr_fault_to = axis2_endpoint_ref_create(env, anonymous_uri);
            }
        }

        if(epr_fault_to)
        {
            /* optional */
            axis2_addr_out_handler_add_to_soap_header(env, epr_fault_to, AXIS2_WSA_FAULT_TO,
                soap_header, addr_ns);
        }

        message_id = axis2_msg_info_headers_get_message_id(msg_info_headers, env);

        if(message_id)
        {
            axis2_addr_out_handler_process_string_info(env, message_id, AXIS2_WSA_MESSAGE_ID,
				&soap_header, addr_ns, set_must_understand);
        }

        relates_to = axis2_msg_info_headers_get_relates_to(msg_info_headers, env);

        if(relates_to)
        {
            const axis2_char_t *value = NULL;
            value = axis2_relates_to_get_value(relates_to, env);
            relates_to_header_node = axis2_addr_out_handler_process_string_info(env, value,
				AXIS2_WSA_RELATES_TO, &soap_header, addr_ns, set_must_understand);
        }

        if(relates_to_header_node)
        {
            const axis2_char_t *relationship_type = NULL;
            relationship_type = axis2_relates_to_get_relationship_type(relates_to, env);
            if(relationship_type && *relationship_type)
            {
                axiom_attribute_t *om_attr = NULL;
                axiom_namespace_t *addr_ns_obj = NULL;
                axiom_namespace_t *dec_ns = NULL;
                relates_to_header_ele = (axiom_element_t *)axiom_node_get_data_element(
                    relates_to_header_node, env);
                if(relates_to_header_ele)
                {
                    dec_ns = axiom_element_find_declared_namespace(relates_to_header_ele, env,
                        addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
                    if(dec_ns)
                    {
                        addr_ns_obj = dec_ns;
                    }
                    else
                    {
                        addr_ns_obj
                            = axiom_namespace_create(env, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
                    }

                    if(!axutil_strcmp(addr_ns, AXIS2_WSA_NAMESPACE_SUBMISSION))
                    {
                        om_attr = axiom_attribute_create(env,
                            AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE,
                            AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE_SUBMISSION,
                            addr_ns_obj);
                    }
                    else
                    {
                        om_attr = axiom_attribute_create(env,
                            AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE,
                            AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE, addr_ns_obj);
                    }

                    axiom_element_add_attribute(relates_to_header_ele, env, om_attr,
                        relates_to_header_node);

                    dec_ns = axiom_element_find_declared_namespace(relates_to_header_ele, env,
                        addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
                    if(!dec_ns)
                    {
                        dec_ns = axiom_element_find_namespace(relates_to_header_ele, env,
                            relates_to_header_node, addr_ns, AXIS2_WSA_DEFAULT_PREFIX);
                        if(dec_ns)
                        {
                            axiom_namespace_free(addr_ns_obj, env);
                            addr_ns_obj = NULL;
                            axiom_attribute_set_namespace(om_attr, env, dec_ns);
                        }
                    }
                }

            }
        }
    }
    return AXIS2_SUCCESS;
}
예제 #14
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;
}
static axis2_status_t AXIS2_CALL
axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync(
    axis2_msg_recv_t * msg_recv,
    const axutil_env_t * env,
    axis2_msg_ctx_t * msg_ctx,
    axis2_msg_ctx_t * new_msg_ctx)
{
    axis2_svc_skeleton_t *svc_obj = NULL;
    axis2_op_ctx_t *op_ctx = NULL;
    axis2_op_t *op_desc = NULL;
    const axis2_char_t *style = NULL;
    axiom_node_t *om_node = NULL;
    axiom_element_t *om_element = NULL;
    axis2_char_t *local_name = NULL;
    axiom_node_t *result_node = NULL;
    axiom_node_t *body_content_node = NULL;
    axiom_element_t *body_content_element = NULL;
    axiom_soap_envelope_t *default_envelope = NULL;
    axiom_soap_body_t *out_body = NULL;
    axiom_soap_header_t *out_header = NULL;
    axiom_soap_fault_t *soap_fault = NULL;
    axiom_node_t *out_node = NULL;
    axis2_status_t status = AXIS2_SUCCESS;
    axis2_bool_t skel_invoked = AXIS2_FALSE;
    const axis2_char_t *soap_ns = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI;
    int soap_version = AXIOM_SOAP12;
    axiom_namespace_t *env_ns = NULL;
    axiom_node_t *fault_node = NULL;
    axiom_soap_fault_detail_t *fault_detail;
    axis2_bool_t is_fault = AXIS2_FALSE;

    AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, new_msg_ctx, AXIS2_FAILURE);

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
        "[axis2]Entry:axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync");

    /* get the implementation class for the Web Service */
    svc_obj = axis2_msg_recv_make_new_svc_obj(msg_recv, env, msg_ctx);

    if(!svc_obj)
    {
        const axis2_char_t *svc_name = NULL;
        axis2_svc_t *svc = axis2_msg_ctx_get_svc(msg_ctx, env);

        if(svc)
        {
            svc_name = axis2_svc_get_name(svc, env);
        }
        else
        {
            svc_name = "unknown";
        }

        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Impl object for service '%s' not set in message receiver. %d :: %s", svc_name,
            env->error->error_number, AXIS2_ERROR_GET_MESSAGE(env->error));

        status = AXIS2_FAILURE;
    }
    else
    {
        op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
        op_desc = axis2_op_ctx_get_op(op_ctx, env);

        style = axis2_op_get_style(op_desc, env);
        if(0 == axutil_strcmp(AXIS2_STYLE_DOC, style))
        {
            axiom_soap_envelope_t *envelope = NULL;
            axiom_soap_body_t *body = NULL;

            envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
            body = axiom_soap_envelope_get_body(envelope, env);
            om_node = axiom_soap_body_get_base_node(body, env);
            om_element = axiom_node_get_data_element(om_node, env);
            om_node = axiom_node_get_first_element(om_node, env);
        }
        else if(0 == axutil_strcmp(AXIS2_STYLE_RPC, style))
        {
            axiom_soap_envelope_t *envelope = NULL;
            axiom_soap_body_t *body = NULL;
            axiom_node_t *op_node = NULL;
            axiom_element_t *op_element = NULL;

            envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
            body = axiom_soap_envelope_get_body(envelope, env);
            op_node = axiom_soap_body_get_base_node(body, env);
            op_element = axiom_node_get_data_element(op_node, env);
            if(op_element)
            {
                local_name = axiom_element_get_localname(op_element, env);
                if(local_name)
                {
                    axutil_array_list_t *function_arr = NULL;
                    int i = 0;
                    int size = 0;
                    axis2_bool_t matches = AXIS2_FALSE;

                    function_arr = svc_obj->func_array;
                    if(function_arr)
                    {
                        size = axutil_array_list_size(function_arr, env);
                    }

                    for(i = 0; i < size; i++)
                    {
                        axis2_char_t *function_name = NULL;

                        function_name = (axis2_char_t *)axutil_array_list_get(function_arr, env, i);
                        if(!axutil_strcmp(function_name, local_name))
                        {
                            matches = AXIS2_TRUE;

                        }
                    }

                    if(matches)
                    {
                        om_node = axiom_node_get_first_child(op_node, env);
                        om_element = axiom_node_get_data_element(om_node, env);
                    }
                    else
                    {
                        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OM_ELEMENT_MISMATCH, AXIS2_FAILURE);
                        status = AXIS2_FAILURE;
                    }
                }
                else
                {
                    AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OM_ELEMENT_INVALID_STATE, AXIS2_FAILURE);
                    status = AXIS2_FAILURE;
                }
            }
            else
            {
                AXIS2_ERROR_SET(env->error, AXIS2_ERROR_RPC_NEED_MATCHING_CHILD, AXIS2_FAILURE);
                status = AXIS2_FAILURE;
            }
        }
        else
        {
            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_UNKNOWN_STYLE, AXIS2_FAILURE);
            status = AXIS2_FAILURE;
        }

        if(status == AXIS2_SUCCESS)
        {
            skel_invoked = AXIS2_TRUE;
            result_node = AXIS2_SVC_SKELETON_INVOKE(svc_obj, env, om_node, new_msg_ctx);
        }

        if(result_node)
        {
            if(0 == axutil_strcmp(style, AXIS2_STYLE_RPC))
            {
                axiom_namespace_t *ns = NULL;
                axis2_char_t *res_name = NULL;

                res_name = axutil_stracat(env, local_name, "Response");
                ns = axiom_namespace_create(env, "http://soapenc/", "res");
                if(!ns)
                {
                    status = AXIS2_FAILURE;
                }
                else
                {
                    body_content_element = axiom_element_create(env, NULL, res_name, ns,
                        &body_content_node);
                    axiom_node_add_child(body_content_node, env, result_node);
                }
            }
            else
            {
                body_content_node = result_node;
            }
        }
        else
        {
            axis2_char_t *mep = (axis2_char_t *)axis2_op_get_msg_exchange_pattern(op_desc, env);
            if(axutil_strcmp(mep, AXIS2_MEP_URI_IN_ONLY) && axutil_strcmp(mep,
				AXIS2_MEP_URI_ROBUST_IN_ONLY) && axutil_strcmp(mep, AXIS2_MEP_URI_IN_ONLY_WSDL2) &&						axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY_WSDL2))
            {
                status = AXIS2_ERROR_GET_STATUS_CODE(env->error);
                if(status == AXIS2_SUCCESS)
                {
                    axis2_msg_ctx_set_no_content(new_msg_ctx, env, AXIS2_TRUE);
                }
                else
                {
                    axis2_msg_ctx_set_status_code(msg_ctx, env, axis2_msg_ctx_get_status_code(
                        new_msg_ctx, env));
                }
                /* The new_msg_ctx is passed to the service. The status code must
                 * be taken from here and set to the old message context which is
                 * used by the worker when the request processing fails.
                 */
                if(svc_obj->ops->on_fault)
                {
                    fault_node = AXIS2_SVC_SKELETON_ON_FAULT(svc_obj, env, om_node);
                }
                is_fault = AXIS2_TRUE;
            }
            else
            {
                /* If we have a in only message result node is NULL. We create fault only if
                 * an error is set
                 */
                status = AXIS2_ERROR_GET_STATUS_CODE(env->error);
                if(status == AXIS2_SUCCESS)
                {
                    axis2_msg_ctx_set_no_content(new_msg_ctx, env, AXIS2_TRUE);
                }
                else
                {
                    axis2_msg_ctx_set_status_code(msg_ctx, env, axis2_msg_ctx_get_status_code(
                        new_msg_ctx, env));
					if((!axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY)) || 
						(!axutil_strcmp(mep, AXIS2_MEP_URI_ROBUST_IN_ONLY_WSDL2)))
                    {
                        /* The new_msg_ctx is passed to the service. The status code must
                         * be taken from here and set to the old message context which is
                         * used by the worker when the request processing fails.
                         */
                        if(svc_obj->ops->on_fault)
                        {
                            fault_node = AXIS2_SVC_SKELETON_ON_FAULT(svc_obj, env, om_node);
                        }
                        is_fault = AXIS2_TRUE;
                    }
                }
            }
        }
    }

    if(msg_ctx && axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
    {
        soap_ns = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; /* default is 1.2 */
        soap_version = AXIOM_SOAP11;
    }

    if(axis2_msg_ctx_get_soap_envelope(new_msg_ctx, env))
    {
        /* service implementation has set the envelope,
         useful when setting a SOAP fault.
         No need to further process */
        return AXIS2_SUCCESS;
    }

    /* create the soap envelope here */
    env_ns = axiom_namespace_create(env, soap_ns, "soapenv");
    if(!env_ns)
    {
        return AXIS2_FAILURE;
    }

    default_envelope = axiom_soap_envelope_create(env, env_ns);
	axiom_namespace_free(env_ns, env);

    if(!default_envelope)
    {
        return AXIS2_FAILURE;
    }

    out_header = axiom_soap_header_create_with_parent(env, default_envelope);
    if(!out_header)
    {
        return AXIS2_FAILURE;
    }

    out_body = axiom_soap_body_create_with_parent(env, default_envelope);
    if(!out_body)
    {
        return AXIS2_FAILURE;
    }

    out_node = axiom_soap_body_get_base_node(out_body, env);
    if(!out_node)
    {
        return AXIS2_FAILURE;
    }

    if(status != AXIS2_SUCCESS || is_fault)
    {
        /* something went wrong. set a SOAP Fault */
        const axis2_char_t *fault_value_str = "soapenv:Sender";
        const axis2_char_t *fault_reason_str = NULL;
        const axis2_char_t *err_msg = NULL;

        if(!skel_invoked)
        {
            if(axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
            {
fault_value_str            =
            AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
            AXIOM_SOAP11_FAULT_CODE_RECEIVER;
        }
        else
        {
            fault_value_str =
            AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
            AXIOM_SOAP12_SOAP_FAULT_VALUE_RECEIVER;
        }
    }

    err_msg = AXIS2_ERROR_GET_MESSAGE(env->error);
    if (err_msg && axutil_strcmp(err_msg, ""))
    {
        if(!axutil_strcmp(err_msg, "No Error"))
        {
            fault_reason_str = "An error has occurred, but could not determine exact details";
        }
        else
        {
            fault_reason_str = err_msg;
        }
    }
    else
    {
        fault_reason_str = "An error has occurred, but could not determine exact details";
    }

    soap_fault = axiom_soap_fault_create_default_fault(env, out_body, fault_value_str,
        fault_reason_str, soap_version);

    if (fault_node)
    {
        axiom_node_t *fault_detail_node = NULL;
        axis2_char_t *om_str = NULL;

        fault_detail = axiom_soap_fault_detail_create_with_parent(env, soap_fault);
        fault_detail_node = axiom_soap_fault_detail_get_base_node(fault_detail, env);

        om_str = axiom_node_to_string(fault_detail_node, env);
        if (om_str)
        {
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "fault_detail:%s", om_str);
            AXIS2_FREE(env->allocator, om_str);
        }

        axiom_soap_fault_detail_add_detail_entry(fault_detail, env, fault_node);
    }
}

if (body_content_node)
{
    axiom_node_add_child(out_node, env, body_content_node);
    status = axis2_msg_ctx_set_soap_envelope(new_msg_ctx, env, default_envelope);
}
else if (soap_fault)
{
    axis2_msg_ctx_set_soap_envelope(new_msg_ctx, env, default_envelope);
    status = AXIS2_SUCCESS;
}
else
{
    /* we should free the memory as the envelope is not used, one way case */
    axiom_soap_envelope_free(default_envelope, env);
    default_envelope = NULL;
}

AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
    "[axis2]Exit:axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync");

return status;
}
예제 #16
0
axiom_soap_envelope_t* AXIS2_CALL 
sandesha2_rm_elements_to_soap_envelope(
    sandesha2_rm_elements_t *rm_elements,
    const axutil_env_t *env,
    axiom_soap_envelope_t *soap_envelope)
{
    axiom_soap_header_t *soap_header = NULL;
    axiom_soap_body_t *soap_body = NULL;
    axiom_node_t *body_node = NULL;
    
    AXIS2_PARAM_CHECK(env->error, soap_envelope, NULL);
    
    soap_header = axiom_soap_envelope_get_header(soap_envelope, env);
    soap_body = axiom_soap_envelope_get_body(soap_envelope, env);
    body_node = axiom_soap_body_get_base_node(soap_body, env);
    
    if(rm_elements->seq)
    {
        sandesha2_seq_to_om_node(
            rm_elements->seq, env, soap_header);
    }
    if(rm_elements->seq_ack)
    {
        sandesha2_seq_ack_to_om_node(
            rm_elements->seq_ack, env, soap_header);
    }
    if(rm_elements->msg_pending)
    {
        sandesha2_msg_pending_to_om_node(
            rm_elements->msg_pending, env, soap_header);
    }
    if(rm_elements->create_seq)
    {
        sandesha2_create_seq_to_om_node(
            rm_elements->create_seq, env, body_node);
    }
    if(rm_elements->create_seq_res)
    {
        sandesha2_create_seq_res_to_om_node(
            rm_elements->create_seq_res, env, body_node);
    }
    if(rm_elements->terminate_seq)
    {
        sandesha2_terminate_seq_to_om_node(
            rm_elements->terminate_seq, env, body_node);
    }
    if(rm_elements->terminate_seq_res)
    {
        sandesha2_terminate_seq_res_to_om_node(
            rm_elements->terminate_seq_res, env, body_node);
    }
    if(rm_elements->close_seq)
    {
        sandesha2_close_seq_to_om_node(rm_elements->close_seq, env, body_node);
    }
    if(rm_elements->close_seq_res)
    {
        sandesha2_close_seq_res_to_om_node(rm_elements->close_seq_res, env, 
            body_node);
    }
    if(rm_elements->make_connection)
    {
        sandesha2_make_connection_to_om_node(
            rm_elements->make_connection, env, body_node);
    }
    return soap_envelope;
}
예제 #17
0
axis2_op_t *AXIS2_CALL
axis2_rest_disp_find_op(
    axis2_msg_ctx_t * msg_ctx,
    const axutil_env_t * env,
    axis2_svc_t * svc)
{
    axis2_endpoint_ref_t *endpoint_ref = NULL;
    axis2_op_t *op = NULL;
    axiom_soap_envelope_t *soap_env = NULL;
    axiom_soap_body_t *soap_body = NULL;
    axiom_element_t *body_child = NULL;
    axiom_node_t *body_child_node = NULL;
    axiom_node_t *body_element_node = NULL;
    axis2_bool_t soap_env_exists = AXIS2_TRUE;
    int i = 0;

    axutil_array_list_t *param_keys = NULL;
    axutil_array_list_t *param_values = NULL;

    AXIS2_PARAM_CHECK(env->error, svc, NULL);

    if(!axis2_msg_ctx_get_doing_rest(msg_ctx, env))
        return NULL;

    endpoint_ref = axis2_msg_ctx_get_to(msg_ctx, env);

    if(endpoint_ref)
    {
        const axis2_char_t *address = NULL;

        address = axis2_endpoint_ref_get_address(endpoint_ref, env);
        if(address)
        {
            axis2_char_t **url_tokens = NULL;

            url_tokens = axutil_parse_request_url_for_svc_and_op(env, address);

            if(url_tokens)
            {
                if(url_tokens[0])
                {
                    axis2_char_t *location = NULL;

                    location = strstr(address, url_tokens[0]);
                    if(location)
                    {
                        const axis2_char_t *method = NULL;

                        location += strlen(url_tokens[0]);
                        param_keys = axutil_array_list_create(env, 10);
                        if(!param_keys)
                        {
                            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                                "No memory. Cannot create the live rest parameter maps");
                            return NULL;
                        }
                        param_values = axutil_array_list_create(env, 10);

                        if(!param_values)
                        {
                            axutil_array_list_free(param_keys, env);
                            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                                "No memory. Cannot create the live rest parameter maps");
                            return NULL;
                        }
                        method = axis2_msg_ctx_get_rest_http_method(msg_ctx, env);
                        op = axis2_core_utils_get_rest_op_with_method_and_location(svc, env,
                            method, location, param_keys, param_values);
                    }
                }
                if(url_tokens[0])
                    AXIS2_FREE(env->allocator, url_tokens[0]);
                if(url_tokens[1])
                    AXIS2_FREE(env->allocator, url_tokens[1]);
                AXIS2_FREE(env->allocator, url_tokens);
            }
        }
    }

    if(!op)
    {
        if(param_keys)
        {
            for(i = 0; i < axutil_array_list_size(param_keys, env); i++)
            {
                void *value = axutil_array_list_get(param_keys, env, i);
                AXIS2_FREE(env->allocator, value);
            }
            axutil_array_list_free(param_keys, env);
        }
        if(param_values)
        {
            for(i = 0; i < axutil_array_list_size(param_values, env); i++)
            {
                void *value = axutil_array_list_get(param_values, env, i);
                AXIS2_FREE(env->allocator, value);
            }
            axutil_array_list_free(param_values, env);
        }
        return NULL;
    }

    soap_env = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);

    if(!soap_env)
    {
        soap_env_exists = AXIS2_FALSE;
        soap_env = axiom_soap_envelope_create_default_soap_envelope(env, AXIOM_SOAP11);
    }
    if(soap_env)
    {
        soap_body = axiom_soap_envelope_get_body(soap_env, env);
    }
    if(!soap_body)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL, AXIS2_FAILURE);

        if(param_keys)
        {
            for(i = 0; i < axutil_array_list_size(param_keys, env); i++)
            {
                void *value = axutil_array_list_get(param_keys, env, i);
                AXIS2_FREE(env->allocator, value);
            }
            axutil_array_list_free(param_keys, env);
        }
        if(param_values)
        {
            for(i = 0; i < axutil_array_list_size(param_values, env); i++)
            {
                void *value = axutil_array_list_get(param_values, env, i);
                AXIS2_FREE(env->allocator, value);
            }
            axutil_array_list_free(param_values, env);
        }
        return NULL;
    }

    body_element_node = axiom_soap_body_get_base_node(soap_body, env);

    if(body_element_node)
    {
        body_child_node = axiom_node_get_first_child(body_element_node, env);
    }

    if(!body_child_node)
    {
        body_child = axiom_element_create_with_qname(env, NULL, axis2_op_get_qname(op, env),
            &body_child_node);
        axiom_soap_body_add_child(soap_body, env, body_child_node);
    }

    if(param_keys && param_values)
    {
        for(i = 0; i < axutil_array_list_size(param_keys, env); i++)
        {
            axis2_char_t *param_key = NULL;
            axis2_char_t *param_value = NULL;

            axiom_node_t *node = NULL;
            axiom_element_t *element = NULL;

            param_key = axutil_array_list_get(param_keys, env, i);
            param_value = axutil_array_list_get(param_values, env, i);

            element = axiom_element_create(env, NULL, param_key, NULL, &node);
            axiom_element_set_text(element, env, param_value, node);
            axiom_node_add_child(body_child_node, env, node);

            AXIS2_FREE(env->allocator, param_key);
            AXIS2_FREE(env->allocator, param_value);
        }

        axutil_array_list_free(param_keys, env);
        axutil_array_list_free(param_values, env);
    }

    if(!soap_env_exists)
    {
        axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_env);
    }

    return op;
}
예제 #18
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;
    axiom_node_t *ret_node = NULL;

    const axis2_char_t *google_key = NULL;
    const axis2_char_t *word_to_spell = NULL;
    const axis2_char_t *operation = NULL;

    operation = "doSpellingSuggestion";
    google_key = "00000000000000000000000000000000";
    word_to_spell = "salvasion";

    /* Set up the environment */
    env = axutil_env_create_all("google_client.log", AXIS2_LOG_LEVEL_TRACE);

    /* Set end point reference of google service */
    address = "http://api.google.com/search/beta2";

    if ((argc > 1) && (axutil_strcmp("-h", argv[1]) == 0))
    {
        printf("\nUsage : %s [google_key] [word_to_spell] \n", argv[0]);
        printf
            ("\tgoogle_key Your Google license key. Default value won't work. You must use your key here.\n");
        printf
            ("\tword_to_spell Word to be spelled by Google service. Default is %s\n",
             word_to_spell);
        printf
            ("NOTE: command line arguments must appear in given order, with trailing ones being optional\n");
        printf("\tUse -h for help\n");
        return 0;
    }

    if (argc > 1)
        google_key = argv[1];
    if (argc > 2)
        word_to_spell = argv[2];
    if (argc > 3)
        address = argv[3];

    printf("Using endpoint : %s\n", address);
    printf("\nInvoking operation %s with params %s and %s\n", operation,
           google_key, word_to_spell);

    /* 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_soap_version(options, env, AXIOM_SOAP11);

    /* Set up deploy folder. */
    client_home = AXIS2_GETENV("WSFC_HOME");
    if (!client_home || !strcmp(client_home, ""))
        client_home = "../..";

    /* Create service client */
    svc_client = axis2_svc_client_create(env, client_home);
    if (!svc_client)
    {
        printf
            ("Error creating service client, Please check WSFC_HOME again\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;
    }

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

    /* Build the SOAP request message payload using OM API. */
    payload =
        build_soap_body_content(env, operation, google_key, word_to_spell);

    /* 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;
        axis2_char_t *fault_string = 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)
        {
            fault_string = axiom_node_to_string(axiom_soap_fault_get_base_node
                                                (soap_fault, env), env);
            printf("\nReturned SOAP fault: %s\n", fault_string);
            AXIS2_FREE (env->allocator, fault_string);
        }

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

    if (ret_node)
    {
        if (axiom_node_get_node_type(ret_node, env) == AXIOM_ELEMENT)
        {
            axis2_char_t *result = NULL;
            axiom_element_t *result_ele = NULL;
            axiom_node_t *ret_node1 = NULL;

            result_ele =
                (axiom_element_t *) axiom_node_get_data_element(ret_node, env);
            if (axutil_strcmp
                (axiom_element_get_localname(result_ele, env),
                 "doSpellingSuggestionResponse") != 0)
            {
                print_invalid_om(env, ret_node);
                return AXIS2_FAILURE;
            }

            ret_node1 = axiom_node_get_first_element(ret_node, env);    /*return */
            if (!ret_node1)
            {
                print_invalid_om(env, ret_node);
                return AXIS2_FAILURE;
            }
            result_ele =
                (axiom_element_t *) axiom_node_get_data_element(ret_node1, env);
            result = axiom_element_get_text(result_ele, env, ret_node1);
            printf("\nResult = %s\n", result);
        }
        else
        {
            print_invalid_om(env, ret_node);
            return AXIS2_FAILURE;
        }
    }
    else
    {
        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));
        printf("Google client invoke FAILED!\n");
    }

    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;
}
예제 #19
0
axis2_status_t AXIS2_CALL
wsf_xml_msg_recv_invoke_business_logic_sync(
        axis2_msg_recv_t * msg_recv,
        const axutil_env_t * env,
        axis2_msg_ctx_t * in_msg_ctx,
        axis2_msg_ctx_t * out_msg_ctx)
{

    axis2_op_ctx_t *op_ctx = NULL;
    axis2_op_t *op_desc = NULL;

    axiom_namespace_t *env_ns = NULL;

    int soap_version = AXIOM_SOAP12;
    axis2_status_t status = AXIS2_SUCCESS;
    axis2_bool_t skel_invoked = AXIS2_FALSE;

    const axis2_char_t *style = NULL;
    axis2_char_t *local_name = NULL;
    axis2_char_t *soap_ns = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI;
    axis2_char_t *operation_name = NULL;
    char *classname = NULL;

    axutil_property_t *svc_info_prop = NULL;
    axutil_property_t *req_info_prop = NULL;
    wsf_svc_info_t *svc_info = NULL;
    wsf_request_info_t *req_info = NULL;

    /** store in_msg_ctx envelope */
    axiom_soap_envelope_t *envelope = NULL;
    axiom_soap_body_t *body = NULL;
    axiom_node_t *in_body_node = NULL;

    /* store out_msg_ctx envelope */
    axiom_soap_envelope_t *default_envelope = NULL;
    axiom_soap_body_t *out_body = NULL;
    axiom_soap_header_t *out_header = NULL;
    axiom_soap_fault_t *out_soap_fault = NULL;

    axiom_node_t *result_node = NULL;

    axiom_node_t *out_body_content_node = NULL;
    axiom_element_t *out_body_content_element = NULL;
    axiom_node_t *out_node = NULL;

    zval **output_headers_zval = NULL;

    TSRMLS_FETCH();

    AXIS2_PARAM_CHECK(env->error, in_msg_ctx, AXIS2_FAILURE);
    AXIS2_PARAM_CHECK(env->error, out_msg_ctx, AXIS2_FAILURE);

    op_ctx = axis2_msg_ctx_get_op_ctx(in_msg_ctx, env);
    op_desc = axis2_op_ctx_get_op(op_ctx, env);
    style = axis2_op_get_style(op_desc, env);

    envelope = axis2_msg_ctx_get_soap_envelope(in_msg_ctx, env);

    body = axiom_soap_envelope_get_body(envelope, env);

    in_body_node = axiom_soap_body_get_base_node(body, env);


    if (0 == axutil_strcmp(AXIS2_STYLE_DOC, style))
    {
        local_name = wsf_xml_msg_recv_get_method_name(in_msg_ctx, env);
        if (!local_name)
        {
            return AXIS2_FAILURE;
        }
    } else if (0 == axutil_strcmp(AXIS2_STYLE_RPC, style))
    {

        axiom_node_t *op_node = NULL;
        axiom_element_t *op_element = NULL;
        op_node = axiom_node_get_first_child(in_body_node, env);
        if (!op_node)
        {
            return AXIS2_FAILURE;
        }
        op_element = axiom_node_get_data_element(op_node, env);

        if (!op_element)
        {
            return AXIS2_FAILURE;
        }
        local_name = axiom_element_get_localname(op_element, env);
        if (!local_name)
        {
            return AXIS2_FAILURE;
        }
    }

    /** set soap version and soap namespace to local variables */
    if (in_msg_ctx && axis2_msg_ctx_get_is_soap_11(in_msg_ctx, env))
    {
        soap_ns = AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI; /* default is 1.2 */
        soap_version = AXIOM_SOAP11;
    }

    svc_info_prop = axis2_msg_ctx_get_property(in_msg_ctx, env, WSF_SVC_INFO);
    if (svc_info_prop)
    {
        svc_info = (wsf_svc_info_t *) axutil_property_get_value(svc_info_prop, env);
        if (svc_info)
        {
            operation_name = axutil_hash_get(svc_info->ops_to_functions, local_name,
                    AXIS2_HASH_KEY_STRING);
            if (!operation_name)
            {
                return AXIS2_FAILURE;
            }
        } else
        {
            return AXIS2_FAILURE;
        }
        if (svc_info->ops_to_classes)
        {
            classname = axutil_hash_get(svc_info->ops_to_classes, local_name, AXIS2_HASH_KEY_STRING);
        }
    }

    req_info_prop = axis2_msg_ctx_get_property(in_msg_ctx, env, WSF_REQ_INFO);
    if (req_info_prop)
    {
        req_info = (wsf_request_info_t *) axutil_property_get_value(req_info_prop, env);

        if (axis2_msg_ctx_get_doing_rest(in_msg_ctx, env))
        {
            axis2_op_t *op = NULL;
            axiom_node_t *body_child_node = NULL;
            axiom_element_t *body_child = NULL;
            int i = 0;

            body_child_node = axiom_node_get_first_child(in_body_node, env);

            if (!body_child_node)
            {
                op = axis2_msg_ctx_get_op(in_msg_ctx, env);
                if (op)
                {
                    body_child = axiom_element_create_with_qname(env, NULL,
                            axis2_op_get_qname(op, env), &body_child_node);
                    axiom_soap_body_add_child(body, env, body_child_node);
                }
            }
            if (req_info->param_keys && req_info->param_values)
            {
                int i = 0;
                for (i = 0; i < axutil_array_list_size(req_info->param_keys, env); i++)
                {
                    axiom_node_t *node = NULL;
                    axiom_element_t *element = NULL;

                    axis2_char_t *param_key = NULL;
                    axis2_char_t *param_value = NULL;

                    param_key = axutil_array_list_get(req_info->param_keys, env, i);
                    param_value = axutil_array_list_get(req_info->param_values, env, i);

                    element = axiom_element_create(env, NULL, param_key,
                            NULL, &node);
                    axiom_element_set_text(element, env, param_value, node);
                    axiom_node_add_child(body_child_node, env, node);

                    AXIS2_FREE(env->allocator, param_key);
                    AXIS2_FREE(env->allocator, param_value);
                }
                axutil_array_list_free(req_info->param_keys, env);
                axutil_array_list_free(req_info->param_values, env);
            }
        }
    }

    if (svc_info->ht_op_params)
    {
        zval **tmp;
        char *function_type = NULL;
        if (zend_hash_find(svc_info->ht_op_params,
                operation_name, strlen(operation_name) + 1,
                (void **) & tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_STRING)
        {
            function_type = Z_STRVAL_PP(tmp);

            if (strcmp(function_type, WSF_MIXED) == 0)
            {
                result_node = wsf_xml_msg_recv_invoke_mixed(env, svc_info,
                        in_msg_ctx, out_msg_ctx, operation_name,
                        classname, &output_headers_zval TSRMLS_CC);

            } else if (strcmp(function_type, WSF_WSMESSAGE) == 0)
            {
                result_node = wsf_xml_msg_recv_invoke_wsmsg(env, operation_name,
                        in_msg_ctx, out_msg_ctx, svc_info, classname, req_info->content_type TSRMLS_CC);
            }
        }
    } else
    {
        /* this is where the default value for opParam is set,
           If the wsdl option is set go for the MIXED mode by default */
		if (svc_info->wsdl == NULL || svc_info->omit_wsdl)
        {
            result_node = wsf_xml_msg_recv_invoke_wsmsg(env, operation_name,
                    in_msg_ctx, out_msg_ctx, svc_info, classname, req_info->content_type TSRMLS_CC);
        } else
        {
            result_node = wsf_xml_msg_recv_invoke_mixed(env, svc_info,
                    in_msg_ctx, out_msg_ctx, operation_name,
                    classname, &output_headers_zval TSRMLS_CC);
        }
    }
    if (!result_node)
    {
        status = AXIS2_ERROR_GET_STATUS_CODE(env->error);
    } else
    {
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "Response node is not null");
    }

    if (result_node)
    {
        if (0 == axutil_strcmp(style, AXIS2_STYLE_RPC))
        {
            axiom_namespace_t *ns = NULL;
            axis2_char_t *response_name = NULL;

            response_name = axutil_stracat(env, local_name, "Response");
            ns = axiom_namespace_create(env, "http://soapenc/", "res");
            if (!ns)
            {
                return AXIS2_FAILURE;
            }

            out_body_content_element = axiom_element_create(env, NULL, response_name,
                    ns, &out_body_content_node);
            axiom_node_add_child(out_body_content_node, env, result_node);

        } else
        {
            out_body_content_node = result_node;
        }
    }

    if (axis2_msg_ctx_get_soap_envelope(out_msg_ctx, env))
    {
        /* service implementation has set the envelope, useful when setting a SOAP fault.
           No need to further process */
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "soap fault is set");
        return AXIS2_SUCCESS;
    }

    /* create the soap envelope here */
    env_ns = axiom_namespace_create(env, soap_ns, AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX);
    if (!env_ns)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] error seting the namespces for the "
                AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX);
        return AXIS2_FAILURE;
    }

    default_envelope = axiom_soap_envelope_create(env, env_ns);

    if (!default_envelope)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "failed in creating the response soap envelope");
        return AXIS2_FAILURE;
    }


    out_body = axiom_soap_body_create_with_parent(env, default_envelope);
    if (!out_body)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] failed in creating the response soap body");
        return AXIS2_FAILURE;
    }

    out_header = axiom_soap_header_create_with_parent(env, default_envelope);
    if (!out_header)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, WSF_PHP_LOG_PREFIX "failed in creating the response soap headers");
        return AXIS2_FAILURE;
    }

    if (output_headers_zval)
    {
        axiom_node_t *header_base_node = NULL;

        HashPosition pos;
        zval **param;
        char *header_str;
        axiom_node_t *header_node;

        for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(output_headers_zval), &pos);
                zend_hash_get_current_data_ex(Z_ARRVAL_PP(output_headers_zval),
                (void **) & param, &pos) == SUCCESS;
                zend_hash_move_forward_ex(Z_ARRVAL_PP(output_headers_zval), &pos))
        {

            if (Z_TYPE_PP(param) == IS_STRING)
            {

                header_base_node = axiom_soap_header_get_base_node(out_header, env);

                if (header_base_node)
                {
                    header_str = Z_STRVAL_PP(param);
                    header_node = wsf_util_deserialize_buffer(env, header_str);
                    axiom_node_add_child(header_base_node, env, header_node);
                } else
                {
                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] failed in retrieving the response soap headers node");
                    return AXIS2_FAILURE;
                }
            }
        }
    }

    out_node = axiom_soap_body_get_base_node(out_body, env);
    if (!out_node)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[wsfphp] failed in retrieving the response soap body node");
        return AXIS2_FAILURE;
    }

    if (status != AXIS2_SUCCESS)
    {
        /* something went wrong, set a SOAP Fault */
        axis2_char_t *fault_value_str =
                AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" AXIOM_SOAP12_SOAP_FAULT_VALUE_SENDER;

        axis2_char_t *fault_reason_str = NULL;
        axis2_char_t *err_msg = NULL;

        if (!skel_invoked)
            fault_value_str = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":" AXIOM_SOAP12_SOAP_FAULT_VALUE_RECEIVER;
        ;

        err_msg = (char *) AXIS2_ERROR_GET_MESSAGE(env->error);

        if (err_msg)
        {
            fault_reason_str = err_msg;
        } else
        {
            fault_reason_str = "Error occurred while processing SOAP message";
        }

        out_soap_fault = axiom_soap_fault_create_default_fault(env, out_body,
                fault_value_str, fault_reason_str, soap_version);
    }

    if (out_body_content_node)
    {
        axiom_node_add_child(out_node, env, out_body_content_node);
        status = axis2_msg_ctx_set_soap_envelope(out_msg_ctx, env,
                default_envelope);
    } else if (out_soap_fault)
    {
        axis2_msg_ctx_set_soap_envelope(out_msg_ctx, env, default_envelope);
        status = AXIS2_FAILURE; /* if there is a failure we have to return a failure code */
    } else
    {
        /* we should free the memory as the envelope is not used, one way case */
        axiom_soap_envelope_free(default_envelope, env);
        default_envelope = NULL;
    }
    return AXIS2_SUCCESS;
}
예제 #20
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;
}
예제 #21
0
static axis2_bool_t
axis2_svc_client_fill_soap_envelope(
    const axutil_env_t * env,
    axis2_svc_client_t * svc_client,
    axis2_msg_ctx_t * msg_ctx,
    const axiom_node_t * payload)
{
    const axis2_char_t *soap_version_uri;
    int soap_version;
    axiom_soap_envelope_t *envelope = NULL;
    AXIS2_PARAM_CHECK(env->error, svc_client, AXIS2_FAILURE);

    soap_version_uri = axis2_options_get_soap_version_uri(svc_client->options, env);

    if(!soap_version_uri)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot find soap version uri.");
        return AXIS2_FALSE;
    }

    if(axutil_strcmp(soap_version_uri, AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI) == 0)
    {
        soap_version = AXIOM_SOAP11;
    }
    else
    {
        soap_version = AXIOM_SOAP12;
    }

    envelope = axiom_soap_envelope_create_default_soap_envelope(env, soap_version);
    if(!envelope)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create default soap envelope.");
        return AXIS2_FALSE;
    }

    if(svc_client->headers)
    {
        axiom_soap_header_t *soap_header = NULL;
        soap_header = axiom_soap_envelope_get_header(envelope, env);

        if(soap_header)
        {
            axiom_node_t *header_node = NULL;
            header_node = axiom_soap_header_get_base_node(soap_header, env);

            if(header_node)
            {
                int size = 0;
                int i = 0;
                size = axutil_array_list_size(svc_client->headers, env);
                while(i < size)
                {
                    axiom_node_t *node = NULL;
                    node = axutil_array_list_remove(svc_client->headers, env, 0);
                    /* This removes and retrieves data. The order of the 
                     * removal is chosen such that the headers are appended
                     * in the order they were added.
                     */
                    size--;
                    if(node)
                    {
                        axiom_node_add_child(header_node, env, node);
                    }
                }
            }
        }
    }

    if(payload)
    {
        axiom_soap_body_t *soap_body = NULL;
        soap_body = axiom_soap_envelope_get_body(envelope, env);
        if(soap_body)
        {
            axiom_node_t *node = NULL;
            node = axiom_soap_body_get_base_node(soap_body, env);
            if(node)
            {
                axiom_node_add_child(node, env, (axiom_node_t *)payload);
            }
        }
    }

    axis2_msg_ctx_set_soap_envelope(msg_ctx, env, envelope);

    return AXIS2_TRUE;
}