You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by da...@apache.org on 2006/08/03 12:59:25 UTC

svn commit: r428321 - /webservices/axis2/trunk/c/samples/client/dynamic_client/calc_client.c

Author: damitha
Date: Thu Aug  3 03:59:25 2006
New Revision: 428321

URL: http://svn.apache.org/viewvc?rev=428321&view=rev
Log:
Changed the dynamic client so that it can be used for
Calculator and Hotel Reservation wsdl's

Modified:
    webservices/axis2/trunk/c/samples/client/dynamic_client/calc_client.c

Modified: webservices/axis2/trunk/c/samples/client/dynamic_client/calc_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/client/dynamic_client/calc_client.c?rev=428321&r1=428320&r2=428321&view=diff
==============================================================================
--- webservices/axis2/trunk/c/samples/client/dynamic_client/calc_client.c (original)
+++ webservices/axis2/trunk/c/samples/client/dynamic_client/calc_client.c Thu Aug  3 03:59:25 2006
@@ -24,23 +24,31 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-axiom_node_t *
-build_om_programatically(axis2_env_t *env);
+static axiom_node_t *
+build_om_programatically_for_wsdl1(
+        const axis2_env_t *env);
+
+static axiom_node_t *
+build_om_programatically_for_wsdl2(
+        const axis2_env_t *env);
+
+static int
+process_for_wsdl1(
+        const axis2_env_t *env,
+        axis2_char_t *wsdl_uri_str);
+
+static int
+process_for_wsdl2(
+        const axis2_env_t *env,
+        axis2_char_t *wsdl_uri_str);
 
 int main(int argc, char** argv)
 {
-	axiom_node_t *payload = NULL;
-	axiom_node_t *response = NULL;
 	axis2_env_t *env = NULL;
     axis2_error_t *error = NULL;
     axis2_log_t *log = NULL;
     axis2_allocator_t *allocator = NULL;
-    axis2_uri_t *wsdl_uri = NULL;
     axis2_char_t *wsdl_uri_str = NULL;
-    axis2_qname_t *op_qname = NULL;
-    axis2_svc_client_t *svc_client = NULL;
-    const axis2_char_t *client_home = NULL;
-    axis2_qname_t *wsdl_svc_qname = NULL;
 
     /* set up the envioronment with allocator and log*/
     allocator = axis2_allocator_init (NULL);
@@ -56,6 +64,32 @@
       return 1;
     }
     wsdl_uri_str = argv[1];
+    if(strstr(wsdl_uri_str, "Calculator"))
+    {
+        printf("Calculator\n");
+        process_for_wsdl1(env, wsdl_uri_str);
+    }
+    else
+    {
+        printf("Hotel Reservation\n");
+        process_for_wsdl2(env, wsdl_uri_str);
+    }
+    return 0;
+}
+
+static int
+process_for_wsdl1(
+        const axis2_env_t *env,
+        axis2_char_t *wsdl_uri_str)
+{
+    axiom_node_t *payload = NULL;
+	axiom_node_t *response = NULL;
+    axis2_uri_t *wsdl_uri = NULL;
+    axis2_qname_t *op_qname = NULL;
+    axis2_svc_client_t *svc_client = NULL;
+    const axis2_char_t *client_home = NULL;
+    axis2_qname_t *wsdl_svc_qname = NULL;
+
 
     /* Set up deploy folder. It is from the deploy folder, the configuration 
      * is picked up using the axis2.xml file.
@@ -81,7 +115,7 @@
         AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Service client is NULL");
         return 1;
     }
-    payload = build_om_programatically(env);
+    payload = build_om_programatically_for_wsdl1(env);
     op_qname = axis2_qname_create(env, "add", "http://localhost/axis/Calculator", 
             NULL); 
     response = AXIS2_SVC_CLIENT_SEND_RECEIVE_WITH_OP_QNAME(svc_client, env, 
@@ -106,9 +140,130 @@
 	return 0;
 }
 
+static int
+process_for_wsdl2(
+        const axis2_env_t *env,
+        axis2_char_t *wsdl_uri_str)
+{
+    axiom_node_t *payload = NULL;
+	axiom_node_t *response = NULL;
+    axis2_uri_t *wsdl_uri = NULL;
+    axis2_qname_t *op_qname = NULL;
+    axis2_svc_client_t *svc_client = NULL;
+    const axis2_char_t *client_home = NULL;
+    axis2_qname_t *wsdl_svc_qname = NULL;
+
+    /* 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 = AXIS2_GETENV("AXIS2C_HOME");
+    if (!client_home)
+        client_home = "../../deploy";
+
+    wsdl_svc_qname = axis2_qname_create(env, "Calculator", 
+            "http://localhost/axis/Calculator", NULL);
+    wsdl_uri = axis2_uri_parse_string(env, wsdl_uri_str);
+    svc_client = 
+        axis2_svc_client_create_for_dynamic_invocation(
+                env, NULL, wsdl_uri, wsdl_svc_qname, "Calculator", client_home);
+    if(!svc_client)
+    {
+		printf("Service client is NULL \n");
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Service client is NULL");
+        return 1;
+    }
+    payload = build_om_programatically_for_wsdl2(env);
+    op_qname = axis2_qname_create(env, "add", "http://localhost/axis/Calculator", 
+            NULL); 
+    response = AXIS2_SVC_CLIENT_SEND_RECEIVE_WITH_OP_QNAME(svc_client, env, 
+            op_qname, payload);
+        
+	if(response)
+    {
+        axis2_char_t *om_str = NULL;
+        
+        om_str = AXIOM_NODE_TO_STRING(response, env);
+        if (om_str)
+            printf("\nReceived OM : %s\n", om_str);
+		printf("status:%s\n", "Success");
+    }
+	else
+		printf("status:%s\n", "Failure");
+    if(svc_client)
+    {
+        AXIS2_SVC_CLIENT_FREE(svc_client, env);
+        svc_client = NULL;
+    }
+	return 0;
+}
+
+
+/* build SOAP request message content using OM */
+static axiom_node_t *
+build_om_programatically_for_wsdl1(
+        const axis2_env_t *env)
+{
+    axiom_node_t *add_om_node = NULL;
+    axiom_element_t* add_om_ele = NULL;
+    axiom_node_t *arg0_om_node = NULL;
+    axiom_element_t* arg0_om_ele = NULL;
+    axiom_node_t *arg1_om_node = NULL;
+    axiom_element_t* arg1_om_ele = NULL;
+    axiom_node_t *seq_om_node = NULL;
+    axiom_element_t* seq_om_ele = NULL;
+    axiom_node_t *cmplx_type_om_node = NULL;
+    axiom_element_t* cmplx_type_om_ele = NULL;
+    axiom_namespace_t *ns1 = NULL;
+    axiom_attribute_t *attr = NULL;
+    axiom_attribute_t *attr_name_arg0 = NULL;
+    axiom_attribute_t *attr_name_arg1 = NULL;
+    
+
+    axiom_xml_writer_t *xml_writer = NULL;
+    axiom_output_t *om_output = NULL;
+    axis2_char_t *buffer = NULL;
+    axis2_char_t *ns = NULL;
+
+    ns = AXIS2_STRDUP("http://localhost/axis/Calculator", env);
+    ns1 = axiom_namespace_create (env, ns, "tns0");
+    
+    add_om_ele = axiom_element_create(env, NULL, "add", ns1, &add_om_node);
+    cmplx_type_om_ele = axiom_element_create(env, add_om_node, "complexType", ns1, &cmplx_type_om_node);
+    seq_om_ele = axiom_element_create(env, cmplx_type_om_node, "sequence", ns1, &seq_om_node);
+    attr = axiom_attribute_create(env, "type", "xsd:int", ns1);
+    attr_name_arg0 = axiom_attribute_create(env, "name", "arg_0_0", ns1);
+    attr_name_arg1 = axiom_attribute_create(env, "name", "arg_1_0", ns1);
+    arg0_om_ele = axiom_element_create(env, seq_om_node, "arg_0_0", NULL, &arg0_om_node);
+    AXIOM_ELEMENT_SET_TEXT(arg0_om_ele, env, "5", arg0_om_node);
+    AXIOM_ELEMENT_ADD_ATTRIBUTE(arg0_om_ele, env, attr, arg0_om_node);
+    AXIOM_ELEMENT_ADD_ATTRIBUTE(arg0_om_ele, env, attr_name_arg0, arg0_om_node);
+    arg1_om_ele = axiom_element_create(env, seq_om_node, "arg_1_0", NULL, &arg1_om_node);
+    AXIOM_ELEMENT_SET_TEXT(arg1_om_ele, env, "10", arg1_om_node);
+    AXIOM_ELEMENT_ADD_ATTRIBUTE(arg1_om_ele, env, attr_name_arg1, arg1_om_node);
+    AXIOM_ELEMENT_ADD_ATTRIBUTE(arg1_om_ele, env, attr, arg1_om_node);
+    
+    xml_writer = axiom_xml_writer_create_for_memory(env, NULL, AXIS2_FALSE, 
+            AXIS2_FALSE, AXIS2_XML_PARSER_TYPE_BUFFER);
+    om_output = axiom_output_create( env, xml_writer);
+    
+    AXIOM_NODE_SERIALIZE(add_om_node, env, om_output);
+    buffer = AXIOM_XML_WRITER_GET_XML(xml_writer, env);         
+    printf("\nOM node in XML : %s \n",  buffer); 
+    AXIS2_FREE(env->allocator, buffer);
+    AXIOM_OUTPUT_FREE(om_output, env);
+
+    return add_om_node;
+}
+
 /* build SOAP request message content using OM */
-axiom_node_t *
-build_om_programatically(axis2_env_t *env)
+static axiom_node_t *
+build_om_programatically_for_wsdl2(
+        const axis2_env_t *env)
 {
     axiom_node_t *add_om_node = NULL;
     axiom_element_t* add_om_ele = NULL;
@@ -149,7 +304,7 @@
     AXIOM_ELEMENT_ADD_ATTRIBUTE(arg1_om_ele, env, attr_name_arg1, arg1_om_node);
     AXIOM_ELEMENT_ADD_ATTRIBUTE(arg1_om_ele, env, attr, arg1_om_node);
     
-    /*xml_writer = axiom_xml_writer_create_for_memory(env, NULL, AXIS2_FALSE, 
+    xml_writer = axiom_xml_writer_create_for_memory(env, NULL, AXIS2_FALSE, 
             AXIS2_FALSE, AXIS2_XML_PARSER_TYPE_BUFFER);
     om_output = axiom_output_create( env, xml_writer);
     
@@ -157,7 +312,7 @@
     buffer = AXIOM_XML_WRITER_GET_XML(xml_writer, env);         
     printf("\nOM node in XML : %s \n",  buffer); 
     AXIS2_FREE(env->allocator, buffer);
-    AXIOM_OUTPUT_FREE(om_output, env);*/
+    AXIOM_OUTPUT_FREE(om_output, env);
 
     return add_om_node;
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org