int main( int argc, char **argv) { const axutil_env_t *env = NULL; 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; axiom_node_t *ret_node = NULL; const axis2_char_t *google_key = NULL; const axis2_char_t *word_to_spell = NULL; const axis2_char_t *operation = NULL; operation = "doSpellingSuggestion"; google_key = "00000000000000000000000000000000"; word_to_spell = "salvasion"; /* Set up the environment */ env = axutil_env_create_all("google_client.log", AXIS2_LOG_LEVEL_TRACE); /* Set end point reference of google service */ address = "http://api.google.com/search/beta2"; if ((argc > 1) && (axutil_strcmp("-h", argv[1]) == 0)) { printf("\nUsage : %s [google_key] [word_to_spell] \n", argv[0]); printf ("\tgoogle_key Your Google license key. Default value won't work. You must use your key here.\n"); printf ("\tword_to_spell Word to be spelled by Google service. Default is %s\n", word_to_spell); printf ("NOTE: command line arguments must appear in given order, with trailing ones being optional\n"); printf("\tUse -h for help\n"); return 0; } if (argc > 1) google_key = argv[1]; if (argc > 2) word_to_spell = argv[2]; if (argc > 3) address = argv[3]; printf("Using endpoint : %s\n", address); printf("\nInvoking operation %s with params %s and %s\n", operation, google_key, word_to_spell); /* Create EPR with given address */ endpoint_ref = axis2_endpoint_ref_create(env, address); /* Setup options */ options = axis2_options_create(env); axis2_options_set_to(options, env, endpoint_ref); axis2_options_set_soap_version(options, env, AXIOM_SOAP11); /* Set up deploy folder. */ client_home = AXIS2_GETENV("WSFC_HOME"); if (!client_home || !strcmp(client_home, "")) client_home = "../.."; /* Create service client */ svc_client = axis2_svc_client_create(env, client_home); if (!svc_client) { printf ("Error creating service client, Please check WSFC_HOME again\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 -1; } /* Set service client options */ axis2_svc_client_set_options(svc_client, env, options); /* Build the SOAP request message payload using OM API. */ payload = build_soap_body_content(env, operation, google_key, word_to_spell); /* Send request */ ret_node = axis2_svc_client_send_receive(svc_client, env, payload); if (axis2_svc_client_get_last_response_has_fault(svc_client, env)) { axiom_soap_envelope_t *soap_envelope = NULL; axiom_soap_body_t *soap_body = NULL; axiom_soap_fault_t *soap_fault = NULL; axis2_char_t *fault_string = NULL; printf("\nResponse has a SOAP fault\n"); soap_envelope = axis2_svc_client_get_last_response_soap_envelope(svc_client, env); if (soap_envelope) { soap_body = axiom_soap_envelope_get_body(soap_envelope, env); } if (soap_body) { soap_fault = axiom_soap_body_get_fault(soap_body, env); } if (soap_fault) { fault_string = axiom_node_to_string(axiom_soap_fault_get_base_node (soap_fault, env), env); printf("\nReturned SOAP fault: %s\n", fault_string); AXIS2_FREE (env->allocator, fault_string); } if (svc_client) { axis2_svc_client_free(svc_client, env); svc_client = NULL; } if (env) { axutil_env_free((axutil_env_t *) env); env = NULL; } return -1; } if (ret_node) { if (axiom_node_get_node_type(ret_node, env) == AXIOM_ELEMENT) { axis2_char_t *result = NULL; axiom_element_t *result_ele = NULL; axiom_node_t *ret_node1 = NULL; result_ele = (axiom_element_t *) axiom_node_get_data_element(ret_node, env); if (axutil_strcmp (axiom_element_get_localname(result_ele, env), "doSpellingSuggestionResponse") != 0) { print_invalid_om(env, ret_node); return AXIS2_FAILURE; } ret_node1 = axiom_node_get_first_element(ret_node, env); /*return */ if (!ret_node1) { print_invalid_om(env, ret_node); return AXIS2_FAILURE; } result_ele = (axiom_element_t *) axiom_node_get_data_element(ret_node1, env); result = axiom_element_get_text(result_ele, env, ret_node1); printf("\nResult = %s\n", result); } else { print_invalid_om(env, ret_node); return AXIS2_FAILURE; } } 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("Google client invoke FAILED!\n"); } if (svc_client) { axis2_svc_client_free(svc_client, env); svc_client = NULL; } if (env) { axutil_env_free((axutil_env_t *) env); env = NULL; } return 0; }
int main( int argc, char **argv) { axutil_env_t *env = NULL; 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; axiom_node_t *ret_node = NULL; axiom_element_t *ret_ele = NULL; axis2_char_t *om_str = NULL; axis2_char_t *result = NULL; const axis2_char_t *echo_operation = NULL; const axis2_char_t *word_to_echo = NULL; const axis2_char_t *echo_type = NULL; axis2_char_t operation[32]; axis2_char_t echo_response_buff[32]; echo_operation = "String"; word_to_echo = "helloworld"; echo_type = "string"; if ((argc > 1) && (axutil_strcmp("-h", argv[1]) == 0)) { printf("\nUsage : %s [echo_operation] [echo_value] [XSD_type]\n", argv[0]); printf("use -h for help\n"); return 0; } if (argc > 1) echo_operation = argv[1]; if (argc > 2) word_to_echo = argv[2]; if (argc > 3) echo_type = argv[3]; /* address = "http://localhost:7070/cgi-bin/interopserver"; */ address = "http://easysoap.sourceforge.net/cgi-bin/interopserver"; sprintf(operation, "echo%s", echo_operation); printf("Using endpoint : %s\n", address); printf("Invoking %s with param %s\n", operation, word_to_echo); /* Set up the environment */ env = axutil_env_create_all("echo.log", AXIS2_LOG_LEVEL_TRACE); /* Create EPR with given address */ endpoint_ref = axis2_endpoint_ref_create(env, address); options = axis2_options_create(env); axis2_options_set_to(options, env, endpoint_ref); /* this itest requried soap 1.1 message */ axis2_options_set_soap_version(options, env, AXIOM_SOAP11); client_home = 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, axutil_error_get_message(env->error)); } /* Set service client options */ axis2_svc_client_set_options(svc_client, env, options); payload = build_soap_body_content(env, echo_operation, echo_type, word_to_echo); /* Send request */ ret_node = axis2_svc_client_send_receive(svc_client, env, payload); if (ret_node) { om_str = AXIOM_NODE_TO_STRING(ret_node, env); if (om_str) printf("\nRecieving OM : %s\n", om_str); if (AXIOM_NODE_GET_NODE_TYPE(ret_node, env) == AXIOM_ELEMENT) { sprintf(echo_response_buff, "echo%sResponse", echo_operation); ret_ele = (axiom_element_t *) AXIOM_NODE_GET_DATA_ELEMENT(ret_node, env); if (axutil_strcmp (axiom_element_get_localname(ret_ele, env), echo_response_buff) != 0) { printf("%s != %s\n", axiom_element_get_localname(ret_ele, env), echo_response_buff); printf("\nFAIL\n\n"); return AXIS2_FAILURE; } ret_node = AXIOM_NODE_GET_FIRST_CHILD(ret_node, env); ret_ele = (axiom_element_t *) AXIOM_NODE_GET_DATA_ELEMENT(ret_node, env); result = axiom_element_get_text(ret_ele, env, ret_node); if (!strcmp(word_to_echo, result)) { printf("\nSUCCESS\n\n"); } else { printf("\nFAIL\n\n"); } } else { printf("\nFAIL\n\n"); return AXIS2_FAILURE; } } else { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Stub invoke FAILED: Error code:" " %d :: %s", env->error->error_number, axutil_error_get_message(env->error)); printf("round1 stub invoke FAILED!\n"); return AXIS2_FAILURE; } return AXIS2_SUCCESS; }