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 sa...@apache.org on 2006/05/18 05:37:32 UTC

svn commit: r407449 - in /webservices/axis2/trunk/c/samples/client: echo/echo_client.c notify/notify_client.c

Author: samisa
Date: Wed May 17 20:37:32 2006
New Revision: 407449

URL: http://svn.apache.org/viewvc?rev=407449&view=rev
Log:
Removed unwated files and fixed the notify client to use service client API

Removed:
    webservices/axis2/trunk/c/samples/client/echo/echo_client.c
Modified:
    webservices/axis2/trunk/c/samples/client/notify/notify_client.c

Modified: webservices/axis2/trunk/c/samples/client/notify/notify_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/client/notify/notify_client.c?rev=407449&r1=407448&r2=407449&view=diff
==============================================================================
--- webservices/axis2/trunk/c/samples/client/notify/notify_client.c (original)
+++ webservices/axis2/trunk/c/samples/client/notify/notify_client.c Wed May 17 20:37:32 2006
@@ -14,76 +14,31 @@
  * limitations under the License.
  */
 
-#include <axis2_call.h>
-#include <axis2_om_stax_builder.h>
-#include <axis2_om_document.h>
-#include <axis2_om_node.h>
-#include <axis2_om_element.h>
-#include <axis2_om_text.h>
-#include <axis2_stream.h>
-#include <axis2_log_default.h>
-#include <axis2_error_default.h>
-#include <axis2_xml_reader.h>
 #include <stdio.h>
-#include <axis2_xml_writer.h>
-#include <axis2_soap_builder.h>
-#include <axis2_soap_const.h>
-#include <axis2_soap_envelope.h>
-#include <axis2_soap_body.h>
-#include <axis2_soap_header.h>
-#include <axis2_soap_message.h>
-#include <axis2_soap_header_block.h>
-#include <axis2_soap_fault.h>
-#include <axis2_soap_fault_code.h>
-#include <axis2_soap_fault_role.h>
-#include <platforms/axis2_platform_auto_sense.h>
+#include <axis2_om.h>
+#include <axis2_util.h>
+#include <axis2_soap.h>
+#include <axis2_client.h>
 
 axis2_om_node_t *
 build_om_programatically(axis2_env_t **env);
 
 int main(int argc, char** argv)
 {
-    axis2_om_node_t *node = NULL;
-    axis2_status_t status = AXIS2_FAILURE;
     axis2_env_t *env = NULL;
-    axis2_error_t *error = NULL;
-    axis2_log_t *log = NULL;
-    axis2_allocator_t *allocator = NULL;
     axis2_char_t *address = NULL;
-    axis2_char_t *wsa_action = NULL;
-    axis2_char_t *client_home = NULL;
-    axis2_svc_t *svc = NULL;
-    axis2_op_t *op = NULL;
-    axis2_call_t *call = NULL;
-    axis2_msg_ctx_t *msg_ctx = NULL;
-    axis2_mep_client_t *mep_client = NULL;
-    axis2_msg_info_headers_t *msg_info_headers = NULL;
     axis2_endpoint_ref_t* endpoint_ref = NULL;
-    axis2_conf_t *conf = NULL;
-    axis2_msg_ctx_t *response_ctx = NULL;
-    
-    /* set up the envioronment with allocator and log*/
-    allocator = axis2_allocator_init (NULL);
-    error = axis2_error_create(allocator);
-    log = axis2_log_create(allocator, NULL, "notify.log");
-    env = axis2_env_create_with_error_log(allocator, error, log);
-    env->log->level = AXIS2_LOG_LEVEL_TRACE;
-    axis2_error_init();
+    axis2_options_t *options = NULL;
+    axis2_char_t *client_home = NULL;
+    axis2_svc_client_t* svc_client = NULL;
+    axis2_om_node_t *payload = NULL;
+    axis2_status_t status = AXIS2_FAILURE;
+   
+    /* Set up the envioronment */
+    env = axis2_env_create_all("notify.log", AXIS2_LOG_LEVEL_TRACE);
 
-    /* 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";
-    
-    /* Set end point reference of notify service */
+    /* Set end point reference of echo service */
     address = "http://localhost:9090/axis2/services/notify";
-    wsa_action = "http://example.org/action/notify";
     if (argc > 1 )
         address = argv[1];
     if (AXIS2_STRCMP(address, "-h") == 0)
@@ -92,102 +47,73 @@
         printf("use -h for help\n");
         return 0;
     }
-
     printf ("Using endpoint : %s\n", address);
+    
+    /* Create EPR with given address */
+    endpoint_ref = axis2_endpoint_ref_create(&env, address);
 
-    /* build the SOAP request message content using OM API.*/
-    node = build_om_programatically(&env);
+    /* Setup options */
+    options = axis2_options_create(&env);
+    AXIS2_OPTIONS_SET_TO(options, &env, endpoint_ref);
+    AXIS2_OPTIONS_SET_ACTION(options, &env,
+        "http://example.org/action/notify");
 
-    /* create call struct */
-    call = axis2_call_create(&env, NULL, client_home);
-    mep_client = AXIS2_CALL_GET_BASE(call, &env);
+    /* 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";
 
-    /* Prepare the SOAP envelope, using the SOAP message content to be sent.
-     * Get a reference to the message context */
-    msg_ctx = AXIS2_MEP_CLIENT_PREPARE_SOAP_ENVELOPE(mep_client, &env, node);
-    if (!msg_ctx)
+    /* Create service client */
+    svc_client = axis2_svc_client_create(&env, client_home);
+    if (!svc_client)
     {
-        printf("ERROR: Could not prepare message context. ");
-        printf("May be you havent set the repository corretly.\n");
-        return -1;
+        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));
     }
 
-    /* Get the reference to message info headers structure from the message context. 
-       This can be used to manipulate SOAP header content when using WS-Addressing. */
-    msg_info_headers = AXIS2_MSG_CTX_GET_MSG_INFO_HEADERS(msg_ctx, &env);
-
-    /* create an axis2_endpoint_ref_t struct with ERP assigned */
-    endpoint_ref = axis2_endpoint_ref_create(&env, address);
-
-    /* Set header parameters, required for WS-Addressing. 
-     * Required only if you need to make use of WS-Addressing.
-     */
-    AXIS2_MSG_INFO_HEADERS_SET_TO(msg_info_headers, &env, endpoint_ref);
-    AXIS2_MSG_INFO_HEADERS_SET_ACTION(msg_info_headers, &env, wsa_action); 
+    /* Set service client options */
+    AXIS2_SVC_CLIENT_SET_OPTIONS(svc_client, &env, options);    
     
-    AXIS2_CALL_SET_TO(call, &env, endpoint_ref);
-
-    /* Get the configuration context */
-    conf = AXIS2_CONF_CTX_GET_CONF(
-                            AXIS2_SVC_CTX_GET_CONF_CTX(
-                                AXIS2_MEP_CLIENT_GET_SVC_CTX(mep_client, &env), 
-                                &env), 
-                                &env);
-
-    /* Get the notify service context if it is already loaded to service context*/
-    svc = AXIS2_CONF_GET_SVC(conf, &env, "notify");
-    if (svc)
-    {
-        op = AXIS2_SVC_GET_OP_WITH_NAME(svc, &env, "notify");
-        if (op)
-        {
-            AXIS2_OP_SET_MSG_EXCHANGE_PATTERN(op, &env, AXIS2_MEP_URI_OUT_IN);
-        }
-    }
-    else
-    {
-       /* notify service is not in the configuration context. We need to create the 
-        * operation and add it to service context. Then add service context into 
-        * configuration context.
-        */
-        axis2_qname_t *op_qname = NULL;
-        axis2_qname_t *svc_qname = axis2_qname_create(&env, "notify", NULL, NULL);
-        svc = axis2_svc_create_with_qname(&env, svc_qname);
-        op_qname = axis2_qname_create(&env, "notify", NULL, NULL);
-        op = axis2_op_create_with_qname(&env, op_qname);
-        AXIS2_OP_SET_MSG_EXCHANGE_PATTERN(op, &env, AXIS2_MEP_URI_OUT_IN);
-        AXIS2_SVC_ADD_OP(svc, &env, op);
-        AXIS2_CONF_ADD_SVC(conf, &env, svc);
-    }
-
-    if (!op)
-    {
-        printf("ERROR: operation not present in service\n");
-        return -1;
-    }
-
-   /* Invoke the operation. Client blocks until the response message comes. 
-    * Response message gets set in the response message context.
-    */
-    response_ctx = AXIS2_CALL_INVOKE_BLOCKING(call, &env, op, msg_ctx);
-
-    if (response_ctx)
+    /* Engage addressing module */
+    AXIS2_SVC_CLIENT_ENGAGE_MODULE(svc_client, &env, AXIS2_MODULE_ADDRESSING);
+    
+    /* Build the SOAP request message payload using OM API.*/
+    payload = build_om_programatically(&env);
+    
+    /* Send request */
+    status = AXIS2_SVC_CLIENT_SEND_ROBUST(svc_client, &env, payload);
+    
+    if(status == AXIS2_SUCCESS)
     {
-        printf("\nnotify stub invoke SUCCESSFUL!\n");
+        printf("\nnotify client invoke SUCCESSFUL!\n");
     }
     else
     {
 		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));
-        printf("notify stub invoke FAILED!\n");
+        printf("notify client invoke FAILED!\n");
     }
     
-    if (call)
+    if (svc_client)
+    {
+        AXIS2_SVC_CLIENT_FREE(svc_client, &env);
+        svc_client = NULL;
+    }
+    if (endpoint_ref)
     {
-        AXIS2_CALL_FREE(call, &env);
+        AXIS2_ENDPOINT_REF_FREE(endpoint_ref, &env);
+        endpoint_ref = NULL;
     }
-    return status;
+    return 0;
 }
 
 /* build SOAP request message content using OM */
@@ -197,25 +123,13 @@
     axis2_om_node_t *notify_om_node = NULL;
     axis2_om_element_t* notify_om_ele = NULL;
     axis2_om_namespace_t *ns1 = NULL;
-    
-
-    axis2_xml_writer_t *xml_writer = NULL;
-    axis2_om_output_t *om_output = NULL;
     axis2_char_t *buffer = NULL;
-
+    
     ns1 = axis2_om_namespace_create (env, "http://example.org/notify", "m");
-
     notify_om_ele = axis2_om_element_create(env, NULL, "notify", ns1, &notify_om_node);
-    
     AXIS2_OM_ELEMENT_SET_TEXT(notify_om_ele, env, "notify5", notify_om_node);
     
-    
-    xml_writer = axis2_xml_writer_create_for_memory(env, NULL, AXIS2_FALSE, AXIS2_FALSE,
-					AXIS2_XML_PARSER_TYPE_BUFFER);
-    om_output = axis2_om_output_create( env, xml_writer);
-    
-    AXIS2_OM_NODE_SERIALIZE(notify_om_node, env, om_output);
-    buffer = (axis2_char_t*)AXIS2_XML_WRITER_GET_XML(xml_writer, env);         
+    buffer = AXIS2_OM_NODE_TO_STRING(notify_om_node, env);
     printf("\nSending OM node in XML : %s \n",  buffer); 
 
     return notify_om_node;