AXIS2_EXTERN axis2_svc_t *AXIS2_CALL axis2_svc_create_with_qname( const axutil_env_t * env, const axutil_qname_t * qname) { axis2_svc_t *svc = NULL; axis2_status_t status = AXIS2_FAILURE; AXIS2_PARAM_CHECK(env->error, qname, NULL); svc = axis2_svc_create(env); if(!svc) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service creation failed for name %s", axutil_qname_get_localpart(qname, env)); return NULL; } status = axis2_svc_set_qname(svc, env, qname); if(AXIS2_FAILURE == status) { axis2_svc_free(svc, env); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Setting name %s to service failed", axutil_qname_get_localpart(qname, env)); return NULL; } return svc; }
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; }
bool Axis2UtilsRemoveVirtualService(const std::string& sServiceName, const struct axutil_env* pEnv, struct axis2_conf* pConf, bool bIsShuttingDown) { axis2_svc* pService = axis2_conf_get_svc(pConf, pEnv, sServiceName.c_str()); if (!pService) { staff::LogError() << "axis2_conf_get_svc"; return false; } if (!bIsShuttingDown) { std::string sServiceGroupName = sServiceName.c_str(); sServiceGroupName += "SvcGroup"; // removing from conf axis2_svc_grp* pServiceGroup = axis2_conf_get_svc_grp(pConf, pEnv, sServiceGroupName.c_str()); if (!pServiceGroup) { staff::LogError() << "axis2_conf_get_svc_grp"; return false; } axutil_hash_t* pAllServiceGroups = axis2_conf_get_all_svc_grps(pConf, pEnv); if (!pAllServiceGroups) { staff::LogError() << "axis2_conf_get_all_svc_grps"; return false; } axutil_hash_set(pAllServiceGroups, sServiceGroupName.c_str(), AXIS2_HASH_KEY_STRING, NULL); axis2_svc_grp_free(pServiceGroup, pEnv); } // axis2_svc_grp_free does not destroy the services in group if (axis2_conf_remove_svc(pConf, pEnv, sServiceName.c_str()) != AXIS2_SUCCESS) { staff::LogError() << "axis2_conf_remove_svc"; return false; } axis2_svc_free(pService, pEnv); return true; }
bool Axis2UtilsCreateVirtualService(const staff::ServiceWrapper* pServiceWrapper, const struct axutil_env* pEnv, struct axis2_conf* pConf) { if (!pServiceWrapper) { staff::LogError() << "pService is NULL"; return false; } const std::string& sServiceName = pServiceWrapper->GetName(); std::string sServiceGroupName = sServiceName + "SvcGroup"; std::string sServiceUri = "http://staff.tempui.org:9090/axis2/services/"; sServiceUri += sServiceName.c_str(); std::string sWsdlPath = staff::Runtime::Inst().GetComponentHome(pServiceWrapper->GetComponent()->GetName()) + STAFF_PATH_SEPARATOR + pServiceWrapper->GetName() + ".wsdl"; axutil_qname_t* pQName = axutil_qname_create(pEnv, sServiceName.c_str(), sServiceUri.c_str(), NULL); if (!pQName) { staff::LogError() << "pQName"; return false; } axis2_svc_t* pAxis2Service = axis2_svc_create_with_qname(pEnv, pQName); if (!pAxis2Service) { axutil_qname_free(pQName, pEnv); staff::LogError() << "pAxis2Service"; return false; } axutil_qname_free(pQName, pEnv); // set "virtual" service flag static char szParamName[] = "IsStaffVirtualService"; // allocate data C-way, so axis2/c can free it int* pnParam = reinterpret_cast<int*>(AXIS2_MALLOC(pEnv->allocator, sizeof(int))); if (!pnParam) { axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "can't allocate param"; return false; } *pnParam = 1; axutil_param_t* pParam = axutil_param_create(pEnv, static_cast<axis2_char_t*>(szParamName), pnParam); if (!pParam) { axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "pParam"; return false; } if (axis2_svc_add_param(pAxis2Service, pEnv, pParam) != AXIS2_SUCCESS) { axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "pParam"; return false; } { // adding operations const staff::DataObject& rdoOperations = pServiceWrapper->GetOperations(); for (staff::DataObject tdoOperation = rdoOperations.FirstChild(); !tdoOperation.IsNull(); tdoOperation.SetNextSibling()) { const std::string& sOpName = tdoOperation.GetChildByLocalName("Name").GetText(); struct axis2_op* pOperation = axis2_op_create(pEnv); pQName = axutil_qname_create(pEnv, sOpName.c_str(), NULL, NULL); if (!pQName) { axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "pQName(op)"; return false; } if (axis2_op_set_qname(pOperation, pEnv, pQName) != AXIS2_SUCCESS) { axutil_qname_free(pQName, pEnv); axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "axis2_op_set_qname"; return false; } axutil_qname_free(pQName, pEnv); // add REST params if exists std::string sRestMethod; std::string sRestLocation; { const staff::DataObject& rdoOperationConst = tdoOperation; staff::DataObject::ConstIterator itRestTmp = rdoOperationConst.FindChildByLocalName("RestMethod"); if (itRestTmp != rdoOperationConst.End()) { sRestMethod = itRestTmp->GetText(); } itRestTmp = rdoOperationConst.FindChildByLocalName("RestLocation"); if (itRestTmp != rdoOperationConst.End()) { sRestLocation = itRestTmp->GetText(); } } if (!sRestLocation.empty() && !sRestMethod.empty()) { if (axis2_op_set_rest_http_method(pOperation, pEnv, sRestMethod.c_str()) != AXIS2_SUCCESS) { staff::LogError() << "Failed to set \"RESTMethod\" to service [" << sServiceName <<"] operation " << sOpName; } else { staff::LogDebug2() << "\"RESTMethod=" << sRestMethod << "\" param set to service [" << sServiceName <<"] operation " << sOpName; } if (axis2_op_set_rest_http_location(pOperation, pEnv, sRestLocation.c_str()) != AXIS2_SUCCESS) { staff::LogError() << "Failed to set \"RESTLocation\" to service [" << sServiceName <<"] operation " << sOpName; } else { staff::LogDebug2() << "\"RESTLocation=" << sRestLocation << "\" param set to service [" << sServiceName <<"] operation " << sOpName; } if (axis2_svc_add_rest_mapping(pAxis2Service, pEnv, sRestMethod.c_str(), sRestLocation.c_str(), pOperation) != AXIS2_SUCCESS) { staff::LogError() << "Failed to set REST mapping to service [" << sServiceName <<"] operation " << sOpName; } } // add service operation if (axis2_svc_add_op(pAxis2Service, pEnv, pOperation) != AXIS2_SUCCESS) { axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "axis2_svc_add_op"; return false; } } } std::string sServiceDescr = pServiceWrapper->GetDescr(); FILE* pFile = fopen(sWsdlPath.c_str(), "rb"); if (pFile) { fclose(pFile); sServiceDescr += " <sup>[<a style='font-size: x-small' href='/axis2/services/staff.wsdl.Wsdl/get/" + pServiceWrapper->GetComponent()->GetName() + "/" + pServiceWrapper->GetName() + ".wsdl'>wsdl</a>]</sup>"; if (axis2_svc_set_svc_wsdl_path(pAxis2Service, pEnv, sWsdlPath.c_str()) != AXIS2_SUCCESS) { staff::LogError() << "axis2_svc_set_svc_wsdl_path"; } } if (axis2_svc_set_svc_desc(pAxis2Service, pEnv, sServiceDescr.c_str()) != AXIS2_SUCCESS) { axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "axis2_svc_set_svc_desc"; return false; } // creating service group axis2_svc_grp_t* pServiceGroup = axis2_svc_grp_create_with_conf(pEnv, pConf); if (!pServiceGroup) { axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "axis2_svc_grp_create_with_conf"; return false; } if (axis2_svc_grp_set_name(pServiceGroup, pEnv, sServiceGroupName.c_str()) != AXIS2_SUCCESS) { axis2_svc_grp_free(pServiceGroup, pEnv); axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "axis2_svc_grp_set_name"; return false; } if (axis2_svc_grp_add_svc(pServiceGroup, pEnv, pAxis2Service) != AXIS2_SUCCESS) { axis2_svc_grp_free(pServiceGroup, pEnv); axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "axis2_svc_grp_add_svc"; return false; } // adding to configuration if (axis2_conf_add_svc_grp(pConf, pEnv, pServiceGroup) != AXIS2_SUCCESS) { axis2_svc_grp_free(pServiceGroup, pEnv); axis2_svc_free(pAxis2Service, pEnv); staff::LogError() << "axis2_conf_add_svc_grp"; return false; } return true; }
AXIS2_EXTERN axis2_svc_t *AXIS2_CALL axis2_svc_create( const axutil_env_t * env) { axis2_svc_t *svc = NULL; svc = (axis2_svc_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_svc_t)); if(!svc) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory"); return NULL; } svc->parent = NULL; svc->axis_svc_name = NULL; svc->filename = NULL; svc->svc_desc = NULL; svc->wsdl_path = NULL; svc->folder_path = NULL; svc->last_update = 0; svc->param_container = NULL; svc->flow_container = NULL; svc->op_alias_map = NULL; svc->op_action_map = NULL; svc->op_rest_map = NULL; svc->module_list = NULL; svc->ns_map = NULL; svc->ns_count = 0; svc->schema_list = NULL; svc->schema_mapping_table = NULL; svc->schema_loc_adjusted = AXIS2_FALSE; svc->custom_schema_name_prefix = NULL; svc->custom_schema_name_suffix = NULL; svc->schema_target_ns = NULL; svc->schema_target_ns_prefix = NULL; svc->target_ns = NULL; svc->target_ns_prefix = NULL; svc->sc_calc_count = 0; svc->impl_class = NULL; svc->qname = NULL; svc->style = NULL; svc->base = NULL; svc->param_container = axutil_param_container_create(env); if(!svc->param_container) { axis2_svc_free(svc, env); AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service param container creation failed"); return NULL; } svc->flow_container = axis2_flow_container_create(env); if(!svc->flow_container) { axis2_svc_free(svc, env); AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service flow container creation failed"); return NULL; } svc->op_alias_map = axutil_hash_make(env); if(!svc->op_alias_map) { axis2_svc_free(svc, env); AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service operation alias map creation failed"); return NULL; } svc->op_action_map = axutil_hash_make(env); if(!svc->op_action_map) { axis2_svc_free(svc, env); AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service operation action map creation failed"); return NULL; } svc->op_rest_map = axutil_hash_make(env); if(!svc->op_rest_map) { axis2_svc_free(svc, env); AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service operation rest map creation failed"); return NULL; } /** Create module list of default size */ svc->module_list = axutil_array_list_create(env, 0); if(!svc->module_list) { axis2_svc_free(svc, env); AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service module list creation failed"); return NULL; } svc->schema_list = axutil_array_list_create(env, AXIS2_ARRAY_LIST_DEFAULT_CAPACITY); if(!svc->schema_list) { axis2_svc_free(svc, env); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service schema list creation failed"); return NULL; } svc->engaged_module_list = axutil_array_list_create(env, AXIS2_ARRAY_LIST_DEFAULT_CAPACITY); if(!svc->engaged_module_list) { axis2_svc_free(svc, env); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service engaged modules list creation failed"); return NULL; } svc->schema_loc_adjusted = AXIS2_FALSE; if(svc->schema_target_ns_prefix) { AXIS2_FREE(env->allocator, svc->schema_target_ns_prefix); svc->schema_target_ns_prefix = NULL; } svc->schema_target_ns_prefix = axutil_strdup(env, "ns"); if(svc->target_ns) { AXIS2_FREE(env->allocator, svc->target_ns); svc->target_ns = NULL; } svc->target_ns = axutil_strdup(env, "http://ws.apache.org/axis2"); if(svc->target_ns_prefix) { AXIS2_FREE(env->allocator, svc->target_ns_prefix); svc->target_ns_prefix = NULL; } svc->target_ns_prefix = axutil_strdup(env, "tns"); svc->sc_calc_count = 0; svc->base = axis2_desc_create(env); if(!svc->base) { axis2_svc_free(svc, env); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service base creation failed"); return NULL; } svc->mutex = axutil_thread_mutex_create(env->allocator, AXIS2_THREAD_MUTEX_DEFAULT); if(!svc->mutex) { axis2_svc_free(svc, env); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service mutex creation failed"); return NULL; } return svc; }
AXIS2_EXTERN void AXIS2_CALL axis2_svc_client_free( axis2_svc_client_t * svc_client, const axutil_env_t * env) { if(!svc_client) { return; } if(svc_client->headers) { axis2_svc_client_remove_all_headers(svc_client, env); axutil_array_list_free(svc_client->headers, env); svc_client->headers = NULL; } if(svc_client->svc && !svc_client->keep_externally_passed_ctx_and_svc) { axis2_svc_free(svc_client->svc, env); } if(svc_client->callback_recv) { AXIS2_CALLBACK_RECV_FREE(svc_client->callback_recv, env); } if(svc_client->op_client) { axis2_op_client_free(svc_client->op_client, env); svc_client->op_client = NULL; } if(svc_client->options) { axis2_options_free(svc_client->options, env); } if(svc_client->listener_manager) { axis2_listener_manager_free(svc_client->listener_manager, env); } if(svc_client->conf_ctx && !svc_client->keep_externally_passed_ctx_and_svc) { axis2_conf_ctx_free(svc_client->conf_ctx, env); } if(svc_client->auth_type) { AXIS2_FREE(env->allocator, svc_client->auth_type); } if(svc_client->http_headers) { axis2_svc_client_set_http_info(svc_client, env, NULL); } AXIS2_FREE(env->allocator, svc_client); return; }