Author: damitha
Date: Wed Aug 15 02:17:47 2007
New Revision: 566073

URL: http://svn.apache.org/viewvc?view=rev&rev=566073
Log:
make svc_client reuse whenever possible

Modified:
    webservices/savan/trunk/c/include/savan_constants.h
    webservices/savan/trunk/c/include/savan_util.h
    webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h
    webservices/savan/trunk/c/src/subs_mgr/services.xml
    webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c
    webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c
    webservices/savan/trunk/c/src/util/savan_util.c

Modified: webservices/savan/trunk/c/include/savan_constants.h
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/include/savan_constants.h?view=diff&rev=566073&r1=566072&r2=566073
==============================================================================
--- webservices/savan/trunk/c/include/savan_constants.h (original)
+++ webservices/savan/trunk/c/include/savan_constants.h Wed Aug 15 02:17:47 2007
@@ -48,6 +48,7 @@
     axis2_char_t *name;
     axutil_hash_t *list;
     axis2_svc_t *svc;
+    axis2_conf_t *conf;
     axutil_env_t *env;
     void *svc_client;
 }savan_subs_mgr_info_t;

Modified: webservices/savan/trunk/c/include/savan_util.h
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/include/savan_util.h?view=diff&rev=566073&r1=566072&r2=566073
==============================================================================
--- webservices/savan/trunk/c/include/savan_util.h (original)
+++ webservices/savan/trunk/c/include/savan_util.h Wed Aug 15 02:17:47 2007
@@ -200,6 +200,22 @@
         const axutil_env_t *env,
         axis2_char_t *topic_url);
 
+    /**
+    * Get the topics registered in a subscription manager
+    * @param env pointer to environment struct
+    * @param subs_mgr_url url of the subscription manager
+    * @return subscribers in a array list
+    */
+    axutil_array_list_t *AXIS2_CALL
+    savan_util_get_topic_list_from_remote_subs_mgr(
+        const axutil_env_t *env,
+        axis2_char_t *subs_mgr_url,
+        void *s_client);
+
+    void *AXIS2_CALL
+    savan_util_get_svc_client(
+        const axutil_env_t *env);
+
 /** @} */
 #ifdef __cplusplus
 }

Modified: webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h?view=diff&rev=566073&r1=566072&r2=566073
==============================================================================
--- webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h (original)
+++ webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h Wed Aug 15 02:17:47 
2007
@@ -42,5 +42,11 @@
     axiom_node_t *node,
     axis2_msg_ctx_t *msg_ctx);
 
+AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+savan_subs_mgr_get_topic_list(
+    const axutil_env_t *env,
+    axiom_node_t *node,
+    axis2_msg_ctx_t *msg_ctx);
+
 #endif /* WSFES_SUBSCRIPTION_H*/
 

Modified: webservices/savan/trunk/c/src/subs_mgr/services.xml
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/subs_mgr/services.xml?view=diff&rev=566073&r1=566072&r2=566073
==============================================================================
--- webservices/savan/trunk/c/src/subs_mgr/services.xml (original)
+++ webservices/savan/trunk/c/src/subs_mgr/services.xml Wed Aug 15 02:17:47 2007
@@ -3,9 +3,7 @@
         This is a subscription manager service
    </description>
     <parameter name="ServiceClass" locked="xsd:false">subscription</parameter>
-    <parameter name="xmpp_id" locked="xsd:false">[EMAIL PROTECTED]</parameter>
-    <parameter name="xmpp_password" locked="xsd:false">123</parameter>
-    <!--parameter name="loadServiceAtStartup" 
locked="xsd:false">true</parameter-->
+    <parameter name="loadServiceAtStartup" locked="xsd:false">true</parameter>
 
    <operation name="add_subscriber">
            <!--messageReceiver class="axis2_receivers" /-->
@@ -26,11 +24,10 @@
    <operation name="get_topic_list">
            <!--messageReceiver class="axis2_receivers" /-->
            <parameter name="wsamapping" 
>http://ws.apache.org/axis2/c/subscription/get_topic_list</parameter>
-           <parameter name="heartbeat" 
locked="xsd:false">http://localhost:9090/axis2/services/ganglia_heartbeat</parameter>
-           <parameter name="discovery" 
locked="xsd:false">http://localhost:9090/axis2/services/ganglia_discovery</parameter>
-           <parameter name="power" 
locked="xsd:false">http://localhost:9090/axis2/services/ganglia_power</parameter>
-           <parameter name="load" 
locked="xsd:false">http://localhost:9090/axis2/services/ganglia_load</parameter>
-           <parameter name="syslog" 
locked="xsd:false">http://localhost:9090/axis2/services/syslog</parameter>
+           <parameter name="ganglia_heartbeat" 
locked="xsd:false">http://localhost:9090/axis2/services/ganglia_heartbeat</parameter>
+           <parameter name="ganglia_discovery" 
locked="xsd:false">http://localhost:9090/axis2/services/ganglia_discovery</parameter>
+           <parameter name="ganglia_power" 
locked="xsd:false">http://localhost:9090/axis2/services/ganglia_power</parameter>
+           <parameter name="ganglia_load" 
locked="xsd:false">http://localhost:9090/axis2/services/ganglia_load</parameter>
    </operation>
 
 </service>

Modified: webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c?view=diff&rev=566073&r1=566072&r2=566073
==============================================================================
--- webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c (original)
+++ webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c Wed Aug 15 02:17:47 2007
@@ -69,7 +69,7 @@
     axis2_char_t *filter = NULL;
 
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-        "[savan] Start:savan_subs_mgr_add_subscriber");
+        "[ML] Start:savan_subs_mgr_add_subscriber");
     subs_svc = axis2_msg_ctx_get_svc(msg_ctx, env);
     param = axis2_svc_get_param(subs_svc, env, SAVAN_TOPIC_LIST);
     if (!param)
@@ -82,13 +82,13 @@
     topic_store = (axutil_hash_t*)axutil_param_get_value(param, env);
     if(!topic_store)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to extract the 
"
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to extract the "
             "subscriber store"); 
         return NULL;
     }
     add_sub_elem = (axiom_element_t*)axiom_node_get_data_element(add_sub_node, 
env);
     
-    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[savan] node:%s", 
axiom_node_to_string(add_sub_node, env));
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[ML] node:%s", 
axiom_node_to_string(add_sub_node, env));
     /*Get topic element from node */
     qname = axutil_qname_create(env, ELEM_NAME_TOPIC, SAVAN_NAMESPACE, NULL);
     topic_elem = axiom_element_get_first_child_with_qname(add_sub_elem, env, 
qname,
@@ -96,7 +96,7 @@
     axutil_qname_free(qname, env);
     topic_url = axiom_element_get_text(topic_elem, env, topic_node);
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-        "[savan] Subscriber will be added to the topic:%s ", topic_url);
+        "[ML] Subscriber will be added to the topic:%s ", topic_url);
     topic = savan_util_get_topic_name_from_topic_url(env, topic_url);
     store = axutil_hash_get(topic_store, topic, AXIS2_HASH_KEY_STRING);
     if(!store)
@@ -104,12 +104,12 @@
         store = axutil_hash_make(env);
         axutil_hash_set(topic_store, topic, AXIS2_HASH_KEY_STRING, store);
         AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-            "[savan] Topic:%s is added to the store", topic);
+            "[ML] Topic:%s is added to the store", topic);
     }
     subscriber = savan_subscriber_create(env);
     if (!subscriber)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to create a"
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to create a"
             "subscriber instance"); 
         return NULL;
     }
@@ -184,11 +184,11 @@
     if(store)
     {
         AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-            "[savan] Subscriber %s added to the topic:%s", id, topic_url);
+            "[ML] Subscriber %s added to the topic:%s", id, topic_url);
         axutil_hash_set(store, id, AXIS2_HASH_KEY_STRING, subscriber);
     }
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-        "[savan] End:savan_subs_mgr_add_subscriber");
+        "[ML] End:savan_subs_mgr_add_subscriber");
     return NULL;   
 }
 
@@ -218,12 +218,12 @@
     axis2_char_t *id = NULL;
 
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-        "[savan] Start:savan_subs_mgr_remove_subscriber");
+        "[ML] Start:savan_subs_mgr_remove_subscriber");
     subs_svc = axis2_msg_ctx_get_svc(msg_ctx, env);
     param = axis2_svc_get_param(subs_svc, env, SAVAN_TOPIC_LIST);
     if (!param)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to extract the 
"
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to extract the "
             "subscriber store"); 
         return NULL;
     }
@@ -231,14 +231,14 @@
     topic_store = (axutil_hash_t*)axutil_param_get_value(param, env);
     if(!topic_store)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to extract the 
"
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to extract the "
             "subscriber store"); 
         return NULL;
     }
     remove_sub_elem = (axiom_element_t*)axiom_node_get_data_element(
         remove_sub_node, env);
     
-    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[savan] node:%s", 
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[ML] node:%s", 
         axiom_node_to_string(remove_sub_node, env));
     /*Get topic element from node */
     qname = axutil_qname_create(env, ELEM_NAME_TOPIC, SAVAN_NAMESPACE, NULL);
@@ -248,12 +248,12 @@
     topic_url = axiom_element_get_text(topic_elem, env, topic_node);
     topic = savan_util_get_topic_name_from_topic_url(env, topic_url);
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-        "[savan] Subscriber will be removed from the topic:%s ", topic);
+        "[ML] Subscriber will be removed from the topic:%s ", topic);
     store = axutil_hash_get(topic_store, topic, AXIS2_HASH_KEY_STRING);
     if(!store)
     {
         AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-            "[savan] There are no subscribers for the ", topic_url);
+            "[ML] There are no subscribers for the ", topic_url);
         return NULL;
     }
 
@@ -266,16 +266,16 @@
     id = axiom_element_get_text(id_elem, env, id_node);
     
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-        "[savan] Removing subscriber with id %s from topic %s", id, topic_url);
+        "[ML] Removing subscriber with id %s from topic %s", id, topic_url);
     
     axutil_hash_set(store, id, AXIS2_HASH_KEY_STRING, NULL);
     subscriber = axutil_hash_get(store, id, AXIS2_HASH_KEY_STRING);
     if(subscriber)
         savan_subscriber_free(subscriber, env);
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-        "[savan] Subscriber %s removed from the topic:%s", id, topic_url);
+        "[ML] Subscriber %s removed from the topic:%s", id, topic_url);
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-        "[savan] End:savan_subs_mgr_remove_subscriber");
+        "[ML] End:savan_subs_mgr_remove_subscriber");
     return NULL;   
 }
 
@@ -314,7 +314,7 @@
     topic_store = (axutil_hash_t*)axutil_param_get_value(param, env);
     if(!topic_store)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to extract the 
"
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to extract the "
             "subscriber store"); 
         return NULL;
     }
@@ -508,7 +508,7 @@
     topic_store = (axutil_hash_t*)axutil_param_get_value(param, env);
     if(!topic_store)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to extract the 
"
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to extract the "
             "topic store"); 
         return NULL;
     }
@@ -532,12 +532,18 @@
     for (hi = axutil_hash_first(topic_store, env); hi; hi =
         axutil_hash_next(env, hi))
     {
+        axis2_op_t *op = NULL;
+        axutil_param_t *topic_param = NULL;
         axis2_char_t *topic = NULL;
+        axis2_char_t *topic_url = NULL;
         const void *key = NULL;
         axutil_hash_this(hi, &key, NULL, NULL);
         topic = (axis2_char_t *)key;
-
-        if (topic)
+        op = axis2_svc_get_op_with_name(subs_svc, env, "get_topic_list");
+        topic_param = axis2_op_get_param(op, env, topic);
+        topic_url = axutil_param_get_value(topic_param, env);
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "topic_url:%s", topic_url);
+        if (topic_url)
         {
             axiom_node_t *topic_node = NULL;
             axiom_element_t* topic_elem = NULL;
@@ -546,7 +552,7 @@
             topic_elem = axiom_element_create(env, topic_list_node, 
                 ELEM_NAME_TOPIC, ns1, &topic_node);
             if(topic)
-                axiom_element_set_text(topic_elem, env, topic, topic_node); 
+                axiom_element_set_text(topic_elem, env, topic_url, 
topic_node); 
         }
         key = NULL;
     }

Modified: webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c?view=diff&rev=566073&r1=566072&r2=566073
==============================================================================
--- webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c (original)
+++ webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c Wed Aug 15 02:17:47 
2007
@@ -29,9 +29,9 @@
 #include <axis2_util.h>
 #include <axis2_svc_client.h>
 #include <axis2_options.h>
-#include <savan_constants.h>
 
 #include "savan_subs_mgr.h"
+#include <savan_constants.h>
 
 int AXIS2_CALL
 savan_subs_mgr_free(
@@ -116,7 +116,6 @@
     axutil_array_list_add(svc_skeleton->func_array, env, 
"get_subscriber_list");
     axutil_array_list_add(svc_skeleton->func_array, env, "add_topic");
     axutil_array_list_add(svc_skeleton->func_array, env, "get_topic_list");
-
     return AXIS2_SUCCESS;
 }
 
@@ -133,6 +132,8 @@
     axutil_param_t *param = NULL;
     int i = 0, size = 0;
 
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[savan] Start:savan_subs_mgr_init_with_conf");
     savan_subs_mgr_init(svc_skeleton, env);
     subs_svc = axis2_conf_get_svc(conf, env, "subscription");
     param = axis2_svc_get_param(subs_svc, env, SAVAN_TOPIC_LIST);
@@ -153,6 +154,7 @@
     topic_param_list = axis2_op_get_all_params(op, env);
     if(topic_param_list)
         size = axutil_array_list_size(topic_param_list, env);
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "dam_size:%d", size);
     for(i = 0; i < size; i++)
     {
         axutil_param_t *topic_param = NULL;
@@ -162,6 +164,8 @@
         topic_param = axutil_array_list_get(topic_param_list, env, i);
         topic_url_str = axutil_param_get_value(topic_param, env);
         topic_name = axutil_param_get_name(topic_param, env);
+        if(0 == axutil_strcmp(topic_name, "wsamapping"))
+            continue;
         subs_list = axutil_hash_get(topic_list, topic_name, 
             AXIS2_HASH_KEY_STRING);
         if(!subs_list)
@@ -174,6 +178,8 @@
         }
 
     }
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[savan] End:savan_subs_mgr_init_with_conf");
     return AXIS2_SUCCESS;
 }
 
@@ -200,6 +206,7 @@
         op_qname = (axutil_qname_t *)axis2_op_get_qname(op, env);
         if(op_qname)
             op_name = axutil_qname_get_localpart(op_qname, env);
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "dam_op_name:%s", op_name);
         if(op_name)
         {
             if (axutil_strcmp(op_name, "add_subscriber") == 0)
@@ -208,10 +215,10 @@
                 return savan_subs_mgr_remove_subscriber(env, node, msg_ctx);
             if (axutil_strcmp(op_name, "get_subscriber_list") == 0)
                 return savan_subs_mgr_get_subscriber_list(env, node, msg_ctx);
-            /*if (axutil_strcmp(op_name, "add_topic") == 0)
-                return savan_subs_mgr_add_topic(env, node, msg_ctx);
             if (axutil_strcmp(op_name, "get_topic_list") == 0)
-                return savan_subs_mgr_get_topic_list(env, node, msg_ctx);*/
+                return savan_subs_mgr_get_topic_list(env, node, msg_ctx);
+            /*if (axutil_strcmp(op_name, "add_topic") == 0)
+                return savan_subs_mgr_add_topic(env, node, msg_ctx);*/
         }
     }
     return NULL;

Modified: webservices/savan/trunk/c/src/util/savan_util.c
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/util/savan_util.c?view=diff&rev=566073&r1=566072&r2=566073
==============================================================================
--- webservices/savan/trunk/c/src/util/savan_util.c (original)
+++ webservices/savan/trunk/c/src/util/savan_util.c Wed Aug 15 02:17:47 2007
@@ -65,11 +65,20 @@
     const axutil_env_t *env,
     axis2_char_t *topic);
 
+static axiom_node_t *
+build_topics_request_om_payload(
+    const axutil_env_t *env);
+
 static axutil_hash_t *
 process_subscriber_list_node(
     const axutil_env_t *env,
     axiom_node_t *subs_list_node);
 
+static axutil_array_list_t *
+process_topic_list_node(
+    const axutil_env_t *env,
+    axiom_node_t *subs_list_node);
+
 /*axis2_status_t AXIS2_CALL
 savan_util_set_filter_template_for_subscriber(
     savan_subscriber_t *subscriber,
@@ -403,12 +412,24 @@
             param = axis2_svc_get_param(pubs_svc, env, "SubscriptionMgrURL");
             if(param)
             {
+                axis2_svc_client_t* svc_client = NULL;
+                axutil_param_t *svc_client_param = NULL;
+
                 subs_mgr_url = axutil_param_get_value(param, env);
                 topic_epr = axis2_msg_ctx_get_to(msg_ctx, env);
                 topic_url = (axis2_char_t *) 
axis2_endpoint_ref_get_address(topic_epr, 
                     env);
+                svc_client_param = axis2_svc_get_param(pubs_svc, env, 
"svc_client");
+                if(svc_client_param)
+                    svc_client = axutil_param_get_value(svc_client_param, env);
+                if(!svc_client)
+                {
+                    svc_client = (axis2_svc_client_t *) 
savan_util_get_svc_client(env);
+                    svc_client_param = axutil_param_create(env, "svc_client", 
svc_client);
+                    axis2_svc_add_param(pubs_svc, env, svc_client_param);
+                }
                 store = 
savan_util_get_subscriber_list_from_remote_subs_mgr(env, 
-                    topic_url, subs_mgr_url, NULL);
+                    topic_url, subs_mgr_url, svc_client);
             }
         }
     }
@@ -673,49 +694,17 @@
     const axis2_char_t *address = NULL;
     axis2_endpoint_ref_t* endpoint_ref = NULL;
     axis2_options_t *options = NULL;
-    const axis2_char_t *client_home = NULL;
     axis2_svc_client_t* svc_client = NULL;
     axiom_node_t *payload = NULL;
 
-    /* Set end point reference of echo service */
+    svc_client = (axis2_svc_client_t *) savan_util_get_svc_client(env);
+    options = (axis2_options_t *) axis2_svc_client_get_options(svc_client, 
env);
     address = subs_mgr_url;
-
-    /* Create EPR with given address */
     endpoint_ref = axis2_endpoint_ref_create(env, address);
-
-    /* Setup options */
-    options = axis2_options_create(env);
-    axis2_options_set_xml_parser_reset(options, env, AXIS2_FALSE);
     axis2_options_set_to(options, env, endpoint_ref);
     axis2_options_set_action(options, env,
         "http://ws.apache.org/axis2/c/subscription/add_subscriber";);
 
-    /* Set up deploy folder. It is from the deploy folder, the configuration 
is 
-     * picked up using the axis2.xml file.
-     * In this sample client_home points to the Axis2/C default deploy folder. 
-     * The client_home can be different from this folder on your system. For 
-     * example, you may have a different folder (say, my_client_folder) with 
its 
-     * own axis2.xml file. my_client_folder/modules will have the modules that 
-     * the client uses
-     */
-    client_home = (const axis2_char_t *) AXIS2_GETENV("AXIS2C_HOME");
-    if (!client_home)
-        client_home = "../../deploy";
-
-    /* Create service client */
-    svc_client = axis2_svc_client_create(env, client_home);
-    if (!svc_client)
-    {
-        printf("Error creating service client\n");
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error 
code:"
-            " %d :: %s", env->error->error_number,
-            AXIS2_ERROR_GET_MESSAGE(env->error));
-        return AXIS2_FAILURE;
-    }
-    /* Set service client options */
-    axis2_svc_client_set_options(svc_client, env, options);    
-    
-    axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);
     payload = build_add_subscriber_om_payload(env, subscriber);
     /* Send request */
     axis2_svc_client_send_robust(svc_client, env, payload);
@@ -734,49 +723,17 @@
     const axis2_char_t *address = NULL;
     axis2_endpoint_ref_t* endpoint_ref = NULL;
     axis2_options_t *options = NULL;
-    const axis2_char_t *client_home = NULL;
     axis2_svc_client_t* svc_client = NULL;
     axiom_node_t *payload = NULL;
 
-    /* Set end point reference of echo service */
+    svc_client = (axis2_svc_client_t *) savan_util_get_svc_client(env);
+    options = (axis2_options_t *) axis2_svc_client_get_options(svc_client, 
env);
     address = subs_mgr_url;
-
-    /* Create EPR with given address */
     endpoint_ref = axis2_endpoint_ref_create(env, address);
-
-    /* Setup options */
-    options = axis2_options_create(env);
-    axis2_options_set_xml_parser_reset(options, env, AXIS2_FALSE);
     axis2_options_set_to(options, env, endpoint_ref);
     axis2_options_set_action(options, env,
         "http://ws.apache.org/axis2/c/subscription/remove_subscriber";);
 
-    /* Set up deploy folder. It is from the deploy folder, the configuration 
is 
-     * picked up using the axis2.xml file.
-     * In this sample client_home points to the Axis2/C default deploy folder. 
-     * The client_home can be different from this folder on your system. For 
-     * example, you may have a different folder (say, my_client_folder) with 
its 
-     * own axis2.xml file. my_client_folder/modules will have the modules that 
-     * the client uses
-     */
-    client_home = (const axis2_char_t *) AXIS2_GETENV("AXIS2C_HOME");
-    if (!client_home)
-        client_home = "../../deploy";
-
-    /* Create service client */
-    svc_client = axis2_svc_client_create(env, client_home);
-    if (!svc_client)
-    {
-        printf("Error creating service client\n");
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error 
code:"
-            " %d :: %s", env->error->error_number,
-            AXIS2_ERROR_GET_MESSAGE(env->error));
-        return AXIS2_FAILURE;
-    }
-    /* Set service client options */
-    axis2_svc_client_set_options(svc_client, env, options);    
-    
-    axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);
     payload = build_remove_subscriber_om_payload(env, subscriber);
     /* Send request */
     axis2_svc_client_send_robust(svc_client, env, payload);
@@ -795,7 +752,6 @@
 {
     axis2_endpoint_ref_t* endpoint_ref = NULL;
     axis2_options_t *options = NULL;
-    const axis2_char_t *client_home = NULL;
     axis2_svc_client_t* svc_client = NULL;
     axiom_node_t *payload = NULL;
     axiom_node_t *ret_node = NULL;
@@ -803,43 +759,11 @@
 
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
         "[savan] Start:savan_util_get_subscriber_list_from_remote_subs_mgr");
-    if(!s_client)
-    {
-        client_home = AXIS2_GETENV("AXIS2C_HOME");
-        if (!client_home)
-            client_home = "../../deploy";
-        options = axis2_options_create(env);
-        svc_client = axis2_svc_client_create(env, client_home);
-        if (!svc_client)
-        {
-            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
-                "[savan] Stub invoke FAILED: Error code:"
-                " %d :: %s", env->error->error_number,
-                AXIS2_ERROR_GET_MESSAGE(env->error));
-            return NULL;
-        }
-        endpoint_ref = axis2_endpoint_ref_create(env, subs_mgr_url);
-        axis2_options_set_to(options, env, endpoint_ref);
-        axis2_svc_client_set_options(svc_client, env, options);    
-        axis2_svc_client_engage_module(svc_client, env, 
AXIS2_MODULE_ADDRESSING);
-    }
-    else
-    {
-        svc_client = (axis2_svc_client_t *) s_client;
-        options = (axis2_options_t *)axis2_svc_client_get_options(svc_client, 
-            env);
-        endpoint_ref = axis2_options_get_to(options, env);
-        if(endpoint_ref)
-        {
-            axis2_endpoint_ref_set_address(endpoint_ref, env, subs_mgr_url);
-        }
-        else
-        {
-            endpoint_ref = axis2_endpoint_ref_create(env, subs_mgr_url);
-            axis2_options_set_to(options, env, endpoint_ref);
-        }
-
-    }
+    svc_client = (axis2_svc_client_t *) s_client;
+    options = (axis2_options_t *)axis2_svc_client_get_options(svc_client, 
+        env);
+    endpoint_ref = axis2_endpoint_ref_create(env, subs_mgr_url);
+    axis2_options_set_to(options, env, endpoint_ref);
     
     payload = build_subscribers_request_om_payload(env, topic);
     ret_node = axis2_svc_client_send_receive(svc_client, env, payload);
@@ -854,10 +778,6 @@
             " %d :: %s", env->error->error_number,
             AXIS2_ERROR_GET_MESSAGE(env->error));
     }
-    if(!s_client && svc_client)
-    {
-        axis2_svc_client_free(svc_client, env);
-    }
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
         "[savan] End:savan_util_get_subscriber_list_from_remote_subs_mgr");
     return subscriber_list;
@@ -1191,5 +1111,156 @@
     axis2_char_t *topic = NULL;
     topic  = axutil_strdup(env, axutil_rindex(topic_url, '/') + 1);
     return topic;
+}
+
+axutil_array_list_t *AXIS2_CALL
+savan_util_get_topic_list_from_remote_subs_mgr(
+    const axutil_env_t *env,
+    axis2_char_t *subs_mgr_url,
+    void *s_client)
+{
+    axis2_endpoint_ref_t* endpoint_ref = NULL;
+    axis2_options_t *options = NULL;
+    axis2_svc_client_t* svc_client = NULL;
+    axiom_node_t *payload = NULL;
+    axiom_node_t *ret_node = NULL;
+    axutil_array_list_t *topic_list = NULL;
+
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[savan] Start:savan_util_get_topic_list_from_remote_subs_mgr");
+    if(!s_client)
+    {
+        svc_client = (axis2_svc_client_t *) savan_util_get_svc_client(env);
+    }
+    else
+    {
+        svc_client = (axis2_svc_client_t *) s_client;
+    }
+    options = (axis2_options_t *) axis2_svc_client_get_options(svc_client, 
env);
+    endpoint_ref = axis2_endpoint_ref_create(env, subs_mgr_url);
+    axis2_options_set_to(options, env, endpoint_ref);
+    
+    payload = build_topics_request_om_payload(env);
+    ret_node = axis2_svc_client_send_receive(svc_client, env, payload);
+    if (ret_node)
+    {
+        topic_list = process_topic_list_node(env, ret_node);
+    }
+    else
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[savan] Stub invoke FAILED: Error code:"
+            " %d :: %s", env->error->error_number,
+            AXIS2_ERROR_GET_MESSAGE(env->error));
+    }
+    if(!s_client && svc_client)
+    {
+        /*axis2_svc_client_free(svc_client, env);*/
+    }
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[savan] End:savan_util_get_topic_list_from_remote_subs_mgr");
+    return topic_list;
+}
+
+static axiom_node_t *
+build_topics_request_om_payload(
+    const axutil_env_t *env)
+{
+    axiom_node_t *om_node = NULL;
+    axiom_element_t* om_ele = NULL;
+    axiom_namespace_t *ns1 = NULL;
+    axis2_char_t *om_str = NULL;
+
+    ns1 = axiom_namespace_create (env, SAVAN_NAMESPACE, SAVAN_NS_PREFIX);
+    om_ele = axiom_element_create(env, NULL, ELEM_NAME_GET_TOPIC_LIST, ns1, 
&om_node);
+    om_str = axiom_node_to_string(om_node, env);
+    if (om_str)
+    {
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+            "Sending topics_request_om_payload: %s", om_str);
+        AXIS2_FREE(env->allocator, om_str);
+        om_str =  NULL;
+    }
+    return om_node;
+}
+
+static axutil_array_list_t *
+process_topic_list_node(
+    const axutil_env_t *env,
+    axiom_node_t *topic_list_node)
+{
+    axiom_element_t *topic_list_element = NULL;
+    axiom_children_qname_iterator_t *topic_iter = NULL;
+    axutil_qname_t *qname = NULL;
+    axutil_array_list_t *topic_list = NULL;
+
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[savan] Start:process_topic_list_node");
+    topic_list_element = axiom_node_get_data_element(topic_list_node, env); 
+         
+    /* Get topic elements from topic list */
+    qname = axutil_qname_create(env, ELEM_NAME_TOPIC, SAVAN_NAMESPACE, 
+        NULL);
+    topic_iter = axiom_element_get_children_with_qname(topic_list_element, env,
+        qname, topic_list_node);
+    axutil_qname_free(qname, env);
+    if(!topic_iter)
+    {
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+            "[savan] Topic list is empty");
+        return NULL;
+    }
+    if(axiom_children_qname_iterator_has_next(topic_iter, env))
+    {
+        topic_list = axutil_array_list_create(env, 0);
+    }
+
+    while(axiom_children_qname_iterator_has_next(topic_iter, env))
+    {
+        axiom_node_t *topic_node = NULL;
+        axiom_element_t *topic_elem = NULL;
+        axis2_char_t *topic_url_str = NULL;
+
+        topic_node = axiom_children_qname_iterator_next(topic_iter, env);
+        if(topic_node)
+        {
+            topic_elem = axiom_node_get_data_element(topic_node, env);
+            topic_url_str = axiom_element_get_text(topic_elem, env, 
topic_node);
+            axutil_array_list_add(topic_list, env, axutil_strdup(env, 
+                topic_url_str));
+            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "topic_url_str:%s", 
+                topic_url_str);
+        }
+    }
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[savan] End:process_topic_list_node");
+    return topic_list;
+}
+
+void *AXIS2_CALL
+savan_util_get_svc_client(
+    const axutil_env_t *env)
+{
+    const axis2_char_t *client_home = NULL;
+    axis2_options_t *options = NULL;
+    axis2_svc_client_t *svc_client = NULL;
+
+    client_home = AXIS2_GETENV("AXIS2C_HOME");
+    if (!client_home)
+        client_home = "../../deploy";
+    options = axis2_options_create(env);
+    axis2_options_set_xml_parser_reset(options, env, AXIS2_FALSE);
+    svc_client = axis2_svc_client_create(env, client_home);
+    if (!svc_client)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[savan] Stub invoke FAILED: Error code:"
+            " %d :: %s", env->error->error_number,
+            AXIS2_ERROR_GET_MESSAGE(env->error));
+        return NULL;
+    }
+    axis2_svc_client_set_options(svc_client, env, options);    
+    axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);
+    return svc_client;
 }
 


Reply via email to