PageRenderTime 2368ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wso2-wsf-cpp-src-2.1.0/wsf_c/axis2c/src/core/transport/xmpp/samples/client/echo/echo.c

#
C | 197 lines | 133 code | 30 blank | 34 comment | 13 complexity | 77684a95eed679f486b474c251770c98 MD5 | raw file
Possible License(s): Apache-2.0, GPL-3.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, CPL-1.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include <stdio.h>
  18. #include <axiom.h>
  19. #include <axis2_util.h>
  20. #include <axiom_soap.h>
  21. #include <axis2_client.h>
  22. axiom_node_t *
  23. build_om_payload_for_echo_svc(const axutil_env_t *env);
  24. int main(int argc, char** argv)
  25. {
  26. const axutil_env_t *env = NULL;
  27. const axis2_char_t *address = NULL;
  28. axis2_endpoint_ref_t* endpoint_ref = NULL;
  29. axis2_options_t *options = NULL;
  30. const axis2_char_t *client_home = NULL;
  31. axis2_svc_client_t* svc_client = NULL;
  32. axiom_node_t *payload = NULL;
  33. axiom_node_t *ret_node = NULL;
  34. axiom_node_t *payload2 = NULL;
  35. axiom_node_t *ret_node2 = NULL;
  36. axutil_property_t *xmpp_jid = NULL;
  37. axutil_property_t *xmpp_password = NULL;
  38. axutil_property_t *xmpp_sasl = NULL;
  39. /*axutil_allocator_t *allocator = NULL;*/
  40. /* Set up the environment */
  41. env = axutil_env_create_all("echo.log", AXIS2_LOG_LEVEL_TRACE);
  42. /* Set end point reference of echo service */
  43. address = "xmpp://echo@localhost/axis2/services/echo";
  44. if (argc > 1)
  45. address = argv[1];
  46. if (axutil_strcmp(address, "-h") == 0)
  47. {
  48. printf("Usage : %s [endpoint_url]\n", argv[0]);
  49. printf("use -h for help\n");
  50. return 0;
  51. }
  52. printf("Using endpoint : %s\n", address);
  53. /* Create EPR with given address */
  54. endpoint_ref = axis2_endpoint_ref_create(env, address);
  55. /* Setup options */
  56. options = axis2_options_create(env);
  57. axis2_options_set_to(options, env, endpoint_ref);
  58. axis2_options_set_action(options, env,
  59. "http://ws.apache.org/axis2/c/samples/echoString");
  60. /* Set up deploy folder. It is from the deploy folder, the configuration is picked up
  61. * using the axis2.xml file.
  62. * In this sample client_home points to the Axis2/C default deploy folder. The client_home can
  63. * be different from this folder on your system. For example, you may have a different folder
  64. * (say, my_client_folder) with its own axis2.xml file. my_client_folder/modules will have the
  65. * modules that the client uses
  66. */
  67. client_home = AXIS2_GETENV("WSFCPP_HOME");
  68. if (!client_home || !strcmp (client_home, ""))
  69. client_home = "../..";
  70. /* Create service client */
  71. svc_client = axis2_svc_client_create(env, client_home);
  72. if (!svc_client)
  73. {
  74. printf("Error creating service client, Please check WSFCPP_HOME again\n");
  75. AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code:"
  76. " %d :: %s", env->error->error_number,
  77. AXIS2_ERROR_GET_MESSAGE(env->error));
  78. return -1;
  79. }
  80. /* Set service client options */
  81. xmpp_jid = axutil_property_create (env);
  82. axutil_property_set_value (xmpp_jid, env, (void *)axutil_strdup (env, "xyxmpp@xmpp.ws/Home"));
  83. axis2_options_set_property (options, env, "XMPP_JID", (void *)xmpp_jid);
  84. xmpp_password = axutil_property_create (env);
  85. axutil_property_set_value (xmpp_password, env, (void *)axutil_strdup (env, "123"));
  86. axis2_options_set_property (options, env, "XMPP_PASSWORD", (void *)xmpp_password);
  87. xmpp_sasl = axutil_property_create (env);
  88. axutil_property_set_value (xmpp_sasl, env, (void *)axutil_strdup (env, "true"));
  89. axis2_options_set_property (options, env, "XMPP_SASL", (void *)xmpp_sasl);
  90. axis2_svc_client_set_options(svc_client, env, options);
  91. /* Engage addressing module */
  92. axis2_svc_client_disengage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);
  93. /* Build the SOAP request message payload using OM API.*/
  94. payload = build_om_payload_for_echo_svc(env);
  95. /* Send request */
  96. ret_node = axis2_svc_client_send_receive(svc_client, env, payload);
  97. if (ret_node)
  98. {
  99. axis2_char_t *om_str = NULL;
  100. om_str = axiom_node_to_string(ret_node, env);
  101. if (om_str)
  102. printf("\nReceived OM : %s\n", om_str);
  103. printf("\necho client invoke SUCCESSFUL!\n");
  104. AXIS2_FREE(env->allocator, om_str);
  105. ret_node = NULL;
  106. }
  107. else
  108. {
  109. AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code:"
  110. " %d :: %s", env->error->error_number,
  111. AXIS2_ERROR_GET_MESSAGE(env->error));
  112. printf("echo client invoke FAILED!\n");
  113. }
  114. payload2 = build_om_payload_for_echo_svc(env);
  115. ret_node2 = axis2_svc_client_send_receive(svc_client, env, payload2);
  116. if (ret_node2)
  117. {
  118. axis2_char_t *om_str = NULL;
  119. om_str = axiom_node_to_string(ret_node2, env);
  120. if (om_str)
  121. printf("\nReceived OM : %s\n", om_str);
  122. printf("\necho client invoke SUCCESSFUL!\n");
  123. AXIS2_FREE(env->allocator, om_str);
  124. ret_node2 = NULL;
  125. }
  126. else
  127. {
  128. AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code:"
  129. " %d :: %s", env->error->error_number,
  130. AXIS2_ERROR_GET_MESSAGE(env->error));
  131. printf("echo client invoke FAILED!\n");
  132. }
  133. if (svc_client)
  134. {
  135. axis2_svc_client_free(svc_client, env);
  136. svc_client = NULL;
  137. }
  138. if (env)
  139. {
  140. axutil_env_free((axutil_env_t *) env);
  141. env = NULL;
  142. }
  143. return 0;
  144. }
  145. /* build SOAP request message content using OM */
  146. axiom_node_t *
  147. build_om_payload_for_echo_svc(const axutil_env_t *env)
  148. {
  149. axiom_node_t *echo_om_node = NULL;
  150. axiom_element_t* echo_om_ele = NULL;
  151. axiom_node_t* text_om_node = NULL;
  152. axiom_element_t * text_om_ele = NULL;
  153. axiom_namespace_t *ns1 = NULL;
  154. axis2_char_t *om_str = NULL;
  155. ns1 = axiom_namespace_create(env, "http://ws.apache.org/axis2/c/samples", "ns1");
  156. echo_om_ele = axiom_element_create(env, NULL, "echoString", ns1, &echo_om_node);
  157. text_om_ele = axiom_element_create(env, echo_om_node, "text", NULL, &text_om_node);
  158. axiom_element_set_text(text_om_ele, env, "Hello World!", text_om_node);
  159. om_str = axiom_node_to_string(echo_om_node, env);
  160. if (om_str)
  161. {
  162. printf("\nSending OM : %s\n", om_str);
  163. AXIS2_FREE(env->allocator, om_str);
  164. om_str = NULL;
  165. }
  166. return echo_om_node;
  167. }