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; }
bool Axis2QpidReceiver::start( void) { if(!conf_ctx) return false; Connection connection; axis2_bool_t serverSide = AXIS2_TRUE; serverSide = axis2_amqp_util_conf_ctx_get_server_side(conf_ctx, env); while(true) { try { std::list<string> queueNameList; string qpidBrokerIP = axis2_amqp_util_conf_ctx_get_qpid_broker_ip(conf_ctx, env); int qpidBrokerPort = axis2_amqp_util_conf_ctx_get_qpid_broker_port(conf_ctx, env); /* Check if Client Side and Resolve Dynamic Queue Name */ if(serverSide == AXIS2_TRUE) /* Server side */ { std::cout << "Connecting to Qpid Broker on " << qpidBrokerIP << ":" << qpidBrokerPort << " ... "; } /* Create Connection to Qpid Broker */ connection.open(qpidBrokerIP, qpidBrokerPort); if(serverSide == AXIS2_TRUE) /* Server side */ { /* Create queue for each service. Queue name is equal to service name */ axis2_conf_t* conf = axis2_conf_ctx_get_conf(conf_ctx, env); if(!conf) return false; axutil_hash_t* serviceMap = axis2_conf_get_all_svcs(conf, env); if(!serviceMap) return false; axutil_hash_index_t* serviceHI = NULL; void* serviceValue = NULL; for(serviceHI = axutil_hash_first(serviceMap, env); serviceHI; serviceHI = axutil_hash_next(env, serviceHI)) { axutil_hash_this(serviceHI, NULL, NULL, &serviceValue); axis2_svc_t* service = (axis2_svc_t*)serviceValue; if(!service) return false; axis2_char_t* serviceName = axutil_qname_get_localpart(axis2_svc_get_qname( service, env), env); if(!serviceName) return false; queueNameList.push_back(serviceName); } std::cout << "CONNECTED" << std::endl; } else /* Client side separate listener in dual-channel case */ { string queueName = axis2_amqp_util_conf_ctx_get_dual_channel_queue_name(conf_ctx, env); queueNameList.push_back(queueName); } /* Create new session */ Session session = connection.newSession(); /* Create Subscription manager */ SubscriptionManager subscriptionManager(session); Axis2QpidReceiverListener qpidReceiverListener(env, conf_ctx); /* Subscribe to queues */ while(!queueNameList.empty()) { string queueName = queueNameList.front(); session.queueDeclare(arg::queue = queueName, arg::autoDelete = true); session.exchangeBind(arg::exchange = AXIS2_AMQP_EXCHANGE_DIRECT, arg::queue = queueName, arg::bindingKey = queueName); subscriptionManager.subscribe(qpidReceiverListener, queueName); queueNameList.pop_front(); } /* Listen and Wait */ if(serverSide == AXIS2_TRUE) /* Server side */ { std::cout << "Started Axis2 AMQP Server ..." << std::endl; } subscriptionManager.run(); return true; } catch(const std::exception& e) { connection.close(); if(serverSide == AXIS2_TRUE) /* Server side */ { std::cout << "FAILED" << std::endl; } sleep(5); } } connection.close(); return false; }
AXIS2_EXTERN axis2_svc_grp_ctx_t *AXIS2_CALL axis2_conf_ctx_fill_ctxs( axis2_conf_ctx_t * conf_ctx, const axutil_env_t * env, axis2_msg_ctx_t * msg_ctx) { axis2_char_t *svc_grp_ctx_id = NULL; axis2_svc_grp_ctx_t *svc_grp_ctx = NULL; axis2_svc_ctx_t *svc_ctx = NULL; axis2_svc_t *svc = NULL; axis2_svc_grp_t *svc_grp = NULL; const axutil_qname_t *qname = NULL; axis2_char_t *svc_id = NULL; axis2_op_ctx_t *op_ctx = NULL; AXIS2_PARAM_CHECK(env->error, msg_ctx, NULL); svc = axis2_msg_ctx_get_svc(msg_ctx, env); if(!svc) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SERVICE_NOT_YET_FOUND, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service not yet found in message context. Cannot proceed"); return NULL; } qname = axis2_svc_get_qname(svc, env); if(!qname) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_SVC, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service found in message context has no name."); return NULL; } svc_id = axutil_qname_get_localpart(qname, env); if(!svc_id) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_SVC, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service found in message context has no name."); return NULL; } svc_grp = axis2_svc_get_parent(svc, env); if(svc_grp) { svc_grp_ctx_id = (axis2_char_t *)axis2_svc_grp_get_name(svc_grp, env); } if(!svc_grp_ctx_id) { svc_grp_ctx_id = (axis2_char_t *)axutil_string_get_buffer(axis2_msg_ctx_get_svc_grp_ctx_id( msg_ctx, env), env); } /* By this time service group context id must have a value, either from transport or from * addressing */ if(svc_grp_ctx_id) { svc_grp_ctx = (axis2_svc_grp_ctx_t *)axutil_hash_get(conf_ctx->svc_grp_ctx_map, svc_grp_ctx_id, AXIS2_HASH_KEY_STRING); if(svc_grp_ctx) { svc_ctx = axis2_svc_grp_ctx_get_svc_ctx(svc_grp_ctx, env, svc_id); if(!svc_ctx) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_SVC_GRP, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service group context has no servie context set for service %s", svc_id); return NULL; } } } if(!svc_grp_ctx_id) { svc_grp_ctx_id = axutil_uuid_gen(env); if(svc_grp_ctx_id) { axutil_string_t *svc_grp_ctx_id_str = axutil_string_create_assume_ownership(env, &svc_grp_ctx_id); axis2_msg_ctx_set_svc_grp_ctx_id(msg_ctx, env, svc_grp_ctx_id_str); axutil_string_free(svc_grp_ctx_id_str, env); } } if(!svc_grp_ctx) { axis2_svc_grp_t *svc_group; svc_group = axis2_svc_get_parent(svc, env); svc_grp_ctx = axis2_svc_grp_get_svc_grp_ctx(svc_group, env, conf_ctx); svc_ctx = axis2_svc_grp_ctx_get_svc_ctx(svc_grp_ctx, env, svc_id); if(!svc_ctx) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_SVC_GRP, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Service group context has no servie context set for service %s", svc_id); return NULL; } axis2_svc_grp_ctx_set_id(svc_grp_ctx, env, svc_grp_ctx_id); axis2_conf_ctx_register_svc_grp_ctx(conf_ctx, env, svc_grp_ctx_id, svc_grp_ctx); } /* When you come here operation context MUST have already been assigned to the message context */ op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env); if(!op_ctx) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_MSG_CTX, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Operation context not set for message context"); return NULL; } axis2_op_ctx_set_parent(op_ctx, env, svc_ctx); axis2_msg_ctx_set_svc_ctx(msg_ctx, env, svc_ctx); axis2_msg_ctx_set_svc_grp_ctx(msg_ctx, env, svc_grp_ctx); return svc_grp_ctx; }