AXIS2_EXTERN char* AXIS2_CALL remote_registry_resource_get_content( remote_registry_resource_t *resource, const axutil_env_t *env) { if(!resource->is_collection && !resource->is_content_loaded) { /* we have to load the content for the first time */ axis2_char_t *buffer = NULL; axis2_status_t status; int buffer_len = 0; if(!resource->content_src_url) { return resource->content; } if(!resource->rest_client) { return resource->content; } buffer = remote_registry_rest_client_get(resource->rest_client, env, resource->content_src_url, NULL, 0, &buffer_len); status = remote_registry_rest_client_get_last_response_status(resource->rest_client, env); if(status == AXIS2_SUCCESS) { remote_registry_resource_set_is_content_loaded(resource, env, 1); remote_registry_resource_set_content(resource, env, buffer); remote_registry_resource_set_content_len(resource, env, buffer_len); } } return resource->content; }
int add_subscriber() { remote_registry_t *remote_registry = NULL; const axutil_env_t *env = NULL; axis2_char_t *subscription_id = NULL; axis2_char_t *id = NULL; axis2_char_t *path = NULL; axis2_char_t *index_path = NULL; remote_registry_resource_t *res = NULL; axutil_hash_t *properties = NULL; char *content = (char *) strdup("<subscription><syn:endpoint xmlns:syn=\"http://ws.apache.org/ns/synapse\"><syn:address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" /></syn:endpoint></subscription>"); axis2_char_t *epr_type = "application/vnd.epr"; axis2_char_t *filter = "/weather/4/"; axis2_char_t *reg_url = "http://localhost:9762/registry"; env = axutil_env_create_all("test.log", AXIS2_LOG_LEVEL_TRACE); subscription_id = axutil_strcat(env, "urn:uuid:", axutil_uuid_gen(env), NULL); path = axutil_strcat(env, filter, SUBSCRIPTION_COLLECTION_NAME, "/", subscription_id, NULL); id = axutil_strcat(env, reg_url, filter, SUBSCRIPTION_COLLECTION_NAME, "/", subscription_id, NULL); remote_registry = remote_registry_create(env, reg_url, "admin", "admin"); topic_index_init(); res = remote_registry_resource_create(env); remote_registry_resource_set_content(res, env, content); remote_registry_resource_set_content_len(res, env, axutil_strlen(content)); remote_registry_resource_set_media_type(res, env, epr_type); remote_registry_resource_set_description(res, env, ""); properties = axutil_hash_make(env); if(properties) { axutil_hash_set(properties, axutil_strdup(env, "expires"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, "*")); axutil_hash_set(properties, axutil_strdup(env, "staticFlag"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, "false")); axutil_hash_set(properties, axutil_strdup(env, "filterValue"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, filter)); axutil_hash_set(properties, axutil_strdup(env, "subManagerURI"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, "http://10.100.1.44:8280/services/SampleEventSource")); axutil_hash_set(properties, axutil_strdup(env, "filterDialect"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, "http://synapse.apache.org/eventing/dialect/topicFilter")); remote_registry_resource_set_properties(res, env, properties); } remote_registry_put(remote_registry, env, path, res); if(id) { AXIS2_FREE(env->allocator, id); } if(path) { AXIS2_FREE(env->allocator, path); path = NULL; } if(res) { remote_registry_resource_free(res, env); res = NULL; } res = remote_registry_get(remote_registry, env, TOPIC_INDEX, NULL); if(!res) { return 0; } id = axutil_strcat(env, reg_url, TOPIC_INDEX, NULL); properties = remote_registry_resource_get_properties(res, env); if(properties) { path = axutil_strcat(env, filter, SUBSCRIPTION_COLLECTION_NAME, NULL); axutil_hash_set(properties, subscription_id, AXIS2_HASH_KEY_STRING, path); remote_registry_resource_set_properties(res, env, properties); } remote_registry_resource_set_content(res, env, NULL); remote_registry_resource_set_content_len(res, env, 0); index_path = axutil_strcat(env, TOPIC_INDEX, "/TopicIndex", NULL); remote_registry_put(remote_registry, env, TOPIC_INDEX, res); if(id) { AXIS2_FREE(env->allocator, id); } if(res) { remote_registry_resource_free(res, env); res = NULL; } printf("\n"); return 0; }