Esempio n. 1
0
AXIS2_EXTERN void AXIS2_CALL
axis2_svc_client_fire_and_forget_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)
{
    axis2_msg_ctx_t *msg_ctx = NULL;
    axis2_bool_t qname_free_flag = AXIS2_FALSE;

    AXIS2_PARAM_CHECK_VOID(env->error, svc_client);

    if(!op_qname)
    {
        op_qname = axutil_qname_create(env, AXIS2_ANON_OUT_ONLY_OP, NULL, NULL);
        if(!op_qname)
        {
            return;
        }
        qname_free_flag = AXIS2_TRUE;
    }

    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;

    msg_ctx = axis2_msg_ctx_create(env, axis2_svc_ctx_get_conf_ctx(svc_client->svc_ctx, env), NULL,
        NULL);
    if(!axis2_svc_client_fill_soap_envelope(env, svc_client, msg_ctx, payload))
    {
        return;
    }

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

    axis2_op_client_add_out_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));
    }

    if(qname_free_flag)
    {
        axutil_qname_free((axutil_qname_t *)op_qname, env);
    }
}
Esempio n. 2
0
axiom_soap_envelope_t *
wsdl_util_send_receive_soap_envelope_with_op_client(
    const axutil_env_t* env,
    axis2_svc_client_t* svc_client,
    axis2_options_t* options,
    axis2_char_t* buffer)
{
    axiom_soap_envelope_t *res_envelope = NULL, *req_envelope = NULL;
    axis2_svc_ctx_t *svc_ctx = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_msg_ctx_t *req_msg_ctx = NULL, *res_msg_ctx = NULL;
    axutil_qname_t *op_qname = NULL;
    axis2_op_client_t *op_client = NULL;
    axis2_char_t *soap_version_uri = NULL;

    svc_ctx = axis2_svc_client_get_svc_ctx (svc_client, env);

    conf_ctx = axis2_svc_ctx_get_conf_ctx (svc_ctx, env);

    req_msg_ctx = axis2_msg_ctx_create (env, conf_ctx, NULL, NULL);

    op_qname = axutil_qname_create (env, AXIS2_ANON_OUT_IN_OP, NULL, NULL);

    op_client = axis2_svc_client_create_op_client (svc_client, env, op_qname);

    soap_version_uri = (axis2_char_t *) axis2_options_get_soap_version_uri (options, env);

    req_envelope = wsdl_util_create_soap_envelope_from_buffer (env, buffer, soap_version_uri);
    
    axis2_msg_ctx_set_soap_envelope (req_msg_ctx, env, req_envelope);
    
    axis2_op_client_add_msg_ctx (op_client, env, req_msg_ctx);
    
    axis2_op_client_execute (op_client, env, AXIS2_TRUE);
    
    res_msg_ctx =
       (axis2_msg_ctx_t *)axis2_op_client_get_msg_ctx (op_client, env, AXIS2_WSDL_MESSAGE_LABEL_IN);
    
    if (res_msg_ctx) 
    {        
        res_envelope = axis2_msg_ctx_get_soap_envelope (res_msg_ctx, env);
    } 
    else 
    {
        res_envelope = NULL;
    }
    
    return res_envelope;
}
Esempio n. 3
0
AXIS2_EXTERN axis2_bool_t AXIS2_CALL
axis2_tcp_worker_process_request(
    axis2_tcp_worker_t * tcp_worker,
    const axutil_env_t * env,
    axis2_simple_tcp_svr_conn_t * svr_conn,
    axis2_char_t * simple_request)
{
    axis2_conf_ctx_t *conf_ctx = 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_xml_reader_t *reader = NULL;
    axiom_stax_builder_t *builder = NULL;
    axiom_soap_builder_t *soap_builder = NULL;
    axiom_soap_envelope_t *soap_envelope = NULL;
    axis2_engine_t *engine = NULL;
    axis2_status_t status = AXIS2_FALSE;
    axutil_stream_t *svr_stream = NULL;
    axis2_char_t *buffer = NULL;
    int len = 0;
    int write = -1;
    axutil_stream_t *out_stream = NULL;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "start:axis2_tcp_worker_process_request");

    reader = axiom_xml_reader_create_for_memory(env, simple_request, axutil_strlen(simple_request),
        NULL, AXIS2_XML_PARSER_TYPE_BUFFER);
    if(!reader)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create XML reader");
        return AXIS2_FAILURE;
    }

    builder = axiom_stax_builder_create(env, reader);
    if(!builder)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create Stax builder");
        return AXIS2_FAILURE;
    }

    soap_builder= axiom_soap_builder_create(env, builder, NULL);
    if(!soap_builder)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create SOAP builder");
        return AXIS2_FAILURE;
    }

    conf_ctx = tcp_worker->conf_ctx;

    if(!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "conf ctx not available");
        return AXIS2_FAILURE;
    }

    out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(conf_ctx, env), env,
        AXIS2_TRANSPORT_ENUM_TCP);
    if(!out_desc)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport out not set");
        return AXIS2_FAILURE;
    }

    in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(conf_ctx, env), env,
        AXIS2_TRANSPORT_ENUM_TCP);

    msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc);
    axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE);

    out_stream = axutil_stream_create_basic(env);
    axis2_msg_ctx_set_transport_out_stream(msg_ctx, env, out_stream);

    soap_envelope = axiom_soap_builder_get_soap_envelope(soap_builder, env);
    axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_envelope);

    engine = axis2_engine_create(env, conf_ctx);
    status = axis2_engine_receive(engine, env, msg_ctx);

    svr_stream = axis2_simple_tcp_svr_conn_get_stream(svr_conn, env);
    buffer = out_stream->buffer;
    len = out_stream->len;
    buffer[len] = 0;
    if(svr_stream && buffer)
    {
        write = axutil_stream_write(svr_stream, env, buffer, len + 1);
        if(write < 0)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "stream write failed");
            return AXIS2_FAILURE;
        }
        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "stream wrote:%s", buffer);
    }
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "end:axis2_tcp_worker_process_request");
    return AXIS2_SUCCESS;
}
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;
}
Esempio n. 5
0
AXIS2_EXTERN axis2_msg_ctx_t * AXIS2_CALL
axis2_engine_create_fault_msg_ctx(
    axis2_engine_t * engine,
    const axutil_env_t * env,
    axis2_msg_ctx_t * processing_context,
    const axis2_char_t * code_value,
    const axis2_char_t * reason_text)
{
    axis2_msg_ctx_t *fault_ctx = NULL;
    axis2_endpoint_ref_t *fault_to = NULL;
    axis2_endpoint_ref_t *reply_to = NULL;
    axutil_stream_t *stream = NULL;
    axiom_soap_envelope_t *envelope = NULL;
    const axis2_char_t *wsa_action = NULL;
    const axis2_char_t *msg_id = NULL;
    axis2_relates_to_t *relates_to = NULL;
    axis2_char_t *msg_uuid = NULL;
    axis2_msg_info_headers_t *msg_info_headers = NULL;
    axis2_bool_t doing_rest = AXIS2_FALSE;

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

    if(axis2_msg_ctx_get_process_fault(processing_context, env))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_PROCESSING_FAULT_ALREADY,
            AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating fault message contex failed");
        return NULL;
    }

    fault_ctx = axis2_msg_ctx_create(env, engine->conf_ctx, axis2_msg_ctx_get_transport_in_desc(
        processing_context, env), axis2_msg_ctx_get_transport_out_desc(processing_context, env));

    axis2_msg_ctx_set_process_fault(fault_ctx, env, AXIS2_TRUE);

    fault_to = axis2_msg_ctx_get_fault_to(processing_context, env);
    if(fault_to)
    {
        const axis2_char_t *address = axis2_endpoint_ref_get_address(fault_to, env);
        if(!address)
        {
            fault_to = NULL;
        }
        else if(axutil_strcmp(AXIS2_WSA_NONE_URL, address) == 0 || axutil_strcmp(
            AXIS2_WSA_NONE_URL_SUBMISSION, address) == 0)
        {
            reply_to = axis2_msg_ctx_get_reply_to(processing_context, env);
            if(reply_to)
            {
                axis2_msg_ctx_set_fault_to(fault_ctx, env, reply_to);
            }
            else
            {
                axis2_msg_ctx_set_fault_to(fault_ctx, env, fault_to);
            }
        }
        else
        {
            axis2_msg_ctx_set_fault_to(fault_ctx, env, fault_to);
        }

    }

    stream = axis2_msg_ctx_get_transport_out_stream(processing_context, env);

    if(stream)
    {
        axis2_msg_ctx_set_transport_out_stream(fault_ctx, env, stream);
        axis2_msg_ctx_reset_transport_out_stream(processing_context, env);
    }

    if(!fault_to && !stream)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NOWHERE_TO_SEND_FAULT, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Soap fault target destination not found");
        return NULL;
    }

    /* Set WSA action */
    msg_info_headers = axis2_msg_ctx_get_msg_info_headers(processing_context, env);
    if(msg_info_headers)
    {
        wsa_action = axis2_msg_info_headers_get_action(msg_info_headers, env);
        if(wsa_action)
        {
            /*
             We have to use the action set by user,
             cannot use the default always.
             wsa_action = "http://www.w3.org/2005/08/addressing/fault"; */
            axis2_msg_ctx_set_wsa_action(fault_ctx, env, wsa_action);
        }
    }

    /* Set relates to */
    msg_id = axis2_msg_ctx_get_msg_id(processing_context, env);

    /* we can create with default Relates to namespace. 
     Actual namespace based on addressing version will be created in addressing out handler */
    relates_to = axis2_relates_to_create(env, msg_id,
        AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE);
    axis2_msg_ctx_set_relates_to(fault_ctx, env, relates_to);

    /* Set msg id */
    msg_uuid = axutil_uuid_gen(env);
    axis2_msg_ctx_set_message_id(fault_ctx, env, msg_uuid);
    if(msg_uuid)
    {
        AXIS2_FREE(env->allocator, msg_uuid);
        msg_uuid = NULL;
    }

	/** Copy the property map from the current message context to the newly created fault message
		context. */
	{
		axis2_ctx_t *ctx = axis2_msg_ctx_get_base(processing_context, env);
		axis2_ctx_t *fault_base_ctx = axis2_msg_ctx_get_base(fault_ctx, env);

		if(ctx && fault_ctx)
		{
			axis2_ctx_set_property_map(fault_base_ctx, env, axis2_ctx_get_property_map(ctx, env));
		}

	}


    axis2_msg_ctx_set_op_ctx(fault_ctx, env, axis2_msg_ctx_get_op_ctx(processing_context, env));
    axis2_msg_ctx_set_process_fault(fault_ctx, env, AXIS2_TRUE);
    axis2_msg_ctx_set_server_side(fault_ctx, env, AXIS2_TRUE);

    envelope = axis2_msg_ctx_get_fault_soap_envelope(processing_context, env);

    if(!envelope)
    {
        if(axis2_msg_ctx_get_is_soap_11(processing_context, env))
        {
            envelope = axiom_soap_envelope_create_default_soap_fault_envelope(env, code_value,
                reason_text, AXIOM_SOAP11, NULL, NULL);

        }
        else
        {
            envelope = axiom_soap_envelope_create_default_soap_fault_envelope(env, code_value,
                reason_text, AXIOM_SOAP12, NULL, NULL);
        }

        if(!envelope)
        {
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Creating default soap envelope failed");
            return NULL;
        }
    }
    else
    {
        axis2_msg_ctx_set_fault_soap_envelope(processing_context, env, NULL);
    }

    doing_rest = axis2_msg_ctx_get_doing_rest(processing_context, env);
    axis2_msg_ctx_set_doing_rest(fault_ctx, env, doing_rest);

    axis2_msg_ctx_set_soap_envelope(fault_ctx, env, envelope);
    axis2_msg_ctx_set_out_transport_info(fault_ctx, env, axis2_msg_ctx_get_out_transport_info(
        processing_context, env));
    axis2_msg_ctx_reset_out_transport_info(processing_context, env);
    return fault_ctx;
}
Esempio n. 6
0
/* Process a request. If the request has a response the response structure will be populated */
AXIS2_EXTERN axis2_bool_t AXIS2_CALL
axis2_udp_receiver_process_request(
	const axutil_env_t * env,
	axis2_conf_ctx_t *conf_ctx,    
    axis2_udp_request_t * request,
	axis2_udp_response_t * responce)
{   
    axis2_transport_out_desc_t *out_desc = NULL;
    axis2_transport_in_desc_t *in_desc = NULL;
    axis2_msg_ctx_t *msg_ctx = NULL;
    axiom_xml_reader_t *reader = NULL;
    axiom_stax_builder_t *builder = NULL;
    axiom_soap_builder_t *soap_builder = NULL;
    axiom_soap_envelope_t *soap_envelope = NULL;
    axis2_engine_t *engine = NULL;
    axis2_status_t status = AXIS2_FALSE;
    axutil_stream_t *out_stream = NULL;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
                    "start:axis2_udp_worker_process_request");

    if (!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "conf ctx not available");
        return AXIS2_FAILURE;
    }

    reader = axiom_xml_reader_create_for_memory(env, request->buff,
                                                request->buf_size,
                                                NULL,
                                                AXIS2_XML_PARSER_TYPE_BUFFER);
    if (!reader)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create XML reader");
        return AXIS2_FAILURE;
    }

    builder = axiom_stax_builder_create(env, reader);
    if (!builder)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                        "Failed to create Stax builder");
        return AXIS2_FAILURE;
    }

    soap_builder = axiom_soap_builder_create(env, builder,
                                             AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI);

    if (!soap_builder)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                        "Failed to create SOAP builder");
        return AXIS2_FAILURE;
    }    

    out_desc =
        axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(conf_ctx, env),
                                     env, AXIS2_TRANSPORT_ENUM_UDP);
    if (!out_desc)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport out not set");
        return AXIS2_FAILURE;
    }

    in_desc =
        axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(conf_ctx, env), env,
                                    AXIS2_TRANSPORT_ENUM_UDP);

    msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc);
    axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE);

    out_stream = axutil_stream_create_basic(env);
    axis2_msg_ctx_set_transport_out_stream(msg_ctx, env, out_stream);

    soap_envelope = axiom_soap_builder_get_soap_envelope(soap_builder, env);
    axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_envelope);
	if (request->svc)
	{
		axis2_msg_ctx_set_svc(msg_ctx, env, request->svc);
	}
	if (request->op)
	{
		axis2_msg_ctx_set_op(msg_ctx, env, request->op);	
	}
    engine = axis2_engine_create(env, conf_ctx);
    status = axis2_engine_receive(engine, env, msg_ctx);

    responce->buff = axutil_stream_get_buffer(out_stream, env);
	responce->buf_size = axutil_stream_get_len(out_stream, env);
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,
                    "end:axis2_udp_worker_process_request");
    return AXIS2_SUCCESS;
}
Esempio n. 7
0
AXIS2_EXTERN void AXIS2_CALL
axis2_svc_client_send_receive_non_blocking_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,
    axis2_callback_t * callback)
{
    axis2_msg_ctx_t *msg_ctx = NULL;
    AXIS2_TRANSPORT_ENUMS transport_in_protocol;
    axis2_bool_t qname_free_flag = AXIS2_FALSE;

    AXIS2_PARAM_CHECK_VOID(env->error, svc_client);

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

    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;

    msg_ctx = axis2_msg_ctx_create(env, axis2_svc_ctx_get_conf_ctx(svc_client-> svc_ctx, env),
        NULL, NULL);
    if(!msg_ctx)
        return;

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

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

    axis2_op_client_set_callback(svc_client->op_client, env, callback);
    axis2_op_client_add_out_msg_ctx(svc_client->op_client, env, msg_ctx);

    /* If dual channel */
    if(axis2_options_get_use_separate_listener(svc_client->options, env))
    {
        axis2_op_t *op = NULL;

        transport_in_protocol = axis2_options_get_transport_in_protocol(svc_client->options, env);
        if(transport_in_protocol == AXIS2_TRANSPORT_ENUM_MAX)
        {
            axis2_options_set_transport_in_protocol(svc_client->options, env,
                AXIS2_TRANSPORT_ENUM_HTTP);
            transport_in_protocol = AXIS2_TRANSPORT_ENUM_HTTP;
        }
        axis2_listener_manager_make_sure_started(svc_client->listener_manager, env,
            transport_in_protocol, svc_client->conf_ctx);
        /* Following sleep is required to ensure the listener is ready to receive response.
         If it is missing, the response gets lost. - Samisa */
        AXIS2_USLEEP(1);

        op = axis2_svc_get_op_with_qname(svc_client->svc, env, op_qname);
        /* At the end of the incoming flow this message receiver will be hit */
        axis2_op_set_msg_recv(op, env,
            AXIS2_CALLBACK_RECV_GET_BASE(svc_client-> callback_recv, env));
        axis2_op_client_set_callback_recv(svc_client->op_client, env, svc_client->callback_recv);
    }

    axis2_op_client_execute(svc_client->op_client, env, AXIS2_FALSE);
    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));
    }

    if(qname_free_flag)
    {
        axutil_qname_free((axutil_qname_t *)op_qname, env);
        op_qname = NULL;
    }
}
Esempio n. 8
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);
}
Esempio n. 9
0
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_client_send_robust_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)
{
    axis2_msg_ctx_t *msg_ctx = NULL;
    axis2_status_t status = AXIS2_FAILURE;
    axis2_bool_t qname_free_flag = AXIS2_FALSE;

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

    if(!op_qname)
    {
        op_qname = axutil_qname_create(env, AXIS2_ANON_ROBUST_OUT_ONLY_OP, NULL, NULL);
        if(!op_qname)
        {
            return AXIS2_FAILURE;
        }
        qname_free_flag = AXIS2_TRUE;
    }
    else
    {
        axis2_op_t *op = NULL;
        axis2_char_t *mep = NULL;
        axis2_svc_t *svc = NULL;
        svc = axis2_svc_client_get_svc(svc_client, env);
        if(!svc)
        {
            return AXIS2_FAILURE;
        }
        op = axis2_svc_get_op_with_qname(svc, env, op_qname);
        if(!op)
        {
            return AXIS2_FAILURE;
        }
        mep = (axis2_char_t *)axis2_op_get_msg_exchange_pattern(op, env);
        if(!mep || axutil_strcmp(AXIS2_MEP_URI_OUT_ONLY, mep) != 0)
        {
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s%s",
                "To use this method opeation uri should be", AXIS2_MEP_URI_OUT_ONLY);
            return AXIS2_FAILURE;
        }
    }

    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;

    msg_ctx = axis2_msg_ctx_create(env, axis2_svc_ctx_get_conf_ctx(svc_client->svc_ctx, env), NULL,
        NULL);
    if(!axis2_svc_client_fill_soap_envelope(env, svc_client, msg_ctx, payload))
    {
        return AXIS2_FAILURE;
    }

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

    axis2_op_client_add_out_msg_ctx(svc_client->op_client, env, msg_ctx);
    status = 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));
    }

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

    return status;
}