diff options
Diffstat (limited to 'src/core/deployment')
26 files changed, 10975 insertions, 0 deletions
diff --git a/src/core/deployment/Makefile.am b/src/core/deployment/Makefile.am new file mode 100644 index 0000000..7099839 --- /dev/null +++ b/src/core/deployment/Makefile.am @@ -0,0 +1,38 @@ +noinst_LTLIBRARIES = libaxis2_deployment.la + +noinst_HEADERS = axis2_deployment.h \ + axis2_arch_file_data.h \ + axis2_arch_reader.h \ + axis2_conf_builder.h \ + axis2_dep_engine.h \ + axis2_desc_builder.h \ + axis2_module_builder.h \ + axis2_repos_listener.h \ + axis2_svc_builder.h \ + axis2_svc_grp_builder.h \ + axis2_ws_info.h \ + axis2_ws_info_list.h + +libaxis2_deployment_la_SOURCES =phases_info.c \ + desc_builder.c \ + arch_reader.c \ + dep_engine.c \ + arch_file_data.c \ + ws_info.c \ + ws_info_list.c \ + svc_builder.c \ + svc_grp_builder.c \ + module_builder.c \ + conf_builder.c \ + repos_listener.c \ + conf_init.c + +INCLUDES = -I$(top_builddir)/include \ + -I$(top_builddir)/src/core/description \ + -I$(top_builddir)/src/core/engine \ + -I$(top_builddir)/src/core/phaseresolver \ + -I$(top_builddir)/src/core/deployment \ + -I$(top_builddir)/src/core/util \ + -I$(top_builddir)/axiom/include \ + -I$(top_builddir)/neethi/include \ + -I$(top_builddir)/util/include diff --git a/src/core/deployment/arch_file_data.c b/src/core/deployment/arch_file_data.c new file mode 100644 index 0000000..b785399 --- /dev/null +++ b/src/core/deployment/arch_file_data.c @@ -0,0 +1,369 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_arch_file_data.h> +#include <string.h> +#include <axutil_class_loader.h> + +struct axis2_arch_file_data +{ + axutil_file_t *file; + int type; + axis2_char_t *msg_recv; + axis2_char_t *module_name; + axis2_char_t *module_dll_name; + axis2_char_t *name; + /* + * To store services in a service group. Those services are temporarily + * stored in this table + */ + axutil_hash_t *svc_map; + axutil_array_list_t *deployable_svcs; + +}; + +AXIS2_EXTERN axis2_arch_file_data_t *AXIS2_CALL +axis2_arch_file_data_create( + const axutil_env_t * env) +{ + axis2_arch_file_data_t *arch_file_data = NULL; + arch_file_data = (axis2_arch_file_data_t *)AXIS2_MALLOC(env-> allocator, + sizeof(axis2_arch_file_data_t)); + + if(!arch_file_data) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + memset((void *)arch_file_data, 0, sizeof(axis2_arch_file_data_t)); + + arch_file_data->deployable_svcs = axutil_array_list_create(env, 0); + if(!arch_file_data->deployable_svcs) + { + axis2_arch_file_data_free(arch_file_data, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + return arch_file_data; +} + +AXIS2_EXTERN axis2_arch_file_data_t *AXIS2_CALL +axis2_arch_file_data_create_with_type_and_file( + const axutil_env_t * env, + int type, + axutil_file_t * file) +{ + axis2_arch_file_data_t *arch_file_data = NULL; + arch_file_data = (axis2_arch_file_data_t *)axis2_arch_file_data_create(env); + if(!arch_file_data) + { + axis2_char_t *file_name = axutil_file_get_name(file, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not create arch_file_data for file %s", + file_name); + return NULL; + } + + arch_file_data->type = type; + arch_file_data->file = axutil_file_clone(file, env); + return arch_file_data; +} + +AXIS2_EXTERN axis2_arch_file_data_t *AXIS2_CALL +axis2_arch_file_data_create_with_type_and_name( + const axutil_env_t * env, + int type, + const axis2_char_t * name) +{ + axis2_arch_file_data_t *arch_file_data = NULL; + arch_file_data = (axis2_arch_file_data_t *)axis2_arch_file_data_create(env); + if(!arch_file_data) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not create arch_file_data for %s", name); + return NULL; + } + arch_file_data->type = type; + arch_file_data->name = axutil_strdup(env, name); + return arch_file_data; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_arch_file_data_free( + axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + if(arch_file_data->file) + { + axutil_file_free(arch_file_data->file, env); + } + if(arch_file_data->msg_recv) + { + AXIS2_FREE(env->allocator, arch_file_data->msg_recv); + } + if(arch_file_data->module_name) + { + AXIS2_FREE(env->allocator, arch_file_data->module_name); + } + if(arch_file_data->module_dll_name) + { + AXIS2_FREE(env->allocator, arch_file_data->module_dll_name); + } + if(arch_file_data->name) + { + AXIS2_FREE(env->allocator, arch_file_data->name); + } + + if(arch_file_data->svc_map) + { + axutil_hash_index_t *hi = NULL; + void *val = NULL; + + for(hi = axutil_hash_first(arch_file_data->svc_map, env); hi; hi + = axutil_hash_next(env, hi)) + { + axis2_svc_t *svc = NULL; + axutil_hash_this(hi, NULL, NULL, &val); + svc = (axis2_svc_t *)val; + if(svc) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Service name :%s", axis2_svc_get_name(svc, + env)); + axis2_svc_free(svc, env); + } + } + axutil_hash_free(arch_file_data->svc_map, env); + } + if(arch_file_data->deployable_svcs) + { + axutil_array_list_free(arch_file_data->deployable_svcs, env); + } + + if(arch_file_data) + { + AXIS2_FREE(env->allocator, arch_file_data); + } + + return; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_arch_file_data_get_msg_recv( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + return arch_file_data->msg_recv; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_arch_file_data_set_msg_recv( + axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env, + axis2_char_t * msg_recv) +{ + AXIS2_PARAM_CHECK(env->error, msg_recv, AXIS2_FAILURE); + + if(arch_file_data->msg_recv) + { + AXIS2_FREE(env->allocator, arch_file_data->msg_recv); + arch_file_data->msg_recv = NULL; + } + arch_file_data->msg_recv = axutil_strdup(env, msg_recv); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_arch_file_data_get_name( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + return axutil_file_get_name(arch_file_data->file, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_arch_file_data_get_svc_name( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + axis2_char_t *svc_name = NULL; + + if(arch_file_data->file) + { + svc_name = axutil_file_get_name(arch_file_data->file, env); + } + else + { + svc_name = arch_file_data->name; + } + + return svc_name; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_arch_file_data_get_type( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + return arch_file_data->type; +} + +AXIS2_EXTERN axutil_file_t *AXIS2_CALL +axis2_arch_file_data_get_file( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + return arch_file_data->file; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_arch_file_data_get_module_name( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + axis2_char_t *module_name = NULL; + + if(arch_file_data->file) + { + module_name = axutil_file_get_name(arch_file_data->file, env); + } + else + { + module_name = arch_file_data->module_name; + } + return module_name; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_arch_file_data_set_module_name( + axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env, + axis2_char_t * module_name) +{ + AXIS2_PARAM_CHECK(env->error, module_name, AXIS2_FAILURE); + + if(arch_file_data->module_name) + { + AXIS2_FREE(env->allocator, arch_file_data->module_name); + arch_file_data->module_name = NULL; + } + arch_file_data->module_name = axutil_strdup(env, module_name); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_arch_file_data_get_module_dll_name( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + return arch_file_data->module_dll_name; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_arch_file_data_set_module_dll_name( + axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env, + axis2_char_t * module_dll_name) +{ + AXIS2_PARAM_CHECK(env->error, module_dll_name, AXIS2_FAILURE); + + if(arch_file_data->module_dll_name) + { + AXIS2_FREE(env->allocator, arch_file_data->module_dll_name); + arch_file_data->module_dll_name = NULL; + } + arch_file_data->module_dll_name = axutil_strdup(env, module_dll_name); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_arch_file_data_add_svc( + axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env, + axis2_svc_t * svc_desc) +{ + const axutil_qname_t *svc_qname = NULL; + axis2_char_t *svc_name = NULL; + AXIS2_PARAM_CHECK(env->error, svc_desc, AXIS2_FAILURE); + + svc_qname = axis2_svc_get_qname(svc_desc, env); + svc_name = axutil_qname_to_string((axutil_qname_t *)svc_qname, env); + if(!arch_file_data->svc_map) + { + arch_file_data->svc_map = axutil_hash_make(env); + if(!arch_file_data->svc_map) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + axutil_hash_set(arch_file_data->svc_map, svc_name, AXIS2_HASH_KEY_STRING, svc_desc); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN struct axis2_svc *AXIS2_CALL +axis2_arch_file_data_get_svc( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env, + axis2_char_t * svc_name) +{ + axis2_svc_t *svc = NULL; + + AXIS2_PARAM_CHECK(env->error, svc_name, NULL); + + if(arch_file_data->svc_map) + { + svc = (axis2_svc_t *)axutil_hash_get(arch_file_data->svc_map, svc_name, + AXIS2_HASH_KEY_STRING); + } + else + { + return NULL; + } + return svc; +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +axis2_arch_file_data_get_svc_map( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + return arch_file_data->svc_map; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_arch_file_data_get_deployable_svcs( + const axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env) +{ + return arch_file_data->deployable_svcs; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_arch_file_data_set_deployable_svcs( + axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env, + axutil_array_list_t * deployable_svcs) +{ + AXIS2_PARAM_CHECK(env->error, deployable_svcs, AXIS2_FAILURE); + if(arch_file_data->deployable_svcs) + { + AXIS2_FREE(env->allocator, arch_file_data->deployable_svcs); + arch_file_data->deployable_svcs = NULL; + } + arch_file_data->deployable_svcs = deployable_svcs; + return AXIS2_SUCCESS; +} + diff --git a/src/core/deployment/arch_reader.c b/src/core/deployment/arch_reader.c new file mode 100644 index 0000000..3403d8e --- /dev/null +++ b/src/core/deployment/arch_reader.c @@ -0,0 +1,313 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_arch_reader.h> +#include <string.h> +#include <axutil_class_loader.h> +#include <axis2_svc_builder.h> +#include <axis2_module_builder.h> +#include <axis2_svc.h> + +struct axis2_arch_reader +{ + axis2_desc_builder_t *desc_builder; +}; + +AXIS2_EXTERN axis2_arch_reader_t *AXIS2_CALL +axis2_arch_reader_create( + const axutil_env_t * env) +{ + axis2_arch_reader_t *arch_reader = NULL; + + arch_reader = (axis2_arch_reader_t *)AXIS2_MALLOC(env-> allocator, sizeof(axis2_arch_reader_t)); + + if(!arch_reader) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + arch_reader->desc_builder = NULL; + + return arch_reader; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_arch_reader_free( + axis2_arch_reader_t * arch_reader, + const axutil_env_t * env) +{ + /* Description builder is owned by dep_engine, so do not free it here */ + + if(arch_reader) + { + AXIS2_FREE(env->allocator, arch_reader); + } + + return; +} + +AXIS2_EXTERN struct axis2_svc *AXIS2_CALL +axis2_arch_reader_create_svc( + const axutil_env_t * env, + struct axis2_arch_file_data *file) +{ + axis2_svc_t *svc = NULL; + svc = axis2_svc_create(env); + return svc; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_arch_reader_process_svc_grp( + axis2_arch_reader_t * arch_reader, + const axutil_env_t * env, + axis2_char_t * file_name, + struct axis2_dep_engine * dep_engine, + axis2_svc_grp_t * svc_grp) +{ + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t *svc_grp_xml = NULL; + axis2_char_t *repos_path = NULL; + axis2_bool_t file_flag = AXIS2_FALSE; + AXIS2_PARAM_CHECK(env->error, file_name, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, svc_grp, AXIS2_FAILURE); + + file_flag = axis2_dep_engine_get_file_flag(dep_engine, env); + + if(!file_flag) + { + + repos_path = axis2_dep_engine_get_repos_path(dep_engine, env); + + svc_grp_xml = axutil_strcat(env, repos_path, AXIS2_PATH_SEP_STR, AXIS2_SERVICE_FOLDER, + AXIS2_PATH_SEP_STR, file_name, AXIS2_PATH_SEP_STR, AXIS2_SVC_XML, NULL); + } + else + { + repos_path = axis2_dep_engine_get_svc_dir(dep_engine, env); + svc_grp_xml = axutil_strcat(env, repos_path, AXIS2_PATH_SEP_STR, file_name, + AXIS2_PATH_SEP_STR, AXIS2_SVC_XML, NULL); + } + + if(!svc_grp_xml) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service xml file not found for %s", file_name); + return AXIS2_FAILURE; + } + status = axutil_file_handler_access(svc_grp_xml, AXIS2_F_OK); + if(AXIS2_SUCCESS == status) + { + struct axis2_arch_file_data *arch_file_data = NULL; + axis2_char_t *svc_name = NULL; + + status + = axis2_arch_reader_build_svc_grp(arch_reader, env, svc_grp_xml, dep_engine, svc_grp); + if(AXIS2_SUCCESS != status) + { + return status; + } + arch_file_data = axis2_dep_engine_get_current_file_item(dep_engine, env); + svc_name = axis2_arch_file_data_get_svc_name(arch_file_data, env); + axis2_svc_grp_set_name(svc_grp, env, svc_name); + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SERVICE_XML_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Access to service configuration file %s failed", + file_name); + status = AXIS2_FAILURE; + } + AXIS2_FREE(env->allocator, svc_grp_xml); + return status; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_arch_reader_build_svc_grp( + axis2_arch_reader_t * arch_reader, + const axutil_env_t * env, + axis2_char_t * svc_xml, + axis2_dep_engine_t * dep_engine, + axis2_svc_grp_t * svc_grp) +{ + axis2_char_t *root_element_name = NULL; + axiom_node_t *svc_grp_node = NULL; + axiom_element_t *svc_grp_element = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, svc_xml, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, svc_grp, AXIS2_FAILURE); + + arch_reader->desc_builder = axis2_desc_builder_create_with_file_and_dep_engine(env, svc_xml, + dep_engine); + if(!arch_reader->desc_builder) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Creating description builder for service file %s failed", svc_xml); + return AXIS2_FAILURE; + } + axis2_dep_engine_add_desc_builder(dep_engine, env, arch_reader->desc_builder); + + svc_grp_node = axis2_desc_builder_build_om(arch_reader->desc_builder, env); + + if(svc_grp_node) + { + svc_grp_element = axiom_node_get_data_element(svc_grp_node, env); + if(svc_grp_element) + { + root_element_name = axiom_element_get_localname(svc_grp_element, env); + } + } + + if(root_element_name && 0 == axutil_strcmp(AXIS2_SVC_ELEMENT, root_element_name)) + { + /* If service group is actually a service. In this case service group + * contain only single service */ + axis2_svc_t *svc = NULL; + axis2_svc_builder_t *svc_builder = NULL; + axis2_arch_file_data_t *file_data = NULL; + axutil_array_list_t *dep_svcs = NULL; + axis2_char_t *svc_name = NULL; + + file_data = axis2_dep_engine_get_current_file_item(dep_engine, env); + svc_name = axis2_arch_file_data_get_name(file_data, env); + svc = axis2_arch_file_data_get_svc(file_data, env, svc_name); + if(!svc) + { + axutil_qname_t *svc_qname = NULL; + + svc_qname = axutil_qname_create(env, svc_name, NULL, NULL); + svc = axis2_svc_create_with_qname(env, svc_qname); + status = axis2_arch_file_data_add_svc(file_data, env, svc); + axutil_qname_free(svc_qname, env); + if(AXIS2_SUCCESS != status) + { + axis2_svc_free(svc, env); + return status; + } + } + axis2_svc_set_parent(svc, env, svc_grp); + + svc_builder = axis2_svc_builder_create_with_dep_engine_and_svc(env, dep_engine, svc); + status = axis2_svc_builder_populate_svc(svc_builder, env, svc_grp_node); + axis2_dep_engine_add_svc_builder(dep_engine, env, svc_builder); + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Populating service failed for %s", svc_name); + return AXIS2_FAILURE; + } + + dep_svcs = axis2_arch_file_data_get_deployable_svcs(file_data, env); + if(!dep_svcs) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Deployable services list is NULL within arch file data"); + return AXIS2_FAILURE; + } + status = axutil_array_list_add(dep_svcs, env, svc); + if(AXIS2_SUCCESS != status) + { + return AXIS2_FAILURE; + } + + } + else if(root_element_name && 0 == axutil_strcmp(AXIS2_SVC_GRP_ELEMENT, root_element_name)) + { + axis2_svc_grp_builder_t *grp_builder = NULL; + grp_builder = axis2_svc_grp_builder_create_with_svc_and_dep_engine(env, svc_grp_node, + dep_engine); + status = axis2_svc_grp_builder_populate_svc_grp(grp_builder, env, svc_grp); + axis2_dep_engine_add_svc_grp_builder(dep_engine, env, grp_builder); + } + return status; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_arch_reader_read_module_arch( + const axutil_env_t * env, + axis2_char_t * file_name, + axis2_dep_engine_t * dep_engine, + axis2_module_desc_t * module_desc) +{ + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t *module_xml = NULL; + axis2_char_t *repos_path = NULL; + axis2_bool_t file_flag; + + AXIS2_PARAM_CHECK(env->error, file_name, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, module_desc, AXIS2_FAILURE); + + file_flag = axis2_dep_engine_get_file_flag(dep_engine, env); + if(!file_flag) + { + repos_path = axis2_dep_engine_get_repos_path(dep_engine, env); + module_xml = axutil_strcat(env, repos_path, AXIS2_PATH_SEP_STR, AXIS2_MODULE_FOLDER, + AXIS2_PATH_SEP_STR, file_name, AXIS2_PATH_SEP_STR, AXIS2_MODULE_XML, NULL); + } + else + { + repos_path = axis2_dep_engine_get_module_dir(dep_engine, env); + module_xml = axutil_strcat(env, repos_path, AXIS2_PATH_SEP_STR, file_name, + AXIS2_PATH_SEP_STR, AXIS2_MODULE_XML, NULL); + } + + if(!module_xml) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return AXIS2_FAILURE; + } + status = axutil_file_handler_access(module_xml, AXIS2_F_OK); + + if(AXIS2_SUCCESS == status) + { + axis2_module_builder_t *module_builder = NULL; + module_builder = axis2_module_builder_create_with_file_and_dep_engine_and_module(env, + module_xml, dep_engine, module_desc); + status = axis2_module_builder_populate_module(module_builder, env); + axis2_dep_engine_add_module_builder(dep_engine, env, module_builder); + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MODULE_XML_NOT_FOUND_FOR_THE_MODULE, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Module configuration file access failed for module file %s", module_xml); + status = AXIS2_FAILURE; + } + AXIS2_FREE(env->allocator, module_xml); + return status; +} + +AXIS2_EXTERN axutil_file_t *AXIS2_CALL +axis2_arch_reader_create_module_arch( + const axutil_env_t * env, + axis2_char_t * module_name) +{ + axutil_file_t *file = NULL; + + file = axutil_file_create(env); + if(!file) + { + return NULL; + } + axutil_file_set_name(file, env, module_name); + return file; +} + diff --git a/src/core/deployment/axis2_arch_file_data.h b/src/core/deployment/axis2_arch_file_data.h new file mode 100644 index 0000000..d27d065 --- /dev/null +++ b/src/core/deployment/axis2_arch_file_data.h @@ -0,0 +1,265 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_ARCH_FILE_DATA_H +#define AXIS2_ARCH_FILE_DATA_H + +/** @defgroup axis2_arch_file_data Arch File Data + * @ingroup axis2_deployment + * @{ + */ + +/** + * @file axis2_arch_file_data.h + * @brief Axis2 Arch File Data interface. arch_file_data construct contain + * deployment information retrieved from a module or service configuration file. + */ +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_qname.h> +#include <axis2_conf.h> +#include <axutil_array_list.h> +#include <axutil_dir_handler.h> +#include <axutil_file.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct axis2_conf; + + /** Type name for struct axis2_arch_fila_data */ + typedef struct axis2_arch_file_data axis2_arch_file_data_t; + + /** + * De-allocate memory + * @param arch_file_data pointer to arch_file_data + * @param env pointer to environment struct + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_arch_file_data_free( + axis2_arch_file_data_t * arch_file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axis2_arch_file_data_get_msg_recv( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + * @param msg_recv pointer to message receiver + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_arch_file_data_set_msg_recv( + axis2_arch_file_data_t * file_data, + const axutil_env_t * env, + axis2_char_t * msg_recv); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + * @return the name of the contained file. + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axis2_arch_file_data_get_name( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + * @return the service name. If contained file is not null this is the + * file name. else this is the name property + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axis2_arch_file_data_get_svc_name( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + */ + AXIS2_EXTERN int AXIS2_CALL + axis2_arch_file_data_get_type( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + */ + AXIS2_EXTERN axutil_file_t *AXIS2_CALL + axis2_arch_file_data_get_file( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + + axis2_arch_file_data_get_module_name( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + * @param module_name pointer to module_name + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_arch_file_data_set_module_name( + axis2_arch_file_data_t * file_data, + const axutil_env_t * env, + axis2_char_t * module_name); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + + axis2_arch_file_data_get_module_dll_name( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_arch_file_data_set_module_dll_name( + axis2_arch_file_data_t * file_data, + const axutil_env_t * env, + axis2_char_t * module_dll_name); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_arch_file_data_add_svc( + axis2_arch_file_data_t * file_data, + const axutil_env_t * env, + struct axis2_svc *svc_desc); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + */ + AXIS2_EXTERN struct axis2_svc *AXIS2_CALL + axis2_arch_file_data_get_svc( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env, + axis2_char_t * svc_name); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + */ + AXIS2_EXTERN axutil_hash_t *AXIS2_CALL + axis2_arch_file_data_get_svc_map( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + */ + AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL + + axis2_arch_file_data_get_deployable_svcs( + const axis2_arch_file_data_t * file_data, + const axutil_env_t * env); + + /** + * @param file_data pointer to arch_file_data + * @param env pointer to environment struct + * @param deployable_svcs pointer to deployable services + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_arch_file_data_set_deployable_svcs( + axis2_arch_file_data_t * file_data, + const axutil_env_t * env, + axutil_array_list_t * deployable_svcs); + + /** + * Creates arch file data struct + * @param env pointer to environment struct + * @return pointer to newly created arch file data + */ + AXIS2_EXTERN axis2_arch_file_data_t *AXIS2_CALL + + axis2_arch_file_data_create( + const axutil_env_t * env); + + /** + * Creates arch file data struct + * @param env pointer to environment struct + * @param type type + * @param file folder name of service or module + * @return pointer to newly created arch file data + */ + AXIS2_EXTERN axis2_arch_file_data_t *AXIS2_CALL + + axis2_arch_file_data_create_with_type_and_file( + const axutil_env_t * env, + int type, + axutil_file_t * file); + + /** + * Creates arch file data struct + * @param env pointer to environment struct + * @param type type + * @param name pointer to name + * @return pointer to newly created arch file data + */ + AXIS2_EXTERN axis2_arch_file_data_t *AXIS2_CALL + + axis2_arch_file_data_create_with_type_and_name( + const axutil_env_t * env, + int type, + const axis2_char_t * name); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_ARCH_FILE_DATA_H */ diff --git a/src/core/deployment/axis2_arch_reader.h b/src/core/deployment/axis2_arch_reader.h new file mode 100644 index 0000000..274ded2 --- /dev/null +++ b/src/core/deployment/axis2_arch_reader.h @@ -0,0 +1,152 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_ARCH_READER_H +#define AXIS2_ARCH_READER_H + +/** @defgroup axis2_arch_reader Arch Reader + * @ingroup axis2_deployment + * @{ + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_qname.h> +#include <axis2_conf.h> +#include <axis2_deployment.h> +#include <axis2_arch_file_data.h> +#include <axis2_dep_engine.h> +#include <axutil_file_handler.h> +#include <axiom_element.h> +#include <axis2_desc_builder.h> +#include <axis2_svc_grp_builder.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct axis2_conf; + struct axis2_arch_file_data; + struct axis2_dep_engine; + + /** Type name for struct axis2_arch_reader */ + typedef struct axis2_arch_reader axis2_arch_reader_t; + + /** + * De-allocate memory + * @param arch_reader pointer to arch reader + * @param env pointer to environment struct + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_arch_reader_free( + axis2_arch_reader_t * arch_reader, + const axutil_env_t * env); + + /** + * To create a service descrption <code>axis2_svc_t</code> using given + * deployment info file. + * @param env pointer to environment struct + * @param file pointer to file + */ + AXIS2_EXTERN struct axis2_svc *AXIS2_CALL + axis2_arch_reader_create_svc( + const axutil_env_t * env, + struct axis2_arch_file_data *file); + + /** + * Construct the path to the service group configuration file(services.xml) + * using the passed file name and populate the passed service group + * description. + * @param arch_reader pointer to arch reader + * @param env pointer to environment struct + * @param file_name pointer to service group configuration file. + * @param dep_engine pointer to deployment engine + * @param svc_grp pointer to service group to be populated. + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_arch_reader_process_svc_grp( + axis2_arch_reader_t * arch_reader, + const axutil_env_t * env, + axis2_char_t * file_name, + struct axis2_dep_engine *dep_engine, + axis2_svc_grp_t * svc_grp); + + /** + * Populate the passed service group description using the service group + * configuration file(services.xml). + * @param arch_reader pointer to arch reader + * @param env pointer to environment struct + * @param file_path path to the service group configuration file(services.xml) + * @param dep_engine pointer to deployment engine + * @param svc_grp pointer to service group + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_arch_reader_build_svc_grp( + axis2_arch_reader_t * arch_reader, + const axutil_env_t * env, + axis2_char_t * file_path, + struct axis2_dep_engine *dep_engine, + struct axis2_svc_grp *svc_grp); + + /** + * Construct the path to the module configuration file(module.xml) + * using the passed file name and populate the passed module description. + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_arch_reader_read_module_arch( + const axutil_env_t * env, + axis2_char_t * file_path, + struct axis2_dep_engine *dep_engine, + axis2_module_desc_t * module); + + /** + * Create an axis2 file using the passed module name. + * @param env pointer to environment struct + * @param module_name pointer to module name + */ + AXIS2_EXTERN axutil_file_t *AXIS2_CALL + + axis2_arch_reader_create_module_arch( + const axutil_env_t * env, + axis2_char_t * module_name); + + /** + * Creates arch reader struct + * @param env pointer to environment struct + * @return pointer to newly created arch reader + */ + AXIS2_EXTERN axis2_arch_reader_t *AXIS2_CALL + axis2_arch_reader_create( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_ARCH_READER_H */ diff --git a/src/core/deployment/axis2_conf_builder.h b/src/core/deployment/axis2_conf_builder.h new file mode 100644 index 0000000..9a0aa91 --- /dev/null +++ b/src/core/deployment/axis2_conf_builder.h @@ -0,0 +1,116 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_CONF_BUILDER_H +#define AXIS2_CONF_BUILDER_H + +/** + * @defgroup axis2_conf_builder Conf Builder + * @ingroup axis2_deployment + * @{ + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_qname.h> +#include "axis2_desc_builder.h" +#include <axis2_conf.h> +#include "axis2_dep_engine.h" +#include <axiom_children_qname_iterator.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct axis2_desc_builder; + struct axis2_dep_engine; + + /** Type name for struct axis2_conf_builder */ + typedef struct axis2_conf_builder axis2_conf_builder_t; + + /** + * De-allocate memory + * @param conf_builder pointer to configuration builder + * @param env pointer to environment struct + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_conf_builder_free( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env); + + /** + * @param conf_builder pointer to configuration builder + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_conf_builder_populate_conf( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env); + + /** + * To get the list og modules that is requird to be engage globally + * @param conf_builder pointer to configuration builder + * @param env pointer to environment struct + * @param module_refs pointer to module refs + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_conf_builder_process_module_refs( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_refs); + + /** + * Creates conf builder struct + * @param env pointer to environment struct + * @return pointer to newly created conf builder + */ + AXIS2_EXTERN axis2_conf_builder_t *AXIS2_CALL + axis2_conf_builder_create( + const axutil_env_t * env); + + /** + * Creates conf builder struct + * @param env pointer to environment struct + * @param file This is the full path to the server xml file + * @param dep_engine pointer to dep engine + * @param conf pointer to conf + * @return pointer to newly created conf builder + */ + + AXIS2_EXTERN axis2_conf_builder_t *AXIS2_CALL + + axis2_conf_builder_create_with_file_and_dep_engine_and_conf( + const axutil_env_t * env, + axis2_char_t * file, + struct axis2_dep_engine *dep_engine, + axis2_conf_t * conf); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_CONF_BUILDER_H */ diff --git a/src/core/deployment/axis2_dep_engine.h b/src/core/deployment/axis2_dep_engine.h new file mode 100644 index 0000000..a9130af --- /dev/null +++ b/src/core/deployment/axis2_dep_engine.h @@ -0,0 +1,418 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_DEP_ENGINE_H +#define AXIS2_DEP_ENGINE_H + +/** + * @defgroup axis2_dep_engine Deployment Engine + * @ingroup axis2_deployment + * @{ + */ + +/** + * @file axis2_dep_engine.h + * @brief Axis2 Deployment Engine interface + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include "axis2_arch_file_data.h" +#include "axis2_ws_info.h" +#include "axis2_conf_builder.h" +#include "axis2_repos_listener.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + struct axis2_arch_file_data; + struct axis2_arch_reader; + struct axis2_ws_info; + struct axis2_phases_info; + struct axis2_svc; + + /** Type name for struct axis2_dep_engine */ + typedef struct axis2_dep_engine axis2_dep_engine_t; + struct axis2_desc_builder; + struct axis2_module_builder; + struct axis2_svc_builder; + struct axis2_grp_builder; + struct axis2_svc_grp_builder; + + /** + * De-allocate memory + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_dep_engine_free( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * while parsing the axis2.xml the module refferences have to be stored some + * where , since at that time none of module availble (they load after parsing + * the document) + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param module_qname <code>QName</code> + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_add_module( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axutil_qname_t * module_qname); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param module_name pointer to module name + */ + AXIS2_EXTERN struct axis2_module_desc *AXIS2_CALL + + axis2_dep_engine_get_module( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axutil_qname_t * module_name); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + */ + AXIS2_EXTERN struct axis2_arch_file_data *AXIS2_CALL + + axis2_dep_engine_get_current_file_item( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param file pointer to file + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_add_ws_to_deploy( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_arch_file_data *file); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param file pointer to file + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_dep_engine_add_ws_to_undeploy( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_ws_info *file); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + */ + AXIS2_EXTERN struct axis2_phases_info *AXIS2_CALL + axis2_dep_engine_get_phases_info( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @return AxisConfiguration <code>AxisConfiguration</code> + */ + AXIS2_EXTERN struct axis2_conf *AXIS2_CALL + axis2_dep_engine_get_axis_conf( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + */ + AXIS2_EXTERN struct axis2_conf *AXIS2_CALL + axis2_dep_engine_load( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + */ + AXIS2_EXTERN struct axis2_conf *AXIS2_CALL + axis2_dep_engine_load_client( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + const axis2_char_t * client_home); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param dll_name pointer to dll_name + */ + AXIS2_EXTERN void *AXIS2_CALL + axis2_dep_engine_get_handler_dll( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_char_t * dll_name); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_do_deploy( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_undeploy( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axis2_dep_engine_is_hot_update( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param phases_info pointer to phases info + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_set_phases_info( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_phases_info *phases_info); + + /** + * This method is used to fill a axisservice object using services.xml , first it should create + * an axisservice object using WSDL and then fill that using given servic.xml and load all the requed + * class and build the chains , finally add the servicecontext to EngineContext and axisservice into + * EngineConfiguration + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param svc pointer to service + * @param file_name pointer to file name + */ + AXIS2_EXTERN struct axis2_svc *AXIS2_CALL + axis2_dep_engine_build_svc( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_svc *svc, + axis2_char_t * file_name); + + /** + * This method can be used to build ModuleDescription for a given module archiev file + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param module_archive pointer to module archive + * @param conf pointer to conf + */ + AXIS2_EXTERN struct axis2_module_desc *AXIS2_CALL + axis2_dep_engine_build_module( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axutil_file_t * module_archive, + struct axis2_conf *conf); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axis2_dep_engine_get_repos_path( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * @param dep_engine pointer to module directory + * @param env pointer to environment struct + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axis2_dep_engine_get_file_flag( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + + /** + * @param dep_engine pointer to module directory + * @param env pointer to environment struct + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axis2_dep_engine_get_module_dir( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + /** + * @param dep_engine pointer to module directory + * @param env pointer to environment struct + * @param module_dir pointer of the directory path + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_set_module_dir( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + const axis2_char_t *module_dir); + + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axis2_dep_engine_get_svc_dir( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_set_svc_dir( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + const axis2_char_t *svc_dir); + + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param file_data pointer to file data + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_set_current_file_item( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_arch_file_data *file_data); + + /** + * @param dep_engine pointer to deployment engine + * @param env pointer to environment struct + * @param arch_reader pointer to arch reader + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_set_arch_reader( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_arch_reader *arch_reader); + + /** + * No param constructor is need to deploye module and service programatically + * @param env pointer to environment struct + * @return pointer to newly created deployment engine + */ + AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL + axis2_dep_engine_create( + const axutil_env_t * env); + + /** + * Creates description builder struct + * This the constructor which is used by Engine in order to start + * Deployment module, + * @param env pointer to environment struct + * @param repos_path is the path to which Repositary Listner should listen. + * @return pointer to newly created deployment engine + */ + AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL + axis2_dep_engine_create_with_repos_name( + const axutil_env_t * env, + const axis2_char_t * repos_path); + + + /** + * Creates description builder struct using axis2 xml + * This the constructor which is used by Engine in order to start + * Deployment module, + * @param env pointer to environment struct + * @param axis2_xml is the path of the axis2.xml . + * @return pointer to newly created deployment engine + */ + AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL + axis2_dep_engine_create_with_axis2_xml( + const axutil_env_t * env, + const axis2_char_t * axis2_xml); + + + /** + * Creates deployment engine struct + * @param env pointer to environment struct + * @param repos_path is the path to which Repositary Listner should listen. + * @param svr_xml_file pointer to service xml file + * @return pointer to newly created deployment engine + */ + AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL + + axis2_dep_engine_create_with_repos_name_and_svr_xml_file( + const axutil_env_t * env, + const axis2_char_t * repos_path, + const axis2_char_t * svr_xml_file); + + AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL + axis2_dep_engine_create_with_svr_xml_file( + const axutil_env_t * env, + const axis2_char_t * svr_xml_file); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_add_desc_builder( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_desc_builder *desc_builder); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_add_module_builder( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_module_builder *module_builder); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_dep_engine_add_svc_builder( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_svc_builder *svc_builder); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_dep_engine_add_svc_grp_builder( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_svc_grp_builder *svc_grp_builder); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_DEP_ENGINE_H */ diff --git a/src/core/deployment/axis2_deployment.h b/src/core/deployment/axis2_deployment.h new file mode 100644 index 0000000..044f10f --- /dev/null +++ b/src/core/deployment/axis2_deployment.h @@ -0,0 +1,119 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_DEPLOYMENT_H +#define AXIS2_DEPLOYMENT_H + +/** + * @file axis2_axis2_deployment.h + * @brief axis2 deployment + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_string.h> +#include <axutil_hash.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +/*********************************** Constansts********************************/ + +/** + * DeployCons interface is to keep constent value required for Deployemnt + */ + +#define AXIS2_SVC 0 /* if it is a service */ +#define AXIS2_MODULE 1 /* if it is a module */ + +#define AXIS2_SVC_XML "services.xml" +#define AXIS2_MODULE_XML "module.xml" +#define AXIS2_PARAMETERST "parameter" /* paramater start tag */ +#define AXIS2_HANDLERST "handler" +#define AXIS2_MODULEST "module" +#define AXIS2_PHASEST "phase" +#define AXIS2_PHASE_ORDER "phaseOrder" +#define AXIS2_OPERATIONST "operation" /* operation start tag */ +#define AXIS2_IN_FLOW_START "inflow" /* inflow start tag */ +#define AXIS2_OUT_FLOW_START "outflow" /* outflowr start tag */ +#define AXIS2_IN_FAILTFLOW "INfaultflow" /* faultflow start tag */ +#define AXIS2_OUT_FAILTFLOW "Outfaultflow" /* faultflow start tag */ + +#define AXIS2_MODULE_PATH "modules" +#define AXIS2_SVC_PATH "services" + +/* for parameters */ +#define AXIS2_ATTNAME "name" +#define AXIS2_ATTLOCKED "locked" +#define AXIS2_TYPE "type" + +/* for operations */ +#define AXIS2_MEP "mep" + +/* for messages */ +#define AXIS2_MESSAGE "message" +#define AXIS2_LABEL "label" + +/* for handlers */ +#define AXIS2_REF "ref" +#define AXIS2_CLASSNAME "class" +#define AXIS2_BEFORE "before" +#define AXIS2_AFTER "after" +#define AXIS2_PHASE "phase" +#define AXIS2_PHASEFIRST "phaseFirst" +#define AXIS2_PHASELAST "phaseLast" +#define AXIS2_ORDER "order" /* to resolve the order tag */ +#define AXIS2_DESCRIPTION "description" + +#define AXIS2_TRANSPORTSENDER "transportSender" +#define AXIS2_TRANSPORTRECEIVER "transportReceiver" + +#define AXIS2_MESSAGERECEIVER "messageReceiver" + +#define AXIS2_HOTDEPLOYMENT "hotdeployment" +#define AXIS2_HOTUPDATE "hotupdate" +#define AXIS2_DISPATCH_ORDER "dispatchOrder" +#define AXIS2_DISPATCHER "dispatcher" + +/* element in a services.xml */ +#define AXIS2_SVC_ELEMENT "service" +#define AXIS2_SVC_WSDL_PATH "wsdl_path" +#define AXIS2_SVC_GRP_ELEMENT "serviceGroup" + +#define AXIS2_SERVER_XML_FILE "axis2.xml" + +#define AXIS2_MODULE_FOLDER "modules" +#define AXIS2_SERVICE_FOLDER "services" +#define AXIS2_LIB_FOLDER "lib" +#define AXIS2_LIB_DIR "libDir" + +#define AXIS2_ATTRIBUTE_DEFAULT_VERSION "version" +#define AXIS2_DEFAULT_MODULE_VERSION "defaultModuleVersions" + +/*********************************** Constants*********************************/ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_DEPLOYMENT_H */ diff --git a/src/core/deployment/axis2_desc_builder.h b/src/core/deployment/axis2_desc_builder.h new file mode 100644 index 0000000..347f592 --- /dev/null +++ b/src/core/deployment/axis2_desc_builder.h @@ -0,0 +1,292 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_DESC_BUILDER_H +#define AXIS2_DESC_BUILDER_H + +/** @defgroup axis2_desc_builder Description Builder + * @ingroup axis2_deployment + * @{ + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include "axis2_deployment.h" +#include "axis2_dep_engine.h" +#include <axis2_flow.h> +#include <axiom_stax_builder.h> +#include <axiom_document.h> +#include <axiom_element.h> +#include <axiom_node.h> +#include <axutil_param_container.h> +#include <axis2_handler_desc.h> +#include <axiom_attribute.h> +#include <axiom_xml_reader.h> +#include <axis2_handler_desc.h> +#include <axis2_op.h> +#include <axiom_children_with_specific_attribute_iterator.h> +#include <axis2_phase.h> +#include <axis2_core_dll_desc.h> +#include <axis2_policy_include.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct axis2_flow; + struct axis2_phase; + struct axis2_dep_engine; + + /** Type name for struct axis2_desc_builder */ + typedef struct axis2_desc_builder axis2_desc_builder_t; + + /** + * De-allocate memory + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_desc_builder_free( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env); + + /** + * This will creat OMElemnt for a given descrition document (axis2.xml , + * services.xml and module.xml) + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + * @return OMElement <code>OMElement</code> + */ + AXIS2_EXTERN axiom_node_t *AXIS2_CALL + axis2_desc_builder_build_om( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env); + + /** + * To process Flow elements in services.xml + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + * @param flow_element <code>axiom_element_t</code> + * @param parent pointer to parent + * @param node pointer to node + * @return flow + */ + AXIS2_EXTERN axis2_flow_t *AXIS2_CALL + axis2_desc_builder_process_flow( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_element_t * flow_element, + axutil_param_container_t * parent, + axiom_node_t * node); + + /** + * To process Handler element + * @param handler_element <code>OMElement</code> + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + * @param handler_element pointer to handler element + * @param parent pointer to parent + */ + AXIS2_EXTERN axis2_handler_desc_t *AXIS2_CALL + + axis2_desc_builder_process_handler( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_node_t * handler_element, + axutil_param_container_t * parent); + + /** + * To get the Param out from the OM + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + * @param params <code>axutil_param_t</code> + * @param param_container <code>axutil_param_container_t</code> + * @param parent <code>axutil_param_container_t</code> + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_desc_builder_process_params( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * params, + axutil_param_container_t * param_container, + axutil_param_container_t * parent); + + /** + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + * @param module_refs pointer to module refs + * @param op pointer to op + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_desc_builder_process_op_module_refs( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_refs, + axis2_op_t * op); + + /** + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + * @param recv_element pointer to recv element + */ + AXIS2_EXTERN axis2_msg_recv_t *AXIS2_CALL + + axis2_desc_builder_load_msg_recv( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_element_t * recv_element); + + /** + * This method is used to retrive service name form the arechive file name + * if the archive file name is service1.aar , then axis service name would be service1 + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + * @param file_name pointer to file name + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + + axis2_desc_builder_get_short_file_name( + const axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axis2_char_t * file_name); + + /** + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + * @param short_file_name pointer to short file name + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + + axis2_desc_builder_get_file_name_without_prefix( + const axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axis2_char_t * short_file_name); + + /** + * this method is to get the value of attribue + * eg xsd:anyVal --> anyVal + * @param desc_builder pointer to desc builder + * @param env pointer to environment struct + * @param in pointer to in + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axis2_desc_builder_get_value( + const axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axis2_char_t * in); + + /** + * Populate the Axis2 Operation with details from the actionMapping, + * outputActionMapping and faultActionMapping elements from the operation + * element. + * @param operation + * @param op_desc + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_desc_builder_process_action_mappings( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_node_t * op_node, + axis2_op_t * op_desc); + + /** + * Populate the Axis2 Operation with details from the RESTLocation, + * RESTMethod elements from the operation element. + * @param operation + * @param op_desc + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_desc_builder_process_rest_params( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_node_t * op_node, + axis2_op_t * op_desc); + + /** + * @param env pointer to environment struct + */ + AXIS2_EXTERN struct axis2_msg_recv *AXIS2_CALL + axis2_desc_builder_load_default_msg_recv( + const axutil_env_t * env); + + AXIS2_EXTERN struct axis2_dep_engine *AXIS2_CALL + axis2_desc_builder_get_dep_engine( + const axis2_desc_builder_t * desc_builder, + const axutil_env_t * env); + + /** + * Creates description builder struct + * @param env pointer to environment struct + * @return pointer to newly created description builder + */ + AXIS2_EXTERN axis2_desc_builder_t *AXIS2_CALL + axis2_desc_builder_create( + const axutil_env_t * env); + + /** + * Creates description builder struct + * @param env pointer to environment struct + * @param engine pointer to engine + * @return pointer to newly created description builder + */ + AXIS2_EXTERN axis2_desc_builder_t *AXIS2_CALL + + axis2_desc_builder_create_with_dep_engine( + const axutil_env_t * env, + struct axis2_dep_engine *engine); + + /** + * Creates description builder struct + * @param env pointer to environment struct + * @param file_name pointer to file name + * @param engine pointer to engine + * @return pointer to newly created description builder + */ + AXIS2_EXTERN axis2_desc_builder_t *AXIS2_CALL + + axis2_desc_builder_create_with_file_and_dep_engine( + const axutil_env_t * env, + axis2_char_t * file_name, + struct axis2_dep_engine *engine); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_process_policy_elements( + const axutil_env_t * env, + int type, + axiom_children_qname_iterator_t * iterator, + axis2_policy_include_t * policy_include); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_process_policy_reference_elements( + const axutil_env_t * env, + int type, + axiom_children_qname_iterator_t * iterator, + axis2_policy_include_t * policy_include); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_DESC_BUILDER_H */ diff --git a/src/core/deployment/axis2_module_builder.h b/src/core/deployment/axis2_module_builder.h new file mode 100644 index 0000000..cd713d6 --- /dev/null +++ b/src/core/deployment/axis2_module_builder.h @@ -0,0 +1,101 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_MODULE_BUILDER_H +#define AXIS2_MODULE_BUILDER_H + +/** @defgroup axis2_module_builder Module Builder + * @ingroup axis2_deployment + * @{ + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_qname.h> +#include <axis2_module_desc.h> +#include <axis2_dep_engine.h> +#include <axis2_desc_builder.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** Type name for struct axis2_module_builder */ + typedef struct axis2_module_builder axis2_module_builder_t; + + /** + * De-allocate memory + * @param module_builder pointer to module builder + * @param env pointer to environment struct + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_module_builder_free( + axis2_module_builder_t * module_builder, + const axutil_env_t * env); + + /** + * @param module_builder pointer to module builder + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_module_builder_populate_module( + axis2_module_builder_t * module_builder, + const axutil_env_t * env); + + /** + * Creates module builder struct + * @param env pointer to environment struct + * @return pointer to newly created module builder + */ + AXIS2_EXTERN axis2_module_builder_t *AXIS2_CALL + + axis2_module_builder_create( + const axutil_env_t * env); + + /** + * Creates module builder struct + * @param env pointer to environment struct + * @param file_name pointer to file name + * @param dep_engine pointer to deployment engine + * @return pointer to newly created module builder + */ + AXIS2_EXTERN axis2_module_builder_t *AXIS2_CALL + + axis2_module_builder_create_with_file_and_dep_engine_and_module( + const axutil_env_t * env, + axis2_char_t * file_name, + struct axis2_dep_engine *dep_engine, + axis2_module_desc_t * module); + + /** Populates the module. + #define AXIS2_MODULE_BUILDER_POPULATE_MODULE(module_builder, env) \ + axis2_module_builder_populate_module (module_builder, env)*/ + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_MODULE_BUILDER_H */ diff --git a/src/core/deployment/axis2_repos_listener.h b/src/core/deployment/axis2_repos_listener.h new file mode 100644 index 0000000..56a37c8 --- /dev/null +++ b/src/core/deployment/axis2_repos_listener.h @@ -0,0 +1,144 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_REPOS_LISTENER_H +#define AXIS2_REPOS_LISTENER_H + +/** @defgroup axis2_repos_listener Repos Listener + * @ingroup axis2_deployment + * @{ + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_qname.h> +#include <axutil_array_list.h> +#include "axis2_ws_info_list.h" +#include "axis2_dep_engine.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct axis2_dep_engine; + + /** Type name for struct axis2_repos_listener */ + typedef struct axis2_repos_listener axis2_repos_listener_t; + + /** + * De-allocate memory + * @param repos_listener pointer to repos listener + * @param env pointer to environment struct + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_repos_listener_free( + axis2_repos_listener_t * repos_listener, + const axutil_env_t * env); + + /** + * + * @param repos_listener pointer to repos listener + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_repos_listener_check_modules( + axis2_repos_listener_t * listener, + const axutil_env_t * env); + + /** + * + * @param repos_listener pointer to repos listener + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_repos_listener_check_svcs( + axis2_repos_listener_t * listener, + const axutil_env_t * env); + + /** + * + * @param repos_listener pointer to repos listener + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_repos_listener_update( + axis2_repos_listener_t * listener, + const axutil_env_t * env); + + /** + * + * then it call to check_modules to load all the modules. + * and then it call to update() method inorder to update the deployment engine and engine. + * @param repos_listener pointer to repos listener + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_repos_listener_init( + axis2_repos_listener_t * listener, + const axutil_env_t * env); + + /** + * @param env pointer to environment struct + * @return pointer to newly created deployment engine + */ + AXIS2_EXTERN axis2_repos_listener_t *AXIS2_CALL + axis2_repos_listener_create( + const axutil_env_t * env); + + /** + * @param env pointer to environment struct + * @param folder_name this is the axis2 deployment root directory(repository path) + * @param dep_engine pointer to deployment engine + * @return pointer to newly created deployment engine + */ + AXIS2_EXTERN axis2_repos_listener_t *AXIS2_CALL + axis2_repos_listener_create_with_folder_name_and_dep_engine( + const axutil_env_t * env, + axis2_char_t * folder_name, + struct axis2_dep_engine *dep_engine); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_repos_listener_set_conf( + axis2_repos_listener_t *repo_listener, + const axutil_env_t * env, + axis2_conf_t *conf); + + AXIS2_EXTERN axis2_conf_t *AXIS2_CALL + axis2_repos_listener_get_conf( + axis2_repos_listener_t *repo_listener, + const axutil_env_t * env); + + + + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_REPOS_LISTENER_H */ diff --git a/src/core/deployment/axis2_svc_builder.h b/src/core/deployment/axis2_svc_builder.h new file mode 100644 index 0000000..c71e7dc --- /dev/null +++ b/src/core/deployment/axis2_svc_builder.h @@ -0,0 +1,149 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_SVC_BUILDER_H +#define AXIS2_SVC_BUILDER_H + +/** + * @defgroup axis2_svc_builder Service Builder + * @ingroup axis2_deployment + * @{ + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_qname.h> +#include <axis2_desc_builder.h> +#include <axis2_addr.h> +#include <axis2_dep_engine.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct axis2_dep_engine; + + /** Type name for struct axis2_svc_builder */ + typedef struct axis2_svc_builder axis2_svc_builder_t; + + /** + * De-allocate memory + * @param svc_builder pointer to service builder + * @param env pointer to environment struct + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_svc_builder_free( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env); + + /** + * top most method that is used to populate service from corresponding OM + * @param svc_builder pointer to service builder + * @param env pointer to environment struct + * @param svc_node pointer to service node + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_svc_builder_populate_svc( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_node_t * svc_node); + + /** + * @param svc_builder pointer to service builder + * @param env pointer to environment struct + * @param module_confs pointer to module configurations + * @param parent pointer to parent + * @param svc pointer to service + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_svc_builder_process_svc_module_conf( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_confs, + axutil_param_container_t * parent, + axis2_svc_t * svc); + + /** + * To get the list og modules that is requird to be engage globally + * @param svc_builder pointer to service builder + * @param env pointer to environment struct + * @param module_refs pointer to module refs + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_svc_builder_process_module_refs( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_refs); + + AXIS2_EXTERN struct axis2_desc_builder *AXIS2_CALL + + axis2_svc_builder_get_desc_builder( + const axis2_svc_builder_t * svc_builder, + const axutil_env_t * env); + + /** + * Creates svc builder struct + * @param env pointer to environment struct + * @return pointer to newly created service builder + */ + AXIS2_EXTERN axis2_svc_builder_t *AXIS2_CALL + axis2_svc_builder_create( + const axutil_env_t * env); + + /** + * Creates svc builder struct + * @param env pointer to environment struct + * @param file_name pointer to file name + * @param dep_engine pointer to deployment engine + * @param svc pointer to service + * @return pointer to newly created service builder + */ + AXIS2_EXTERN axis2_svc_builder_t *AXIS2_CALL + + axis2_svc_builder_create_with_file_and_dep_engine_and_svc( + const axutil_env_t * env, + axis2_char_t * file_name, + struct axis2_dep_engine *dep_engine, + axis2_svc_t * svc); + + /** + * Creates svc builder struct + * @param env pointer to environment struct + * @param dep_engine pointer to deployment engine + * @param svc pointer to service + * @return pointer to newly created service builder + */ + AXIS2_EXTERN axis2_svc_builder_t *AXIS2_CALL + + axis2_svc_builder_create_with_dep_engine_and_svc( + const axutil_env_t * env, + struct axis2_dep_engine *dep_engine, + axis2_svc_t * svc); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_SVC_BUILDER_H */ diff --git a/src/core/deployment/axis2_svc_grp_builder.h b/src/core/deployment/axis2_svc_grp_builder.h new file mode 100644 index 0000000..852c9a7 --- /dev/null +++ b/src/core/deployment/axis2_svc_grp_builder.h @@ -0,0 +1,122 @@ + +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not svc_grp this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_SVC_GRP_BUILDER_H +#define AXIS2_SVC_GRP_BUILDER_H + +/** @defgroup axis2_svc_grp_builder Service Group Builder + * @ingroup axis2_deployment + * @{ + */ + +/** + * @file axis2_svc_grp_builder.h + * @brief Axis2 Service Group Builder interface + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_qname.h> +#include <axis2_desc_builder.h> +#include <axis2_svc_builder.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** Type name for struct axis2_svc_grp_builder */ + typedef struct axis2_svc_grp_builder axis2_svc_grp_builder_t; + + /** + * De-allocate memory + * @param svc_grp_builder pointer to service group builder + * @param env pointer to environment struct + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_svc_grp_builder_free( + axis2_svc_grp_builder_t * svc_grp_builder, + const axutil_env_t * env); + + /** + * @param grp_builder pointer to group builder + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_svc_grp_builder_populate_svc_grp( + axis2_svc_grp_builder_t * grp_builder, + const axutil_env_t * env, + axis2_svc_grp_t * svc_grp); + + /** + * To get the list og modules that is requird to be engage globally + * @param grp_builder pointer to group builder + * @param env pointer to environment struct + * @param module_refs <code>axiom_children_qname_iterator_t</code> + * @param svc_group pointer to service group + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_svc_grp_builder_process_module_refs( + axis2_svc_grp_builder_t * grp_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_refs, + axis2_svc_grp_t * svc_grp); + + AXIS2_EXTERN axis2_desc_builder_t *AXIS2_CALL + + axis2_svc_grp_builder_get_desc_builder( + const axis2_svc_grp_builder_t * svc_grp_builder, + const axutil_env_t * env); + + /** + * Creates svc_grp builder struct + * @param env pointer to environment struct + * @return pointer to newly created service group builder + */ + AXIS2_EXTERN axis2_svc_grp_builder_t *AXIS2_CALL + + axis2_svc_grp_builder_create( + const axutil_env_t * env); + + /** + * Creates svc_grp builder struct + * @param env pointer to environment strut + * @param svc pointer to service + * @param dep_engine pointer to deployment engine + * @return pointer to newly created service group builder + */ + AXIS2_EXTERN axis2_svc_grp_builder_t *AXIS2_CALL + + axis2_svc_grp_builder_create_with_svc_and_dep_engine( + const axutil_env_t * env, + axiom_node_t * svc, + axis2_dep_engine_t * dep_engine); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_SVC_GRP_BUILDER_H */ diff --git a/src/core/deployment/axis2_ws_info.h b/src/core/deployment/axis2_ws_info.h new file mode 100644 index 0000000..d6fd117 --- /dev/null +++ b/src/core/deployment/axis2_ws_info.h @@ -0,0 +1,144 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_WS_INFO_H +#define AXIS2_WS_INFO_H + +/** + * @defgroup axis2_ws_info Ws Info + * @ingroup axis2_deployment + * @{ + */ + +/** + * @file axis2_ws_info.h + * @brief Axis2 Ws Info interface. ws_info construct contain file information + * for module or service configuration file. + */ +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_qname.h> +#include <axis2_conf.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct axis2_conf; + + /** Type name for struct axis2_ws_info */ + typedef struct axis2_ws_info axis2_ws_info_t; + + /** + * De-allocate memory + * @param ws_info pointer to ws info + * @param env pointer to environment struct + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_ws_info_free( + axis2_ws_info_t * ws_info, + const axutil_env_t * env); + + /** + * @param ws_info pointer to ws info + * @param env pointer to environment struct + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axis2_ws_info_get_file_name( + const axis2_ws_info_t * ws_info, + const axutil_env_t * env); + + /** + * @param ws_info pointer to ws info + * @param env pointer to environment struct + * @param file_name pointer to file name + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_ws_info_set_file_name( + axis2_ws_info_t * ws_info, + const axutil_env_t * env, + axis2_char_t * file_name); + + /** + * @param ws_info pointer to ws info + * @param env pointer to environment struct + */ + AXIS2_EXTERN long AXIS2_CALL + axis2_ws_info_get_last_modified_date( + const axis2_ws_info_t * ws_info, + const axutil_env_t * env); + + /** + * @param ws_info pointer to ws info + * @param env pointer to environment struct + * @param modified_data pointer to modified date + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_ws_info_set_last_modified_date( + axis2_ws_info_t * ws_info, + const axutil_env_t * env, + long last_modified_date); + + /** + * @param ws_info pointer to ws info + * @param env pointer to environment struct + */ + AXIS2_EXTERN int AXIS2_CALL + axis2_ws_info_get_type( + const axis2_ws_info_t * ws_info, + const axutil_env_t * env); + + /** + * Creates ws_info struct + * @param env pointer to environment struct + * @param file_name pointer to file name + * @param last_modified_date pointer to last modified date + * @return pointer to newly created ws info + */ + AXIS2_EXTERN axis2_ws_info_t *AXIS2_CALL + + axis2_ws_info_create_with_file_name_and_last_modified_date( + const axutil_env_t * env, + axis2_char_t * file_name, + long last_modified_date); + + /** + * @param env pointer to environment struct + * @param file_name pointer to file name + * @param last_modifile_date last modified date + * @param type type + */ + AXIS2_EXTERN axis2_ws_info_t *AXIS2_CALL + + axis2_ws_info_create_with_file_name_and_last_modified_date_and_type( + const axutil_env_t * env, + axis2_char_t * file_name, + long last_modified_date, + int type); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_WS_INFO_H */ diff --git a/src/core/deployment/axis2_ws_info_list.h b/src/core/deployment/axis2_ws_info_list.h new file mode 100644 index 0000000..3ffb68d --- /dev/null +++ b/src/core/deployment/axis2_ws_info_list.h @@ -0,0 +1,192 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AXIS2_WS_INFO_LIST_H +#define AXIS2_WS_INFO_LIST_H + +/** @defgroup axis2_ws_info_list Ws Info List + * @ingroup axis2_deployment + * @{ + */ + +/** + * @file axis2_ws_info_list.h + * @brief Axis2 Ws Info List interface. Ws Info List is the list of ws_info structs. + * Each ws_info construct contain file information for module or service configuration file. + */ + +#include <axis2_const.h> +#include <axutil_error.h> +#include <axis2_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_qname.h> +#include <axis2_conf.h> +#include "axis2_deployment.h" +#include <axutil_file_handler.h> +#include <axutil_dir_handler.h> +#include "axis2_ws_info.h" +#include "axis2_arch_file_data.h" +#include "axis2_dep_engine.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct axis2_ws_info; + struct axis2_dep_engine; + + /** Type name for struct axis2_ws_info_list */ + typedef struct axis2_ws_info_list axis2_ws_info_list_t; + + /** + * De-allocate memory + * @param ws_info_list pointer to ws info list + * @param env pointer to environment struct + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_ws_info_list_free( + axis2_ws_info_list_t * ws_info_list, + const axutil_env_t * env); + + /** + * This method is used to initialize the ws info list. + * @param info_list pointer to ws info list + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_ws_info_list_init( + axis2_ws_info_list_t * info_list, + const axutil_env_t * env); + + /** + * This will add the deployment info struct(ws_info) into the deployment info + * list and deployment info file to the deployment engine as new + * service or module deployment info struct/file. + * In doing this, it first create an deployment info struct called ws_info + * to keep the file info that will be added to deployment info file + * list and then create deployment info file called arch_file_data that will + * be added to deployment engine for actual deployment of the service/module. + * + * This will add two entries to deployment engine one for new Deployment and + * other for undeployment. + * @param info_list pointer to ws info list + * @param env pointer to environment struct + * @param file actual axis2 configuration file for module/service. + * @param type indicate either service or module + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_ws_info_list_add_ws_info_item( + axis2_ws_info_list_t * info_list, + const axutil_env_t * env, + axutil_file_t * file, + int type); + + /** + * This method is used to check whether the service/module configuration + * file exist and if so it will return related ws_info object to the file, + * else return NULL; + * @param info_list pointer to ws info list + * @param env pointer to environment struct + * @param file_name pointer to file name + */ + AXIS2_EXTERN axis2_ws_info_t *AXIS2_CALL + + axis2_ws_info_list_get_file_item( + axis2_ws_info_list_t * info_list, + const axutil_env_t * env, + axis2_char_t * file_name); + + /** + * Compare the last update dates of both files and if those differ + * it will be assumed as the file has been modified. + * @param info_list pointer to ws info list + * @param env pointer to environment struct + * @param file pointer to servie/module configuration file. + * @param ws_info pointer to ws info struct. + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axis2_ws_info_list_is_modified( + axis2_ws_info_list_t * info_list, + const axutil_env_t * env, + axutil_file_t * file, + struct axis2_ws_info *ws_info); + + /** + * To check whether the deployment info file is alredy in the list. + * @param info_list pointer to ws info list + * @param env pointer to environment struct + * @param file_name pointer to file name + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axis2_ws_info_list_is_file_exist( + axis2_ws_info_list_t * info_list, + const axutil_env_t * env, + axis2_char_t * file_name); + + /** + * This is to check whether to undeploy ws info struct. + * What this realy does is, it check ws_info list and current deployment + * info name list. If ws_info exists in the ws_info_list but it's + * corresponding file name does not exist in the current deploymet file + * name list then, struct is deemed non existant. ie. that is hot + * undeployment. + * @param info_list pointer to ws info list + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axis2_ws_info_list_check_for_undeploy( + axis2_ws_info_list_t * info_list, + const axutil_env_t * env); + + /** + * @param info_list pointer to ws info list + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_ws_info_list_update( + axis2_ws_info_list_t * info_list, + const axutil_env_t * env); + + /** + * Creates ws info list struct + * @param env pointer to environment struct + * @param dep_engine pointer to deployment engine + * @return pointer to newly created ws info list + */ + AXIS2_EXTERN axis2_ws_info_list_t *AXIS2_CALL + + axis2_ws_info_list_create_with_dep_engine( + const axutil_env_t * env, + struct axis2_dep_engine *dep_engine); + + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_WS_INFO_LIST_H */ diff --git a/src/core/deployment/conf_builder.c b/src/core/deployment/conf_builder.c new file mode 100644 index 0000000..15485b0 --- /dev/null +++ b/src/core/deployment/conf_builder.c @@ -0,0 +1,1337 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_conf_builder.h> +#include <axis2_disp.h> +#include <axis2_conf.h> +#include <axutil_class_loader.h> +#include <axis2_transport_in_desc.h> +#include <axis2_transport_out_desc.h> +#include <axutil_utils.h> +#include <axis2_transport_receiver.h> + +struct axis2_conf_builder +{ + axis2_conf_t *conf; + struct axis2_desc_builder *desc_builder; +}; + +static axis2_status_t +axis2_conf_builder_process_disp_order( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_node_t * disp_order_node); + +static axis2_status_t +axis2_conf_builder_process_phase_orders( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * phase_orders); + +static axutil_array_list_t * +axis2_conf_builder_get_phase_list( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_node_t * phase_orders_node); + +static axis2_status_t +axis2_conf_builder_process_transport_senders( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * trs_senders); + +static axis2_status_t +axis2_conf_builder_process_transport_recvs( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * trs_recvs); + +static axis2_status_t AXIS2_CALL +axis2_conf_builder_process_default_module_versions( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_versions); + +AXIS2_EXTERN axis2_conf_builder_t *AXIS2_CALL +axis2_conf_builder_create( + const axutil_env_t * env) +{ + axis2_conf_builder_t *conf_builder = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + conf_builder = (axis2_conf_builder_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_conf_builder_t)); + + if(!conf_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + conf_builder->conf = NULL; + + return conf_builder; +} + +AXIS2_EXTERN axis2_conf_builder_t *AXIS2_CALL +axis2_conf_builder_create_with_file_and_dep_engine_and_conf( + const axutil_env_t * env, + axis2_char_t * file, + axis2_dep_engine_t * engine, + axis2_conf_t * conf) +{ + axis2_conf_builder_t *conf_builder = NULL; + + conf_builder = (axis2_conf_builder_t *)axis2_conf_builder_create(env); + if(!conf_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + conf_builder->desc_builder = axis2_desc_builder_create_with_file_and_dep_engine(env, file, + engine); + conf_builder->conf = conf; + + return conf_builder; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_conf_builder_free( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env) +{ + if(conf_builder->desc_builder) + { + axis2_desc_builder_free(conf_builder->desc_builder, env); + } + + if(conf_builder) + { + AXIS2_FREE(env->allocator, conf_builder); + } + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_conf_builder_populate_conf( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env) +{ + axutil_qname_t *qparamst = NULL; + axutil_qname_t *qmsgrecv = NULL; + axutil_qname_t *qdisporder = NULL; + axutil_qname_t *qmodulest = NULL; + axutil_qname_t *qtransportsender = NULL; + axutil_qname_t *qtransportrecv = NULL; + axutil_qname_t *qphaseorder = NULL; + axutil_qname_t *qdefmodver = NULL; + axiom_children_qname_iterator_t *itr = NULL; + axiom_children_qname_iterator_t *msg_recvs = NULL; + axiom_children_qname_iterator_t *module_itr = NULL; + axiom_children_qname_iterator_t *trs_senders = NULL; + axiom_children_qname_iterator_t *trs_recvs = NULL; + axiom_children_qname_iterator_t *phase_orders = NULL; + axiom_children_qname_iterator_t *def_mod_versions = NULL; + axiom_element_t *conf_element = NULL; + axiom_node_t *conf_node = NULL; + axiom_element_t *disp_order_element = NULL; + axiom_node_t *disp_order_node = NULL; + axis2_status_t status = AXIS2_FAILURE; + axutil_param_t *param = NULL; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_conf_builder_populate_conf"); + conf_node = axis2_desc_builder_build_om(conf_builder->desc_builder, env); + if(!conf_node) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Building om tree failed. Unable to continue"); + return AXIS2_FAILURE; + } + conf_element = axiom_node_get_data_element(conf_node, env); + /* processing Paramters */ + /* Processing service level paramters */ + qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + itr = axiom_element_get_children_with_qname(conf_element, env, qparamst, conf_node); + axutil_qname_free(qparamst, env); + axis2_desc_builder_process_params(conf_builder->desc_builder, env, itr, + axis2_conf_get_param_container(conf_builder->conf, env), axis2_conf_get_param_container( + conf_builder->conf, env)); + /* process Message Reciver */ + qmsgrecv = axutil_qname_create(env, AXIS2_MESSAGERECEIVER, NULL, NULL); + msg_recvs = axiom_element_get_children_with_qname(conf_element, env, qmsgrecv, conf_node); + axutil_qname_free(qmsgrecv, env); + while(axiom_children_qname_iterator_has_next(msg_recvs, env)) + { + axiom_node_t *msg_recv_node = NULL; + axiom_element_t *msg_recv_element = NULL; + axis2_msg_recv_t *msg_recv = NULL; + axiom_attribute_t *recv_name = NULL; + axutil_qname_t *class_qname = NULL; + axis2_char_t *class_name = NULL; + + msg_recv_node = (axiom_node_t *)axiom_children_qname_iterator_next(msg_recvs, env); + msg_recv_element = (axiom_element_t *)axiom_node_get_data_element(msg_recv_node, env); + msg_recv = axis2_desc_builder_load_msg_recv(conf_builder->desc_builder, env, + msg_recv_element); + if(!msg_recv) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Message receiver loading failed. Unable to continue"); + return AXIS2_FAILURE; + } + + class_qname = axutil_qname_create(env, AXIS2_CLASSNAME, NULL, NULL); + recv_name = axiom_element_get_attribute(msg_recv_element, env, class_qname); + axutil_qname_free(class_qname, env); + class_name = axiom_attribute_get_value(recv_name, env); + axis2_conf_add_msg_recv(conf_builder->conf, env, class_name, msg_recv); + } + + /* processing Dispatching Order */ + qdisporder = axutil_qname_create(env, AXIS2_DISPATCH_ORDER, NULL, NULL); + disp_order_element = axiom_element_get_first_child_with_qname(conf_element, env, qdisporder, + conf_node, &disp_order_node); + axutil_qname_free(qdisporder, env); + if(disp_order_element) + { + axis2_conf_builder_process_disp_order(conf_builder, env, disp_order_node); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Found the custom disptaching" + " order and continue with that order"); + } + else + { + status = axis2_conf_set_default_dispatchers(conf_builder->conf, env); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting default dispatchers to configuration failed, " + "unable to continue."); + return AXIS2_FAILURE; + } + + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No custom dispatching order" + " found. Continue with the default dispatching order"); + } + + /* Process Module refs */ + qmodulest = axutil_qname_create(env, AXIS2_MODULEST, NULL, NULL); + module_itr = axiom_element_get_children_with_qname(conf_element, env, qmodulest, conf_node); + axutil_qname_free(qmodulest, env); + status = axis2_conf_builder_process_module_refs(conf_builder, env, module_itr); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Processing module ref's failed, unable to continue."); + return AXIS2_FAILURE; + } + /* Proccessing Transport Sennders */ + qtransportsender = axutil_qname_create(env, AXIS2_TRANSPORTSENDER, NULL, NULL); + trs_senders = axiom_element_get_children_with_qname(conf_element, env, qtransportsender, + conf_node); + axutil_qname_free(qtransportsender, env); + status = axis2_conf_builder_process_transport_senders(conf_builder, env, trs_senders); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Processing transport senders failed, unable to continue"); + return AXIS2_FAILURE; + } + + /* Proccessing Transport Recivers */ + qtransportrecv = axutil_qname_create(env, AXIS2_TRANSPORTRECEIVER, NULL, NULL); + trs_recvs = axiom_element_get_children_with_qname(conf_element, env, qtransportrecv, conf_node); + axutil_qname_free(qtransportrecv, env); + status = axis2_conf_builder_process_transport_recvs(conf_builder, env, trs_recvs); + + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Processing transport receivers failed, unable to continue"); + return AXIS2_FAILURE; + } + + /* processing Phase orders */ + qphaseorder = axutil_qname_create(env, AXIS2_PHASE_ORDER, NULL, NULL); + phase_orders = axiom_element_get_children_with_qname(conf_element, env, qphaseorder, conf_node); + axutil_qname_free(qphaseorder, env); + status = axis2_conf_builder_process_phase_orders(conf_builder, env, phase_orders); + + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Processing phase orders failed, unable to continue"); + return AXIS2_FAILURE; + } + + /* Processing default module versions */ + qdefmodver = axutil_qname_create(env, AXIS2_DEFAULT_MODULE_VERSION, NULL, NULL); + def_mod_versions = axiom_element_get_children_with_qname(conf_element, env, qdefmodver, + conf_node); + axutil_qname_free(qdefmodver, env); + if(def_mod_versions) + { + status = axis2_conf_builder_process_default_module_versions(conf_builder, env, + def_mod_versions); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Processing default module versions failed, unable to continue"); + return AXIS2_FAILURE; + } + } + + param = axutil_param_container_get_param( + axis2_conf_get_param_container(conf_builder->conf, env), env, AXIS2_ENABLE_MTOM); + if(param) + { + axis2_char_t *value = NULL; + value = axutil_param_get_value(param, env); + if(value) + { + axis2_conf_set_enable_mtom(conf_builder->conf, env, (!axutil_strcmp(value, + AXIS2_VALUE_TRUE))); + } + } + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_conf_builder_populate_conf"); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_conf_builder_process_module_refs( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_refs) +{ + axis2_status_t status = AXIS2_SUCCESS; + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_conf_builder_process_module_refs"); + AXIS2_PARAM_CHECK(env->error, module_refs, AXIS2_FAILURE); + + while(axiom_children_qname_iterator_has_next(module_refs, env)) + { + axiom_node_t *module_ref_node = NULL; + axiom_element_t *module_ref_element = NULL; + axutil_qname_t *qref = NULL; + + axiom_attribute_t *module_ref_att = NULL; + module_ref_node = (axiom_node_t *)axiom_children_qname_iterator_next(module_refs, env); + if(!module_ref_node) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Module ref node is empty. Unable to continue"); + return AXIS2_FAILURE; + } + module_ref_element = axiom_node_get_data_element(module_ref_node, env); + qref = axutil_qname_create(env, AXIS2_REF, NULL, NULL); + module_ref_att = axiom_element_get_attribute(module_ref_element, env, qref); + if(qref) + { + axutil_qname_free(qref, env); + } + + if(module_ref_att) + { + axutil_qname_t *qrefname = NULL; + axis2_char_t *ref_name = NULL; + + ref_name = axiom_attribute_get_value(module_ref_att, env); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Module %s found in axis2.xml", ref_name); + qrefname = axutil_qname_create(env, ref_name, NULL, NULL); + status = axis2_dep_engine_add_module(axis2_desc_builder_get_dep_engine( + conf_builder->desc_builder, env), env, qrefname); + if(qrefname) + { + axutil_qname_free(qrefname, env); + } + } + } + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_conf_builder_process_module_refs"); + return status; +} + +static axis2_status_t +axis2_conf_builder_process_disp_order( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_node_t * disp_order_node) +{ + axiom_element_t *disp_order_element = NULL; + axiom_children_qname_iterator_t *disps = NULL; + axutil_qname_t *qdisp = NULL; + axis2_bool_t found_disp = AXIS2_FALSE; + axis2_phase_t *disp_phase = NULL; + int count = 0; + axis2_bool_t qname_itr_has_next = AXIS2_FALSE; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_conf_builder_process_disp_order"); + AXIS2_PARAM_CHECK(env->error, disp_order_node, AXIS2_FAILURE); + + disp_order_element = axiom_node_get_data_element(disp_order_node, env); + qdisp = axutil_qname_create(env, AXIS2_DISPATCHER, NULL, NULL); + disps = axiom_element_get_children_with_qname(disp_order_element, env, qdisp, disp_order_node); + axutil_qname_free(qdisp, env); + disp_phase = axis2_phase_create(env, AXIS2_PHASE_DISPATCH); + if(!disp_phase) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Dispatch phase creation failed. Unable to continue"); + return AXIS2_FAILURE; + } + if(disps) + { + qname_itr_has_next = axiom_children_qname_iterator_has_next(disps, env); + } + while(qname_itr_has_next) + { + axiom_node_t *disp_node = NULL; + axiom_element_t *disp_element = NULL; + axiom_attribute_t *disp_att = NULL; + axis2_char_t *class_name = NULL; + axis2_char_t *dll_name = NULL; + axutil_qname_t *class_qname = NULL; + axis2_disp_t *disp_dll = NULL; + axutil_dll_desc_t *dll_desc = NULL; + axutil_param_t *impl_info_param = NULL; + axis2_handler_desc_t *handler_desc = NULL; + axis2_handler_t *handler = NULL; + + found_disp = AXIS2_TRUE; + disp_node = (axiom_node_t *)axiom_children_qname_iterator_next(disps, env); + disp_element = (axiom_element_t *) axiom_node_get_data_element(disp_node, env); + class_qname = axutil_qname_create(env, AXIS2_CLASSNAME, NULL, NULL); + disp_att = axiom_element_get_attribute(disp_element, env, class_qname); + axutil_qname_free(class_qname, env); + if(!disp_att) + { + qname_itr_has_next = axiom_children_qname_iterator_has_next(disps, env); + continue; + } + class_name = axiom_attribute_get_value(disp_att, env); + dll_desc = axutil_dll_desc_create(env); + dll_name = axutil_dll_desc_create_platform_specific_dll_name(dll_desc, env, class_name); + axutil_dll_desc_set_name(dll_desc, env, dll_name); + axutil_dll_desc_set_type(dll_desc, env, AXIS2_HANDLER_DLL); + impl_info_param = axutil_param_create(env, class_name, NULL); + if(!impl_info_param) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Parameter creation failed for %s. Unable to continue", class_name); + + axis2_phase_free(disp_phase, env); + + return AXIS2_FAILURE; + } + + axutil_param_set_value(impl_info_param, env, dll_desc); + axutil_param_set_value_free(impl_info_param, env, axutil_dll_desc_free_void_arg); + axutil_class_loader_init(env); + disp_dll = (axis2_disp_t *)axutil_class_loader_create_dll(env, impl_info_param); + + handler = axis2_disp_get_base(disp_dll, env); + handler_desc = axis2_handler_get_handler_desc(handler, env); + axis2_handler_desc_add_param(handler_desc, env, impl_info_param); + + axis2_phase_add_handler_at(disp_phase, env, count, handler); + count++; + qname_itr_has_next = axiom_children_qname_iterator_has_next(disps, env); + + } + + if(!found_disp) + { + axis2_phase_free(disp_phase, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_DISPATCHER_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No dispatcher found. Unable to continue"); + + return AXIS2_FAILURE; + } + else + { + status = axis2_conf_set_dispatch_phase(conf_builder->conf, env, disp_phase); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting dispatch phase failed. Unable to continue"); + + axis2_phase_free(disp_phase, env); + + return status; + } + } + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_conf_builder_process_disp_order"); + return AXIS2_SUCCESS; +} + +/** + * To process all the phase orders which are defined in axis2.xml retrieve each phase order node + * from the iterator passed as parameter and from each phase order node retrieve phases list + * defined for that phase order. Add the phases names into a array list and set it into the + * dep_engine->phases_info with the corresponding phase order name. + * @param phase_orders + */ +static axis2_status_t +axis2_conf_builder_process_phase_orders( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * phase_orders) +{ + axis2_phases_info_t *info = NULL; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_conf_builder_process_phase_orders"); + + AXIS2_PARAM_CHECK(env->error, phase_orders, AXIS2_FAILURE); + + info = axis2_dep_engine_get_phases_info(axis2_desc_builder_get_dep_engine( + conf_builder->desc_builder, env), env); + + while(axiom_children_qname_iterator_has_next(phase_orders, env)) + { + axiom_node_t *phase_orders_node = NULL; + axiom_element_t *phase_orders_element = NULL; + axiom_attribute_t *phase_orders_att = NULL; + axutil_qname_t *qtype = NULL; + axis2_char_t *flow_type = NULL; + axutil_array_list_t *phase_list = NULL; + + phase_orders_node = (axiom_node_t *)axiom_children_qname_iterator_next(phase_orders, env); + if(phase_orders_node) + { + phase_orders_element = axiom_node_get_data_element(phase_orders_node, env); + } + if(phase_orders_element) + { + qtype = axutil_qname_create(env, AXIS2_TYPE, NULL, NULL); + phase_orders_att = axiom_element_get_attribute(phase_orders_element, env, qtype); + axutil_qname_free(qtype, env); + } + + if(phase_orders_att) + { + flow_type = axiom_attribute_get_value(phase_orders_att, env); + } + + phase_list = axis2_conf_builder_get_phase_list(conf_builder, env, phase_orders_node); + if(!phase_list) + { + axis2_status_t status_code = AXIS2_FAILURE; + + status_code = AXIS2_ERROR_GET_STATUS_CODE(env->error); + if(AXIS2_SUCCESS != status_code) + { + return status_code; + } + + return AXIS2_SUCCESS; + } + + if(flow_type && !axutil_strcmp(AXIS2_IN_FLOW_START, flow_type)) + { + axis2_phases_info_set_in_phases(info, env, phase_list); + } + else if(flow_type && !axutil_strcmp(AXIS2_IN_FAILTFLOW, flow_type)) + { + axis2_phases_info_set_in_faultphases(info, env, phase_list); + } + else if(flow_type && !axutil_strcmp(AXIS2_OUT_FLOW_START, flow_type)) + { + axis2_phases_info_set_out_phases(info, env, phase_list); + } + else if(flow_type && !axutil_strcmp(AXIS2_OUT_FAILTFLOW, flow_type)) + { + axis2_phases_info_set_out_faultphases(info, env, phase_list); + } + } + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_conf_builder_process_phase_orders"); + + return AXIS2_SUCCESS; +} + +/* From the phase order node passed as parameter retrieve all phase element nodes. From them extract + * the phase name and add it to a array list. Return the array list. + */ +static axutil_array_list_t * +axis2_conf_builder_get_phase_list( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_node_t * phase_orders_node) +{ + axutil_array_list_t *phase_list = NULL; + axiom_children_qname_iterator_t *phases = NULL; + axutil_qname_t *qphase = NULL; + axiom_element_t *phase_orders_element; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_conf_builder_get_phase_list"); + + AXIS2_PARAM_CHECK(env->error, phase_orders_node, NULL); + + phase_orders_element = axiom_node_get_data_element(phase_orders_node, env); + if(!phase_orders_element) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_DATA_ELEMENT_IS_NULL, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Retrieving phase orders data element from phase orders node failed. Unable to continue"); + + return NULL; + } + + phase_list = axutil_array_list_create(env, 0); + qphase = axutil_qname_create(env, AXIS2_PHASE, NULL, NULL); + phases = axiom_element_get_children_with_qname(phase_orders_element, env, qphase, + phase_orders_node); + + axutil_qname_free(qphase, env); + if(!phases) + { + axutil_array_list_free(phase_list, env); + + /* I guess this is not an error. So adding debug message*/ + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No phase node found in the phase orders node"); + + return NULL; + } + + while(axiom_children_qname_iterator_has_next(phases, env)) + { + axiom_node_t *phase_node = NULL; + axiom_element_t *phase_element = NULL; + axiom_attribute_t *phase_att = NULL; + axutil_qname_t *qattname = NULL; + axis2_char_t *att_value = NULL; + + phase_node = (axiom_node_t *)axiom_children_qname_iterator_next(phases, env); + if(phase_node) + { + phase_element = (axiom_element_t *)axiom_node_get_data_element(phase_node, env); + } + + qattname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + if(phase_element) + { + phase_att = axiom_element_get_attribute(phase_element, env, qattname); + } + + if(phase_att) + { + att_value = axiom_attribute_get_value(phase_att, env); + } + + if(att_value) + { + axutil_array_list_add(phase_list, env, att_value); + } + + axutil_qname_free(qattname, env); + } + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_conf_builder_get_phase_list"); + + return phase_list; +} + +static axis2_status_t +axis2_conf_builder_process_transport_senders( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * trs_senders) +{ + axis2_status_t status = AXIS2_FAILURE; + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_conf_builder_process_transport_senders"); + while(axiom_children_qname_iterator_has_next(trs_senders, env)) + { + axis2_transport_out_desc_t *transport_out = NULL; + axiom_node_t *transport_node = NULL; + axiom_element_t *transport_element = NULL; + axiom_attribute_t *trs_name = NULL; + axutil_qname_t *qattname = NULL; + + transport_node = (axiom_node_t *)axiom_children_qname_iterator_next(trs_senders, env); + + if(transport_node) + { + transport_element = (axiom_element_t *)axiom_node_get_data_element(transport_node, env); + if(!transport_element) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Retrieving data element failed from the transport node." + " Unable to continue"); + return AXIS2_FAILURE; + } + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport node is empty. Unable to continue"); + return AXIS2_FAILURE; + } + + /* getting trsnport Name */ + qattname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + if(transport_element) + { + trs_name = axiom_element_get_attribute(transport_element, env, qattname); + } + + axutil_qname_free(qattname, env); + if(trs_name) + { + axis2_char_t *name = NULL; + axiom_attribute_t *trs_dll_att = NULL; + axis2_char_t *dll_name = NULL; + axis2_char_t *class_name = NULL; + axiom_children_qname_iterator_t *itr = NULL; + axutil_qname_t *qparamst = NULL; + axutil_qname_t *qinflowst = NULL; + axutil_qname_t *qoutflowst = NULL; + axutil_qname_t *qinfaultflowst = NULL; + axutil_qname_t *qoutfaultflowst = NULL; + axutil_qname_t *qdllname = NULL; + axiom_element_t *in_flow_element = NULL; + axiom_node_t *in_flow_node = NULL; + axiom_element_t *out_flow_element = NULL; + axiom_node_t *out_flow_node = NULL; + axiom_element_t *in_fault_flow_element = NULL; + axiom_node_t *in_fault_flow_node = NULL; + axiom_element_t *out_fault_flow_element = NULL; + axiom_node_t *out_fault_flow_node = NULL; + axutil_dll_desc_t *dll_desc = NULL; + axutil_param_t *impl_info_param = NULL; + void *transport_sender = NULL; + axis2_char_t *path_qualified_dll_name = NULL; + axis2_char_t *repos_name = NULL; + axis2_char_t *temp_path = NULL; + axis2_char_t *temp_path2 = NULL; + axis2_char_t *temp_path3 = NULL; + AXIS2_TRANSPORT_ENUMS transport_enum = AXIS2_TRANSPORT_ENUM_HTTP; + /* AXIS2_TRANSPORT_ENUMS transport_enum = AXIS2_TRANSPORT_ENUM_HTTP + * set to avoid C4701 on Windows + */ + axis2_bool_t axis2_flag = AXIS2_FALSE; + axutil_param_t *libparam; + axis2_char_t *libdir = NULL; + axis2_conf_t *conf; + + conf = conf_builder->conf; + axis2_flag = axis2_conf_get_axis2_flag(conf, env); + + name = axiom_attribute_get_value(trs_name, env); + + if(name) + { + if(!axutil_strcmp(name, AXIS2_TRANSPORT_HTTP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_HTTP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_SMTP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_SMTP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_XMPP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_XMPP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_TCP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_TCP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_HTTPS)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_HTTPS; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_AMQP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_AMQP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_UDP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_UDP; + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Transport name %s doesn't match with transport enum. " + "Unable to continue", name); + return AXIS2_FAILURE; + } + + transport_out = axis2_transport_out_desc_create(env, transport_enum); + } + + if(!transport_out) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Transport_out value is NULL for transport %s", name); + return AXIS2_FAILURE; + } + + /* transport impl class */ + qdllname = axutil_qname_create(env, AXIS2_CLASSNAME, NULL, NULL); + trs_dll_att = axiom_element_get_attribute(transport_element, env, qdllname); + axutil_qname_free(qdllname, env); + if(!trs_dll_att) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_TRANSPORT_SENDER_ERROR, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Transport dll name attribute is not set in the " + "%s transport element node", name); + return AXIS2_FAILURE; + } + class_name = axiom_attribute_get_value(trs_dll_att, env); + impl_info_param = axutil_param_create(env, class_name, NULL); + if(!impl_info_param) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Creating module dll name parameter failed for %s. Unable " + "to continue", class_name); + axis2_transport_out_desc_free(transport_out, env); + return AXIS2_FAILURE; + } + dll_desc = axutil_dll_desc_create(env); + dll_name = axutil_dll_desc_create_platform_specific_dll_name(dll_desc, env, class_name); + if(!axis2_flag) + { + repos_name = axis2_dep_engine_get_repos_path(axis2_desc_builder_get_dep_engine( + conf_builder->desc_builder, env), env); + temp_path = axutil_stracat(env, repos_name, AXIS2_PATH_SEP_STR); + temp_path2 = axutil_stracat(env, temp_path, AXIS2_LIB_FOLDER); + temp_path3 = axutil_stracat(env, temp_path2, AXIS2_PATH_SEP_STR); + path_qualified_dll_name = axutil_stracat(env, temp_path3, dll_name); + AXIS2_FREE(env->allocator, temp_path); + AXIS2_FREE(env->allocator, temp_path2); + AXIS2_FREE(env->allocator, temp_path3); + } + else + { + libparam = axis2_conf_get_param(conf, env, AXIS2_LIB_DIR); + if(libparam) + { + libdir = axutil_param_get_value(libparam, env); + } + + if(!libdir) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Specifying" + "services and modules directories using axis2.xml but" + " path of the library directory is not present"); + return AXIS2_FAILURE; + } + path_qualified_dll_name = axutil_strcat(env, libdir, AXIS2_PATH_SEP_STR, dll_name, + NULL); + } + + axutil_dll_desc_set_name(dll_desc, env, path_qualified_dll_name); + AXIS2_FREE(env->allocator, path_qualified_dll_name); + + axutil_dll_desc_set_type(dll_desc, env, AXIS2_TRANSPORT_SENDER_DLL); + axutil_param_set_value(impl_info_param, env, dll_desc); + axutil_param_set_value_free(impl_info_param, env, axutil_dll_desc_free_void_arg); + axutil_class_loader_init(env); + transport_sender = axutil_class_loader_create_dll(env, impl_info_param); + axis2_transport_out_desc_add_param(transport_out, env, impl_info_param); + + if(!transport_sender) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Transport sender is NULL for transport %s, unable to " + "continue", name); + axis2_transport_out_desc_free(transport_out, env); + return status; + } + + status = axis2_transport_out_desc_set_sender(transport_out, env, transport_sender); + if(!status) + { + axis2_transport_out_desc_free(transport_out, env); + return status; + } + + /* Process Parameters */ + /* Processing service level paramters */ + qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + itr = axiom_element_get_children_with_qname(transport_element, env, qparamst, + transport_node); + axutil_qname_free(qparamst, env); + + if(itr) + { + status = axis2_desc_builder_process_params(conf_builder->desc_builder, env, itr, + axis2_transport_out_desc_param_container(transport_out, env), + axis2_conf_get_param_container(conf_builder->conf, env)); + } + if(!status) + { + axis2_transport_out_desc_free(transport_out, env); + return status; + } + /* process IN_FLOW */ + qinflowst = axutil_qname_create(env, AXIS2_IN_FLOW_START, NULL, NULL); + in_flow_element = axiom_element_get_first_child_with_qname(transport_element, env, + qinflowst, transport_node, &in_flow_node); + axutil_qname_free(qinflowst, env); + if(in_flow_element) + { + axis2_transport_out_desc_free(transport_out, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_IN_FLOW_NOT_ALLOWED_IN_TRS_OUT, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Transport in flow element is not allowed in the out path"); + return AXIS2_FAILURE; + } + qoutflowst = axutil_qname_create(env, AXIS2_OUT_FLOW_START, NULL, NULL); + out_flow_element = axiom_element_get_first_child_with_qname(transport_element, env, + qoutflowst, transport_node, &out_flow_node); + axutil_qname_free(qoutflowst, env); + if(out_flow_element) + { + axis2_flow_t *flow = NULL; + + flow = axis2_desc_builder_process_flow(conf_builder->desc_builder, env, + out_flow_element, axis2_conf_get_param_container(conf_builder->conf, env), + out_flow_node); + status = axis2_transport_out_desc_set_out_flow(transport_out, env, flow); + if(!status) + { + axis2_transport_out_desc_free(transport_out, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting the out flow failed on the trasnport out " + "description for the transport %s", name); + return status; + } + } + + /* process IN FAULT FLOW */ + qinfaultflowst = axutil_qname_create(env, AXIS2_IN_FAILTFLOW, NULL, NULL); + in_fault_flow_element = axiom_element_get_first_child_with_qname(transport_element, + env, qinfaultflowst, transport_node, &in_fault_flow_node); + axutil_qname_free(qinfaultflowst, env); + if(in_fault_flow_element) + { + axis2_transport_out_desc_free(transport_out, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_IN_FLOW_NOT_ALLOWED_IN_TRS_OUT, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "A soap fault has occured in the in flow while " + "processing transport senders. Unable to continue"); + return AXIS2_FAILURE; + } + + qoutfaultflowst = axutil_qname_create(env, AXIS2_OUT_FAILTFLOW, NULL, NULL); + out_fault_flow_element = axiom_element_get_first_child_with_qname(transport_element, + env, qoutfaultflowst, transport_node, &out_fault_flow_node); + axutil_qname_free(qoutfaultflowst, env); + if(out_fault_flow_element) + { + axis2_flow_t *flow = NULL; + + flow = axis2_desc_builder_process_flow(conf_builder->desc_builder, env, + out_fault_flow_element, + axis2_conf_get_param_container(conf_builder->conf, env), out_fault_flow_node); + status = axis2_transport_out_desc_set_fault_out_flow(transport_out, env, flow); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting the fault out flow into the transport out " + "failed"); + axis2_transport_out_desc_free(transport_out, env); + return status; + } + } + + /* adding to axis config */ + status = axis2_conf_add_transport_out(conf_builder->conf, env, transport_out, + transport_enum); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Adding transport out for %s into main configuration failed", name); + axis2_transport_out_desc_free(transport_out, env); + return status; + } + } + } + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_conf_builder_process_transport_senders"); + return AXIS2_SUCCESS; +} + +static axis2_status_t +axis2_conf_builder_process_transport_recvs( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * trs_recvs) +{ + axis2_status_t status = AXIS2_FAILURE; + axis2_conf_t *conf; + axis2_bool_t axis2_flag = AXIS2_FALSE; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_conf_builder_process_transport_recvs"); + AXIS2_PARAM_CHECK(env->error, trs_recvs, AXIS2_FAILURE); + + conf = conf_builder->conf; + axis2_flag = axis2_conf_get_axis2_flag(conf, env); + + while(axiom_children_qname_iterator_has_next(trs_recvs, env)) + { + axis2_transport_in_desc_t *transport_in = NULL; + axiom_node_t *transport_node = NULL; + axiom_element_t *transport_element = NULL; + axiom_attribute_t *trs_name = NULL; + axutil_qname_t *qattname = NULL; + + transport_node = (axiom_node_t *)axiom_children_qname_iterator_next(trs_recvs, env); + if(transport_node) + { + transport_element = axiom_node_get_data_element(transport_node, env); + if(!transport_element) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Retrieving data element from the transport node failed."); + return AXIS2_FAILURE; + } + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport node is NULL. Unable to continue"); + return AXIS2_FAILURE; + } + + /* getting transport Name */ + qattname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + trs_name = axiom_element_get_attribute(transport_element, env, qattname); + axutil_qname_free(qattname, env); + + if(trs_name) + { + axis2_char_t *name = NULL; + axiom_attribute_t *trs_class_name = NULL; + axiom_children_qname_iterator_t *itr = NULL; + axutil_qname_t *class_qname = NULL; + axutil_qname_t *qparamst = NULL; + axutil_qname_t *qinflowst = NULL; + axutil_qname_t *qoutflowst = NULL; + axutil_qname_t *qinfaultflowst = NULL; + axutil_qname_t *qoutfaultflowst = NULL; + axiom_element_t *in_flow_element = NULL; + axiom_node_t *in_flow_node = NULL; + axiom_element_t *out_flow_element = NULL; + axiom_node_t *out_flow_node = NULL; + axiom_element_t *in_fault_flow_element = NULL; + axiom_node_t *in_fault_flow_node = NULL; + axiom_element_t *out_fault_flow_element = NULL; + axiom_node_t *out_fault_flow_node = NULL; + AXIS2_TRANSPORT_ENUMS transport_enum = AXIS2_TRANSPORT_ENUM_HTTP; + /* AXIS2_TRANSPORT_ENUMS transport_enum = AXIS2_TRANSPORT_ENUM_HTTP + * set to avoid C4701 on Windows + */ + + name = axiom_attribute_get_value(trs_name, env); + if(name) + { + if(!axutil_strcmp(name, AXIS2_TRANSPORT_HTTP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_HTTP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_SMTP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_SMTP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_XMPP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_XMPP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_TCP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_TCP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_HTTPS)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_HTTPS; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_AMQP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_AMQP; + } + else if(!axutil_strcmp(name, AXIS2_TRANSPORT_UDP)) + { + transport_enum = AXIS2_TRANSPORT_ENUM_UDP; + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Transport %s could not be recognized.", name); + return AXIS2_FAILURE; + } + + transport_in = axis2_transport_in_desc_create(env, transport_enum); + } + if(!transport_in) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Creating trasport_in_desc for transport %s failed", name); + return AXIS2_FAILURE; + } + + /* transport impl class */ + class_qname = axutil_qname_create(env, AXIS2_CLASSNAME, NULL, NULL); + trs_class_name = axiom_element_get_attribute(transport_element, env, class_qname); + axutil_qname_free(class_qname, env); + + if(trs_class_name) + { + axis2_char_t *class_name = NULL; + axis2_char_t *dll_name = NULL; + axutil_dll_desc_t *dll_desc = NULL; + axutil_param_t *impl_info_param = NULL; + axis2_transport_receiver_t *recv = NULL; + axis2_status_t stat = AXIS2_FAILURE; + axis2_char_t *path_qualified_dll_name = NULL; + axis2_char_t *repos_name = NULL; + axis2_char_t *temp_path = NULL; + axis2_char_t *temp_path2 = NULL; + axis2_char_t *temp_path3 = NULL; + + axutil_param_t *tnsparam; + axis2_char_t *libpath; + + class_name = axiom_attribute_get_value(trs_class_name, env); + impl_info_param = axutil_param_create(env, class_name, NULL); + dll_desc = axutil_dll_desc_create(env); + dll_name = axutil_dll_desc_create_platform_specific_dll_name(dll_desc, env, + class_name); + if(!axis2_flag) + { + /* Axis2 Configuration is not built using axis2.xml */ + repos_name = axis2_dep_engine_get_repos_path(axis2_desc_builder_get_dep_engine( + conf_builder->desc_builder, env), env); + temp_path = axutil_stracat(env, repos_name, AXIS2_PATH_SEP_STR); + temp_path2 = axutil_stracat(env, temp_path, AXIS2_LIB_FOLDER); + temp_path3 = axutil_stracat(env, temp_path2, AXIS2_PATH_SEP_STR); + path_qualified_dll_name = axutil_stracat(env, temp_path3, dll_name); + AXIS2_FREE(env->allocator, temp_path); + AXIS2_FREE(env->allocator, temp_path2); + AXIS2_FREE(env->allocator, temp_path3); + } + else + { + /* Axis2 Configuration is built using axis2.xml */ + tnsparam = axis2_conf_get_param(conf, env, AXIS2_LIB_DIR); + if(tnsparam) + { + libpath = (axis2_char_t *)axutil_param_get_value(tnsparam, env); + + if(libpath) + { + path_qualified_dll_name = axutil_strcat(env, libpath, + AXIS2_PATH_SEP_STR, dll_name, NULL); + } + } + } + + axutil_dll_desc_set_name(dll_desc, env, path_qualified_dll_name); + AXIS2_FREE(env->allocator, path_qualified_dll_name); + axutil_dll_desc_set_type(dll_desc, env, AXIS2_TRANSPORT_RECV_DLL); + + axutil_param_set_value(impl_info_param, env, dll_desc); + axutil_param_set_value_free(impl_info_param, env, axutil_dll_desc_free_void_arg); + axutil_class_loader_init(env); + recv = (axis2_transport_receiver_t *)axutil_class_loader_create_dll(env, + impl_info_param); + axis2_transport_in_desc_add_param(transport_in, env, impl_info_param); + + if(!recv) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Transport receiver loading failed for %s, " + "unable to continue", dll_name); + axis2_transport_in_desc_free(transport_in, env); + return status; + } + axis2_transport_receiver_set_is_application_client_side(recv, env, AXIS2_TRUE); + stat = axis2_transport_in_desc_set_recv(transport_in, env, recv); + + if(!stat) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting transport receiver for transport %s into " + "transport in description failed, unable to continue", name); + axis2_transport_in_desc_free(transport_in, env); + return stat; + } + + } + + /* process Parameters */ + /* processing Paramters */ + /* Processing service level paramters */ + qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + itr = axiom_element_get_children_with_qname(transport_element, env, qparamst, + transport_node); + axutil_qname_free(qparamst, env); + status = axis2_desc_builder_process_params(conf_builder->desc_builder, env, itr, + axis2_transport_in_desc_param_container(transport_in, env), + axis2_conf_get_param_container(conf_builder->conf, env)); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Processing transport receiver parameters failed. " + "Unable to continue"); + axis2_transport_in_desc_free(transport_in, env); + return status; + } + /* process OUT_FLOW */ + qoutflowst = axutil_qname_create(env, AXIS2_OUT_FLOW_START, NULL, NULL); + out_flow_element = axiom_element_get_first_child_with_qname(transport_element, env, + qoutflowst, transport_node, &out_flow_node); + axutil_qname_free(qoutflowst, env); + if(out_flow_element) + { + axis2_transport_in_desc_free(transport_in, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OUT_FLOW_NOT_ALLOWED_IN_TRS_IN, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Out flow element not allowed in transport in path"); + return AXIS2_FAILURE; + } + + qinflowst = axutil_qname_create(env, AXIS2_IN_FLOW_START, NULL, NULL); + in_flow_element = axiom_element_get_first_child_with_qname(transport_element, env, + qinflowst, transport_node, &in_flow_node); + axutil_qname_free(qinflowst, env); + if(in_flow_element) + { + axis2_flow_t *flow = NULL; + + flow = axis2_desc_builder_process_flow(conf_builder->desc_builder, env, + in_flow_element, axis2_conf_get_param_container(conf_builder->conf, env), + in_flow_node); + status = axis2_transport_in_desc_set_in_flow(transport_in, env, flow); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting in flow into transport_in_desc of transport " + "%s failed", name); + axis2_transport_in_desc_free(transport_in, env); + return status; + } + } + + qinfaultflowst = axutil_qname_create(env, AXIS2_IN_FAILTFLOW, NULL, NULL); + in_fault_flow_element = axiom_element_get_first_child_with_qname(transport_element, + env, qinfaultflowst, transport_node, &in_fault_flow_node); + axutil_qname_free(qinfaultflowst, env); + if(in_fault_flow_element) + { + axis2_flow_t *flow = NULL; + + flow = axis2_desc_builder_process_flow(conf_builder->desc_builder, env, + in_fault_flow_element, axis2_conf_get_param_container(conf_builder->conf, env), + in_fault_flow_node); + status = axis2_transport_in_desc_set_fault_in_flow(transport_in, env, flow); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting in fault flow into transport_in_desc of " + "transport %s failed", name); + axis2_transport_in_desc_free(transport_in, env); + return status; + } + } + + qoutfaultflowst = axutil_qname_create(env, AXIS2_OUT_FAILTFLOW, NULL, NULL); + out_fault_flow_element = axiom_element_get_first_child_with_qname(transport_element, + env, qoutfaultflowst, transport_node, &out_fault_flow_node); + if(out_fault_flow_element) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OUT_FLOW_NOT_ALLOWED_IN_TRS_IN, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Out flow element is not allowed in transport in path"); + return AXIS2_FAILURE; + } + + /* adding to axis config */ + status = axis2_conf_add_transport_in(conf_builder->conf, env, transport_in, + transport_enum); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Adding transport_in_desc for transport %s into main " + "configuration failed.", name); + axis2_transport_in_desc_free(transport_in, env); + return status; + } + + axutil_qname_free(qoutfaultflowst, env); + + } + } + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_conf_builder_process_transport_recvs"); + return AXIS2_SUCCESS; +} + +static axis2_status_t AXIS2_CALL +axis2_conf_builder_process_default_module_versions( + axis2_conf_builder_t * conf_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_versions) +{ + AXIS2_PARAM_CHECK(env->error, module_versions, AXIS2_FAILURE); + + while(axiom_children_qname_iterator_has_next(module_versions, env)) + { + axiom_element_t *om_element = NULL; + axis2_char_t *name = NULL; + axis2_char_t *default_version = NULL; + axutil_qname_t *attribute_qname = NULL; + + om_element = (axiom_element_t *)axiom_children_qname_iterator_next(module_versions, env); + if(!om_element) + { + continue; + } + attribute_qname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + if(!attribute_qname) + { + continue; + } + name = axiom_element_get_attribute_value(om_element, env, attribute_qname); + axutil_qname_free(attribute_qname, env); + attribute_qname = NULL; + if(!name) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Attribute value is NULL for " + "attribute %s", AXIS2_ATTNAME); + return AXIS2_FAILURE; + } + attribute_qname = axutil_qname_create(env, AXIS2_ATTRIBUTE_DEFAULT_VERSION, NULL, NULL); + if(!attribute_qname) + { + continue; + } + default_version = axiom_element_get_attribute_value(om_element, env, attribute_qname); + axutil_qname_free(attribute_qname, env); + attribute_qname = NULL; + if(!default_version) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Attribute value is NULL for " + "attribute %s", AXIS2_ATTRIBUTE_DEFAULT_VERSION); + return AXIS2_FAILURE; + } + axis2_conf_add_default_module_version(conf_builder->conf, env, name, default_version); + } + return AXIS2_SUCCESS; +} + diff --git a/src/core/deployment/conf_init.c b/src/core/deployment/conf_init.c new file mode 100644 index 0000000..6a622b4 --- /dev/null +++ b/src/core/deployment/conf_init.c @@ -0,0 +1,460 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_conf_init.h> +#include <axis2_transport_sender.h> +#include <axis2_transport_receiver.h> +#include <axis2_const.h> +#include <axutil_error.h> +#include <axutil_allocator.h> +#include <axutil_class_loader.h> +#include <axis2_dep_engine.h> +#include <axis2_module.h> + +#define DEFAULT_REPO_PATH "." + +axis2_status_t AXIS2_CALL +axis2_init_modules( + const axutil_env_t * env, + axis2_conf_ctx_t * conf_ctx); + +static axis2_status_t AXIS2_CALL +axis2_load_services( + const axutil_env_t * env, + axis2_conf_ctx_t * conf_ctx); + +axis2_status_t AXIS2_CALL +axis2_init_transports( + const axutil_env_t * env, + axis2_conf_ctx_t * conf_ctx); + +static axis2_conf_ctx_t *AXIS2_CALL +axis2_build_conf_ctx_with_dep_engine( + const axutil_env_t * env, + axis2_dep_engine_t *dep_engine, + axis2_char_t *is_server_side) +{ + axis2_conf_ctx_t *conf_ctx = NULL; + axis2_conf_t *conf = NULL; + axutil_property_t *property = NULL; + axis2_ctx_t *conf_ctx_base = NULL; + + conf = axis2_dep_engine_load(dep_engine, env); + if(!conf) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Loading deployment engine failed"); + axis2_dep_engine_free(dep_engine, env); + return NULL; + } + axis2_conf_set_dep_engine(conf, env, dep_engine); + + conf_ctx = axis2_conf_ctx_create(env, conf); + if(!conf_ctx) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating Axis2 configuration context failed."); + return NULL; + } + axis2_conf_ctx_set_root_dir(conf_ctx, env, axis2_dep_engine_get_repos_path(dep_engine, env)); + + conf_ctx_base = axis2_conf_ctx_get_base(conf_ctx, env); + property = axutil_property_create_with_args(env, 2, 0, 0, is_server_side); + axis2_ctx_set_property(conf_ctx_base, env, AXIS2_IS_SVR_SIDE, property); + + axis2_init_modules(env, conf_ctx); + axis2_init_transports(env, conf_ctx); + + if(!axutil_strcmp(is_server_side, AXIS2_VALUE_TRUE)) + { + axis2_load_services(env, conf_ctx); + } + + return conf_ctx; +} + +AXIS2_EXTERN axis2_conf_ctx_t *AXIS2_CALL +axis2_build_conf_ctx( + const axutil_env_t * env, + const axis2_char_t * repo_name) +{ + axis2_conf_ctx_t *conf_ctx = NULL; + axis2_dep_engine_t *dep_engine = NULL; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_build_conf_ctx"); + dep_engine = axis2_dep_engine_create_with_repos_name(env, repo_name); + if(!dep_engine) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Creating deployment engine failed for repository %s", repo_name); + return NULL; + } + + conf_ctx = axis2_build_conf_ctx_with_dep_engine(env, dep_engine, AXIS2_VALUE_TRUE); + if(!conf_ctx) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Loading configuration context failed for repository %s.", repo_name); + return NULL; + } + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_build_conf_ctx"); + return conf_ctx; +} + +AXIS2_EXTERN axis2_conf_ctx_t *AXIS2_CALL +axis2_build_conf_ctx_with_file( + const axutil_env_t * env, + const axis2_char_t * file) +{ + axis2_conf_ctx_t *conf_ctx = NULL; + axis2_dep_engine_t *dep_engine = NULL; + axis2_char_t *repos_path = NULL; + axis2_char_t *temp_path = NULL; + axis2_char_t *index = NULL; + axis2_char_t *xmlfile = NULL; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_build_conf_ctx_with_file"); + temp_path = axutil_strdup(env, file); + index = axutil_rindex(temp_path, AXIS2_PATH_SEP_CHAR); + if(!index) + {/* searching from windows specific path seperator */ + index = axutil_rindex(temp_path, '\\'); + } + + if(!index) + { + /** only the xml file name is provided. Assume the default repo path */ + repos_path = AXIS2_GETENV("AXIS2C_HOME"); + xmlfile = (axis2_char_t*)file; + }else + { + xmlfile = index+1; + temp_path[index-temp_path] = '\0'; + repos_path = temp_path; + } + + dep_engine = axis2_dep_engine_create_with_repos_name_and_svr_xml_file(env, repos_path, xmlfile); + if(!dep_engine) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Creating deployment engine for given Axis2 configuration file" + "(axis2.xml) failed"); + return NULL; + } + + conf_ctx = axis2_build_conf_ctx_with_dep_engine(env, dep_engine, AXIS2_VALUE_TRUE); + if(!conf_ctx) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Loading configuration context failed for given Axis2 configuration %s.", file); + return NULL; + } + AXIS2_FREE(env->allocator, temp_path); + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_build_conf_ctx_with_file"); + return conf_ctx; +} + +axis2_conf_ctx_t *AXIS2_CALL +axis2_build_client_conf_ctx( + const axutil_env_t * env, + const axis2_char_t * axis2_home) +{ + axis2_conf_ctx_t *conf_ctx = NULL; + axis2_dep_engine_t *dep_engine = NULL; + axis2_conf_t *conf = NULL; + axutil_property_t *property = NULL; + axis2_ctx_t *conf_ctx_base = NULL; + + axis2_status_t status; + unsigned int len = 0; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_build_client_conf_ctx"); + /* Building conf using axis2.xml, in that case we check whether + * last 9 characters of the axis2_home equals to the "axis2.xml" + * else treat it as a directory + */ + + status = axutil_file_handler_access (axis2_home, AXIS2_R_OK); + if (status == AXIS2_SUCCESS) + { + len = (int)strlen (axis2_home); + /* We are sure that the difference lies within the int range */ + if ((len >= 9) && + !strcmp ((axis2_home + (len - 9)), "axis2.xml")) + { + dep_engine = axis2_dep_engine_create_with_axis2_xml (env, + axis2_home); + } + else + { + dep_engine = axis2_dep_engine_create(env); + } + } + else + { + AXIS2_LOG_WARNING (env->log, AXIS2_LOG_SI, + "Provided client repository path %s does not exsist or no "\ + "permission to read, therefore set axis2c home to DEFAULT_REPO_PATH.", + axis2_home); + axis2_home = DEFAULT_REPO_PATH; + dep_engine = axis2_dep_engine_create(env); + } + if (!dep_engine) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Creating deployment engine for client repository %s failed." , + axis2_home); + return NULL; + } + conf = axis2_dep_engine_load_client(dep_engine, env, axis2_home); + if (!conf) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Loading deployment engine failed for client repository %s", + axis2_home); + axis2_dep_engine_free(dep_engine, env); + return NULL; + } + axis2_conf_set_dep_engine(conf, env, dep_engine); + + conf_ctx = axis2_conf_ctx_create(env, conf); + if (!conf_ctx) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Creating Axis2 configuration context failed"); + return NULL; + } + axis2_conf_ctx_set_root_dir(conf_ctx, env, axis2_dep_engine_get_repos_path(dep_engine, env)); + + conf_ctx_base = axis2_conf_ctx_get_base(conf_ctx, env); + property = axutil_property_create_with_args(env, 2, 0, 0, AXIS2_VALUE_FALSE); + axis2_ctx_set_property(conf_ctx_base, env, AXIS2_IS_SVR_SIDE, property); + + axis2_init_modules(env, conf_ctx); + axis2_init_transports(env, conf_ctx); + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_build_client_conf_ctx"); + return conf_ctx; +} + +axis2_status_t AXIS2_CALL +axis2_init_modules( + const axutil_env_t * env, + axis2_conf_ctx_t * conf_ctx) +{ + axis2_conf_t *conf = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_init_modules"); + AXIS2_PARAM_CHECK(env->error, conf_ctx, AXIS2_FAILURE); + + conf = axis2_conf_ctx_get_conf(conf_ctx, env); + if(conf) + { + axutil_hash_t *module_map = axis2_conf_get_all_modules(conf, env); + if(module_map) + { + axutil_hash_index_t *hi = NULL; + void *module = NULL; + for(hi = axutil_hash_first(module_map, env); hi; hi = axutil_hash_next(env, hi)) + { + axutil_hash_this(hi, NULL, NULL, &module); + if(module) + { + axis2_module_desc_t *mod_desc = (axis2_module_desc_t *)module; + if(mod_desc) + { + axis2_module_t *mod = axis2_module_desc_get_module(mod_desc, env); + if(mod) + { + axis2_module_init(mod, env, conf_ctx, mod_desc); + } + } + } + } + } + status = AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, + "Retrieving Axis2 configuration from Axis2 configuration context " + "failed. Initializing modules failed"); + } + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_init_modules"); + return status; +} + +static axis2_status_t AXIS2_CALL +axis2_load_services( + const axutil_env_t * env, + axis2_conf_ctx_t * conf_ctx) +{ + axis2_conf_t *conf = NULL; + axis2_status_t status = AXIS2_FAILURE; + axutil_hash_t *svc_map = NULL; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_load_services"); + AXIS2_PARAM_CHECK(env->error, conf_ctx, AXIS2_FAILURE); + + conf = axis2_conf_ctx_get_conf(conf_ctx, env); + if(!conf) + { + AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "Retrieving Axis2 configuration from Axis2 " + "configuration context failed, Loading services failed"); + return status; + } + + svc_map = axis2_conf_get_all_svcs_to_load(conf, env); + if(svc_map) + { + axutil_hash_index_t *hi = NULL; + void *svc = NULL; + for(hi = axutil_hash_first(svc_map, env); hi; hi = axutil_hash_next(env, hi)) + { + void *impl_class = NULL; + axutil_hash_t *ops_hash = NULL; + axis2_msg_recv_t *msg_recv = NULL; + axutil_hash_this(hi, NULL, NULL, &svc); + if(!svc) + { + continue; + } + impl_class = axis2_svc_get_impl_class(svc, env);
+ if(impl_class)
+ continue; + + ops_hash = axis2_svc_get_all_ops(svc, env);
+ if(ops_hash)
+ {
+ axutil_hash_index_t *op_hi = NULL;
+ void *op = NULL;
+ op_hi = axutil_hash_first(ops_hash, env);
+ if(op_hi)
+ {
+ axutil_hash_this(op_hi, NULL, NULL, &op);
+ if(op)
+ {
+ msg_recv = axis2_op_get_msg_recv(op, env);
+ if(msg_recv)
+ {
+ axis2_msg_recv_set_conf_ctx(msg_recv, env, conf_ctx);
+ axis2_msg_recv_load_and_init_svc(msg_recv, env, svc);
+ }
+ }
+ }
+
+ } + /* + svc_desc = (axis2_svc_t *)svc; + if(!svc_desc) + { + continue; + } + + svc_name = axis2_svc_get_name(svc_desc, env); + impl_info_param = axis2_svc_get_param(svc_desc, env, AXIS2_SERVICE_CLASS); + + if(!impl_info_param) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_SVC, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid state of the service %s", svc_name); + return AXIS2_FAILURE; + } + axutil_class_loader_init(env); + impl_class = axutil_class_loader_create_dll(env, impl_info_param); + if(!impl_class) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service %s could not be loaded", svc_name); + return AXIS2_FAILURE; + } + + axis2_svc_set_impl_class(svc_desc, env, impl_class); + if(AXIS2_SVC_SKELETON_INIT_WITH_CONF((axis2_svc_skeleton_t *)impl_class, env, conf) + != AXIS2_SUCCESS) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Initialization failed for the service %s. " + "Check the service's init_with_conf() function for errors and retry", svc_name); + } + */ + + } + } + status = AXIS2_SUCCESS; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_load_services"); + return status; +} + +axis2_status_t AXIS2_CALL +axis2_init_transports( + const axutil_env_t * env, + axis2_conf_ctx_t * conf_ctx) +{ + axis2_conf_t *conf = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_init_transports"); + AXIS2_PARAM_CHECK(env->error, conf_ctx, AXIS2_FAILURE); + + conf = axis2_conf_ctx_get_conf(conf_ctx, env); + if(conf) + { + axis2_transport_in_desc_t **transport_in_map = NULL; + axis2_transport_out_desc_t **transport_out_map = NULL; + int i = 0; + + transport_in_map = axis2_conf_get_all_in_transports(conf, env); + for(i = 0; i < AXIS2_TRANSPORT_ENUM_MAX; i++) + { + if(transport_in_map[i]) + { + axis2_transport_receiver_t *listener = axis2_transport_in_desc_get_recv( + transport_in_map[i], env); + if(listener) + { + status = axis2_transport_receiver_init(listener, env, conf_ctx, + transport_in_map[i]); + } + } + } + + transport_out_map = axis2_conf_get_all_out_transports(conf, env); + for(i = 0; i < AXIS2_TRANSPORT_ENUM_MAX; i++) + { + if(transport_out_map[i]) + { + axis2_transport_sender_t *sender = axis2_transport_out_desc_get_sender( + transport_out_map[i], env); + if(sender) + { + status = AXIS2_TRANSPORT_SENDER_INIT(sender, env, conf_ctx, + transport_out_map[i]); + } + } + } + status = AXIS2_SUCCESS; + } + else + { + AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, + "Retrieving Axis2 configuration from Axis2 configuration context " + "failed. Initializing transports failed"); + } + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_init_transports"); + return status; +} + diff --git a/src/core/deployment/dep_engine.c b/src/core/deployment/dep_engine.c new file mode 100644 index 0000000..2c43380 --- /dev/null +++ b/src/core/deployment/dep_engine.c @@ -0,0 +1,1988 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "axis2_dep_engine.h" +#include <axutil_array_list.h> +#include <axis2_deployment.h> +#include <axutil_file_handler.h> +#include <axis2_flow.h> +#include <axis2_arch_reader.h> +#include <axis2_module_builder.h> +#include <axis2_svc_builder.h> +#include <axis2_svc_grp_builder.h> +#include <axiom_node.h> +#include <axutil_class_loader.h> +#include <axutil_string.h> +#include <axutil_utils.h> +#include <axis2_core_utils.h> +#include <axis2_module.h> + +struct axis2_dep_engine +{ + axis2_arch_file_data_t *curr_file; + axis2_arch_reader_t *arch_reader; + + /** + * To keep a reference to engine configuration. + * This reference will pass to engine when it call start() + * function + */ + axis2_conf_t *conf; + axis2_char_t *axis2_repos; + axis2_bool_t hot_dep; /* to do hot deployment or not */ + axis2_bool_t hot_update; /* to do hot update or not */ + + /* Whether dep_engine built using axis2.xml */ + axis2_bool_t file_flag; + + /** + * This will store all the web services to deploy + */ + axutil_array_list_t *ws_to_deploy; + + /** + * This will store all the web services to undeploy + */ + axutil_array_list_t *ws_to_undeploy; + axis2_phases_info_t *phases_info; /* To store phases list in axis2.xml */ + + axis2_char_t *folder_name; + + /** + * Module directory, dep_engine holds in the module build scenario. + */ + axis2_char_t *module_dir; + + /** + * Services directory, services are avialble in services directory + */ + + axis2_char_t *svc_dir; + + /** + * Full path to the server xml file(axis2.xml) + */ + axis2_char_t *conf_name; + + /** + * To store the module specified in the server.xml(axis2.xml) at the + * document parsing time + */ + axutil_array_list_t *module_list; + axis2_repos_listener_t *repos_listener; /*Added this here to help with freeing + memory allocated for this - Samisa */ + axis2_conf_builder_t *conf_builder; + axis2_svc_builder_t *svc_builder; + axutil_array_list_t *desc_builders; + axutil_array_list_t *module_builders; + axutil_array_list_t *svc_builders; + axutil_array_list_t *svc_grp_builders; +}; + +static axis2_status_t +axis2_dep_engine_set_dep_features( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + +static axis2_status_t +axis2_dep_engine_check_client_home( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + const axis2_char_t * client_home); + +static axis2_status_t +axis2_dep_engine_engage_modules( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + +static axis2_status_t +axis2_dep_engine_validate_system_predefined_phases( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env); + +static axis2_status_t +axis2_dep_engine_add_new_svc( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_svc_grp_t * svc_metadata); + +static axis2_status_t +axis2_dep_engine_load_module_dll( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_module_desc_t * module_desc); + +static axis2_status_t +axis2_dep_engine_add_module_flow_handlers( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_flow_t * flow, + axutil_hash_t * handler_create_func_map); + +static axis2_status_t +axis2_dep_engine_add_new_module( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_module_desc_t * module_metadata); + +static axis2_char_t * +axis2_dep_engine_get_axis_svc_name( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_char_t * file_name); + +static axis2_status_t +axis2_dep_engine_set_svc_and_module_dir_path( + axis2_dep_engine_t *dep_engine, + const axutil_env_t *env); + +AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL +axis2_dep_engine_create( + const axutil_env_t * env) +{ + axis2_dep_engine_t *dep_engine = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + dep_engine = (axis2_dep_engine_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_dep_engine_t)); + + if(!dep_engine) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return NULL; + } + dep_engine = (axis2_dep_engine_t *)memset(dep_engine, 0, sizeof(axis2_dep_engine_t)); + dep_engine->curr_file = NULL; + dep_engine->arch_reader = NULL; + dep_engine->conf = NULL; + dep_engine->axis2_repos = NULL; + dep_engine->ws_to_deploy = NULL; + dep_engine->ws_to_undeploy = NULL; + dep_engine->phases_info = NULL; + dep_engine->folder_name = NULL; + dep_engine->module_dir = NULL; + dep_engine->svc_dir = NULL; + dep_engine->conf_name = NULL; + dep_engine->module_list = NULL; + dep_engine->repos_listener = NULL; + dep_engine->conf_builder = NULL; + dep_engine->svc_builder = NULL; + dep_engine->desc_builders = NULL; + dep_engine->module_builders = NULL; + dep_engine->svc_builders = NULL; + dep_engine->svc_grp_builders = NULL; + + dep_engine->ws_to_deploy = axutil_array_list_create(env, 0); + if(!(dep_engine->ws_to_deploy)) + { + axis2_dep_engine_free(dep_engine, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return NULL; + } + + dep_engine->desc_builders = axutil_array_list_create(env, 0); + dep_engine->module_builders = axutil_array_list_create(env, 0); + dep_engine->svc_builders = axutil_array_list_create(env, 0); + dep_engine->svc_grp_builders = axutil_array_list_create(env, 0); + + dep_engine->phases_info = axis2_phases_info_create(env); + if(!(dep_engine->phases_info)) + { + axis2_dep_engine_free(dep_engine, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return NULL; + } + + return dep_engine; +} + +AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL +axis2_dep_engine_create_with_repos_name( + const axutil_env_t * env, + const axis2_char_t * repos_path) +{ + axis2_dep_engine_t *dep_engine = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + dep_engine = (axis2_dep_engine_t *)axis2_dep_engine_create_with_repos_name_and_svr_xml_file( + env, repos_path, AXIS2_SERVER_XML_FILE); + + if(!dep_engine) + { + return NULL; + } + + dep_engine->file_flag = AXIS2_FALSE; + + return dep_engine; +} + +AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL +axis2_dep_engine_create_with_axis2_xml( + const axutil_env_t * env, + const axis2_char_t * axis2_xml) +{ + axis2_dep_engine_t *dep_engine = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + dep_engine = (axis2_dep_engine_t *)axis2_dep_engine_create_with_svr_xml_file(env, axis2_xml); + if(!dep_engine) + { + return NULL; + } + dep_engine->file_flag = AXIS2_TRUE; + + return dep_engine; +} + +AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL +axis2_dep_engine_create_with_repos_name_and_svr_xml_file( + const axutil_env_t * env, + const axis2_char_t * repos_path, + const axis2_char_t * svr_xml_file) +{ + axis2_dep_engine_t *dep_engine = NULL; + axis2_char_t *conf_file_l = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, repos_path, NULL); + AXIS2_PARAM_CHECK(env->error, svr_xml_file, NULL); + if(!axutil_strcmp("", repos_path)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_REPO_CAN_NOT_BE_NULL, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Repository path cannot be empty"); + return NULL; + } + + dep_engine = (axis2_dep_engine_t *)axis2_dep_engine_create(env); + + if(!dep_engine) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return NULL; + } + + status = axutil_file_handler_access(repos_path, AXIS2_F_OK); + if(AXIS2_SUCCESS != status) + { + axis2_dep_engine_free(dep_engine, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_REPOSITORY_NOT_EXIST, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Repository path %s does not exist", repos_path); + return NULL; + } + + dep_engine->folder_name = axutil_strdup(env, repos_path); + if(!dep_engine->folder_name) + { + axis2_dep_engine_free(dep_engine, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return NULL; + } + + dep_engine->axis2_repos = axutil_strdup(env, repos_path); + if(!dep_engine->axis2_repos) + { + axis2_dep_engine_free(dep_engine, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return NULL; + } + + conf_file_l = axutil_stracat(env, repos_path, AXIS2_PATH_SEP_STR); + dep_engine->conf_name = axutil_stracat(env, conf_file_l, svr_xml_file); + + AXIS2_FREE(env->allocator, conf_file_l); + if(!dep_engine->conf_name) + { + axis2_dep_engine_free(dep_engine, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_REPO_CAN_NOT_BE_NULL, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Axis2 Configuration file name cannot be NULL"); + return NULL; + } + + status = axutil_file_handler_access(dep_engine->conf_name, AXIS2_F_OK); + if(AXIS2_SUCCESS != status) + { + axis2_dep_engine_free(dep_engine, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CONFIG_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Axis2 Configuration file name not found"); + return NULL; + } + + return dep_engine; +} + +AXIS2_EXTERN axis2_dep_engine_t *AXIS2_CALL +axis2_dep_engine_create_with_svr_xml_file( + const axutil_env_t * env, + const axis2_char_t * svr_xml_file) +{ + axis2_dep_engine_t *dep_engine = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, svr_xml_file, NULL); + + dep_engine = (axis2_dep_engine_t *)axis2_dep_engine_create(env); + + if(!dep_engine) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return NULL; + } + + dep_engine->conf_name = axutil_strdup(env, (axis2_char_t *)svr_xml_file); + if(!dep_engine->conf_name) + { + axis2_dep_engine_free(dep_engine, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_REPO_CAN_NOT_BE_NULL, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Axis2 Configuration file name cannot be NULL"); + return NULL; + } + status = axutil_file_handler_access(dep_engine->conf_name, AXIS2_F_OK); + if(AXIS2_SUCCESS != status) + { + axis2_dep_engine_free(dep_engine, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CONFIG_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Axis2 Configuration file name not found"); + return NULL; + } + + return dep_engine; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_dep_engine_free( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, void); + if(!dep_engine) + { + return; + } + + if(dep_engine->curr_file) + { + axis2_arch_file_data_free(dep_engine->curr_file, env); + } + + if(dep_engine->phases_info) + { + axis2_phases_info_free(dep_engine->phases_info, env); + } + + if(dep_engine->conf_builder) + { + axis2_conf_builder_free(dep_engine->conf_builder, env); + } + + if(dep_engine->arch_reader) + { + axis2_arch_reader_free(dep_engine->arch_reader, env); + } + + if(dep_engine->svc_builder) + { + axis2_svc_builder_free(dep_engine->svc_builder, env); + } + + if(dep_engine->ws_to_deploy) + { + int i = 0; + int size = 0; + + size = axutil_array_list_size(dep_engine->ws_to_deploy, env); + for(i = 0; i < size; i++) + { + axis2_arch_file_data_t *file_data = NULL; + + file_data = (axis2_arch_file_data_t *)axutil_array_list_get(dep_engine->ws_to_deploy, + env, i); + + axis2_arch_file_data_free(file_data, env); + } + + axutil_array_list_free(dep_engine->ws_to_deploy, env); + dep_engine->ws_to_deploy = NULL; + } + + if(dep_engine->desc_builders) + { + int i = 0; + int size = 0; + + size = axutil_array_list_size(dep_engine->desc_builders, env); + for(i = 0; i < size; i++) + { + axis2_desc_builder_t *desc_builder = NULL; + + desc_builder = (axis2_desc_builder_t *)axutil_array_list_get(dep_engine->desc_builders, + env, i); + + axis2_desc_builder_free(desc_builder, env); + } + + axutil_array_list_free(dep_engine->desc_builders, env); + } + + if(dep_engine->module_builders) + { + int i = 0; + int size = 0; + + size = axutil_array_list_size(dep_engine->module_builders, env); + for(i = 0; i < size; i++) + { + axis2_module_builder_t *module_builder = NULL; + + module_builder = (axis2_module_builder_t *)axutil_array_list_get( + dep_engine->module_builders, env, i); + + axis2_module_builder_free(module_builder, env); + } + + axutil_array_list_free(dep_engine->module_builders, env); + } + + if(dep_engine->svc_builders) + { + int i = 0; + int size = 0; + + size = axutil_array_list_size(dep_engine->svc_builders, env); + for(i = 0; i < size; i++) + { + axis2_svc_builder_t *svc_builder = NULL; + + svc_builder = (axis2_svc_builder_t *)axutil_array_list_get(dep_engine->svc_builders, + env, i); + + axis2_svc_builder_free(svc_builder, env); + } + + axutil_array_list_free(dep_engine->svc_builders, env); + } + + if(dep_engine->svc_grp_builders) + { + int i = 0; + int size = 0; + + size = axutil_array_list_size(dep_engine->svc_grp_builders, env); + for(i = 0; i < size; i++) + { + axis2_svc_grp_builder_t *svc_grp_builder = NULL; + + svc_grp_builder = (axis2_svc_grp_builder_t *)axutil_array_list_get( + dep_engine->svc_grp_builders, env, i); + + axis2_svc_grp_builder_free(svc_grp_builder, env); + } + + axutil_array_list_free(dep_engine->svc_grp_builders, env); + } + + if(dep_engine->ws_to_undeploy) + { + int i = 0; + int size = 0; + + size = axutil_array_list_size(dep_engine->ws_to_undeploy, env); + + for(i = 0; i < size; i++) + { + axis2_arch_file_data_t *file_data = NULL; + + file_data = (axis2_arch_file_data_t *)axutil_array_list_get(dep_engine->ws_to_undeploy, + env, i); + + axis2_arch_file_data_free(file_data, env); + } + + axutil_array_list_free(dep_engine->ws_to_undeploy, env); + dep_engine->ws_to_undeploy = NULL; + } + + if(dep_engine->module_list) + { + int size = 0; + int i = 0; + + size = axutil_array_list_size(dep_engine->module_list, env); + + for(i = 0; i < size; i++) + { + axutil_qname_t *qname = NULL; + qname = axutil_array_list_get(dep_engine->module_list, env, i); + if(qname) + { + axutil_qname_free(qname, env); + } + } + + axutil_array_list_free(dep_engine->module_list, env); + } + + if(dep_engine->folder_name) + { + AXIS2_FREE(env->allocator, dep_engine->folder_name); + } + + if(dep_engine->conf_name) + { + AXIS2_FREE(env->allocator, dep_engine->conf_name); + } + + if(dep_engine->axis2_repos) + { + AXIS2_FREE(env->allocator, dep_engine->axis2_repos); + } + + if(dep_engine->repos_listener) + { + axis2_repos_listener_free(dep_engine->repos_listener, env); + } + + if(dep_engine) + { + AXIS2_FREE(env->allocator, dep_engine); + } + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_add_module( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axutil_qname_t * module_qname) +{ + axutil_qname_t *qname = NULL; + + AXIS2_PARAM_CHECK(env->error, module_qname, AXIS2_FAILURE); + + qname = axutil_qname_clone(module_qname, env); + if(!dep_engine->module_list) + { + dep_engine->module_list = axutil_array_list_create(env, 0); + if(!dep_engine->module_list) + { + axutil_qname_free(qname, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return AXIS2_FAILURE; + } + } + return axutil_array_list_add(dep_engine->module_list, env, qname); +} + +struct axis2_module_desc *AXIS2_CALL +axis2_dep_engine_get_module( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axutil_qname_t * module_qname) +{ + AXIS2_PARAM_CHECK(env->error, module_qname, NULL); + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + + return axis2_conf_get_module(dep_engine->conf, env, module_qname); +} + +AXIS2_EXTERN struct axis2_arch_file_data *AXIS2_CALL +axis2_dep_engine_get_current_file_item( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + return dep_engine->curr_file; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_add_ws_to_deploy( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_arch_file_data_t * file) +{ + AXIS2_PARAM_CHECK(env->error, file, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + return axutil_array_list_add(dep_engine->ws_to_deploy, env, file); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_add_ws_to_undeploy( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_ws_info_t * file) +{ + AXIS2_PARAM_CHECK(env->error, file, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + if(!(dep_engine->ws_to_undeploy)) + { + dep_engine->ws_to_undeploy = axutil_array_list_create(env, 0); + } + return axutil_array_list_add(dep_engine->ws_to_undeploy, env, file); +} + +AXIS2_EXTERN axis2_phases_info_t *AXIS2_CALL +axis2_dep_engine_get_phases_info( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + return dep_engine->phases_info; +} + +AXIS2_EXTERN axis2_conf_t *AXIS2_CALL +axis2_dep_engine_get_axis_conf( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + return dep_engine->conf; +} + +/** + * To set hot deployment and hot update + */ +static axis2_status_t +axis2_dep_engine_set_dep_features( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + axis2_char_t *value = NULL; + axutil_param_t *para_hot_dep = NULL; + axutil_param_t *para_hot_update = NULL; + + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + para_hot_dep = axis2_conf_get_param(dep_engine->conf, env, AXIS2_HOTDEPLOYMENT); + para_hot_update = axis2_conf_get_param(dep_engine->conf, env, AXIS2_HOTUPDATE); + + if(para_hot_dep) + { + value = (axis2_char_t *)axutil_param_get_value(para_hot_dep, env); + if(0 == axutil_strcasecmp(AXIS2_VALUE_FALSE, value)) + { + dep_engine->hot_dep = AXIS2_FALSE; + } + } + + if(para_hot_update) + { + value = (axis2_char_t *)axutil_param_get_value(para_hot_update, env); + if(0 == axutil_strcasecmp(AXIS2_VALUE_FALSE, value)) + { + dep_engine->hot_update = AXIS2_FALSE; + } + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_conf_t *AXIS2_CALL +axis2_dep_engine_load( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + axis2_status_t status = AXIS2_FAILURE; + axutil_array_list_t *out_fault_phases = NULL; + + if(!dep_engine->conf_name) + { + AXIS2_ERROR_SET(env->error, AXIS2_PATH_TO_CONFIG_CAN_NOT_BE_NULL, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Path to axis2 configuration file is NULL. Unable to continue"); + return NULL; + } + + dep_engine->conf = axis2_conf_create(env); + if(!dep_engine->conf) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Allocation to configuration failed"); + return NULL; + } + + /* Set a flag to mark that conf is created using axis2 xml. To find out that conf is build using + * axis2 xml , this flag can be used. + */ + axis2_conf_set_axis2_flag(dep_engine->conf, env, dep_engine->file_flag); + axis2_conf_set_axis2_xml(dep_engine->conf, env, dep_engine->conf_name); + + dep_engine->conf_builder = axis2_conf_builder_create_with_file_and_dep_engine_and_conf(env, + dep_engine->conf_name, dep_engine, dep_engine->conf); + if(!(dep_engine->conf_builder)) + { + axis2_conf_free(dep_engine->conf, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Configuration builder creation failed"); + dep_engine->conf = NULL; + } + + /* Populate the axis2 configuration from reading axis2.xml. + */ + status = axis2_conf_builder_populate_conf(dep_engine->conf_builder, env); + if(AXIS2_SUCCESS != status) + { + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Populating Axis2 Configuration failed"); + return NULL; + } + + status = axis2_dep_engine_set_svc_and_module_dir_path(dep_engine, env); + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting service and module directory paths failed"); + return NULL; + } + + status = axis2_dep_engine_set_dep_features(dep_engine, env); + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting deployment features failed"); + return NULL; + } + + if(dep_engine->repos_listener) + { + axis2_repos_listener_free(dep_engine->repos_listener, env); + } + + dep_engine->repos_listener = axis2_repos_listener_create_with_folder_name_and_dep_engine(env, + dep_engine->folder_name, dep_engine); + if(!dep_engine->repos_listener) + { + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "dep_engine repos listener creation failed, folder name is %s", dep_engine->folder_name); + return NULL; + } + + axis2_conf_set_repo(dep_engine->conf, env, dep_engine->axis2_repos); + axis2_core_utils_calculate_default_module_version(env, axis2_conf_get_all_modules( + dep_engine->conf, env), dep_engine->conf); + + status = axis2_dep_engine_validate_system_predefined_phases(dep_engine, env); + if(AXIS2_SUCCESS != status) + { + axis2_repos_listener_free(dep_engine->repos_listener, env); + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MODULE_VALIDATION_FAILED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Validating system predefined phases failed"); + return NULL; + } + + status = axis2_conf_set_phases_info(dep_engine->conf, env, dep_engine->phases_info); + if(AXIS2_SUCCESS != status) + { + axis2_repos_listener_free(dep_engine->repos_listener, env); + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting phases info into Axis2 Configuration failed"); + return NULL; + } + + out_fault_phases = axis2_phases_info_get_op_out_faultphases(dep_engine->phases_info, env); + if(out_fault_phases) + { + status = axis2_conf_set_out_fault_phases(dep_engine->conf, env, out_fault_phases); + } + + if(AXIS2_SUCCESS != status) + { + axis2_repos_listener_free(dep_engine->repos_listener, env); + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting out fault phases into Axis2 Configuratin failed"); + return NULL; + } + + status = axis2_dep_engine_engage_modules(dep_engine, env); + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "dep engine failed to engaged_modules"); + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MODULE_VALIDATION_FAILED, AXIS2_FAILURE); + return NULL; + } + + return dep_engine->conf; +} + +AXIS2_EXTERN axis2_conf_t *AXIS2_CALL +axis2_dep_engine_load_client( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + const axis2_char_t * client_home) +{ + axis2_bool_t is_repos_exist = AXIS2_FALSE; + axis2_status_t status = AXIS2_FAILURE; + axis2_bool_t flag = AXIS2_FALSE; + + AXIS2_PARAM_CHECK(env->error, client_home, NULL); + + flag = axis2_dep_engine_get_file_flag(dep_engine, env); + + if(!flag) + { + dep_engine->axis2_repos = axutil_strdup(env, client_home); + if(!dep_engine->axis2_repos) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return NULL; + } + + if(client_home && axutil_strcmp("", client_home)) + { + status = axis2_dep_engine_check_client_home(dep_engine, env, client_home); + if(AXIS2_SUCCESS == status) + { + is_repos_exist = AXIS2_TRUE; + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "axis2.xml is not available in client repo %s ", client_home); + + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CONFIG_NOT_FOUND, AXIS2_FAILURE); + + return NULL; + } + } + else + { + dep_engine->conf_name = axutil_strdup(env, AXIS2_CONFIGURATION_RESOURCE); + + if(!dep_engine->conf_name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_REPO_CAN_NOT_BE_NULL, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Axis2 Configuration file name cannot be NULL"); + return NULL; + } + } + } + + else + { + is_repos_exist = AXIS2_TRUE; + } + + dep_engine->conf = axis2_conf_create(env); + if(!dep_engine->conf) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "No memory. Allocation for Axis2 Configuration failed"); + return NULL; + } + dep_engine->conf_builder = axis2_conf_builder_create_with_file_and_dep_engine_and_conf(env, + dep_engine->conf_name, dep_engine, dep_engine->conf); + + if(!(dep_engine->conf_builder)) + { + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + } + + /** + Very important: Only after populating we will be able to access + parameters in axis2 xml. + */ + + axis2_conf_set_axis2_flag(dep_engine->conf, env, dep_engine->file_flag); + axis2_conf_set_axis2_xml(dep_engine->conf, env, dep_engine->conf_name); + + status = axis2_conf_builder_populate_conf(dep_engine->conf_builder, env); + if(AXIS2_SUCCESS != status) + { + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Populating Axis2 Configuration failed"); + return NULL; + } + + status = axis2_dep_engine_set_svc_and_module_dir_path(dep_engine, env); + if(AXIS2_SUCCESS != status) + { + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting service and module paths failed"); + return NULL; + } + + if(is_repos_exist) + { + dep_engine->hot_dep = AXIS2_FALSE; + dep_engine->hot_update = AXIS2_FALSE; + if(dep_engine->repos_listener) + { + axis2_repos_listener_free(dep_engine->repos_listener, env); + } + + dep_engine->repos_listener = axis2_repos_listener_create_with_folder_name_and_dep_engine( + env, dep_engine->folder_name, dep_engine); + } + + axis2_conf_set_repo(dep_engine->conf, env, dep_engine->axis2_repos); + axis2_core_utils_calculate_default_module_version(env, axis2_conf_get_all_modules( + dep_engine->conf, env), dep_engine->conf); + + axis2_conf_set_phases_info(dep_engine->conf, env, dep_engine->phases_info); + status = axis2_dep_engine_engage_modules(dep_engine, env); + if(AXIS2_SUCCESS != status) + { + axis2_repos_listener_free(dep_engine->repos_listener, env); + axis2_conf_free(dep_engine->conf, env); + dep_engine->conf = NULL; + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MODULE_VALIDATION_FAILED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Module engage failed for deployment engine"); + return NULL; + } + + return dep_engine->conf; +} + +static axis2_status_t +axis2_dep_engine_check_client_home( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + const axis2_char_t * client_home) +{ + axis2_char_t *path_l = NULL; + axis2_status_t status = AXIS2_FAILURE; + + dep_engine->folder_name = axutil_strdup(env, client_home); + if(!dep_engine->folder_name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return AXIS2_FAILURE; + } + path_l = axutil_stracat(env, client_home, AXIS2_PATH_SEP_STR); + dep_engine->conf_name = axutil_stracat(env, path_l, AXIS2_SERVER_XML_FILE); + AXIS2_FREE(env->allocator, path_l); + + if(!dep_engine->conf_name) + { + dep_engine->conf_name = axutil_strdup(env, AXIS2_CONFIGURATION_RESOURCE); + if(!dep_engine->conf_name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CONFIG_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Axis2 Configuration file name cannot be NULL"); + return AXIS2_FAILURE; + } + } + + status = axutil_file_handler_access(dep_engine->conf_name, AXIS2_F_OK); + if(AXIS2_SUCCESS != status) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CONFIG_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Axis2 Configuration file name not found"); + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +static axis2_status_t +axis2_dep_engine_engage_modules( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + int size = 0; + int i = 0; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + if(!dep_engine->module_list) + { + /* There are no modules */ + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No modules configured"); + return AXIS2_SUCCESS; + } + + size = axutil_array_list_size(dep_engine->module_list, env); + + for(i = 0; i < size; i++) + { + axutil_qname_t *qname = NULL; + qname = (axutil_qname_t *)axutil_array_list_get(dep_engine->module_list, env, i); + if(qname && dep_engine->conf) + { + status = axis2_conf_engage_module(dep_engine->conf, env, qname); + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Engaging module %s to Axis2 Configuration failed", axutil_qname_get_localpart( + qname, env)); + + return status; + } + } + } + + return AXIS2_SUCCESS; +} + +static axis2_status_t +axis2_dep_engine_validate_system_predefined_phases( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + axutil_array_list_t *in_phases = NULL; + axis2_char_t *phase0 = NULL; + axis2_char_t *phase1 = NULL; + axis2_char_t *phase2 = NULL; + axis2_char_t *phase3 = NULL; + + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + in_phases = axis2_phases_info_get_in_phases(dep_engine->phases_info, env); + if(in_phases) + { + phase0 = (axis2_char_t *)axutil_array_list_get(in_phases, env, 0); + phase1 = (axis2_char_t *)axutil_array_list_get(in_phases, env, 1); + phase2 = (axis2_char_t *)axutil_array_list_get(in_phases, env, 2); + phase3 = (axis2_char_t *)axutil_array_list_get(in_phases, env, 3); + } + + if((phase0 && 0 != axutil_strcmp(phase0, AXIS2_PHASE_TRANSPORT_IN)) || (phase1 && 0 + != axutil_strcmp(phase1, AXIS2_PHASE_PRE_DISPATCH)) || (phase2 && 0 != axutil_strcmp( + phase2, AXIS2_PHASE_DISPATCH)) || (phase3 && 0 != axutil_strcmp(phase3, + AXIS2_PHASE_POST_DISPATCH))) + { + AXIS2_ERROR_SET(env->error, AXI2_ERROR_INVALID_PHASE, AXIS2_FAILURE); + return AXIS2_SUCCESS; + } + + return AXIS2_SUCCESS; +} + +/* For each searvices belonging to the service group passed as parameter, + * 1) Modules defined to be engaged to passed service group are engaged. + * 2) Modules defined to be engaged to service are engaged. + * + * Then for each service operation modules defined to be engaged to that operation are engaged. + */ +static axis2_status_t +axis2_dep_engine_add_new_svc( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_svc_grp_t * svc_metadata) +{ + axutil_array_list_t *svcs = NULL; + int sizei = 0; + int i = 0; + + AXIS2_PARAM_CHECK(env->error, svc_metadata, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + svcs = axis2_arch_file_data_get_deployable_svcs(dep_engine->curr_file, env); + if(svcs) + { + sizei = axutil_array_list_size(svcs, env); + } + + for(i = 0; i < sizei; i++) + { + axis2_svc_t *svc = NULL; + axutil_file_t *file = NULL; + axutil_array_list_t *grp_modules = NULL; + axutil_array_list_t *list = NULL; + int sizej = 0; + int j = 0; + axutil_hash_t *ops = NULL; + axutil_hash_index_t *index_i = NULL; + axis2_char_t *file_name = NULL; + + svc = (axis2_svc_t *)axutil_array_list_get(svcs, env, i); + + file = axis2_arch_file_data_get_file(dep_engine->curr_file, env); + file_name = axutil_file_get_name(file, env); + axis2_svc_set_file_name(svc, env, file_name); + + /* Modules from service group */ + grp_modules = axis2_svc_grp_get_all_module_qnames(svc_metadata, env); + if(grp_modules) + { + sizej = axutil_array_list_size(grp_modules, env); + } + for(j = 0; j < sizej; j++) + { + axis2_module_desc_t *module_desc = NULL; + axutil_qname_t *qmodulename = NULL; + + qmodulename = (axutil_qname_t *)axutil_array_list_get(grp_modules, env, j); + module_desc = axis2_conf_get_module(dep_engine->conf, env, qmodulename); + if(module_desc) + { + axis2_svc_engage_module(svc, env, module_desc, dep_engine->conf); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid module reference taken from conf"); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_MODUELE_REF, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + + /* Modules from service */ + list = axis2_svc_get_all_module_qnames(svc, env); + sizej = axutil_array_list_size(list, env); + for(j = 0; j < sizej; j++) + { + axis2_module_desc_t *module_desc = NULL; + axutil_qname_t *qmodulename = NULL; + + qmodulename = (axutil_qname_t *)axutil_array_list_get(list, env, j); + module_desc = axis2_conf_get_module(dep_engine->conf, env, qmodulename); + if(module_desc) + { + axis2_status_t status = AXIS2_FAILURE; + status = axis2_svc_engage_module(svc, env, module_desc, dep_engine->conf); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Engaging module %s to service %s failed", axutil_qname_get_localpart( + qmodulename, env), file_name); + return status; + } + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid module reference taken from conf"); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_MODUELE_REF, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + + ops = axis2_svc_get_all_ops(svc, env); + for(index_i = axutil_hash_first(ops, env); index_i; index_i + = axutil_hash_next(env, index_i)) + { + void *v = NULL; + axis2_op_t *op_desc = NULL; + axutil_array_list_t *modules = NULL; + int sizek = 0; + int k = 0; + + axutil_hash_this(index_i, NULL, NULL, &v); + op_desc = (axis2_op_t *)v; + + modules = axis2_op_get_all_module_qnames(op_desc, env); + if(modules) + { + sizek = axutil_array_list_size(modules, env); + } + for(k = 0; k < sizek; k++) + { + axutil_qname_t *module_qname = NULL; + axis2_module_desc_t *module = NULL; + + module_qname = (axutil_qname_t *)axutil_array_list_get(modules, env, k); + module = axis2_conf_get_module(dep_engine->conf, env, module_qname); + + if(module) + { + axis2_op_engage_module(op_desc, env, module, dep_engine->conf); + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_MODUELE_REF_BY_OP, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Module %s is not added to the Axis2 Configuration", + axutil_qname_get_localpart(module_qname, env)); + + return AXIS2_FAILURE; + } + } + } + + axis2_svc_grp_add_svc(svc_metadata, env, svc); + } + + return axis2_conf_add_svc_grp(dep_engine->conf, env, svc_metadata); +} + +/* Here we will load the actual module implementation dll using the class loader and store it in + * module description. + */ +static axis2_status_t +axis2_dep_engine_load_module_dll( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_module_desc_t * module_desc) +{ + axis2_char_t *read_in_dll = NULL; + axis2_module_t *module = NULL; + axutil_dll_desc_t *dll_desc = NULL; + axutil_param_t *impl_info_param = NULL; + axutil_file_t *module_folder = NULL; + AXIS2_TIME_T timestamp = 0; + axis2_char_t *module_folder_path = NULL; + axis2_char_t *temp_path = NULL; + axis2_char_t *dll_path = NULL; + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t *dll_name = NULL; + + AXIS2_PARAM_CHECK(env->error, module_desc, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + read_in_dll = axis2_arch_file_data_get_module_dll_name(dep_engine->curr_file, env); + dll_desc = axutil_dll_desc_create(env); + dll_name = axutil_dll_desc_create_platform_specific_dll_name(dll_desc, env, read_in_dll); + + module_folder = axis2_arch_file_data_get_file(dep_engine->curr_file, env); + timestamp = axutil_file_get_timestamp(module_folder, env); + axutil_dll_desc_set_timestamp(dll_desc, env, timestamp); + module_folder_path = axutil_file_get_path(module_folder, env); + temp_path = axutil_stracat(env, module_folder_path, AXIS2_PATH_SEP_STR); + dll_path = axutil_stracat(env, temp_path, dll_name); + + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "axis2_dep_engine_load_module_dll: DLL path is : %s", + dll_path); + status = axutil_dll_desc_set_name(dll_desc, env, dll_path); + if(AXIS2_SUCCESS != status) + { + axutil_dll_desc_free(dll_desc, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting dll path %s to the dll description failed", dll_path); + + return AXIS2_FAILURE; + } + + /* Free all temp vars */ + AXIS2_FREE(env->allocator, temp_path); + temp_path = NULL; + AXIS2_FREE(env->allocator, dll_path); + dll_path = NULL; + + axutil_dll_desc_set_type(dll_desc, env, AXIS2_MODULE_DLL); + impl_info_param = axutil_param_create(env, read_in_dll, NULL); + axutil_param_set_value(impl_info_param, env, dll_desc); + axutil_param_set_value_free(impl_info_param, env, axutil_dll_desc_free_void_arg); + axutil_class_loader_init(env); + module = (axis2_module_t *)axutil_class_loader_create_dll(env, impl_info_param); + + /* We cannot free the created impl_info_param here because by freeing + * so, it will free dll_desc which in turn unload the module. So we + * add this as a param to module_desc + */ + axis2_module_desc_add_param(module_desc, env, impl_info_param); + + return axis2_module_desc_set_module(module_desc, env, module); +} + +/* For each handler description of the module flow take the corresponding handler create function + * from handler_create_func_map and create the handler instance for the handler description. + */ +static axis2_status_t +axis2_dep_engine_add_module_flow_handlers( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_flow_t * flow, + axutil_hash_t * handler_create_func_map) +{ + int count = 0; + int j = 0; + + AXIS2_PARAM_CHECK(env->error, flow, AXIS2_FAILURE); + + count = axis2_flow_get_handler_count(flow, env); + + for(j = 0; j < count; j++) + { + axis2_handler_desc_t *handlermd = NULL; + axis2_handler_t *handler = NULL; + const axutil_string_t *handler_name = NULL; + AXIS2_HANDLER_CREATE_FUNC handler_create_func = NULL; + + handlermd = axis2_flow_get_handler(flow, env, j); + handler_name = axis2_handler_desc_get_name(handlermd, env); + handler_create_func = axutil_hash_get(handler_create_func_map, axutil_string_get_buffer( + handler_name, env), AXIS2_HASH_KEY_STRING); + + handler = handler_create_func(env, handler_name); + axis2_handler_init(handler, env, handlermd); + axis2_handler_desc_set_handler(handlermd, env, handler); + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void *AXIS2_CALL +axis2_dep_engine_get_handler_dll( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_char_t * class_name) +{ + axutil_dll_desc_t *dll_desc = NULL; + axutil_param_t *impl_info_param = NULL; + axis2_handler_t *handler = NULL; + axis2_char_t *dll_name = NULL; + + AXIS2_PARAM_CHECK(env->error, class_name, NULL); + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + + dll_desc = axutil_dll_desc_create(env); + dll_name = axutil_dll_desc_create_platform_specific_dll_name(dll_desc, env, class_name); + axutil_dll_desc_set_name(dll_desc, env, dll_name); + axutil_dll_desc_set_type(dll_desc, env, AXIS2_HANDLER_DLL); + axutil_class_loader_init(env); + impl_info_param = axutil_param_create(env, NULL, NULL); + axutil_param_set_value(impl_info_param, env, dll_desc); + handler = (axis2_handler_t *)axutil_class_loader_create_dll(env, impl_info_param); + + return handler; +} + +/* Caller has module description filled with the information in module.xml by the time this + * function is called. Now it will load the actual module implementation and fill the module + * flows with the actual handler instances. Finally module description will be added into the + * configuration module list. + */ +static axis2_status_t +axis2_dep_engine_add_new_module( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_module_desc_t * module_metadata) +{ + axis2_flow_t *in_flow = NULL; + axis2_flow_t *out_flow = NULL; + axis2_flow_t *in_fault_flow = NULL; + axis2_flow_t *out_fault_flow = NULL; + axis2_module_t *module = NULL; + axis2_status_t status = AXIS2_FAILURE; + const axutil_qname_t *module_qname = NULL; + axis2_char_t *module_name = NULL; + + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + module_qname = axis2_module_desc_get_qname(module_metadata, env); + module_name = axutil_qname_get_localpart(module_qname, env); + status = axis2_dep_engine_load_module_dll(dep_engine, env, module_metadata); + + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Loading module description %s failed", module_name); + + return status; + } + + module = axis2_module_desc_get_module(module_metadata, env); + if(!module) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Retrieving module from module description %s failed", module_name); + + return AXIS2_FAILURE; + } + + /* Module implementor will provide functions for creating his handlers and by calling this + * function these function pointers will be stored in a hash map in the module. + */ + status = axis2_module_fill_handler_create_func_map(module, env); + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Filling handler create function for module map %s failed", module_name); + return status; + } + + in_flow = axis2_module_desc_get_in_flow(module_metadata, env); + if(in_flow) + { + axis2_dep_engine_add_module_flow_handlers(dep_engine, env, in_flow, + module->handler_create_func_map); + } + + out_flow = axis2_module_desc_get_out_flow(module_metadata, env); + if(out_flow) + { + axis2_dep_engine_add_module_flow_handlers(dep_engine, env, out_flow, + module->handler_create_func_map); + } + + in_fault_flow = axis2_module_desc_get_fault_in_flow(module_metadata, env); + if(in_fault_flow) + { + axis2_dep_engine_add_module_flow_handlers(dep_engine, env, in_fault_flow, + module->handler_create_func_map); + } + + out_fault_flow = axis2_module_desc_get_fault_out_flow(module_metadata, env); + if(out_fault_flow) + { + axis2_dep_engine_add_module_flow_handlers(dep_engine, env, out_fault_flow, + module->handler_create_func_map); + } + + /* Add the module description into the axis2 configuration. Axis2 configuration will keep these + * handlers in a hash_map called all_modules. + */ + axis2_conf_add_module(dep_engine->conf, env, module_metadata); + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_do_deploy( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + int size = 0; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + size = axutil_array_list_size(dep_engine->ws_to_deploy, env); + + if(size > 0) + { + int i = 0; + for(i = 0; i < size; i++) + { + int type = 0; + axis2_svc_grp_t *svc_grp = NULL; + axis2_char_t *file_name = NULL; + axis2_module_desc_t *meta_data = NULL; + + dep_engine->curr_file = (axis2_arch_file_data_t *)axutil_array_list_get( + dep_engine->ws_to_deploy, env, i); + + type = axis2_arch_file_data_get_type(dep_engine->curr_file, env); + switch(type) + { + case AXIS2_SVC: + { + if(dep_engine->arch_reader) + { + axis2_arch_reader_free(dep_engine->arch_reader, env); + dep_engine->arch_reader = NULL; + } + + dep_engine->arch_reader = axis2_arch_reader_create(env); + svc_grp = axis2_svc_grp_create_with_conf(env, dep_engine->conf); + file_name = axis2_arch_file_data_get_name(dep_engine->curr_file, env); + status = axis2_arch_reader_process_svc_grp(dep_engine->arch_reader, env, + file_name, dep_engine, svc_grp); + + if(AXIS2_SUCCESS != status) + { + axis2_arch_reader_free(dep_engine->arch_reader, env); + dep_engine->arch_reader = NULL; + dep_engine->curr_file = NULL; + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_SVC, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Processing service group %s failed", file_name); + + return status; + } + + status = axis2_dep_engine_add_new_svc(dep_engine, env, svc_grp); + if(AXIS2_SUCCESS != status) + { + axis2_arch_reader_free(dep_engine->arch_reader, env); + dep_engine->arch_reader = NULL; + dep_engine->curr_file = NULL; + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_SVC, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Adding new service %s to the deployment engine failed", file_name); + + return status; + } + + dep_engine->curr_file = NULL; + break; + } + + case AXIS2_MODULE: + { + if(dep_engine->arch_reader) + { + axis2_arch_reader_free(dep_engine->arch_reader, env); + dep_engine->arch_reader = NULL; + } + dep_engine->arch_reader = axis2_arch_reader_create(env); + meta_data = axis2_module_desc_create(env); + file_name = axis2_arch_file_data_get_name(dep_engine->curr_file, env); + status = axis2_arch_reader_read_module_arch(env, file_name, dep_engine, + meta_data); + if(AXIS2_SUCCESS != status) + { + axis2_arch_reader_free(dep_engine->arch_reader, env); + dep_engine->arch_reader = NULL; + dep_engine->curr_file = NULL; + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_MODULE, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Reading module archive for file %s failed", file_name); + + return AXIS2_FAILURE; + } + + status = axis2_dep_engine_add_new_module(dep_engine, env, meta_data); + if(AXIS2_SUCCESS != status) + { + axis2_arch_reader_free(dep_engine->arch_reader, env); + dep_engine->arch_reader = NULL; + dep_engine->curr_file = NULL; + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_MODULE, AXIS2_FAILURE); + + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Adding new module %s to the deployment engine failed", file_name); + + return AXIS2_FAILURE; + } + + dep_engine->curr_file = NULL; + break; + } + }; + + axis2_arch_reader_free(dep_engine->arch_reader, env); + dep_engine->arch_reader = NULL; + dep_engine->curr_file = NULL; + } + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_undeploy( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + int size = 0; + axis2_char_t *svc_name = NULL; + + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + size = axutil_array_list_size(dep_engine->ws_to_undeploy, env); + + if(size > 0) + { + int i = 0; + for(i = 0; i < size; i++) + { + int type = 0; + axis2_ws_info_t *ws_info = NULL; + axutil_hash_t *faulty_svcs = NULL; + + ws_info = (axis2_ws_info_t *)axutil_array_list_get(dep_engine->ws_to_undeploy, env, i); + type = axis2_ws_info_get_type(ws_info, env); + if(type == AXIS2_SVC) + { + axis2_char_t *file_name = NULL; + + file_name = axis2_ws_info_get_file_name(ws_info, env); + svc_name = axis2_dep_engine_get_axis_svc_name(dep_engine, env, file_name); + + axis2_conf_remove_svc(dep_engine->conf, env, svc_name); + } + + faulty_svcs = axis2_conf_get_all_faulty_svcs(dep_engine->conf, env); + axutil_hash_set(faulty_svcs, svc_name, AXIS2_HASH_KEY_STRING, NULL); + } + + } + + axutil_array_list_free(dep_engine->ws_to_undeploy, env); + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_dep_engine_is_hot_update( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + return dep_engine->hot_update; +} + +static axis2_char_t * +axis2_dep_engine_get_axis_svc_name( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_char_t * file_name) +{ + axis2_char_t name_sep = '.'; + axis2_char_t *temp_name = NULL; + axis2_char_t *ptr = NULL; + axis2_char_t *file_name_l = NULL; + axis2_char_t *svc_name = NULL; + int len = 0; + + file_name_l = axutil_strdup(env, file_name); + ptr = AXIS2_STRRCHR(file_name_l, AXIS2_PATH_SEP_CHAR); + + temp_name = ptr + 1; + ptr = AXIS2_STRRCHR(temp_name, name_sep); + ptr[0] = '\0'; + len = (int)strlen(temp_name); + /* We are sure that the difference lies within the int range */ + svc_name = AXIS2_MALLOC(env->allocator, len + 1); + sscanf(temp_name, "%s", svc_name); + AXIS2_FREE(env->allocator, file_name_l); + + return svc_name; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_set_phases_info( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_phases_info_t * phases_info) +{ + AXIS2_PARAM_CHECK(env->error, phases_info, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + dep_engine->phases_info = phases_info; + return AXIS2_SUCCESS; +} + +/** + * This method is used to fill a axis2 service instance using services.xml , + * first it should create an axis service instance and then fill that using + * given service.xml and load all the required class and build the chains , + * finally add the service context to engine context and axis2 service into + * Engine Configuration. + */ +AXIS2_EXTERN axis2_svc_t *AXIS2_CALL +axis2_dep_engine_build_svc( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_svc_t * svc, + axis2_char_t * file_name) +{ + axiom_node_t *node = NULL; + + AXIS2_PARAM_CHECK(env->error, file_name, NULL); + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + + dep_engine->curr_file = axis2_arch_file_data_create_with_type_and_name(env, AXIS2_SVC, ""); + + dep_engine->svc_builder = axis2_svc_builder_create_with_file_and_dep_engine_and_svc(env, + file_name, dep_engine, svc); + + node = axis2_desc_builder_build_om(axis2_svc_builder_get_desc_builder(dep_engine->svc_builder, + env), env); + + axis2_svc_builder_populate_svc(dep_engine->svc_builder, env, node); + + return svc; +} + +/** + * This function can be used to build Module Description for a given module + * archieve file. + */ +AXIS2_EXTERN axis2_module_desc_t *AXIS2_CALL +axis2_dep_engine_build_module( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axutil_file_t * module_archive, + axis2_conf_t * conf) +{ + axis2_module_desc_t *module_desc = NULL; + axis2_module_t *module = NULL; + axis2_phases_info_t *phases_info = NULL; + axis2_arch_reader_t *arch_reader = NULL; + axis2_flow_t *in_flow = NULL; + axis2_flow_t *out_flow = NULL; + axis2_flow_t *in_fault_flow = NULL; + axis2_flow_t *out_fault_flow = NULL; + axis2_char_t *file_name = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, module_archive, NULL); + AXIS2_PARAM_CHECK(env->error, conf, NULL); + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + + phases_info = axis2_conf_get_phases_info(conf, env); + axis2_dep_engine_set_phases_info(dep_engine, env, phases_info); + dep_engine->curr_file = axis2_arch_file_data_create_with_type_and_file(env, AXIS2_MODULE, + module_archive); + + module_desc = axis2_module_desc_create(env); + arch_reader = axis2_arch_reader_create(env); + file_name = axutil_file_get_name(module_archive, env); + status = axis2_arch_reader_read_module_arch(env, file_name, dep_engine, module_desc); + axis2_arch_reader_free(arch_reader, env); + if(AXIS2_SUCCESS != status) + { + axis2_module_desc_free(module_desc, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Reading module archive for file %s failed", + file_name); + return NULL; + } + status = axis2_dep_engine_load_module_dll(dep_engine, env, module_desc); + if(AXIS2_SUCCESS != status) + { + axis2_module_desc_free(module_desc, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Loading module dll %s failed", file_name); + return NULL; + } + + module = axis2_module_desc_get_module(module_desc, env); + + /* Module implementor will provide functions for creating his handlers and by calling this + * function these function pointers will be stored in a hash map in the module. + */ + axis2_module_fill_handler_create_func_map(module, env); + + in_flow = axis2_module_desc_get_in_flow(module_desc, env); + if(in_flow) + { + axis2_dep_engine_add_module_flow_handlers(dep_engine, env, in_flow, + module->handler_create_func_map); + } + + out_flow = axis2_module_desc_get_out_flow(module_desc, env); + if(out_flow) + { + axis2_dep_engine_add_module_flow_handlers(dep_engine, env, out_flow, + module->handler_create_func_map); + } + + in_fault_flow = axis2_module_desc_get_fault_in_flow(module_desc, env); + if(in_fault_flow) + { + axis2_dep_engine_add_module_flow_handlers(dep_engine, env, in_fault_flow, + module->handler_create_func_map); + } + + out_fault_flow = axis2_module_desc_get_fault_out_flow(module_desc, env); + if(out_fault_flow) + { + axis2_dep_engine_add_module_flow_handlers(dep_engine, env, out_fault_flow, + module->handler_create_func_map); + } + + dep_engine->curr_file = NULL; + + return module_desc; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_dep_engine_get_repos_path( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + return dep_engine->folder_name; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_set_current_file_item( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_arch_file_data_t * file_data) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + if(dep_engine->curr_file) + { + axis2_arch_file_data_free(dep_engine->curr_file, env); + dep_engine->curr_file = NULL; + } + dep_engine->curr_file = file_data; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_set_arch_reader( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_arch_reader_t * arch_reader) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + if(dep_engine->arch_reader) + { + axis2_arch_reader_free(dep_engine->arch_reader, env); + dep_engine->arch_reader = NULL; + } + dep_engine->arch_reader = arch_reader; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_add_module_builder( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_module_builder_t * module_builder) +{ + AXIS2_PARAM_CHECK(env->error, module_builder, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + return axutil_array_list_add(dep_engine->module_builders, env, module_builder); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_add_svc_builder( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_svc_builder_t * svc_builder) +{ + AXIS2_PARAM_CHECK(env->error, svc_builder, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + return axutil_array_list_add(dep_engine->svc_builders, env, svc_builder); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_add_svc_grp_builder( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + axis2_svc_grp_builder_t * svc_grp_builder) +{ + AXIS2_PARAM_CHECK(env->error, svc_grp_builder, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + return axutil_array_list_add(dep_engine->svc_grp_builders, env, svc_grp_builder); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_add_desc_builder( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + struct axis2_desc_builder * desc_builder) +{ + AXIS2_PARAM_CHECK(env->error, desc_builder, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + + return axutil_array_list_add(dep_engine->desc_builders, env, desc_builder); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_dep_engine_get_module_dir( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + return axutil_strdup(env, dep_engine->module_dir); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_set_module_dir( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + const axis2_char_t *module_dir) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, module_dir, AXIS2_FAILURE); + dep_engine->module_dir = axutil_strdup(env, module_dir); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_dep_engine_get_file_flag( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FALSE); + return dep_engine->file_flag; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_dep_engine_get_svc_dir( + const axis2_dep_engine_t * dep_engine, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + return axutil_strdup(env, dep_engine->svc_dir); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_dep_engine_set_svc_dir( + axis2_dep_engine_t * dep_engine, + const axutil_env_t * env, + const axis2_char_t *svc_dir) +{ + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, svc_dir, AXIS2_FAILURE); + dep_engine->svc_dir = axutil_strdup(env, svc_dir); + return AXIS2_SUCCESS; +} + +static axis2_status_t +axis2_dep_engine_set_svc_and_module_dir_path( + axis2_dep_engine_t *dep_engine, + const axutil_env_t *env) +{ + axis2_bool_t flag; + axis2_conf_t *conf; + axis2_char_t *dirpath; + axutil_param_t *dep_param; + AXIS2_PARAM_CHECK(env->error, dep_engine, AXIS2_FAILURE); + flag = dep_engine->file_flag; + if(!flag) + { + return AXIS2_SUCCESS; + } + else + { + conf = dep_engine->conf; + if(!conf) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Axis2 Configuration cannot be NULL"); + return AXIS2_FAILURE; + } + + dep_param = axis2_conf_get_param(conf, env, AXIS2_MODULE_DIR); + if(dep_param) + { + dirpath = (axis2_char_t *)axutil_param_get_value(dep_param, env); + if(dirpath) + { + dep_engine->module_dir = dirpath; + dirpath = NULL; + } + } + dep_param = NULL; + + dep_param = axis2_conf_get_param(conf, env, AXIS2_SERVICE_DIR); + if(dep_param) + { + dirpath = (axis2_char_t *)axutil_param_get_value(dep_param, env); + if(dirpath) + { + dep_engine->svc_dir = dirpath; + dirpath = NULL; + } + } + } + + return AXIS2_SUCCESS; +} + diff --git a/src/core/deployment/desc_builder.c b/src/core/deployment/desc_builder.c new file mode 100644 index 0000000..a6fde18 --- /dev/null +++ b/src/core/deployment/desc_builder.c @@ -0,0 +1,1148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_desc_builder.h> +#include <axutil_string.h> +#include <axutil_class_loader.h> +#include <axutil_utils.h> +#include <axutil_generic_obj.h> +#include <axis2_raw_xml_in_out_msg_recv.h> +#include <neethi_engine.h> + +struct axis2_desc_builder +{ + /** + * Store the full path to configuration file. + */ + axis2_char_t *file_name; + axiom_node_t *root; + struct axis2_dep_engine *engine; +}; + +static axis2_status_t +set_attrs_and_value( + axutil_param_t * param, + const axutil_env_t * env, + axiom_element_t * param_element, + axiom_node_t * param_node); + +AXIS2_EXTERN axis2_desc_builder_t *AXIS2_CALL +axis2_desc_builder_create( + const axutil_env_t * env) +{ + axis2_desc_builder_t *desc_builder = NULL; + + desc_builder = (axis2_desc_builder_t *)AXIS2_MALLOC(env-> allocator, + sizeof(axis2_desc_builder_t)); + + if(!desc_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot allocate memory to desc_builder"); + return NULL; + } + desc_builder->file_name = NULL; + desc_builder->engine = NULL; + desc_builder->root = NULL; + + return desc_builder; +} + +AXIS2_EXTERN axis2_desc_builder_t *AXIS2_CALL +axis2_desc_builder_create_with_file_and_dep_engine( + const axutil_env_t * env, + axis2_char_t * file_name, + axis2_dep_engine_t * engine) +{ + axis2_desc_builder_t *desc_builder = NULL; + + AXIS2_PARAM_CHECK(env->error, file_name, NULL); + AXIS2_PARAM_CHECK(env->error, engine, NULL); + + desc_builder = (axis2_desc_builder_t *)axis2_desc_builder_create(env); + if(!desc_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot allocate memory to desc_builder"); + return NULL; + } + + desc_builder->root = NULL; + + desc_builder->file_name = axutil_strdup(env, file_name); + if(!desc_builder->file_name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "No memory. Cannot allocate memory to desc_builder->file_name"); + return NULL; + } + desc_builder->engine = engine; + + return desc_builder; +} + +AXIS2_EXTERN axis2_desc_builder_t *AXIS2_CALL +axis2_desc_builder_create_with_dep_engine( + const axutil_env_t * env, + struct axis2_dep_engine * engine) +{ + axis2_desc_builder_t *desc_builder = NULL; + + AXIS2_PARAM_CHECK(env->error, engine, NULL); + + desc_builder = (axis2_desc_builder_t *)axis2_desc_builder_create(env); + if(!desc_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot allocate memory to desc_builder"); + return NULL; + } + + desc_builder->engine = engine; + + return desc_builder; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_desc_builder_free( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env) +{ + if(desc_builder->file_name) + { + AXIS2_FREE(env->allocator, desc_builder->file_name); + } + + if(desc_builder->root) + { + axiom_node_free_tree(desc_builder->root, env); + } + + /* we cannot free deployment engine here */ + desc_builder->engine = NULL; + + if(desc_builder) + { + AXIS2_FREE(env->allocator, desc_builder); + } + return; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +axis2_desc_builder_build_om( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env) +{ + axiom_xml_reader_t *reader = NULL; + axiom_document_t *document = NULL; + axiom_stax_builder_t *builder = NULL; + + if(!desc_builder->file_name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_DESC_BUILDER, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid state desc builder. Unable to continue"); + return NULL; + } + + /** create pull parser using the file path to configuration file */ + reader = axiom_xml_reader_create_for_file(env, desc_builder->file_name, NULL); + + if(!reader) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not create xml reader for %s", + desc_builder->file_name); + return NULL; + }; + + /** create axiom_stax_builder by parsing pull_parser struct */ + builder = axiom_stax_builder_create(env, reader); + + if(!(builder)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Could not create xml stream reader for desc builder %s. Unable " + "to continue", desc_builder->file_name); + return NULL; + } + + /** + get the om document form builder + document is the container of om model created using builder + */ + document = axiom_stax_builder_get_document(builder, env); + + /** + * In description building we don't want defferred building. So build + * the whole tree at once + */ + axiom_document_build_all(document, env); + + /** + get root element , building starts hear + */ + desc_builder->root = axiom_document_get_root_element(document, env); + /** + We have built the whole document. So no need of keeping the builder. + */ + axiom_stax_builder_free_self(builder, env); + + return desc_builder->root; +} + +AXIS2_EXTERN axis2_flow_t *AXIS2_CALL +axis2_desc_builder_process_flow( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_element_t * flow_element, + axutil_param_container_t * parent, + axiom_node_t * flow_node) +{ + axis2_flow_t *flow = NULL; + axiom_children_qname_iterator_t *handlers = NULL; + axutil_qname_t *qchild = NULL; + + AXIS2_PARAM_CHECK(env->error, parent, NULL); + AXIS2_PARAM_CHECK(env->error, flow_node, NULL); + + flow = axis2_flow_create(env); + if(!flow) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Could not allocate to flow"); + return NULL; + } + + if(!flow_element) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "There is no flow element to process"); + return NULL; + } + + qchild = axutil_qname_create(env, AXIS2_HANDLERST, NULL, NULL); + handlers = axiom_element_get_children_with_qname(flow_element, env, qchild, flow_node); + if(qchild) + { + axutil_qname_free(qchild, env); + } + + while(axiom_children_qname_iterator_has_next(handlers, env)) + { + axiom_node_t *handler_node = NULL; + axis2_handler_desc_t *handler_desc = NULL; + axis2_status_t status = AXIS2_FAILURE; + + handler_node = (axiom_node_t *)axiom_children_qname_iterator_next(handlers, env); + + handler_desc = axis2_desc_builder_process_handler(desc_builder, env, handler_node, parent); + status = axis2_flow_add_handler(flow, env, handler_desc); + if(!status) + { + const axutil_string_t *handler_name = NULL; + const axis2_char_t *hname = NULL; + handler_name = axis2_handler_desc_get_name(handler_desc, env); + hname = axutil_string_get_buffer(handler_name, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Adding handler %s to flow failed", hname); + axis2_flow_free(flow, env); + return NULL; + } + } + return flow; +} + +struct axis2_handler_desc *AXIS2_CALL +axis2_desc_builder_process_handler( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_node_t * handler_node, + struct axutil_param_container *parent) +{ + axis2_handler_desc_t *handler_desc = NULL; + axiom_attribute_t *name_attrib = NULL; + axutil_qname_t *attr_qname = NULL; + axiom_attribute_t *class_attrib = NULL; + axutil_qname_t *class_qname = NULL; + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t *attrib_value = NULL; + axiom_element_t *handler_element = NULL; + axiom_node_t *order_node = NULL; + axiom_element_t *order_element = NULL; + axutil_qname_t *order_qname = NULL; + axutil_string_t *handler_name = NULL; + const axis2_char_t *hname = NULL; + + AXIS2_PARAM_CHECK(env->error, handler_node, NULL); + AXIS2_PARAM_CHECK(env->error, parent, NULL); + + handler_desc = axis2_handler_desc_create(env, NULL); + if(!handler_desc) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not create handler description"); + return NULL; + } + /* Setting Handler name */ + attr_qname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + handler_element = axiom_node_get_data_element(handler_node, env); + name_attrib = axiom_element_get_attribute(handler_element, env, attr_qname); + if(attr_qname) + { + axutil_qname_free(attr_qname, env); + } + + if(!name_attrib) + { + axis2_handler_desc_free(handler_desc, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Name attribute not fould for handler."); + return NULL; + } + else + { + axis2_char_t *value = NULL; + + value = axiom_attribute_get_value(name_attrib, env); + handler_name = axutil_string_create(env, value); + status = axis2_handler_desc_set_name(handler_desc, env, handler_name); + if(handler_name) + { + axutil_string_free(handler_name, env); + } + + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting name for handler description failed in %s", desc_builder->file_name); + axis2_handler_desc_free(handler_desc, env); + return NULL; + } + } + hname = axutil_string_get_buffer(handler_name, env); + /*Setting Handler Class name */ + class_qname = axutil_qname_create(env, AXIS2_CLASSNAME, NULL, NULL); + class_attrib = axiom_element_get_attribute(handler_element, env, class_qname); + if(class_qname) + { + axutil_qname_free(class_qname, env); + } + + if(!class_attrib) + { + axis2_handler_desc_free(handler_desc, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Library name attribute not found for handler %s", + hname); + return NULL; + } + else + { + attrib_value = axiom_attribute_get_value(class_attrib, env); + status = axis2_handler_desc_set_class_name(handler_desc, env, attrib_value); + } + + /*processing phase Rules (order) */ + + order_qname = axutil_qname_create(env, AXIS2_ORDER, NULL, NULL); + order_element = axiom_element_get_first_child_with_qname(handler_element, env, order_qname, + handler_node, &order_node); + if(order_qname) + { + axutil_qname_free(order_qname, env); + } + + if(!order_element || !order_node) + { + axis2_handler_desc_free(handler_desc, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Order node not found for handler description %s", + hname); + return NULL; + } + else + { + axutil_hash_t *order_itr = NULL; + axiom_children_qname_iterator_t *params = NULL; + axutil_qname_t *param_qname = NULL; + axutil_hash_index_t *index_i = NULL; + + order_itr = axiom_element_get_all_attributes(order_element, env); + if(!order_itr) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Order element for handler desc %s does not contain any " + "attribute", hname); + axis2_handler_desc_free(handler_desc, env); + return NULL; + } + + index_i = axutil_hash_first(order_itr, env); + + while(index_i) + { + axiom_attribute_t *order_attrib = NULL; + axutil_qname_t *qname = NULL; + axis2_char_t *name = NULL; + axis2_char_t *value = NULL; + void *v = NULL; + + axutil_hash_this(index_i, NULL, NULL, &v); + order_attrib = (axiom_attribute_t *)v; + qname = axiom_attribute_get_qname(order_attrib, env); + name = axutil_qname_get_localpart(qname, env); + + value = axiom_attribute_get_value(order_attrib, env); + if(!axutil_strcmp(AXIS2_AFTER, name)) + { + struct axis2_phase_rule *phase_rule = NULL; + + phase_rule = axis2_handler_desc_get_rules(handler_desc, env); + status = axis2_phase_rule_set_after(phase_rule, env, value); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting %s phase rule failed for handler %s", AXIS2_AFTER, hname); + axis2_handler_desc_free(handler_desc, env); + return NULL; + } + } + if(!axutil_strcmp(AXIS2_BEFORE, name)) + { + struct axis2_phase_rule *phase_rule = NULL; + phase_rule = axis2_handler_desc_get_rules(handler_desc, env); + status = axis2_phase_rule_set_before(phase_rule, env, value); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting %s phase rule failed for handler %s", AXIS2_BEFORE, hname); + axis2_handler_desc_free(handler_desc, env); + return NULL; + } + } + if(!axutil_strcmp(AXIS2_PHASE, name)) + { + struct axis2_phase_rule *phase_rule = NULL; + phase_rule = axis2_handler_desc_get_rules(handler_desc, env); + status = axis2_phase_rule_set_name(phase_rule, env, value); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting phase rule name failed for handler %s", hname); + axis2_handler_desc_free(handler_desc, env); + return NULL; + } + } + if(!axutil_strcmp(AXIS2_PHASEFIRST, name)) + { + axis2_char_t *bool_val = NULL; + + bool_val = axis2_desc_builder_get_value(desc_builder, env, value); + if(!axutil_strcmp(bool_val, AXIS2_VALUE_TRUE)) + { + struct axis2_phase_rule *phase_rule = NULL; + phase_rule = axis2_handler_desc_get_rules(handler_desc, env); + status = axis2_phase_rule_set_first(phase_rule, env, AXIS2_TRUE); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting %s property for phase rules for handler " + "%s failed", AXIS2_PHASEFIRST, hname); + axis2_handler_desc_free(handler_desc, env); + AXIS2_FREE(env->allocator, bool_val); + return NULL; + } + } + else if(!axutil_strcmp(bool_val, AXIS2_VALUE_FALSE)) + { + struct axis2_phase_rule *phase_rule = NULL; + phase_rule = axis2_handler_desc_get_rules(handler_desc, env); + status = axis2_phase_rule_set_first(phase_rule, env, AXIS2_FALSE); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting %s property for phase rules for handler " + "%s failed", AXIS2_PHASEFIRST, hname); + axis2_handler_desc_free(handler_desc, env); + AXIS2_FREE(env->allocator, bool_val); + return NULL; + } + } + AXIS2_FREE(env->allocator, bool_val); + } + index_i = axutil_hash_next(env, index_i); + } + + param_qname = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + params = axiom_element_get_children_with_qname(handler_element, env, param_qname, + handler_node); + axutil_qname_free(param_qname, env); + status = axis2_desc_builder_process_params(desc_builder, env, params, + axis2_handler_desc_get_param_container(handler_desc, env), parent); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Processing params failed for handler %s", + hname); + axis2_handler_desc_free(handler_desc, env); + return NULL; + } + } + + status = axis2_handler_desc_set_parent(handler_desc, env, parent); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting parent failed for handler %s", hname); + axis2_handler_desc_free(handler_desc, env); + return NULL; + } + + return handler_desc; +} + +static axis2_status_t +set_attrs_and_value( + axutil_param_t * param, + const axutil_env_t * env, + axiom_element_t * param_element, + axiom_node_t * param_node) +{ + axis2_status_t status = AXIS2_FAILURE; + axutil_hash_t *attrs = NULL; + axiom_child_element_iterator_t *childs = NULL; + + AXIS2_PARAM_CHECK(env->error, param, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, param_element, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, param_node, AXIS2_FAILURE); + + /* Setting attributes */ + attrs = axiom_element_extract_attributes(param_element, env, param_node); + if(attrs) + { + axutil_hash_index_t *i = NULL; + + for(i = axutil_hash_first(attrs, env); i; i = axutil_hash_next(env, i)) + { + void *v = NULL; + axiom_attribute_t *value = NULL; + axutil_generic_obj_t *obj = NULL; + axutil_qname_t *attr_qname = NULL; + axis2_char_t *attr_name = NULL; + + axutil_hash_this(i, NULL, NULL, &v); + if(!v) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Attibute missing in the parameter element"); + axutil_param_free(param, env); + return AXIS2_FAILURE; + } + obj = axutil_generic_obj_create(env); + if(!obj) + { + axutil_param_free(param, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return AXIS2_FAILURE; + } + value = (axiom_attribute_t *)v; + axutil_generic_obj_set_value(obj, env, value); + axutil_generic_obj_set_free_func(obj, env, axiom_attribute_free_void_arg); + attr_qname = axiom_attribute_get_qname(value, env); + attr_name = axutil_qname_to_string(attr_qname, env); + axutil_hash_set(attrs, attr_name, AXIS2_HASH_KEY_STRING, obj); + } + axutil_param_set_attributes(param, env, attrs); + } + + childs = axiom_element_get_child_elements(param_element, env, param_node); + if(childs) + { + axutil_array_list_t *value_list = NULL; + + value_list = axutil_array_list_create(env, 0); + axutil_param_set_value_list(param, env, value_list); + + while(AXIOM_CHILD_ELEMENT_ITERATOR_HAS_NEXT(childs, env)) + { + axiom_node_t *node = NULL; + axiom_element_t *element = NULL; + axutil_param_t *param = NULL; + axis2_char_t *pname = NULL; + + node = AXIOM_CHILD_ELEMENT_ITERATOR_NEXT(childs, env); + element = axiom_node_get_data_element(node, env); + param = axutil_param_create(env, NULL, NULL); + pname = axiom_element_get_localname(element, env); + status = axutil_param_set_name(param, env, pname); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting name to parameter failed"); + axutil_param_free(param, env); + return status; + } + axutil_param_set_param_type(param, env, AXIS2_DOM_PARAM); + set_attrs_and_value(param, env, element, node); + axutil_array_list_add(value_list, env, param); + } + } + else + { + axis2_char_t *para_test_value = NULL; + axis2_char_t *temp = NULL; + + temp = axiom_element_get_text(param_element, env, param_node); + para_test_value = axutil_strdup(env, temp); + status = axutil_param_set_value(param, env, para_test_value); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting value to parameter failed"); + axutil_param_free(param, env); + AXIS2_FREE(env->allocator, para_test_value); + return status; + } + axutil_param_set_param_type(param, env, AXIS2_TEXT_PARAM); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_desc_builder_process_rest_params( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_node_t * op_node, + axis2_op_t * op_desc) +{ + axiom_element_t *op_element = NULL; + axutil_qname_t *qname = NULL; + axutil_qname_t *param_qname = NULL; + axiom_node_t *rest_node = NULL; + axiom_element_t *rest_element = NULL; + axiom_children_qname_iterator_t *rest_mappings = NULL; + + AXIS2_PARAM_CHECK(env->error, op_desc, AXIS2_FAILURE); + + op_element = axiom_node_get_data_element(op_node, env); + + param_qname = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + qname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + + if(op_element) + { + rest_mappings + = axiom_element_get_children_with_qname(op_element, env, param_qname, op_node); + } + + while(rest_mappings && axiom_children_qname_iterator_has_next(rest_mappings, env)) + { + axis2_char_t *param_value = NULL; + rest_node = (axiom_node_t *)axiom_children_qname_iterator_next(rest_mappings, env); + rest_element = axiom_node_get_data_element(rest_node, env); + param_value = axiom_element_get_attribute_value(rest_element, env, qname); + if(!strcmp(param_value, AXIS2_REST_HTTP_METHOD)) + { + axis2_op_set_rest_http_method(op_desc, env, axiom_element_get_text(rest_element, env, + rest_node)); + } + param_value = axiom_element_get_attribute_value(rest_element, env, qname); + if(!strcmp(param_value, AXIS2_REST_HTTP_LOCATION)) + { + axis2_op_set_rest_http_location(op_desc, env, axiom_element_get_text(rest_element, env, + rest_node)); + } + if(axis2_op_get_rest_http_method(op_desc, env) && axis2_op_get_rest_http_location(op_desc, + env)) + { + break; + } + } + + axutil_qname_free(qname, env); + axutil_qname_free(param_qname, env); + return AXIS2_SUCCESS; +} + +/** + * Populate the Axis2 Operation with details from the actionMapping, + * outputActionMapping and faultActionMapping elements from the operation + * element. + * + * @param operation + * @param op_desc + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_desc_builder_process_action_mappings( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_node_t * op_node, + axis2_op_t * op_desc) +{ + axiom_element_t *op_element = NULL; + axutil_qname_t *qname = NULL; + axiom_children_qname_iterator_t *action_mappings = NULL; + axutil_array_list_t *mapping_list = axutil_array_list_create(env, 0); + AXIS2_PARAM_CHECK(env->error, op_desc, AXIS2_FAILURE); + + op_element = axiom_node_get_data_element(op_node, env); + qname = axutil_qname_create(env, AXIS2_ACTION_MAPPING, NULL, NULL); + if(op_element) + { + action_mappings = axiom_element_get_children_with_qname(op_element, env, qname, op_node); + } + + axutil_qname_free(qname, env); + qname = NULL; + if(!action_mappings) + { + if(mapping_list) + { + axutil_array_list_free(mapping_list, env); + mapping_list = NULL; + } + return AXIS2_SUCCESS; + } + while(axiom_children_qname_iterator_has_next(action_mappings, env)) + { + axiom_element_t *mapping_element = NULL; + axiom_node_t *mapping_node = NULL; + axis2_char_t *input_action_string = NULL; + axis2_char_t *temp_str = NULL; + + /* This is to check whether some one has locked the parmter at the top + * level + */ + mapping_node = (axiom_node_t *)axiom_children_qname_iterator_next(action_mappings, env); + mapping_element = axiom_node_get_data_element(mapping_node, env); + temp_str = axiom_element_get_text(mapping_element, env, mapping_node); + input_action_string = axutil_strtrim(env, temp_str, NULL); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Input action mapping found %s", + input_action_string); + if(axutil_strcmp("", input_action_string)) + { + axutil_array_list_add(mapping_list, env, input_action_string); + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Zero length " + "input_action_string found. Not added to the mapping list"); + } + } + axis2_op_set_wsamapping_list(op_desc, env, mapping_list); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_desc_builder_process_params( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * params, + axutil_param_container_t * param_container, + axutil_param_container_t * parent) +{ + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, params, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, param_container, AXIS2_FAILURE); + + while(axiom_children_qname_iterator_has_next(params, env)) + { + axiom_element_t *param_element = NULL; + axiom_node_t *param_node = NULL; + axutil_param_t *param = NULL; + axutil_param_t *parent_para = NULL; + axiom_attribute_t *para_name = NULL; + axiom_attribute_t *para_locked = NULL; + axutil_qname_t *att_locked = NULL; + axutil_qname_t *att_qname = NULL; + axis2_char_t *pname = NULL; + + /* This is to check whether some one has locked the parmter at the top + * level + */ + param_node = (axiom_node_t *)axiom_children_qname_iterator_next(params, env); + param_element = axiom_node_get_data_element(param_node, env); + param = axutil_param_create(env, NULL, NULL); + + /* Setting paramter name */ + att_qname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + para_name = axiom_element_get_attribute(param_element, env, att_qname); + axutil_qname_free(att_qname, env); + if(!para_name) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Parameter name attribute not found for parameter"); + axutil_param_free(param, env); + return AXIS2_FAILURE; + } + pname = axiom_attribute_get_value(para_name, env); + status = axutil_param_set_name(param, env, pname); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not set parameter name for parameter"); + axutil_param_free(param, env); + return status; + } + + /* Setting paramter Value (the chiled elemnt of the paramter) */ + set_attrs_and_value(param, env, param_element, param_node); + + /* Setting locking attrib */ + att_locked = axutil_qname_create(env, AXIS2_ATTLOCKED, NULL, NULL); + para_locked = axiom_element_get_attribute(param_element, env, att_locked); + axutil_qname_free(att_locked, env); + if(parent) + { + axis2_char_t *param_name = NULL; + + param_name = axutil_param_get_name(param, env); + parent_para = axutil_param_container_get_param(parent, env, param_name); + } + if(para_locked) + { + axis2_char_t *locked_value = NULL; + locked_value = axiom_attribute_get_value(para_locked, env); + if(!axutil_strcmp(AXIS2_VALUE_TRUE, locked_value)) + { + axis2_char_t *param_name = NULL; + axis2_bool_t is_param_locked = AXIS2_FALSE; + /*if the parameter is locked at some level parameter value replace + * by that + */ + param_name = axutil_param_get_name(param, env); + is_param_locked = axutil_param_container_is_param_locked(parent, env, param_name); + if(parent && is_param_locked) + { + axutil_param_free(param, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CONFIG_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Parameter %s is locked", param_name); + return AXIS2_FAILURE; + } + else + { + axutil_param_set_locked(param, env, AXIS2_TRUE); + } + } + else + { + axutil_param_set_locked(param, env, AXIS2_FALSE); + } + } + + if(parent) + { + axis2_char_t *name = NULL; + axis2_bool_t bvalue = AXIS2_FALSE; + + name = axutil_param_get_name(param, env); + bvalue = axutil_param_container_is_param_locked(parent, env, name); + if(parent_para || !bvalue) + { + status = axutil_param_container_add_param(param_container, env, param); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Adding parameter %s failed", name); + axutil_param_free(param, env); + return status; + } + } + } + else + { + status = axutil_param_container_add_param(param_container, env, param); + if(!status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Adding parameter %s failed", pname); + axutil_param_free(param, env); + return status; + } + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_desc_builder_process_op_module_refs( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_refs, + axis2_op_t * op) +{ + axiom_element_t *moduleref = NULL; + axiom_attribute_t *module_ref_attrib = NULL; + axutil_qname_t *qref = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, op, AXIS2_FAILURE); + + while(module_refs && axiom_children_qname_iterator_has_next(module_refs, env)) + { + axiom_node_t *moduleref_node = axiom_children_qname_iterator_next(module_refs, env); + moduleref = (axiom_element_t *)axiom_node_get_data_element(moduleref_node, env); + + qref = axutil_qname_create(env, AXIS2_REF, NULL, NULL); + module_ref_attrib = axiom_element_get_attribute(moduleref, env, qref); + axutil_qname_free(qref, env); + if(module_ref_attrib) + { + axis2_char_t *ref_name = NULL; + axutil_qname_t *ref_qname = NULL; + axis2_module_desc_t *module_desc = NULL; + + ref_name = axiom_attribute_get_value(module_ref_attrib, env); + ref_qname = axutil_qname_create(env, ref_name, NULL, NULL); + module_desc = axis2_dep_engine_get_module(desc_builder->engine, env, ref_qname); + if(!module_desc) + { + axutil_qname_free(ref_qname, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MODULE_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Module %s not found in the deployment engine", ref_name); + + return AXIS2_FAILURE; + } + else + { + status = axis2_op_add_module_qname(op, env, ref_qname); + axutil_qname_free(ref_qname, env); + if(AXIS2_SUCCESS != status) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MODULE_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Adding module ref %s to operation %s failed", ref_name, + axutil_qname_get_localpart(axis2_op_get_qname(op, env), env)); + + return AXIS2_FAILURE; + } + } + } + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_msg_recv_t *AXIS2_CALL +axis2_desc_builder_load_msg_recv( + axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + struct axiom_element * recv_element) +{ + axiom_attribute_t *recv_name = NULL; + axis2_char_t *class_name = NULL; + axis2_msg_recv_t *msg_recv = NULL; + axutil_qname_t *class_qname = NULL; + axutil_param_t *impl_info_param = NULL; + axutil_dll_desc_t *dll_desc = NULL; + axis2_char_t *repos_name = NULL; + axis2_char_t *dll_name = NULL; + axis2_char_t *temp_path = NULL; + axis2_char_t *temp_path2 = NULL; + axis2_char_t *temp_path3 = NULL; + axis2_conf_t *conf = NULL; + axis2_char_t *msg_recv_dll_name = NULL; + + AXIS2_PARAM_CHECK(env->error, recv_element, NULL); + + class_qname = axutil_qname_create(env, AXIS2_CLASSNAME, NULL, NULL); + recv_name = axiom_element_get_attribute(recv_element, env, class_qname); + axutil_qname_free(class_qname, env); + class_name = axiom_attribute_get_value(recv_name, env); + + conf = axis2_dep_engine_get_axis_conf(desc_builder->engine, env); + if(!conf) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Configuration not found in the deployment engine"); + return NULL; + } + impl_info_param = axis2_conf_get_param(conf, env, class_name); + + if(!impl_info_param) + { + dll_desc = axutil_dll_desc_create(env); + msg_recv_dll_name = axutil_dll_desc_create_platform_specific_dll_name(dll_desc, env, + class_name); + repos_name = axis2_dep_engine_get_repos_path(desc_builder->engine, env); + temp_path = axutil_stracat(env, repos_name, AXIS2_PATH_SEP_STR); + temp_path2 = axutil_stracat(env, temp_path, AXIS2_LIB_FOLDER); + temp_path3 = axutil_stracat(env, temp_path2, AXIS2_PATH_SEP_STR); + dll_name = axutil_stracat(env, temp_path3, msg_recv_dll_name); + AXIS2_FREE(env->allocator, temp_path); + AXIS2_FREE(env->allocator, temp_path2); + AXIS2_FREE(env->allocator, temp_path3); + axutil_dll_desc_set_name(dll_desc, env, dll_name); + AXIS2_FREE(env->allocator, dll_name); + axutil_dll_desc_set_type(dll_desc, env, AXIS2_MSG_RECV_DLL); + impl_info_param = axutil_param_create(env, class_name, NULL); + axutil_param_set_value(impl_info_param, env, dll_desc); + axutil_param_set_value_free(impl_info_param, env, axutil_dll_desc_free_void_arg); + /* set the impl_info_param(which contain dll_desc as value) so that + * loaded msg_recv loader lib can be re-used in future + */ + axis2_conf_add_param(conf, env, impl_info_param); + } + + axutil_class_loader_init(env); + msg_recv = (axis2_msg_recv_t *)axutil_class_loader_create_dll(env, impl_info_param); + return msg_recv; +} + +AXIS2_EXTERN struct axis2_msg_recv *AXIS2_CALL +axis2_desc_builder_load_default_msg_recv( + const axutil_env_t * env) +{ + axis2_msg_recv_t *msg_recv = NULL; + + msg_recv = axis2_raw_xml_in_out_msg_recv_create(env); + return msg_recv; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_desc_builder_get_short_file_name( + const axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axis2_char_t * file_name) +{ + const axis2_char_t *separator = NULL; + axis2_char_t *value = NULL; + axis2_char_t *file_name_l = NULL; + axis2_char_t *short_name = NULL; + + AXIS2_PARAM_CHECK(env->error, file_name, NULL); + + file_name_l = axutil_strdup(env, file_name); + if(!file_name_l) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, ""); + return NULL; + } + separator = "."; + + value = axutil_strstr(file_name_l, separator); + + value[0] = AXIS2_EOLN; + short_name = file_name_l; + + return short_name; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_desc_builder_get_file_name_without_prefix( + const axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axis2_char_t * short_file_name) +{ + axis2_char_t *file_name_l = NULL; + axis2_char_t *short_name = NULL; + int len = 0; + AXIS2_PARAM_CHECK(env->error, short_file_name, NULL); + file_name_l = axutil_strdup(env, short_file_name); + if(!file_name_l) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, ""); + return NULL; + } + len = axutil_strlen(AXIS2_LIB_PREFIX); + short_name = &file_name_l[len]; + return short_name; + +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_desc_builder_get_value( + const axis2_desc_builder_t * desc_builder, + const axutil_env_t * env, + axis2_char_t * in) +{ + const axis2_char_t *separator = ":"; + axis2_char_t *value = NULL; + axis2_char_t *in_l = NULL; + + AXIS2_PARAM_CHECK(env->error, in, NULL); + + in_l = axutil_strdup(env, in); + if(!in_l) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, ""); + return NULL; + } + value = axutil_strstr(in_l, separator); + value = value + 1; + + return value; +} + +AXIS2_EXTERN struct axis2_dep_engine *AXIS2_CALL +axis2_desc_builder_get_dep_engine( + const axis2_desc_builder_t * desc_builder, + const axutil_env_t * env) +{ + return desc_builder->engine; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_process_policy_elements( + const axutil_env_t * env, + int type, + axiom_children_qname_iterator_t * iterator, + axis2_policy_include_t * policy_include) +{ + while(axiom_children_qname_iterator_has_next(iterator, env)) + { + axiom_node_t *node = NULL; + node = axiom_children_qname_iterator_next(iterator, env); + if(node) + { + axiom_element_t *element = NULL; + neethi_policy_t *policy = NULL; + + element = axiom_node_get_data_element(node, env); + policy = neethi_engine_get_policy(env, node, element); + if(!policy) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, ""); + return AXIS2_FAILURE; + } + axis2_policy_include_add_policy_element(policy_include, env, type, policy); + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_process_policy_reference_elements( + const axutil_env_t * env, + int type, + axiom_children_qname_iterator_t * iterator, + axis2_policy_include_t * policy_include) +{ + while(axiom_children_qname_iterator_has_next(iterator, env)) + { + axiom_node_t *node = NULL; + node = axiom_children_qname_iterator_next(iterator, env); + if(node) + { + axiom_element_t *element = NULL; + neethi_reference_t *reference = NULL; + + element = axiom_node_get_data_element(node, env); + /* TODO: add neethi_engine_get_policy_reference + reference = neethi_engine_get_policy_reference(env, node, element); */ + axis2_policy_include_add_policy_reference_element(policy_include, env, type, reference); + } + } + return AXIS2_SUCCESS; +} + diff --git a/src/core/deployment/module_builder.c b/src/core/deployment/module_builder.c new file mode 100644 index 0000000..ad91866 --- /dev/null +++ b/src/core/deployment/module_builder.c @@ -0,0 +1,514 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_module_builder.h> +#include <axis2_arch_file_data.h> + +struct axis2_module_builder +{ + axis2_module_desc_t *module_desc; + struct axis2_desc_builder *desc_builder; +}; + +static axutil_array_list_t *AXIS2_CALL axis2_module_builder_process_ops( + axis2_module_builder_t * module_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * op_itr); + +AXIS2_EXTERN axis2_module_builder_t *AXIS2_CALL +axis2_module_builder_create( + const axutil_env_t * env) +{ + axis2_module_builder_t *module_builder = NULL; + + module_builder = (axis2_module_builder_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_module_builder_t)); + + if(!module_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory to create module builder"); + return NULL; + } + + return module_builder; +} + +AXIS2_EXTERN axis2_module_builder_t *AXIS2_CALL +axis2_module_builder_create_with_file_and_dep_engine_and_module( + const axutil_env_t * env, + axis2_char_t * file_name, + axis2_dep_engine_t * dep_engine, + axis2_module_desc_t * module_desc) +{ + axis2_module_builder_t *module_builder = NULL; + + module_builder = (axis2_module_builder_t *)axis2_module_builder_create(env); + if(!module_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory to create module builder %s", file_name); + return NULL; + } + module_builder->desc_builder = axis2_desc_builder_create_with_file_and_dep_engine(env, + file_name, dep_engine); + if(!module_builder->desc_builder) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Description builder creation failed for module builder %s", file_name); + axis2_module_builder_free(module_builder, env); + return NULL; + } + module_builder->module_desc = module_desc; + return module_builder; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_module_builder_free( + axis2_module_builder_t * module_builder, + const axutil_env_t * env) +{ + if(module_builder->desc_builder) + { + axis2_desc_builder_free(module_builder->desc_builder, env); + } + + if(module_builder) + { + AXIS2_FREE(env->allocator, module_builder); + } + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_module_builder_populate_module( + axis2_module_builder_t * module_builder, + const axutil_env_t * env) +{ + axiom_element_t *module_element = NULL; + axiom_node_t *module_node = NULL; + axutil_qname_t *qdllname = NULL; + axutil_qname_t *qparamst = NULL; + axutil_qname_t *qinflowst = NULL; + axutil_qname_t *qoutflowst = NULL; + axutil_qname_t *qinfaultflow = NULL; + axutil_qname_t *qoutfaultflow = NULL; + axutil_qname_t *qopst = NULL; + axiom_attribute_t *module_dll_att = NULL; + axiom_children_qname_iterator_t *itr = NULL; + axiom_children_qname_iterator_t *op_itr = NULL; + axiom_element_t *in_flow_element = NULL; + axiom_node_t *in_flow_node = NULL; + axiom_element_t *out_flow_element = NULL; + axiom_node_t *out_flow_node = NULL; + axiom_element_t *in_fault_flow_element = NULL; + axiom_node_t *in_fault_flow_node = NULL; + axiom_element_t *out_fault_flow_element = NULL; + axiom_node_t *out_fault_flow_node = NULL; + axis2_conf_t *parent = NULL; + axutil_array_list_t *ops = NULL; + axutil_param_container_t *parent_container = NULL; + int size = 0; + int i = 0; + axis2_arch_file_data_t *file_data = NULL; + axis2_char_t *module_name = NULL; + axutil_qname_t *module_qname = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_module_builder_populate_module"); + + module_node = axis2_desc_builder_build_om(module_builder->desc_builder, env); + module_element = axiom_node_get_data_element(module_node, env); + if(!module_element) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Data element not found for the module node, Unable to proceed"); + return AXIS2_FAILURE; + } + file_data = axis2_dep_engine_get_current_file_item(axis2_desc_builder_get_dep_engine( + module_builder->desc_builder, env), env); + module_name = axis2_arch_file_data_get_module_name(file_data, env); + + module_qname = axutil_qname_create(env, module_name, NULL, NULL); + axis2_module_desc_set_qname(module_builder->module_desc, env, module_qname); + + if(module_qname) + { + axutil_qname_free(module_qname, env); + } + /* Setting Module Dll Name , if it is there */ + + qdllname = axutil_qname_create(env, AXIS2_CLASSNAME, NULL, NULL); + module_dll_att = axiom_element_get_attribute(module_element, env, qdllname); + if(qdllname) + { + axutil_qname_free(qdllname, env); + } + + if(module_dll_att) + { + axis2_char_t *class_name = NULL; + + class_name = axiom_attribute_get_value(module_dll_att, env); + if(class_name && (axutil_strcmp("", class_name))) + { + axis2_dep_engine_t *dep_engine = axis2_desc_builder_get_dep_engine( + module_builder->desc_builder, env); + if(dep_engine) + { + axis2_arch_file_data_t *file_data = NULL; + + file_data = axis2_dep_engine_get_current_file_item(dep_engine, env); + axis2_arch_file_data_set_module_dll_name(file_data, env, class_name); + } + } + } + + /* Processing Paramters */ + /* Processing service level paramters */ + + qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + itr = axiom_element_get_children_with_qname(module_element, env, qparamst, module_node); + if(qparamst) + { + axutil_qname_free(qparamst, env); + } + parent = axis2_module_desc_get_parent(module_builder->module_desc, env); + + if(parent) + { + parent_container = axis2_conf_get_param_container(parent, env); + } + axis2_desc_builder_process_params(module_builder->desc_builder, env, itr, + axis2_module_desc_get_param_container(module_builder->module_desc, env), parent_container); + + /* Process IN_FLOW */ + qinflowst = axutil_qname_create(env, AXIS2_IN_FLOW_START, NULL, NULL); + in_flow_element = axiom_element_get_first_child_with_qname(module_element, env, qinflowst, + module_node, &in_flow_node); + if(qinflowst) + { + axutil_qname_free(qinflowst, env); + } + + if(in_flow_element && in_flow_node) + { + axis2_flow_t *flow = NULL; + + flow = axis2_desc_builder_process_flow(module_builder->desc_builder, env, in_flow_element, + axis2_module_desc_get_param_container(module_builder->module_desc, env), in_flow_node); + status = axis2_module_desc_set_in_flow(module_builder->module_desc, env, flow); + + if(!status) + { + if(flow) + { + axis2_flow_free(flow, env); + } + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting in flow failed for module desc %s", + module_name); + return status; + } + } + + qoutflowst = axutil_qname_create(env, AXIS2_OUT_FLOW_START, NULL, NULL); + out_flow_element = axiom_element_get_first_child_with_qname(module_element, env, qoutflowst, + module_node, &out_flow_node); + if(qoutflowst) + { + axutil_qname_free(qoutflowst, env); + } + + if(out_flow_element && out_flow_node) + { + axis2_flow_t *flow = NULL; + + flow = axis2_desc_builder_process_flow(module_builder->desc_builder, env, out_flow_element, + axis2_module_desc_get_param_container(module_builder->module_desc, env), out_flow_node); + status = axis2_module_desc_set_out_flow(module_builder->module_desc, env, flow); + + if(!status) + { + axis2_flow_free(flow, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting out flow failed for module desc %s", + module_name); + return status; + } + } + + qinfaultflow = axutil_qname_create(env, AXIS2_IN_FAILTFLOW, NULL, NULL); + in_fault_flow_element = axiom_element_get_first_child_with_qname(module_element, env, + qinfaultflow, module_node, &in_fault_flow_node); + if(qinfaultflow) + { + axutil_qname_free(qinfaultflow, env); + } + + if(in_fault_flow_element && NULL != in_fault_flow_node) + { + axis2_flow_t *flow = NULL; + + flow = axis2_desc_builder_process_flow(module_builder->desc_builder, env, + in_fault_flow_element, axis2_module_desc_get_param_container( + module_builder->module_desc, env), in_fault_flow_node); + status = axis2_module_desc_set_fault_in_flow(module_builder->module_desc, env, flow); + + if(!status) + { + axis2_flow_free(flow, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting fault in flow failed for module desc %s", module_name); + return status; + } + } + + qoutfaultflow = axutil_qname_create(env, AXIS2_OUT_FAILTFLOW, NULL, NULL); + out_fault_flow_element = axiom_element_get_first_child_with_qname(module_element, env, + qoutfaultflow, module_node, &out_fault_flow_node); + if(qoutfaultflow) + { + axutil_qname_free(qoutfaultflow, env); + } + + if(out_fault_flow_element && NULL != out_fault_flow_node) + { + axis2_flow_t *flow = NULL; + + flow = axis2_desc_builder_process_flow(module_builder->desc_builder, env, + out_fault_flow_element, axis2_module_desc_get_param_container( + module_builder->module_desc, env), out_fault_flow_node); + status = axis2_module_desc_set_fault_out_flow(module_builder->module_desc, env, flow); + if(AXIS2_SUCCESS != status) + { + axis2_flow_free(flow, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Setting fault out flow failed for module desc %s", module_name); + return status; + } + } + + /* Processing Operations */ + qopst = axutil_qname_create(env, AXIS2_OPERATIONST, NULL, NULL); + op_itr = axiom_element_get_children_with_qname(module_element, env, qopst, module_node); + if(qopst) + { + axutil_qname_free(qopst, env); + } + ops = axis2_module_builder_process_ops(module_builder, env, op_itr); + size = axutil_array_list_size(ops, env); + for(i = 0; i < size; i++) + { + axis2_op_t *op_desc = NULL; + + op_desc = (axis2_op_t *)axutil_array_list_get(ops, env, i); + axis2_module_desc_add_op(module_builder->module_desc, env, op_desc); + } + axutil_array_list_free(ops, env); + AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_module_builder_populate_module"); + return AXIS2_SUCCESS; +} + +static axutil_array_list_t *AXIS2_CALL +axis2_module_builder_process_ops( + axis2_module_builder_t * module_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * op_itr) +{ + axutil_array_list_t *ops = NULL; + + AXIS2_PARAM_CHECK(env->error, op_itr, NULL); + + ops = axutil_array_list_create(env, 0); + while(axiom_children_qname_iterator_has_next(op_itr, env)) + { + axiom_element_t *op_element = NULL; + axiom_node_t *op_node = NULL; + axiom_attribute_t *op_name_att = NULL; + axiom_attribute_t *op_mep_att = NULL; + axutil_qname_t *qattname = NULL; + axis2_char_t *mep_url = NULL; + axis2_char_t *op_name = NULL; + axutil_qname_t *qopname = NULL; + axutil_qname_t *qmsgrecv = NULL; + axutil_qname_t *qparamst = NULL; + axutil_qname_t *qmodulest = NULL; + axutil_qname_t *qmep = NULL; + axiom_children_qname_iterator_t *params = NULL; + axiom_children_qname_iterator_t *modules = NULL; + axiom_element_t *recv_element = NULL; + axiom_node_t *recv_node = NULL; + axis2_phases_info_t *info = NULL; + axis2_op_t *op_desc = NULL; + axutil_qname_t *qpolicy = NULL; + axiom_children_qname_iterator_t *itr = NULL; + axis2_desc_t *desc = NULL; + axis2_policy_include_t *policy_include = NULL; + + op_node = (axiom_node_t *)axiom_children_qname_iterator_next(op_itr, env); + op_element = axiom_node_get_data_element(op_node, env); + /* getting operation name */ + qattname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + op_name_att = axiom_element_get_attribute(op_element, env, qattname); + if(qattname) + { + axutil_qname_free(qattname, env); + } + + if(!op_name_att) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OP_NAME_MISSING, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Operation name missing for module operation."); + return NULL; + } + qmep = axutil_qname_create(env, AXIS2_MEP, NULL, NULL); + op_mep_att = axiom_element_get_attribute(op_element, env, qmep); + if(qmep) + { + axutil_qname_free(qmep, env); + } + + if(op_mep_att) + { + mep_url = axiom_attribute_get_value(op_mep_att, env); + } + if(!mep_url) + { + /* Assuming in-out mep */ + op_desc = axis2_op_create_from_module(env); + } + else + { + op_desc = axis2_op_create_from_module(env); + axis2_op_set_msg_exchange_pattern(op_desc, env, mep_url); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "mep_url:%s", mep_url); + } + + op_name = axiom_attribute_get_value(op_name_att, env); + qopname = axutil_qname_create(env, op_name, NULL, NULL); + axis2_op_set_qname(op_desc, env, qopname); + if(qopname) + { + axutil_qname_free(qopname, env); + } + + /* Operation parameters */ + qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + params = axiom_element_get_children_with_qname(op_element, env, qparamst, op_node); + if(qparamst) + { + axutil_qname_free(qparamst, env); + } + + axis2_desc_builder_process_params(module_builder->desc_builder, env, params, + axis2_op_get_param_container(op_desc, env), axis2_module_desc_get_param_container( + module_builder->module_desc, env)); + /* To process wsamapping */ + axis2_desc_builder_process_action_mappings(module_builder->desc_builder, env, op_node, + op_desc); + + /* To process REST params */ + axis2_desc_builder_process_rest_params(module_builder->desc_builder, env, op_node, op_desc); + + /* setting the policy_include */ + + desc = axis2_op_get_base(op_desc, env); + policy_include = axis2_desc_get_policy_include(desc, env); + + /* processing <wsp:Policy> .. </..> elements */ + + qpolicy = axutil_qname_create(env, NEETHI_POLICY, NEETHI_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(op_element, env, qpolicy, op_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + + if((!itr) || (!axiom_children_qname_iterator_has_next(itr, env))) + { + qpolicy = axutil_qname_create(env, NEETHI_POLICY, NEETHI_POLICY_15_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(op_element, env, qpolicy, op_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + } + if(itr) + { + axis2_process_policy_elements(env, AXIS2_MODULE_OPERATION_POLICY, itr, policy_include); + } + + /* processing <wsp:PolicyReference> .. </..> elements */ + qpolicy = axutil_qname_create(env, NEETHI_REFERENCE, NEETHI_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(op_element, env, qpolicy, op_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + + if((!itr) || (!axiom_children_qname_iterator_has_next(itr, env))) + { + qpolicy = axutil_qname_create(env, NEETHI_REFERENCE, NEETHI_POLICY_15_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(op_element, env, qpolicy, op_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + } + + if(itr) + { + axis2_process_policy_reference_elements(env, AXIS2_POLICY_REF, itr, policy_include); + } + + /* setting the mep of the operation */ + + /* loading the message receivers */ + qmsgrecv = axutil_qname_create(env, AXIS2_MESSAGERECEIVER, NULL, NULL); + recv_element = axiom_element_get_first_child_with_qname(op_element, env, qmsgrecv, op_node, + &recv_node); + if(qmsgrecv) + { + axutil_qname_free(qmsgrecv, env); + } + if(recv_element && NULL != recv_node) + { + axis2_msg_recv_t *msg_recv = NULL; + + msg_recv = axis2_desc_builder_load_msg_recv(module_builder-> desc_builder, env, + recv_element); + axis2_op_set_msg_recv(op_desc, env, msg_recv); + } + else + { + axis2_msg_recv_t *msg_recv = NULL; + /* setting default message reciver */ + msg_recv = axis2_desc_builder_load_default_msg_recv(env); + axis2_op_set_msg_recv(op_desc, env, msg_recv); + } + /* Process Module Refs */ + qmodulest = axutil_qname_create(env, AXIS2_MODULEST, NULL, NULL); + modules = axiom_element_get_children_with_qname(op_element, env, qmodulest, op_node); + if(qmodulest) + { + axutil_qname_free(qmodulest, env); + } + axis2_desc_builder_process_op_module_refs(module_builder->desc_builder, env, modules, + op_desc); + /* setting Operation phase */ + info = axis2_dep_engine_get_phases_info(axis2_desc_builder_get_dep_engine( + module_builder->desc_builder, env), env); + axis2_phases_info_set_op_phases(info, env, op_desc); + + /* adding operation */ + axutil_array_list_add(ops, env, op_desc); + } + return ops; +} + diff --git a/src/core/deployment/phases_info.c b/src/core/deployment/phases_info.c new file mode 100644 index 0000000..075fc8e --- /dev/null +++ b/src/core/deployment/phases_info.c @@ -0,0 +1,564 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_phases_info.h> + +struct axis2_phases_info +{ + axutil_array_list_t *in_phases; + axutil_array_list_t *out_phases; + axutil_array_list_t *in_faultphases; + axutil_array_list_t *out_faultphases; + axutil_hash_t *op_in_phases; + axutil_hash_t *op_out_phases; + axutil_hash_t *op_in_faultphases; + axutil_hash_t *op_out_faultphases; + +}; + +AXIS2_EXTERN axis2_phases_info_t *AXIS2_CALL +axis2_phases_info_create( + const axutil_env_t * env) +{ + axis2_phases_info_t *phases_info = NULL; + + phases_info = (axis2_phases_info_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_phases_info_t)); + + if(!phases_info) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + memset((void *)phases_info, 0, sizeof(axis2_phases_info_t)); + phases_info->op_in_phases = axutil_hash_make(env); + phases_info->op_out_phases = axutil_hash_make(env); + phases_info->op_in_faultphases = axutil_hash_make(env); + phases_info->op_out_faultphases = axutil_hash_make(env); + + return phases_info; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_phases_info_free( + axis2_phases_info_t * phases_info, + const axutil_env_t * env) +{ + if(phases_info->in_phases) + { + axutil_array_list_free(phases_info->in_phases, env); + } + + if(phases_info->out_phases) + { + axutil_array_list_free(phases_info->out_phases, env); + } + + if(phases_info->in_faultphases) + { + axutil_array_list_free(phases_info->in_faultphases, env); + } + + if(phases_info->out_faultphases) + { + axutil_array_list_free(phases_info->out_faultphases, env); + } + + if(phases_info->op_in_phases) + { + axutil_hash_free(phases_info->op_in_phases, env); + } + + if(phases_info->op_out_phases) + { + axutil_hash_free(phases_info->op_out_phases, env); + } + + if(phases_info->op_in_faultphases) + { + axutil_hash_free(phases_info->op_in_faultphases, env); + } + + if(phases_info->op_out_faultphases) + { + axutil_hash_free(phases_info->op_out_faultphases, env); + } + + if(phases_info) + { + AXIS2_FREE(env->allocator, phases_info); + } + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_phases_info_set_in_phases( + axis2_phases_info_t * phases_info, + const axutil_env_t * env, + axutil_array_list_t * in_phases) +{ + AXIS2_PARAM_CHECK(env->error, in_phases, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, phases_info, AXIS2_FAILURE); + + if(phases_info->in_phases) + { + axutil_array_list_free(phases_info->in_phases, env); + } + + phases_info->in_phases = in_phases; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_phases_info_set_out_phases( + axis2_phases_info_t * phases_info, + const axutil_env_t * env, + axutil_array_list_t * out_phases) +{ + AXIS2_PARAM_CHECK(env->error, out_phases, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, phases_info, AXIS2_FAILURE); + + if(phases_info->out_phases) + { + axutil_array_list_free(phases_info->out_phases, env); + phases_info->out_phases = NULL; + } + phases_info->out_phases = out_phases; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_phases_info_set_in_faultphases( + axis2_phases_info_t * phases_info, + const axutil_env_t * env, + axutil_array_list_t * in_faultphases) +{ + AXIS2_PARAM_CHECK(env->error, in_faultphases, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, phases_info, AXIS2_FAILURE); + + if(phases_info->in_faultphases) + { + axutil_array_list_free(phases_info->in_faultphases, env); + phases_info->in_faultphases = NULL; + } + phases_info->in_faultphases = in_faultphases; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_phases_info_set_out_faultphases( + axis2_phases_info_t * phases_info, + const axutil_env_t * env, + axutil_array_list_t * out_faultphases) +{ + AXIS2_PARAM_CHECK(env->error, out_faultphases, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, phases_info, AXIS2_FAILURE); + + if(phases_info->out_faultphases) + { + axutil_array_list_free(phases_info->out_faultphases, env); + phases_info->out_faultphases = NULL; + } + phases_info->out_faultphases = out_faultphases; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_phases_info_get_in_phases( + const axis2_phases_info_t * phases_info, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, phases_info, NULL); + return phases_info->in_phases; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_phases_info_get_out_phases( + const axis2_phases_info_t * phases_info, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, phases_info, NULL); + return phases_info->out_phases; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_phases_info_get_in_faultphases( + const axis2_phases_info_t * phases_info, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, phases_info, NULL); + return phases_info->in_faultphases; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_phases_info_get_out_faultphases( + const axis2_phases_info_t * phases_info, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, phases_info, NULL); + return phases_info->out_faultphases; +} + +/* Here we create the operation inflow as an array list and create phases for phases defined in + * inflow of axis2.xml and add them into the array list. + */ +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_phases_info_get_op_in_phases( + const axis2_phases_info_t * phases_info, + const axutil_env_t * env) +{ + struct axis2_phase *phase = NULL; + int i = 0; + int size = 0; + axis2_char_t *phase_name = NULL; + axutil_array_list_t *op_in_phases = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, phases_info, NULL); + + op_in_phases = axutil_array_list_create(env, 0); + if(!op_in_phases) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + if(!phases_info->in_phases) + { + return op_in_phases; + } + + /* For each inflow phase name create a phase instance and add into the inflow. */ + size = axutil_array_list_size(phases_info->in_phases, env); + for(i = 0; i < size; i++) + { + phase_name = (axis2_char_t *)axutil_array_list_get(phases_info->in_phases, env, i); + + if(!axutil_strcmp(AXIS2_PHASE_TRANSPORT_IN, phase_name) || !axutil_strcmp( + AXIS2_PHASE_PRE_DISPATCH, phase_name) || !axutil_strcmp(AXIS2_PHASE_DISPATCH, + phase_name) || !axutil_strcmp(AXIS2_PHASE_POST_DISPATCH, phase_name)) + { + /* We are not concerned here with system phases. */ + } + else + { + /* This is the cause for jira AXIS2C-624. As solution I create new + * phases for each operation specific flow making the operation + * the owner of the flow and the phases contained within it*/ + /*phase = axutil_hash_get(phases_info->op_in_phases, phase_name, + AXIS2_HASH_KEY_STRING); + if(!phase) + { + phase = axis2_phase_create(env, phase_name); + axutil_hash_set(phases_info->op_in_phases, phase_name, + AXIS2_HASH_KEY_STRING, phase); + } */ + phase = axis2_phase_create(env, phase_name); + status = axutil_array_list_add(op_in_phases, env, phase); + if(AXIS2_SUCCESS != status) + { + int i = 0; + int size = 0; + + axis2_phase_free(phase, env); + phase = NULL; + size = axutil_array_list_size(op_in_phases, env); + for(i = 0; i < size; i++) + { + phase = axutil_array_list_get(op_in_phases, env, i); + axis2_phase_free(phase, env); + phase = NULL; + } + axutil_array_list_free(op_in_phases, env); + op_in_phases = NULL; + return NULL; + } + } + } + + return op_in_phases; +} + +/* Here we create the operation outflow as an array list and create phases for phases defined in + * outflow of axis2.xml and add them into the array list. + */ +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_phases_info_get_op_out_phases( + const axis2_phases_info_t * phases_info, + const axutil_env_t * env) +{ + struct axis2_phase *phase = NULL; + int i = 0; + int size = 0; + axis2_char_t *phase_name = NULL; + axutil_array_list_t *op_out_phases = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, phases_info, NULL); + + if(phases_info->out_phases) + { + size = axutil_array_list_size(phases_info->out_phases, env); + } + + op_out_phases = axutil_array_list_create(env, 0); + if(!op_out_phases) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + for(i = 0; i < size; i++) + { + phase_name = (axis2_char_t *)axutil_array_list_get(phases_info->out_phases, env, i); + + phase = axis2_phase_create(env, phase_name); + status = axutil_array_list_add(op_out_phases, env, phase); + if(AXIS2_SUCCESS != status) + { + int i = 0; + int size = 0; + + axis2_phase_free(phase, env); + phase = NULL; + size = axutil_array_list_size(op_out_phases, env); + for(i = 0; i < size; i++) + { + phase = axutil_array_list_get(op_out_phases, env, i); + axis2_phase_free(phase, env); + phase = NULL; + } + + axutil_array_list_free(op_out_phases, env); + op_out_phases = NULL; + return NULL; + } + } + + return op_out_phases; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_phases_info_get_op_in_faultphases( + const axis2_phases_info_t * phases_info, + const axutil_env_t * env) +{ + int i = 0; + int size = 0; + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t *phase_name = NULL; + axutil_array_list_t *op_in_faultphases = NULL; + struct axis2_phase *phase = NULL; + + AXIS2_PARAM_CHECK(env->error, phases_info, NULL); + + if(!phases_info->in_faultphases) + { + return NULL; + } + + size = axutil_array_list_size(phases_info->in_faultphases, env); + if(0 == size) + { + return NULL; + } + + op_in_faultphases = axutil_array_list_create(env, 0); + if(!op_in_faultphases) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + for(i = 0; i < size; i++) + { + phase_name = (axis2_char_t *)axutil_array_list_get(phases_info->in_faultphases, env, i); + + phase = axis2_phase_create(env, phase_name); + status = axutil_array_list_add(op_in_faultphases, env, phase); + if(AXIS2_SUCCESS != status) + { + int i = 0; + int size = 0; + + axis2_phase_free(phase, env); + phase = NULL; + size = axutil_array_list_size(op_in_faultphases, env); + for(i = 0; i < size; i++) + { + phase = axutil_array_list_get(op_in_faultphases, env, i); + axis2_phase_free(phase, env); + phase = NULL; + } + axutil_array_list_free(op_in_faultphases, env); + op_in_faultphases = NULL; + return NULL; + + } + } + + return op_in_faultphases; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_phases_info_get_op_out_faultphases( + const axis2_phases_info_t * phases_info, + const axutil_env_t * env) +{ + int i = 0; + int size = 0; + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t *phase_name = NULL; + axutil_array_list_t *op_out_faultphases = NULL; + struct axis2_phase *phase = NULL; + + AXIS2_PARAM_CHECK(env->error, phases_info, NULL); + + if(!phases_info->out_faultphases) + { + return NULL; + } + size = axutil_array_list_size(phases_info->out_faultphases, env); + + if(0 == size) + { + return NULL; + } + + op_out_faultphases = axutil_array_list_create(env, 0); + if(!op_out_faultphases) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + for(i = 0; i < size; i++) + { + phase_name = (axis2_char_t *)axutil_array_list_get(phases_info->out_faultphases, env, i); + phase = axis2_phase_create(env, phase_name); + status = axutil_array_list_add(op_out_faultphases, env, phase); + if(AXIS2_SUCCESS != status) + { + int i = 0; + int size = 0; + + axis2_phase_free(phase, env); + phase = NULL; + size = axutil_array_list_size(op_out_faultphases, env); + for(i = 0; i < size; i++) + { + phase = axutil_array_list_get(op_out_faultphases, env, i); + axis2_phase_free(phase, env); + phase = NULL; + } + axutil_array_list_free(op_out_faultphases, env); + op_out_faultphases = NULL; + return NULL; + + } + } + + return op_out_faultphases; +} + +/* + * Get user defined phase instances for each flow defined in axis2.xml in an array list and add it + * into operation. This is called service builder, module builder and service client to add phases + * into operations. + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_phases_info_set_op_phases( + axis2_phases_info_t * phases_info, + const axutil_env_t * env, + axis2_op_t * op_desc) +{ + axis2_status_t status = AXIS2_FAILURE; + axutil_array_list_t *op_in_phases = NULL; + axutil_array_list_t *op_out_phases = NULL; + axutil_array_list_t *op_in_faultphases = NULL; + axutil_array_list_t *op_out_faultphases = NULL; + + AXIS2_PARAM_CHECK(env->error, op_desc, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, phases_info, AXIS2_FAILURE); + + op_in_phases = axis2_phases_info_get_op_in_phases(phases_info, env); + if(!op_in_phases) + { + status = AXIS2_ERROR_GET_STATUS_CODE(env->error); + /* op_in_phases cannot be NULL */ + return status; + } + + op_out_phases = axis2_phases_info_get_op_out_phases(phases_info, env); + if(!op_out_phases) + { + status = AXIS2_ERROR_GET_STATUS_CODE(env->error); + /* op_out_phases cannot be NULL */ + return status; + } + + op_in_faultphases = axis2_phases_info_get_op_in_faultphases(phases_info, env); + op_out_faultphases = axis2_phases_info_get_op_out_faultphases(phases_info, env); + + status = axis2_op_set_in_flow(op_desc, env, op_in_phases); + status = axis2_op_set_out_flow(op_desc, env, op_out_phases); + if(op_in_faultphases) + { + status = axis2_op_set_fault_in_flow(op_desc, env, op_in_faultphases); + } + + if(op_out_faultphases) + { + status = axis2_op_set_fault_out_flow(op_desc, env, op_out_faultphases); + } + + return status; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axis2_phases_info_copy_flow( + const axutil_env_t * env, + const axutil_array_list_t * flow_to_copy) +{ + int size = 0, i = 0; + + axutil_array_list_t *new_flow = NULL; + if(flow_to_copy) + { + size = axutil_array_list_size((axutil_array_list_t *)flow_to_copy, env); + } + + if(size > 0) + { + new_flow = axutil_array_list_create(env, 0); + if(!new_flow) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + } + + for(i = 0; i < size; i++) + { + void *item = axutil_array_list_get((axutil_array_list_t *)flow_to_copy, env, i); + axis2_phase_increment_ref((axis2_phase_t *)item, env); + axutil_array_list_add(new_flow, env, item); + } + + return new_flow; +} + diff --git a/src/core/deployment/repos_listener.c b/src/core/deployment/repos_listener.c new file mode 100644 index 0000000..1df1325 --- /dev/null +++ b/src/core/deployment/repos_listener.c @@ -0,0 +1,398 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_repos_listener.h> +#include <axis2_ws_info_list.h> +#include <axutil_dir_handler.h> + +struct axis2_repos_listener +{ + + /** + * Referance to a ws info list + */ + axis2_ws_info_list_t *info_list; + + /** + * The parent directory of the modules and services directories + * that the listener should listen + */ + axis2_char_t *folder_name; + axis2_conf_t *conf; +}; + +static axis2_status_t +axis2_repos_listener_search( + axis2_repos_listener_t * repos_listener, + const axutil_env_t * env, + axis2_char_t * folder_name, + int type); + +AXIS2_EXTERN axis2_repos_listener_t *AXIS2_CALL +axis2_repos_listener_create( + const axutil_env_t * env) +{ + axis2_repos_listener_t *repos_listener = NULL; + + repos_listener = (axis2_repos_listener_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_repos_listener_t)); + + if(!repos_listener) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + repos_listener->folder_name = NULL; + repos_listener->info_list = NULL; + repos_listener->folder_name = AXIS2_FALSE; + + return repos_listener; +} + +/** + * This constructor take two argumnets, folder name and referance to + * deployment engine. Fisrt it initilize the sysetm , by loading all the + * modules in the /modules directory and also create a ws info list to + * keep info about available modules and services. + * @param folderName path to parent directory that the repos_listener + * should listens + * @param deploy_engine refearnce to engine registry inorder to + * inform the updates + */ + +AXIS2_EXTERN axis2_repos_listener_t *AXIS2_CALL +axis2_repos_listener_create_with_folder_name_and_dep_engine( + const axutil_env_t * env, + axis2_char_t * folder_name, + axis2_dep_engine_t * dep_engine) +{ + axis2_repos_listener_t *repos_listener = NULL; + axis2_status_t status = AXIS2_FAILURE; + + axis2_conf_t *conf; + axis2_bool_t file_flag; + + repos_listener = (axis2_repos_listener_t *)axis2_repos_listener_create(env); + + if(!repos_listener) + { + return NULL; + } + + file_flag = axis2_dep_engine_get_file_flag(dep_engine, env); + + if(!file_flag) + { + repos_listener->folder_name = axutil_strdup(env, folder_name); + if(!repos_listener->folder_name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + } + + repos_listener->info_list = axis2_ws_info_list_create_with_dep_engine(env, dep_engine); + if(!repos_listener->info_list) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating ws info list failed"); + return NULL; + } + + /* Here dep_engine's conf will set to repo_listner. Then we could get + * details of the axis2.xml through axis2 configuration. + */ + + conf = axis2_dep_engine_get_axis_conf(dep_engine, env); + if(!conf) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Deployment engines axis2 configuration not available"); + + return NULL; + } + axis2_repos_listener_set_conf(repos_listener, env, conf); + + status = axis2_repos_listener_init(repos_listener, env); + if(AXIS2_SUCCESS != status) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_REPOS_LISTENER_INIT_FAILED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Repository listener initialization failed"); + + return NULL; + } + return repos_listener; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_repos_listener_free( + axis2_repos_listener_t * repos_listener, + const axutil_env_t * env) +{ + if(!repos_listener) + return; + + if(repos_listener->folder_name) + { + AXIS2_FREE(env->allocator, repos_listener->folder_name); + } + + if(repos_listener->info_list) + { + axis2_ws_info_list_free(repos_listener->info_list, env); + } + + AXIS2_FREE(env->allocator, repos_listener); + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_repos_listener_check_modules( + axis2_repos_listener_t * repos_listener, + const axutil_env_t * env) +{ + axis2_char_t *module_path = NULL; + axis2_char_t *temp_path = NULL; + axis2_status_t status = AXIS2_FAILURE; + axis2_bool_t axis2_flag = AXIS2_FALSE; + axis2_conf_t *conf; + + axutil_param_t *module_param; + axis2_char_t *module_dir; + + AXIS2_PARAM_CHECK(env->error, repos_listener, AXIS2_FAILURE); + + conf = axis2_repos_listener_get_conf(repos_listener, env); + + /* Configuration is needed only to decide we are using axis2.xml. Other + * case we don't need. Hence even if conf is NULL we can continue. + */ + + if(conf) + { + axis2_flag = axis2_conf_get_axis2_flag(conf, env); + } + + if(!axis2_flag) + { + + temp_path = axutil_stracat(env, repos_listener->folder_name, AXIS2_PATH_SEP_STR); + module_path = axutil_stracat(env, temp_path, AXIS2_MODULE_PATH); + AXIS2_FREE(env->allocator, temp_path); + } + else + { + module_param = axis2_conf_get_param(conf, env, AXIS2_MODULE_DIR); + if(module_param) + { + module_dir = (axis2_char_t *)axutil_param_get_value(module_param, env); + module_path = axutil_strdup(env, module_dir); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "While creating axis2 configuration using " + "axis2.xml, modulesDir parameter not available."); + } + + } + + status = axis2_repos_listener_search(repos_listener, env, module_path, AXIS2_MODULE); + + AXIS2_FREE(env->allocator, module_path); + + return status; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_repos_listener_check_svcs( + axis2_repos_listener_t * repos_listener, + const axutil_env_t * env) +{ + axis2_char_t *svc_path = NULL; + axis2_char_t *temp_path = NULL; + axis2_status_t status = AXIS2_FAILURE; + + axis2_conf_t *conf; + axis2_bool_t axis2_flag = AXIS2_FALSE; + + axutil_param_t *svc_param; + axis2_char_t *svc_dir; + + AXIS2_PARAM_CHECK(env->error, repos_listener, AXIS2_FAILURE); + + conf = axis2_repos_listener_get_conf(repos_listener, env); + + if(conf) + axis2_flag = axis2_conf_get_axis2_flag(conf, env); + + if(!axis2_flag) + { + temp_path = axutil_stracat(env, repos_listener->folder_name, AXIS2_PATH_SEP_STR); + svc_path = axutil_stracat(env, temp_path, AXIS2_SVC_PATH); + AXIS2_FREE(env->allocator, temp_path); + } + else + { + svc_param = axis2_conf_get_param(conf, env, AXIS2_SERVICE_DIR); + if(svc_param) + { + svc_dir = axutil_param_get_value(svc_param, env); + svc_path = axutil_strdup(env, svc_dir); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "While creating axis2 configuration using axis2.xml, servicesDir" + " parameter not available."); + } + } + + status = axis2_repos_listener_search(repos_listener, env, svc_path, AXIS2_SVC); + AXIS2_FREE(env->allocator, svc_path); + return status; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_repos_listener_update( + axis2_repos_listener_t * repos_listener, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, repos_listener, AXIS2_FAILURE); + return axis2_ws_info_list_update(repos_listener->info_list, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_repos_listener_init( + axis2_repos_listener_t * repos_listener, + const axutil_env_t * env) +{ + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, repos_listener, AXIS2_FAILURE); + + status = axis2_ws_info_list_init(repos_listener->info_list, env); + if(AXIS2_SUCCESS != status) + { + return status; + } + /* if check_modules return AXIS2_FAILURE that means + * there are no modules to load + */ + axis2_repos_listener_check_modules(repos_listener, env); + + /* if check_svcs return AXIS2_FAILURE that means + * there are no services to load + */ + axis2_repos_listener_check_svcs(repos_listener, env); + return axis2_repos_listener_update(repos_listener, env); +} + +/** + * Folder name could be a repository modules or services folder. If it is modules + * folder then current_info_list contain the list of axis2 files corresponding to + * the modules within it. For services folder it should be understood similarly. + */ +static axis2_status_t +axis2_repos_listener_search( + axis2_repos_listener_t * repos_listener, + const axutil_env_t * env, + axis2_char_t * folder_name, + int type) +{ + int size = 0; + int i = 0; + axutil_array_list_t *current_info_list = NULL; + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_PARAM_CHECK(env->error, repos_listener, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, folder_name, AXIS2_FAILURE); + current_info_list = axutil_dir_handler_list_service_or_module_dirs(env, folder_name); + if(!current_info_list) + { + axis2_status_t status_code = AXIS2_FAILURE; + + status_code = AXIS2_ERROR_GET_STATUS_CODE(env->error); + if(AXIS2_SUCCESS != status) + { + return status; + } + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No %s in the folder.", folder_name); + return AXIS2_SUCCESS; + } + + size = axutil_array_list_size(current_info_list, env); + + for(i = 0; i < size; i++) /* Loop until empty */ + { + axutil_file_t *file = NULL; + file = axutil_array_list_get(current_info_list, env, i); + status = axis2_ws_info_list_add_ws_info_item(repos_listener->info_list, env, file, type); + if(AXIS2_SUCCESS != status) + { + int size_j = 0; + int j = 0; + axis2_char_t* file_name = axutil_file_get_name(file, env); + + size_j = axutil_array_list_size(current_info_list, env); + for(j = 0; j < size_j; j++) + { + axutil_file_t *del_file = NULL; + + del_file = axutil_array_list_get(current_info_list, env, j); + axutil_file_free(del_file, env); + } + axutil_array_list_free(current_info_list, env); + current_info_list = NULL; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Adding file %s to ws info list failed", + file_name); + return status; + } + } + + for(i = 0; i < size; i++) + { + axutil_file_t *del_file = NULL; + + del_file = axutil_array_list_get(current_info_list, env, i); + axutil_file_free(del_file, env); + } + axutil_array_list_free(current_info_list, env); + current_info_list = NULL; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_repos_listener_set_conf( + axis2_repos_listener_t *repo_listener, + const axutil_env_t * env, + axis2_conf_t *conf) +{ + AXIS2_PARAM_CHECK(env->error, repo_listener, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, conf, AXIS2_FAILURE); + repo_listener->conf = conf; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_conf_t *AXIS2_CALL +axis2_repos_listener_get_conf( + axis2_repos_listener_t *repo_listener, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, repo_listener, NULL); + return repo_listener->conf; +} + diff --git a/src/core/deployment/svc_builder.c b/src/core/deployment/svc_builder.c new file mode 100644 index 0000000..7f55fb6 --- /dev/null +++ b/src/core/deployment/svc_builder.c @@ -0,0 +1,840 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_svc_builder.h> +#include <axutil_class_loader.h> +#include <axutil_utils.h> +#include <axutil_property.h> +#include <axis2_msg.h> + +struct axis2_svc_builder +{ + axis2_svc_t *svc; + struct axis2_desc_builder *desc_builder; +}; + +static axutil_array_list_t * +axis2_svc_builder_process_ops( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * op_itr); + +static void +axis2_svc_builder_process_msgs( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * iterator, + axis2_op_t * op); + +AXIS2_EXTERN axis2_svc_builder_t *AXIS2_CALL +axis2_svc_builder_create( + const axutil_env_t * env) +{ + axis2_svc_builder_t *svc_builder = NULL; + + svc_builder = (axis2_svc_builder_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_svc_builder_t)); + + if(!svc_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Allocation to svc_builder failed"); + return NULL; + } + + svc_builder->desc_builder = NULL; + svc_builder->svc = NULL; + + return svc_builder; +} + +AXIS2_EXTERN axis2_svc_builder_t *AXIS2_CALL +axis2_svc_builder_create_with_file_and_dep_engine_and_svc( + const axutil_env_t * env, + axis2_char_t * file_name, + struct axis2_dep_engine * dep_engine, + axis2_svc_t * svc) +{ + axis2_svc_builder_t *svc_builder = NULL; + + AXIS2_PARAM_CHECK(env->error, file_name, NULL); + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + AXIS2_PARAM_CHECK(env->error, svc, NULL); + svc_builder = (axis2_svc_builder_t *)axis2_svc_builder_create(env); + if(!svc_builder) + { + return NULL; + } + svc_builder->desc_builder = axis2_desc_builder_create_with_file_and_dep_engine(env, file_name, + dep_engine); + if(!svc_builder->desc_builder) + { + axis2_svc_builder_free(svc_builder, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Creating description builder for service builder %s failed", file_name); + return NULL; + } + svc_builder->svc = svc; + return svc_builder; +} + +AXIS2_EXTERN axis2_svc_builder_t *AXIS2_CALL +axis2_svc_builder_create_with_dep_engine_and_svc( + const axutil_env_t * env, + axis2_dep_engine_t * dep_engine, + axis2_svc_t * svc) +{ + axis2_svc_builder_t *svc_builder = NULL; + + AXIS2_PARAM_CHECK(env->error, dep_engine, NULL); + AXIS2_PARAM_CHECK(env->error, svc, NULL); + svc_builder = (axis2_svc_builder_t *)axis2_svc_builder_create(env); + if(!svc_builder) + { + return NULL; + } + svc_builder->desc_builder = axis2_desc_builder_create_with_dep_engine(env, dep_engine); + if(!svc_builder->desc_builder) + { + axis2_svc_builder_free(svc_builder, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Creating description builder for service builder failed"); + return NULL; + } + svc_builder->svc = svc; + return svc_builder; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_svc_builder_free( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env) +{ + if(svc_builder->desc_builder) + { + axis2_desc_builder_free(svc_builder->desc_builder, env); + } + + svc_builder->svc = NULL; + + if(svc_builder) + { + AXIS2_FREE(env->allocator, svc_builder); + } + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_svc_builder_populate_svc( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_node_t * svc_node) +{ + axiom_element_t *svc_element = NULL; + axiom_children_qname_iterator_t *itr = NULL; + axiom_children_qname_iterator_t *operation_itr = NULL; + axutil_qname_t *qparamst = NULL; + axutil_qname_t *qdesc = NULL; + axutil_qname_t *qmodulest = NULL; + axutil_qname_t *qinflowst = NULL; + axutil_qname_t *qoutflowst = NULL; + axutil_qname_t *qin_faultflowst = NULL; + axutil_qname_t *qout_faultflowst = NULL; + axutil_qname_t *qopst = NULL; + axutil_qname_t *qattname = NULL; + axutil_qname_t *qpolicy = NULL; + axis2_status_t status = AXIS2_FAILURE; + axis2_svc_grp_t *parent = NULL; + axiom_element_t *desc_element = NULL; + axiom_node_t *desc_node = NULL; + axiom_children_qname_iterator_t *module_refs = NULL; + axiom_node_t *in_flow_node = NULL; + axiom_element_t *in_flow_element = NULL; + axiom_node_t *out_flow_node = NULL; + axiom_element_t *out_flow_element = NULL; + axiom_node_t *in_faultflow_node = NULL; + axiom_element_t *in_faultflow_element = NULL; + axiom_node_t *out_faultflow_node = NULL; + axiom_element_t *out_faultflow_element = NULL; + axiom_attribute_t *name_attr = NULL; + axutil_array_list_t *ops = NULL; + axis2_char_t *svc_name = NULL; + axis2_char_t *class_name = NULL; + axis2_char_t *svc_dll_name = NULL; + axutil_dll_desc_t *dll_desc = NULL; + axutil_param_t *impl_info_param = NULL; + axutil_param_t *wsdl_path_param = NULL; + axis2_char_t *wsdl_path = NULL; + axis2_arch_file_data_t *arch_file_data = NULL; + axutil_file_t *svc_folder = NULL; + axis2_char_t *dll_path = NULL; + axis2_char_t *svc_folder_path = NULL; + int i = 0; + int size = 0; + AXIS2_TIME_T timestamp = 0; + axis2_desc_t *desc = NULL; + axis2_policy_include_t *policy_include = NULL; + axutil_qname_t *qname_addressing = NULL; + axis2_bool_t addressing_engaged = AXIS2_FALSE; + axutil_array_list_t *svc_module_qnames = NULL; + int svc_module_qname_size = 0; + + AXIS2_PARAM_CHECK(env->error, svc_node, AXIS2_FAILURE); + + svc_element = axiom_node_get_data_element(svc_node, env); + /* Processing service level paramters */ + qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + if(!qparamst) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); + return AXIS2_FAILURE; + } + itr = axiom_element_get_children_with_qname(svc_element, env, qparamst, svc_node); + axutil_qname_free(qparamst, env); + qparamst = NULL; + + parent = axis2_svc_get_parent(svc_builder->svc, env); + + desc = axis2_svc_get_base(svc_builder->svc, env); + policy_include = axis2_desc_get_policy_include(desc, env); + + status = axis2_desc_builder_process_params(svc_builder->desc_builder, env, itr, + axis2_svc_get_param_container(svc_builder->svc, env), axis2_svc_grp_get_param_container( + parent, env)); + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Processing parameters failed"); + return status; + } + + /* process service description */ + qdesc = axutil_qname_create(env, AXIS2_DESCRIPTION, NULL, NULL); + desc_element = axiom_element_get_first_child_with_qname(svc_element, env, qdesc, svc_node, + &desc_node); + axutil_qname_free(qdesc, env); + qdesc = NULL; + if(desc_element) + { + axiom_element_t *desc_value_element = NULL; + axiom_node_t *desc_value_node = NULL; + axis2_char_t *description_text = NULL; + + desc_value_element = axiom_element_get_first_element(desc_element, env, desc_node, + &desc_value_node); + description_text = axiom_element_get_text(desc_element, env, desc_node); + if(description_text) + { + axis2_svc_set_svc_desc(svc_builder->svc, env, description_text); + } + } + + /* wsdl path */ + wsdl_path_param = axutil_param_container_get_param(axis2_svc_get_param_container( + svc_builder->svc, env), env, AXIS2_SVC_WSDL_PATH); + + if(wsdl_path_param) + { + wsdl_path = axutil_param_get_value(wsdl_path_param, env); + } + + if(wsdl_path) + { + axis2_svc_set_svc_wsdl_path(svc_builder->svc, env, wsdl_path); + } + + qattname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + name_attr = axiom_element_get_attribute(svc_element, env, qattname); + svc_name = axiom_attribute_get_value(name_attr, env); + axis2_svc_set_name(svc_builder->svc, env, svc_name); + axutil_qname_free(qattname, env); + + /* create dll_desc and set it in a parameter. then set that param in param + * container taken from svc + */ + dll_desc = axutil_dll_desc_create(env); + impl_info_param = axutil_param_container_get_param(axis2_svc_get_param_container( + svc_builder->svc, env), env, AXIS2_SERVICE_CLASS); + if(!impl_info_param) + { + axutil_dll_desc_free(dll_desc, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s parameter not found", AXIS2_SERVICE_CLASS); + return AXIS2_FAILURE; + } + class_name = axutil_strtrim(env, axutil_param_get_value(impl_info_param, env), NULL); + svc_dll_name = axutil_dll_desc_create_platform_specific_dll_name(dll_desc, env, class_name); + + if(class_name) + { + AXIS2_FREE(env->allocator, class_name); + class_name = NULL; + } + + arch_file_data = axis2_dep_engine_get_current_file_item(axis2_desc_builder_get_dep_engine( + svc_builder->desc_builder, env), env); + svc_folder = axis2_arch_file_data_get_file(arch_file_data, env); + timestamp = axutil_file_get_timestamp(svc_folder, env); + axutil_dll_desc_set_timestamp(dll_desc, env, timestamp); + svc_folder_path = axutil_file_get_path(svc_folder, env); + axis2_svc_set_svc_folder_path(svc_builder->svc, env, svc_folder_path); + dll_path = axutil_strcat(env, svc_folder_path, AXIS2_PATH_SEP_STR, svc_dll_name, NULL); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "DLL path is : %s", dll_path); + status = axutil_dll_desc_set_name(dll_desc, env, dll_path); + if(AXIS2_SUCCESS != status) + { + axutil_dll_desc_free(dll_desc, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting name to %s dll description failed", + dll_path); + return status; + } + AXIS2_FREE(env->allocator, dll_path); + dll_path = NULL; + + axutil_dll_desc_set_type(dll_desc, env, AXIS2_SVC_DLL); + status = axutil_param_set_value(impl_info_param, env, dll_desc); + axutil_param_set_value_free(impl_info_param, env, axutil_dll_desc_free_void_arg); + if(AXIS2_SUCCESS != status) + { + axutil_dll_desc_free(dll_desc, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting dll_desc to parameter %s failed", + class_name); + return status; + } + /* processing service wide modules which required to engage globally */ + qmodulest = axutil_qname_create(env, AXIS2_MODULEST, NULL, NULL); + module_refs = axiom_element_get_children_with_qname(svc_element, env, qmodulest, svc_node); + axutil_qname_free(qmodulest, env); + qmodulest = NULL; + status = axis2_svc_builder_process_module_refs(svc_builder, env, module_refs); + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Processing module references failed"); + return status; + } + + if(!addressing_engaged) + { + svc_module_qnames = axis2_svc_get_all_module_qnames(svc_builder->svc, env); + if(svc_module_qnames) + { + svc_module_qname_size = axutil_array_list_size(svc_module_qnames, env); + qname_addressing = axutil_qname_create(env, AXIS2_MODULE_ADDRESSING, NULL, NULL); + for(i = 0; i < svc_module_qname_size; i++) + { + if(axutil_qname_equals(axutil_array_list_get(svc_module_qnames, env, i), env, + qname_addressing)) + { + addressing_engaged = AXIS2_TRUE; + break; + } + } + axutil_qname_free(qname_addressing, env); + } + svc_module_qnames = NULL; + } + + /* process IN_FLOW */ + qinflowst = axutil_qname_create(env, AXIS2_IN_FLOW_START, NULL, NULL); + in_flow_element = axiom_element_get_first_child_with_qname( + svc_element, env, qinflowst, svc_node, &in_flow_node); + axutil_qname_free(qinflowst, env); + qinflowst = NULL; + + qoutflowst = axutil_qname_create(env, AXIS2_OUT_FLOW_START, NULL, NULL); + out_flow_element = axiom_element_get_first_child_with_qname( + svc_element, env, qoutflowst, svc_node, &out_flow_node); + axutil_qname_free(qoutflowst, env); + qoutflowst = NULL; + + qin_faultflowst = axutil_qname_create(env, AXIS2_IN_FAILTFLOW, NULL, NULL); + in_faultflow_element = axiom_element_get_first_child_with_qname( + svc_element, env, qin_faultflowst, svc_node, &in_faultflow_node); + axutil_qname_free(qin_faultflowst, env); + qin_faultflowst = NULL; + + qout_faultflowst = axutil_qname_create(env, AXIS2_OUT_FAILTFLOW, NULL, NULL); + out_faultflow_element = axiom_element_get_first_child_with_qname( + svc_element, env, qout_faultflowst, svc_node, &out_faultflow_node); + axutil_qname_free(qout_faultflowst, env); + qout_faultflowst = NULL; + + /* processing operations */ + qopst = axutil_qname_create(env, AXIS2_OPERATIONST, NULL, NULL); + operation_itr = axiom_element_get_children_with_qname(svc_element, env, qopst, svc_node); + axutil_qname_free(qopst, env); + qopst = NULL; + ops = axis2_svc_builder_process_ops(svc_builder, env, operation_itr); + if(ops) + { + size = axutil_array_list_size(ops, env); + } + for(i = 0; i < size; i++) + { + axis2_op_t *op_desc = NULL; + axutil_array_list_t *params = NULL; + int j = 0; + int sizej = 0; + + op_desc = (axis2_op_t *)axutil_array_list_get(ops, env, i); + if(addressing_engaged) + { + params = axis2_op_get_all_params(op_desc, env); + /* Adding wsa-mapping into service */ + sizej = axutil_array_list_size(params, env); + for(j = 0; j < sizej; j++) + { + axutil_param_t *param = NULL; + axis2_char_t *param_name = NULL; + + param = axutil_array_list_get(params, env, j); + param_name = axutil_param_get_name(param, env); + if(0 == axutil_strcmp(param_name, AXIS2_WSA_MAPPING)) + { + axis2_char_t *key = NULL; + + key = (axis2_char_t *)axutil_param_get_value(param, env); + axis2_svc_add_mapping(svc_builder->svc, env, key, op_desc); + } + } + } + axis2_svc_add_op(svc_builder->svc, env, op_desc); + if(axis2_op_get_rest_http_method(op_desc, env) && axis2_op_get_rest_http_location(op_desc, + env)) + { + axis2_svc_add_rest_mapping(svc_builder->svc, env, axis2_op_get_rest_http_method( + op_desc, env), axis2_op_get_rest_http_location(op_desc, env), op_desc); + } + } + axutil_array_list_free(ops, env); + + /* + <schema targetNamespace="http://x.y.z"/> + setting the PolicyInclude + processing <wsp:Policy> .. </..> elements + */ + qpolicy = axutil_qname_create(env, NEETHI_POLICY, NEETHI_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(svc_element, env, qpolicy, svc_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + if((!itr) || (!axiom_children_qname_iterator_has_next(itr, env))) + { + qpolicy = axutil_qname_create(env, NEETHI_POLICY, NEETHI_POLICY_15_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(svc_element, env, qpolicy, svc_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + } + + if(itr) + { + axis2_process_policy_elements(env, AXIS2_SERVICE_POLICY, itr, policy_include); + } + + /* processing <wsp:PolicyReference> .. </..> elements */ + qpolicy = axutil_qname_create(env, NEETHI_REFERENCE, NEETHI_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(svc_element, env, qpolicy, svc_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + + if((!itr) || (!axiom_children_qname_iterator_has_next(itr, env))) + { + qpolicy = axutil_qname_create(env, NEETHI_REFERENCE, NEETHI_POLICY_15_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(svc_element, env, qpolicy, svc_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + } + if(itr) + { + axis2_process_policy_reference_elements(env, AXIS2_POLICY_REF, itr, policy_include); + } + + return AXIS2_SUCCESS; +} + +static axutil_array_list_t * +axis2_svc_builder_process_ops( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * op_itr) +{ + axutil_array_list_t *ops = NULL; + + AXIS2_PARAM_CHECK(env->error, op_itr, NULL); + + ops = axutil_array_list_create(env, 0); + while(AXIS2_TRUE == axiom_children_qname_iterator_has_next(op_itr, env)) + { + axiom_element_t *op_element = NULL; + axiom_node_t *op_node = NULL; + axiom_attribute_t *op_name_att = NULL; + axiom_attribute_t *op_mep_att = NULL; + axutil_qname_t *qmep = NULL; + axutil_qname_t *qopname = NULL; + axutil_qname_t *qparamst = NULL; + axutil_qname_t *qmsgrecv = NULL; + axutil_qname_t *qmodulest = NULL; + axutil_qname_t *qattname = NULL; + axis2_char_t *mep_url = NULL; + axis2_char_t *op_name = NULL; + axis2_op_t *op_desc = NULL; + axiom_children_qname_iterator_t *params_itr = NULL; + axiom_children_qname_iterator_t *module_itr = NULL; + axiom_element_t *recv_element = NULL; + axiom_node_t *recv_node = NULL; + axis2_status_t status = AXIS2_FAILURE; + struct axis2_dep_engine *dep_engine = NULL; + axis2_desc_t *desc = NULL; + axis2_policy_include_t *policy_include = NULL; + axiom_children_qname_iterator_t *itr = NULL; + axutil_qname_t *qpolicy = NULL; + axutil_qname_t *qmessage = NULL; + + op_node = axiom_children_qname_iterator_next(op_itr, env); + /* getting operation name */ + op_element = axiom_node_get_data_element(op_node, env); + qattname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + op_name_att = axiom_element_get_attribute(op_element, env, qattname); + axutil_qname_free(qattname, env); + qattname = NULL; + if(!op_name_att) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_OP_NAME_MISSING, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, ""); + return NULL; + } + + op_name = axiom_attribute_get_value(op_name_att, env); + qopname = axutil_qname_create(env, op_name, NULL, NULL); + op_desc = axis2_op_create(env); + axis2_op_set_qname(op_desc, env, qopname); + axutil_qname_free(qopname, env); + qopname = NULL; + + /* set the mep of the operation */ + qmep = axutil_qname_create(env, AXIS2_MEP, NULL, NULL); + op_mep_att = axiom_element_get_attribute(op_element, env, qmep); + axutil_qname_free(qmep, env); + qmep = NULL; + op_name = axiom_attribute_get_value(op_name_att, env); + + if(op_mep_att) + { + mep_url = axiom_attribute_get_value(op_mep_att, env); + if(mep_url) + { + axis2_op_set_msg_exchange_pattern(op_desc, env, mep_url); + } + } + + desc = axis2_op_get_base(op_desc, env); + policy_include = axis2_desc_get_policy_include(desc, env); + + /* operation parameters */ + qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + params_itr = axiom_element_get_children_with_qname(op_element, env, qparamst, op_node); + axutil_qname_free(qparamst, env); + qparamst = NULL; + status = axis2_desc_builder_process_params(svc_builder->desc_builder, env, params_itr, + axis2_op_get_param_container(op_desc, env), axis2_svc_get_param_container( + svc_builder->svc, env)); + /* To process wsamapping */ + axis2_desc_builder_process_action_mappings(svc_builder->desc_builder, env, op_node, op_desc); + + /* To process REST params */ + axis2_desc_builder_process_rest_params(svc_builder->desc_builder, env, op_node, op_desc); + + /* loading the message receivers */ + qmsgrecv = axutil_qname_create(env, AXIS2_MESSAGERECEIVER, NULL, NULL); + recv_element = axiom_element_get_first_child_with_qname(op_element, env, qmsgrecv, op_node, + &recv_node); + axutil_qname_free(qmsgrecv, env); + qmsgrecv = NULL; + if(recv_element && NULL != recv_node) + { + axis2_msg_recv_t *msg_recv = NULL; + msg_recv = axis2_desc_builder_load_msg_recv(svc_builder->desc_builder, env, + recv_element); + axis2_op_set_msg_recv(op_desc, env, msg_recv); + + } + else + { + axis2_msg_recv_t *msg_recv = NULL; + /* setting the default message receiver */ + msg_recv = axis2_desc_builder_load_default_msg_recv(env); + axis2_op_set_msg_recv(op_desc, env, msg_recv); + } + /* process module refs */ + qmodulest = axutil_qname_create(env, AXIS2_MODULEST, NULL, NULL); + module_itr = axiom_element_get_children_with_qname(op_element, env, qmodulest, op_node); + axutil_qname_free(qmodulest, env); + qmodulest = NULL; + status = axis2_desc_builder_process_op_module_refs(svc_builder-> desc_builder, env, + module_itr, op_desc); + if(AXIS2_SUCCESS != status) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Processing module operation references failed for operation %s", op_name); + return NULL; + } + + /* setting the policy_include */ + + /* processing <wsp:Policy> .. </..> elements */ + + qpolicy = axutil_qname_create(env, NEETHI_POLICY, NEETHI_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(op_element, env, qpolicy, op_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + + if((!itr) || (!axiom_children_qname_iterator_has_next(itr, env))) + { + qpolicy = axutil_qname_create(env, NEETHI_POLICY, NEETHI_POLICY_15_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(op_element, env, qpolicy, op_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + } + + if(itr) + { + axis2_process_policy_elements(env, AXIS2_SERVICE_POLICY, itr, policy_include); + } + + /* processing <wsp:PolicyReference> .. </..> elements */ + qpolicy = axutil_qname_create(env, NEETHI_REFERENCE, NEETHI_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(op_element, env, qpolicy, op_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + + if((!itr) || (!axiom_children_qname_iterator_has_next(itr, env))) + { + qpolicy = axutil_qname_create(env, NEETHI_REFERENCE, NEETHI_POLICY_15_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(op_element, env, qpolicy, op_node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + } + + if(itr) + { + axis2_process_policy_reference_elements(env, AXIS2_POLICY_REF, itr, policy_include); + } + + qmessage = axutil_qname_create(env, AXIS2_MESSAGE, NULL, NULL); + itr = axiom_element_get_children_with_qname(op_element, env, qmessage, op_node); + axutil_qname_free(qmessage, env); + qmessage = NULL; + + if(itr) + { + axis2_svc_builder_process_msgs(svc_builder, env, itr, op_desc); + } + + /* setting operation phase */ + dep_engine = axis2_desc_builder_get_dep_engine(svc_builder->desc_builder, env); + if(dep_engine) + { + axis2_phases_info_t *info = axis2_dep_engine_get_phases_info(dep_engine, env); + axis2_phases_info_set_op_phases(info, env, op_desc); + } + + /* adding operation */ + status = axutil_array_list_add(ops, env, op_desc); + } + + return ops; +} + +static void +axis2_svc_builder_process_msgs( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * iterator, + axis2_op_t * op) +{ + while(axiom_children_qname_iterator_has_next(iterator, env)) + { + axiom_node_t *node = NULL; + axiom_element_t *element = NULL; + axutil_qname_t *qname = NULL; + axis2_char_t *msg_label = NULL; + axis2_msg_t *msg = NULL; + axiom_children_qname_iterator_t *itr = NULL; + axutil_qname_t *qpolicy = NULL; + axis2_desc_t *desc = NULL; + axis2_policy_include_t *policy_include = NULL; + + node = axiom_children_qname_iterator_next(iterator, env); + element = axiom_node_get_data_element(node, env); + qname = axutil_qname_create(env, AXIS2_LABEL, NULL, NULL); + + if(element) + { + msg_label = axiom_element_get_attribute_value(element, env, qname); + } + + if(msg_label) + { + msg = axis2_op_get_msg(op, env, msg_label); + } + + if(msg) + { + /* operation parameters */ + axiom_children_qname_iterator_t *params_itr = NULL; + axutil_qname_t *qparamst = NULL; + qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + params_itr = axiom_element_get_children_with_qname(element, env, qparamst, node); + axutil_qname_free(qparamst, env); + qparamst = NULL; + axis2_desc_builder_process_params(svc_builder->desc_builder, env, params_itr, + axis2_msg_get_param_container(msg, env), axis2_op_get_param_container(op, env)); + + desc = axis2_msg_get_base(msg, env); + policy_include = axis2_desc_get_policy_include(desc, env); + + /* setting the policy_include */ + + /* processing <wsp:Policy> .. </..> elements */ + + qpolicy = axutil_qname_create(env, NEETHI_POLICY, NEETHI_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(element, env, qpolicy, node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + + if((!itr) || (!axiom_children_qname_iterator_has_next(itr, env))) + { + qpolicy = axutil_qname_create(env, NEETHI_POLICY, NEETHI_POLICY_15_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(element, env, qpolicy, node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + } + + if(itr) + { + axis2_process_policy_elements(env, AXIS2_SERVICE_POLICY, itr, policy_include); + /* axis2_process_policy_elements(env, AXIS2_MESSAGE_POLICY, itr, + policy_include); */ + + } + + /* processing <wsp:PolicyReference> .. </..> elements */ + qpolicy = axutil_qname_create(env, NEETHI_REFERENCE, NEETHI_NAMESPACE, NULL); + itr = axiom_element_get_children_with_qname(element, env, qpolicy, node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + + if((!itr) || (!axiom_children_qname_iterator_has_next(itr, env))) + { + qpolicy = axutil_qname_create(env, NEETHI_REFERENCE, NEETHI_POLICY_15_NAMESPACE, + NULL); + itr = axiom_element_get_children_with_qname(element, env, qpolicy, node); + axutil_qname_free(qpolicy, env); + qpolicy = NULL; + } + + if(itr) + { + axis2_process_policy_reference_elements(env, AXIS2_POLICY_REF, itr, policy_include); + } + } + } +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_svc_builder_process_svc_module_conf( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_confs, + axutil_param_container_t * parent, + axis2_svc_t * svc) +{ + while(axiom_children_qname_iterator_has_next(module_confs, env)) + { + axiom_element_t *module_conf_element = NULL; + axiom_node_t *module_conf_node = NULL; + axiom_attribute_t *module_name_att = NULL; + axutil_qname_t *qattname = NULL; + + module_conf_node = axiom_children_qname_iterator_next(module_confs, env); + module_conf_element = axiom_node_get_data_element(module_conf_node, env); + qattname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + module_name_att = axiom_element_get_attribute(module_conf_element, env, qattname); + axutil_qname_free(qattname, env); + qattname = NULL; + if(!module_name_att) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_MODULE_CONF, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Module name attribute not found for module node"); + return AXIS2_FAILURE; + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_svc_builder_process_module_refs( + axis2_svc_builder_t * svc_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_refs) +{ + AXIS2_PARAM_CHECK(env->error, module_refs, AXIS2_FAILURE); + + while(axiom_children_qname_iterator_has_next(module_refs, env)) + { + axiom_element_t *module_ref_element = NULL; + axiom_node_t *module_ref_node = NULL; + axiom_attribute_t *module_ref_att = NULL; + axutil_qname_t *qref = NULL; + + module_ref_node = axiom_children_qname_iterator_next(module_refs, env); + module_ref_element = axiom_node_get_data_element(module_ref_node, env); + qref = axutil_qname_create(env, AXIS2_REF, NULL, NULL); + module_ref_att = axiom_element_get_attribute(module_ref_element, env, qref); + axutil_qname_free(qref, env); + if(module_ref_att) + { + axis2_char_t *ref_name = NULL; + axutil_qname_t *qrefname = NULL; + + ref_name = axiom_attribute_get_value(module_ref_att, env); + qrefname = axutil_qname_create(env, ref_name, NULL, NULL); + if(!axis2_dep_engine_get_module(axis2_desc_builder_get_dep_engine( + svc_builder->desc_builder, env), env, qrefname)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MODULE_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unable to find " + "Module %s, in Service %s", ref_name, axis2_svc_get_name(svc_builder->svc, env)); + return AXIS2_FAILURE; + } + else + { + axis2_svc_add_module_qname(svc_builder->svc, env, qrefname); + } + axutil_qname_free(qrefname, env); + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN struct axis2_desc_builder *AXIS2_CALL +axis2_svc_builder_get_desc_builder( + const axis2_svc_builder_t * svc_builder, + const axutil_env_t * env) +{ + return svc_builder->desc_builder; +} + diff --git a/src/core/deployment/svc_grp_builder.c b/src/core/deployment/svc_grp_builder.c new file mode 100644 index 0000000..6aa07ad --- /dev/null +++ b/src/core/deployment/svc_grp_builder.c @@ -0,0 +1,264 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_svc_grp_builder.h> + +struct axis2_svc_grp_builder +{ + axiom_node_t *svc_grp; + axis2_desc_builder_t *desc_builder; +}; + +AXIS2_EXTERN axis2_svc_grp_builder_t *AXIS2_CALL +axis2_svc_grp_builder_create( + const axutil_env_t * env) +{ + axis2_svc_grp_builder_t *svc_grp_builder = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + svc_grp_builder = (axis2_svc_grp_builder_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_svc_grp_builder_t)); + + if(!svc_grp_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + svc_grp_builder->svc_grp = NULL; + svc_grp_builder->desc_builder = NULL; + + return svc_grp_builder; +} + +AXIS2_EXTERN axis2_svc_grp_builder_t *AXIS2_CALL +axis2_svc_grp_builder_create_with_svc_and_dep_engine( + const axutil_env_t * env, + axiom_node_t * svc_grp, + axis2_dep_engine_t * dep_engine) +{ + axis2_svc_grp_builder_t *svc_grp_builder = NULL; + + svc_grp_builder = (axis2_svc_grp_builder_t *)axis2_svc_grp_builder_create(env); + if(!svc_grp_builder) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + svc_grp_builder = NULL; + } + svc_grp_builder->desc_builder = axis2_desc_builder_create_with_dep_engine(env, dep_engine); + if(!svc_grp_builder->desc_builder) + { + axis2_svc_grp_builder_free(svc_grp_builder, env); + return NULL; + } + svc_grp_builder->svc_grp = svc_grp; + + return svc_grp_builder; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_svc_grp_builder_free( + axis2_svc_grp_builder_t * svc_grp_builder, + const axutil_env_t * env) +{ + if(svc_grp_builder->desc_builder) + { + axis2_desc_builder_free(svc_grp_builder->desc_builder, env); + } + if(svc_grp_builder) + { + AXIS2_FREE(env->allocator, svc_grp_builder); + } + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_svc_grp_builder_populate_svc_grp( + axis2_svc_grp_builder_t * svc_grp_builder, + const axutil_env_t * env, + axis2_svc_grp_t * svc_grp) +{ + axiom_children_qname_iterator_t *itr = NULL; + axiom_children_qname_iterator_t *module_ref_itr = NULL; + axiom_children_qname_iterator_t *svc_itr = NULL; + axutil_qname_t *qparamst = NULL; + axutil_qname_t *qmodulest = NULL; + axutil_qname_t *qsvc_element = NULL; + axiom_element_t *svc_grp_element = NULL; + axis2_status_t status = AXIS2_FAILURE; + axis2_conf_t *parent = NULL; + + /* Processing service level paramters */ + svc_grp_element = axiom_node_get_data_element(svc_grp_builder->svc_grp, env); + qparamst = axutil_qname_create(env, AXIS2_PARAMETERST, NULL, NULL); + + itr = axiom_element_get_children_with_qname(svc_grp_element, env, qparamst, + svc_grp_builder->svc_grp); + + if(qparamst) + { + axutil_qname_free(qparamst, env); + qparamst = NULL; + } + + parent = axis2_svc_grp_get_parent(svc_grp, env); + status = axis2_desc_builder_process_params(svc_grp_builder->desc_builder, env, itr, + axis2_svc_grp_get_param_container(svc_grp, env), + axis2_conf_get_param_container(parent, env)); + + /* Processing service modules required to be engaged globally */ + qmodulest = axutil_qname_create(env, AXIS2_MODULEST, NULL, NULL); + module_ref_itr = axiom_element_get_children_with_qname(svc_grp_element, env, qmodulest, + svc_grp_builder-> svc_grp); + + if(qmodulest) + { + axutil_qname_free(qmodulest, env); + qmodulest = NULL; + } + + axis2_svc_grp_builder_process_module_refs(svc_grp_builder, env, module_ref_itr, svc_grp); + qsvc_element = axutil_qname_create(env, AXIS2_SVC_ELEMENT, NULL, NULL); + svc_itr = axiom_element_get_children_with_qname(svc_grp_element, env, qsvc_element, + svc_grp_builder->svc_grp); + + if(qsvc_element) + { + axutil_qname_free(qsvc_element, env); + qsvc_element = NULL; + } + + while(axiom_children_qname_iterator_has_next(svc_itr, env)) + { + axiom_node_t *svc_node = NULL; + axiom_element_t *svc_element = NULL; + axiom_attribute_t *svc_name_att = NULL; + axis2_char_t *svc_name = NULL; + axutil_qname_t *qattname = NULL; + + svc_node = (axiom_node_t *)axiom_children_qname_iterator_next(svc_itr, env); + svc_element = axiom_node_get_data_element(svc_node, env); + qattname = axutil_qname_create(env, AXIS2_ATTNAME, NULL, NULL); + svc_name_att = axiom_element_get_attribute(svc_element, env, qattname); + + if(qattname) + { + axutil_qname_free(qattname, env); + qattname = NULL; + } + + svc_name = axiom_attribute_get_value(svc_name_att, env); + if(!svc_name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_NAME_ERROR, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service name attribute has no value"); + return AXIS2_FAILURE; + } + else + { + axis2_svc_t *axis_svc = NULL; + axis2_arch_file_data_t *file_data = NULL; + axutil_array_list_t *deployable_svcs = NULL; + axis2_svc_builder_t *svc_builder = NULL; + + file_data = axis2_dep_engine_get_current_file_item(axis2_desc_builder_get_dep_engine( + svc_grp_builder->desc_builder, env), env); + axis_svc = axis2_arch_file_data_get_svc(file_data, env, svc_name); + if(!axis_svc) + { + axutil_qname_t *qsvc_name = NULL; + + qsvc_name = axutil_qname_create(env, svc_name, NULL, NULL); + axis_svc = axis2_svc_create_with_qname(env, qsvc_name); + axutil_qname_free(qsvc_name, env); + axis2_arch_file_data_add_svc(file_data, env, axis_svc); + + } + /* Adding service to the deployable services list */ + deployable_svcs = axis2_arch_file_data_get_deployable_svcs(file_data, env); + axutil_array_list_add(deployable_svcs, env, axis_svc); + axis2_svc_set_parent(axis_svc, env, svc_grp); + svc_builder = axis2_svc_builder_create_with_dep_engine_and_svc(env, + axis2_desc_builder_get_dep_engine(svc_grp_builder-> desc_builder, env), axis_svc); + status = axis2_svc_builder_populate_svc(svc_builder, env, svc_node); + axis2_svc_builder_free(svc_builder, env); + + } + } + return status; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_svc_grp_builder_process_module_refs( + axis2_svc_grp_builder_t * svc_grp_builder, + const axutil_env_t * env, + axiom_children_qname_iterator_t * module_refs, + axis2_svc_grp_t * svc_grp) +{ + AXIS2_PARAM_CHECK(env->error, module_refs, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, svc_grp, AXIS2_FAILURE); + + while(axiom_children_qname_iterator_has_next(module_refs, env)) + { + axiom_node_t *module_ref_node = NULL; + axiom_element_t *module_ref_element = NULL; + axiom_attribute_t *module_ref_att = NULL; + axutil_qname_t *qref = NULL; + + module_ref_node = (axiom_node_t *)axiom_children_qname_iterator_next(module_refs, env); + module_ref_element = axiom_node_get_data_element(module_ref_node, env); + qref = axutil_qname_create(env, AXIS2_REF, NULL, NULL); + module_ref_att = axiom_element_get_attribute(module_ref_element, env, qref); + if(module_ref_att) + { + axis2_char_t *ref_name = NULL; + axutil_qname_t *qrefname = NULL; + axis2_module_desc_t *module = NULL; + + ref_name = axiom_attribute_get_value(module_ref_att, env); + qrefname = axutil_qname_create(env, ref_name, NULL, NULL); + module = axis2_dep_engine_get_module(axis2_desc_builder_get_dep_engine( + svc_grp_builder->desc_builder, env), env, qrefname); + if(!module) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_MODULE_NOT_FOUND, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Module %s not found in deployment engine.", ref_name); + return AXIS2_FAILURE; + } + else + { + axis2_svc_grp_add_module_ref(svc_grp, env, qrefname); + } + axutil_qname_free(qrefname, env); + } + axutil_qname_free(qref, env); + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_desc_builder_t *AXIS2_CALL +axis2_svc_grp_builder_get_desc_builder( + const axis2_svc_grp_builder_t * svc_grp_builder, + const axutil_env_t * env) +{ + return svc_grp_builder->desc_builder; +} + diff --git a/src/core/deployment/ws_info.c b/src/core/deployment/ws_info.c new file mode 100644 index 0000000..0f2fa37 --- /dev/null +++ b/src/core/deployment/ws_info.c @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "axis2_ws_info.h" +#include <string.h> + +struct axis2_ws_info +{ + axis2_char_t *file_name; + long last_modified_date; + + /** + * To check whether the file is a module or a servise + */ + int type; +}; + +AXIS2_EXTERN axis2_ws_info_t *AXIS2_CALL +axis2_ws_info_create_with_file_name_and_last_modified_date( + const axutil_env_t * env, + axis2_char_t * file_name, + long last_modified_date) +{ + axis2_ws_info_t *ws_info = NULL; + + AXIS2_PARAM_CHECK(env->error, file_name, NULL); + + ws_info = (axis2_ws_info_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_ws_info_t)); + + if(!ws_info) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + ws_info->file_name = NULL; + ws_info->last_modified_date = 0; + ws_info->type = 0; + + ws_info->file_name = axutil_strdup(env, file_name); + if(!ws_info->file_name) + { + axis2_ws_info_free(ws_info, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + ws_info->last_modified_date = last_modified_date; + + return ws_info; +} + +AXIS2_EXTERN axis2_ws_info_t *AXIS2_CALL +axis2_ws_info_create_with_file_name_and_last_modified_date_and_type( + const axutil_env_t * env, + axis2_char_t * file_name, + long last_modified_date, + int type) +{ + axis2_ws_info_t *ws_info = NULL; + + AXIS2_PARAM_CHECK(env->error, file_name, NULL); + + ws_info = (axis2_ws_info_t *)axis2_ws_info_create_with_file_name_and_last_modified_date(env, + file_name, last_modified_date); + if(!ws_info) + { + axis2_ws_info_free(ws_info, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + ws_info->type = type; + return ws_info; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_ws_info_free( + axis2_ws_info_t * ws_info, + const axutil_env_t * env) +{ + if(ws_info->file_name) + { + AXIS2_FREE(env->allocator, ws_info->file_name); + } + + if(ws_info) + { + AXIS2_FREE(env->allocator, ws_info); + } + + return; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axis2_ws_info_get_file_name( + const axis2_ws_info_t * ws_info, + const axutil_env_t * env) +{ + return ws_info->file_name; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_ws_info_set_file_name( + axis2_ws_info_t * ws_info, + const axutil_env_t * env, + axis2_char_t * file_name) +{ + AXIS2_PARAM_CHECK(env->error, file_name, AXIS2_FAILURE); + + if(ws_info->file_name) + { + AXIS2_FREE(env->allocator, ws_info->file_name); + ws_info->file_name = NULL; + } + ws_info->file_name = file_name; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN long AXIS2_CALL +axis2_ws_info_get_last_modified_date( + const axis2_ws_info_t * ws_info, + const axutil_env_t * env) +{ + return ws_info->last_modified_date; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_ws_info_set_last_modified_date( + axis2_ws_info_t * ws_info, + const axutil_env_t * env, + long last_modified_date) +{ + ws_info->last_modified_date = last_modified_date; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_ws_info_get_type( + const axis2_ws_info_t * ws_info, + const axutil_env_t * env) +{ + return ws_info->type; +} + diff --git a/src/core/deployment/ws_info_list.c b/src/core/deployment/ws_info_list.c new file mode 100644 index 0000000..41a85c7 --- /dev/null +++ b/src/core/deployment/ws_info_list.c @@ -0,0 +1,370 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <axis2_ws_info_list.h> +#include <string.h> +#include <axutil_class_loader.h> + +struct axis2_ws_info_list +{ + /** + * This is to store all the deployment info about the deployment files + * for services or modules in a specified folder. + */ + axutil_array_list_t *ws_info_list; + + /** + * All the curently updated deployment info list. + */ + axutil_array_list_t *current_info_list; + + /** + * Referance to deployment engine to make update. + */ + struct axis2_dep_engine *dep_engine; + +}; + +AXIS2_EXTERN axis2_ws_info_list_t *AXIS2_CALL +axis2_ws_info_list_create_with_dep_engine( + const axutil_env_t * env, + struct axis2_dep_engine *dep_engine) +{ + axis2_ws_info_list_t *ws_info_list = NULL; + + ws_info_list = (axis2_ws_info_list_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_ws_info_list_t)); + + if(!ws_info_list) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + memset((void *)ws_info_list, 0, sizeof(axis2_ws_info_list_t)); + + ws_info_list->dep_engine = dep_engine; + + ws_info_list->ws_info_list = axutil_array_list_create(env, 0); + if(!(ws_info_list->ws_info_list)) + { + axis2_ws_info_list_free(ws_info_list, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + ws_info_list->current_info_list = axutil_array_list_create(env, 0); + if(!(ws_info_list->current_info_list)) + { + axis2_ws_info_list_free(ws_info_list, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + return ws_info_list; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_ws_info_list_free( + axis2_ws_info_list_t * ws_info_list, + const axutil_env_t * env) +{ + if(ws_info_list->current_info_list) + { + int list_size = 0; + int i = 0; + + list_size = axutil_array_list_size(ws_info_list->current_info_list, env); + for(i = 0; i < list_size; i++) + { + axis2_char_t *file_name = NULL; + + file_name = (axis2_char_t *)axutil_array_list_get(ws_info_list->current_info_list, env, + i); + AXIS2_FREE(env->allocator, file_name); + } + axutil_array_list_free(ws_info_list->current_info_list, env); + } + + if(ws_info_list->ws_info_list) + { + int list_size = 0; + int i = 0; + + list_size = axutil_array_list_size(ws_info_list->ws_info_list, env); + for(i = 0; i < list_size; i++) + { + axis2_ws_info_t *ws_info = NULL; + + ws_info = (axis2_ws_info_t *)axutil_array_list_get(ws_info_list-> ws_info_list, env, i); + axis2_ws_info_free(ws_info, env); + } + axutil_array_list_free(ws_info_list->ws_info_list, env); + } + + if(ws_info_list) + { + AXIS2_FREE(env->allocator, ws_info_list); + } + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_ws_info_list_init( + axis2_ws_info_list_t * ws_info_list, + const axutil_env_t * env) +{ + int size = 0; + int i = 0; + + size = axutil_array_list_size(ws_info_list->ws_info_list, env); + for(i = 0; i < size; i++) + { + axis2_ws_info_t *ws_info = NULL; + + ws_info = (axis2_ws_info_t *)axutil_array_list_get(ws_info_list->ws_info_list, env, i); + axis2_ws_info_free(ws_info, env); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_ws_info_list_add_ws_info_item( + axis2_ws_info_list_t * ws_info_list, + const axutil_env_t * env, + axutil_file_t * file, + int type) +{ + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t *file_name = NULL; + axis2_char_t *temp_name = NULL; + + AXIS2_PARAM_CHECK(env->error, file, AXIS2_FAILURE); + + temp_name = axutil_file_get_name(file, env); + file_name = axutil_strdup(env, temp_name); + if(!file_name) + { + return AXIS2_FAILURE; + } + + switch(type) + { + case AXIS2_SVC: + { + axis2_ws_info_t *ws_info = NULL; + long last_modified_date = 0; + axis2_arch_file_data_t *file_data = NULL; + + last_modified_date = (long)axutil_file_get_timestamp(file, env); + /* We are sure that the difference lies within the long range */ + ws_info = axis2_ws_info_create_with_file_name_and_last_modified_date_and_type(env, + file_name, last_modified_date, AXIS2_SVC); + status = axutil_array_list_add(ws_info_list->ws_info_list, env, ws_info); + + if(AXIS2_SUCCESS != status) + { + return status; + } + file_data = axis2_arch_file_data_create_with_type_and_file(env, AXIS2_SVC, file); + /* To inform that new web service is to be deployed */ + status = axis2_dep_engine_add_ws_to_deploy(ws_info_list->dep_engine, env, file_data); + if(AXIS2_SUCCESS != status) + { + return status; + } + break; + } + case AXIS2_MODULE: + { + axis2_ws_info_t *ws_info = NULL; + long last_modified_date = 0; + axis2_arch_file_data_t *file_data = NULL; + + last_modified_date = (long)axutil_file_get_timestamp(file, env); + /* We are sure that the difference lies within the long range */ + ws_info = axis2_ws_info_create_with_file_name_and_last_modified_date_and_type(env, + file_name, last_modified_date, AXIS2_MODULE); + status = axutil_array_list_add(ws_info_list->ws_info_list, env, ws_info); + + if(AXIS2_SUCCESS != status) + { + return status; + } + file_data = axis2_arch_file_data_create_with_type_and_file(env, AXIS2_MODULE, file); + /* To inform that new module is to be deployed */ + status = axis2_dep_engine_add_ws_to_deploy(ws_info_list->dep_engine, env, file_data); + if(AXIS2_SUCCESS != status) + { + return status; + } + + break; + } + } + return axutil_array_list_add(ws_info_list->current_info_list, env, file_name); +} + +AXIS2_EXTERN axis2_ws_info_t *AXIS2_CALL +axis2_ws_info_list_get_file_item( + axis2_ws_info_list_t * ws_info_list, + const axutil_env_t * env, + axis2_char_t * file_name) +{ + int i = 0; + int size = 0; + AXIS2_PARAM_CHECK(env->error, file_name, NULL); + + size = axutil_array_list_size(ws_info_list->ws_info_list, env); + for(i = 0; i < size; i++) + { + axis2_ws_info_t *ws_info = NULL; + axis2_char_t *file_name_l = NULL; + + ws_info = (axis2_ws_info_t *)axutil_array_list_get(ws_info_list-> ws_info_list, env, i); + + file_name_l = axis2_ws_info_get_file_name(ws_info, env); + if(!axutil_strcmp(file_name_l, file_name)) + { + return ws_info; + } + } + return NULL; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_ws_info_list_is_modified( + axis2_ws_info_list_t * ws_info_list, + const axutil_env_t * env, + axutil_file_t * file, + axis2_ws_info_t * ws_info) +{ + long last_modified_date = 0; + + AXIS2_PARAM_CHECK(env->error, file, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, ws_info, AXIS2_FAILURE); + + last_modified_date = axis2_ws_info_get_last_modified_date(ws_info, env); + return (last_modified_date != axutil_file_get_timestamp(file, env)); +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_ws_info_list_is_file_exist( + axis2_ws_info_list_t * ws_info_list, + const axutil_env_t * env, + axis2_char_t * file_name) +{ + axis2_ws_info_t *ws_info = NULL; + + AXIS2_PARAM_CHECK(env->error, file_name, AXIS2_FAILURE); + ws_info = axis2_ws_info_list_get_file_item(ws_info_list, env, file_name); + return !(ws_info == NULL); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_ws_info_list_check_for_undeploy( + axis2_ws_info_list_t * ws_info_list, + const axutil_env_t * env) +{ + int list_size = 0; + axutil_array_list_t *temp_list = NULL; + int i = 0; + + /* Create temp list */ + temp_list = axutil_array_list_create(env, 0); + if(!temp_list) + { + return AXIS2_FAILURE; + } + list_size = axutil_array_list_size(ws_info_list->ws_info_list, env); + + for(i = 0; i < list_size; i++) + { + /* For each ws_info item in the ws_info_list check whether it is also + * in the current_info_list. If not mark it to be undeployed by adding + * it to a temporarily list. Also add that item to the undeploy list of + * deployment engine.*/ + int current_lists_size = 0; + axis2_ws_info_t *file_item = NULL; + axis2_char_t *file_item_name = NULL; + axis2_bool_t exist = AXIS2_FALSE; + int j = 0; + + file_item = (axis2_ws_info_t *)axutil_array_list_get(ws_info_list-> ws_info_list, env, i); + + file_item_name = axis2_ws_info_get_file_name(file_item, env); + current_lists_size = axutil_array_list_size(ws_info_list->current_info_list, env); + for(j = 0; j < current_lists_size; j++) + { + axis2_char_t *file_name = NULL; + file_name = (axis2_char_t *)axutil_array_list_get(ws_info_list-> current_info_list, + env, j); + if(!axutil_strcmp(file_name, file_item_name)) + { + exist = AXIS2_TRUE; + break; + } + } + + if(!exist) + { + axis2_ws_info_t *ws_info = NULL; + long last_modified_date = 0; + + last_modified_date = axis2_ws_info_get_last_modified_date(file_item, env); + axutil_array_list_add(temp_list, env, file_item); + ws_info = axis2_ws_info_create_with_file_name_and_last_modified_date(env, + file_item_name, last_modified_date); + /* This ws_info is to be undeployed */ + axis2_dep_engine_add_ws_to_undeploy(ws_info_list->dep_engine, env, ws_info); + } + + } + + list_size = axutil_array_list_size(temp_list, env); + for(i = 0; i < list_size; i++) + { + /* Get each ws_info item from the temp list created and remove that + * item from the ws_info_list */ + axis2_ws_info_t *file_item = NULL; + int index = 0; + + file_item = (axis2_ws_info_t *)axutil_array_list_get(temp_list, env, i); + index = axutil_array_list_index_of(ws_info_list->ws_info_list, env, file_item); + axutil_array_list_remove(ws_info_list->ws_info_list, env, index); + } + axutil_array_list_free(temp_list, env); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_ws_info_list_update( + axis2_ws_info_list_t * ws_info_list, + const axutil_env_t * env) +{ + axis2_status_t status = AXIS2_FAILURE; + + status = axis2_ws_info_list_check_for_undeploy(ws_info_list, env); + if(AXIS2_SUCCESS != status) + { + return AXIS2_FAILURE; + } + + return axis2_dep_engine_do_deploy(ws_info_list->dep_engine, env); +} + |