/* build SOAP request message content using OM */ axiom_node_t * build_om_payload_for_echo_svc( const axutil_env_t * env) { axiom_node_t *echo_om_node = NULL; axiom_element_t *echo_om_ele = NULL; axiom_node_t *text_om_node = NULL; axiom_element_t *text_om_ele = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *om_str = NULL; ns1 = axiom_namespace_create(env, "http://ws.apache.org/axis2/services/echo", "ns1"); echo_om_ele = axiom_element_create(env, NULL, "echoString", ns1, &echo_om_node); text_om_ele = axiom_element_create(env, echo_om_node, "text", NULL, &text_om_node); axiom_element_set_text(text_om_ele, env, "Hello World!", text_om_node); om_str = axiom_node_to_string(echo_om_node, env); if (om_str) printf("\nSending OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); return echo_om_node; }
axiom_node_t * generate_request_xml( const axutil_env_t * env) { axiom_node_t *op_node = NULL; axiom_element_t *op_ele = NULL; axiom_node_t *value_node = NULL; axiom_element_t *value_ele = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *om_str = NULL; int value1 = 13; int value2 = 7; char value_str[64]; ns1 = axiom_namespace_create(env, "http://localhost/axis/Calculator", "ns1"); op_ele = axiom_element_create(env, NULL, "add", ns1, &op_node); value_ele = axiom_element_create(env, op_node, "in1", NULL, &value_node); sprintf(value_str, "%d", value1); axiom_element_set_text(value_ele, env, value_str, value_node); value_ele = axiom_element_create(env, op_node, "in2", NULL, &value_node); sprintf(value_str, "%d", value1); axiom_element_set_text(value_ele, env, value_str, value_node); printf("requesting %d + %d \n", value1, value2); om_str = axiom_node_to_string(op_node, env); if (om_str) printf("\nSending OM : %s\n", om_str); return op_node; }
/* build SOAP request message content using OM */ axiom_node_t * build_om_payload_for_echo_svc( const axutil_env_t *env) { axiom_node_t *echo_om_node = NULL; axiom_element_t* echo_om_ele = NULL; axiom_node_t* text_om_node = NULL; axiom_element_t * text_om_ele = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *om_str = NULL; ns1 = axiom_namespace_create(env, "http://ws.apache.org/rampart/c/samples", "ns1"); /*ns1 = axiom_namespace_create(env, "http://echo.services.wsas.wso2.org", "ns1");*/ echo_om_ele = axiom_element_create(env, NULL, "echoIn", ns1, &echo_om_node); text_om_ele = axiom_element_create(env, echo_om_node, "text", NULL, &text_om_node); axiom_element_set_text(text_om_ele, env, "Hello", text_om_node); om_str = axiom_node_to_string(echo_om_node, env); if(om_str) { printf("\nSending OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); om_str = NULL; } return echo_om_node; }
axis2_status_t AXIS2_CALL axutil_log_out_handler_invoke( struct axis2_handler * handler, const axutil_env_t * env, struct axis2_msg_ctx * msg_ctx) { axiom_soap_envelope_t *soap_envelope = NULL; axiom_node_t *ret_node = NULL; AXIS2_ENV_CHECK(env, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE); AXIS2_LOG_INFO(env->log, "Starting logging out handler ........."); soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env); if (soap_envelope) { ret_node = axiom_soap_envelope_get_base_node(soap_envelope, env); if (ret_node) { axis2_char_t *om_str = NULL; om_str = axiom_node_to_string(ret_node, env); if (om_str) { AXIS2_LOG_INFO(env->log, "Output message: %s", om_str); } } } return AXIS2_SUCCESS; }
char *test_endpoint_serialize() { axiom_namespace_t *ns = NULL; axiom_node_t *subs_node = NULL; axiom_element_t *subs_elem = NULL; axiom_node_t *endpoint_node = NULL; axiom_element_t *endpoint_elem = NULL; axiom_node_t *addr_node = NULL; axiom_element_t *addr_elem = NULL; axiom_attribute_t *url_attr = NULL; char *content = NULL; const axutil_env_t *env = NULL; axis2_char_t *nsurl = "http://ws.apache.org/ns/synapse"; axis2_char_t *ns_prefix = "syn"; axis2_char_t *notifyto = "http://localhost:9000/services/SimpleStockQuoteService"; env = axutil_env_create_all("test.log", AXIS2_LOG_LEVEL_TRACE); /* Format of the message is as * <subscription><syn:endpoint xmlns:syn="http://ws.apache.org/ns/synapse"><syn:address uri= * "http://localhost:9000/services/SimpleStockQuoteService" /></syn:endpoint></subscription> */ printf("\ncontent1:<subscription><syn:endpoint xmlns:syn=\"http://ws.apache.org/ns/synapse\"><syn:address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" /></syn:endpoint></subscription>"); ns = axiom_namespace_create (env, nsurl, ns_prefix); subs_elem = axiom_element_create(env, NULL, "subscription", NULL, &subs_node); endpoint_elem = axiom_element_create(env, subs_node, "endpoint", ns, &endpoint_node); addr_elem = axiom_element_create(env, endpoint_node, "address", ns, &addr_node); url_attr = axiom_attribute_create(env, "url", notifyto, NULL); axiom_element_add_attribute(addr_elem, env, url_attr, addr_node); content = (char *) axiom_node_to_string(subs_node, env); printf("\n\ncontent2:%s\n\n", content); return content; }
/* build SOAP request message content using OM */ axiom_node_t * build_om_programatically( const axutil_env_t *env, axis2_char_t *text, axis2_char_t *seq) { axiom_node_t *ping_om_node = NULL; axiom_element_t* ping_om_ele = NULL; axiom_node_t *text_om_node = NULL; axiom_element_t* text_om_ele = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *buffer = NULL; axiom_node_t* seq_om_node = NULL; axiom_element_t * seq_om_ele = NULL; ns1 = axiom_namespace_create (env, "http://tempuri.org/", "ns1"); ping_om_ele = axiom_element_create(env, NULL, "ping", ns1, &ping_om_node); text_om_ele = axiom_element_create(env, ping_om_node, "Text", ns1, &text_om_node); seq_om_ele = axiom_element_create(env, ping_om_node, "Sequence", ns1, &seq_om_node); axiom_element_set_text(text_om_ele, env, text, text_om_node); axiom_element_set_text(text_om_ele, env, seq, seq_om_node); buffer = axiom_node_to_string(ping_om_node, env); if(buffer) { printf("\nSending OM node in XML : %s \n", buffer); AXIS2_FREE(env->allocator, buffer); } return ping_om_node; }
axis2_status_t verify(axutil_env_t *env, axis2_char_t *filename, openssl_pkey_t *prvkey , oxs_x509_cert_t *cert) { oxs_sign_ctx_t *sign_ctx = NULL; axiom_node_t *tmpl = NULL; axis2_status_t status = AXIS2_FAILURE; tmpl = load_sample_xml(env , tmpl, filename); printf("File : \n%s\n", axiom_node_to_string(tmpl, env)); sign_ctx = oxs_sign_ctx_create(env); if(sign_ctx){ axiom_node_t *sig_node = NULL; /*Set the operation*/ oxs_sign_ctx_set_operation(sign_ctx, env, OXS_SIGN_OPERATION_VERIFY); sig_node = oxs_axiom_get_first_child_node_by_name(env, tmpl, OXS_NODE_SIGNATURE, OXS_DSIG_NS, OXS_DS ); if(!sig_node){ printf("Verification : Cannot find ds:Signature node\n"); return AXIS2_FAILURE; } /**If the certificate is not given check key information*/ if(!cert){ axiom_node_t *ki_node = NULL; axiom_node_t *x509_node = NULL; ki_node = oxs_axiom_get_first_child_node_by_name(env, sig_node, OXS_NODE_KEY_INFO, OXS_DSIG_NS, OXS_DS); x509_node = oxs_axiom_get_first_child_node_by_name(env, ki_node, OXS_NODE_X509_DATA, OXS_DSIG_NS, OXS_DS); cert = oxs_x509_cert_create(env); printf("No certificate is given. Fetching certificate from the KeyInfo\n"); status = oxs_xml_key_process_X509Data(env, x509_node, cert); if(AXIS2_FAILURE == status){ printf("Error reading KeyInfo\n"); return AXIS2_FAILURE; } } /*Set certificate*/ if(cert){ oxs_sign_ctx_set_certificate(sign_ctx, env, cert); }else{ printf("Certificate is NULL\n"); return AXIS2_FAILURE; } /*Verify*/ status = oxs_xml_sig_verify(env, sign_ctx, sig_node, tmpl); if(AXIS2_SUCCESS != status){ printf("\nSignature Failed :-(\n"); }else{ printf("\nSignature Verified :-)\n"); } } return status; }
axiom_node_t* ajSoapAxis2Call(axis2_svc_client_t *client, const axutil_env_t *env, axiom_node_t *payload) { axiom_node_t *ret_node = NULL; axis2_char_t * om_str = NULL; if (ajDebugOn()) { om_str = axiom_node_to_string(payload, env); if (om_str) { ajDebug("\nSending OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); om_str = NULL; } } /* Send request */ ret_node = axis2_svc_client_send_receive(client, env, payload); if (ret_node) { if(ajDebugOn()) { om_str = axiom_node_to_string(ret_node, env); if (om_str) ajDebug("\nReceived OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); om_str = NULL; } } else { ajDebug("seqAxis2wsCall: webservice call failed: %s\n", AXIS2_ERROR_GET_MESSAGE(env->error)); ajErr("webservice call FAILED: %s\n", AXIS2_ERROR_GET_MESSAGE(env->error)); } return ret_node; }
axiom_node_t * build_soap_body_content( const axutil_env_t * env, const axis2_char_t * operation, const axis2_char_t * google_key, const axis2_char_t * word_to_spell) { axiom_node_t *google_om_node = NULL; axiom_element_t *google_om_ele = NULL; axiom_node_t *text_om_node = NULL; axiom_element_t *text_om_ele = NULL; axiom_namespace_t *ns0 = NULL, *ns1 = NULL, *ns2 = NULL, *ns3 = NULL; axiom_attribute_t *attri1 = NULL; axis2_char_t *buffer = NULL; ns0 = axiom_namespace_create(env, AXIOM_SOAP11_SOAP_ENVELOPE_NAMESPACE_URI, "soapenv"); ns1 = axiom_namespace_create(env, "urn:GoogleSearch", "ns1"); ns2 = axiom_namespace_create(env, "http://www.w3.org/1999/XMLSchema-instance", "xsi"); ns3 = axiom_namespace_create(env, "http://www.w3.org/1999/XMLSchema", "xsd"); attri1 = axiom_attribute_create(env, "encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/", ns0); google_om_ele = axiom_element_create(env, NULL, operation, ns1, &google_om_node); axiom_element_add_attribute(google_om_ele, env, attri1, google_om_node); axiom_element_declare_namespace(google_om_ele, env, google_om_node, ns2); axiom_element_declare_namespace(google_om_ele, env, google_om_node, ns3); text_om_ele = axiom_element_create(env, google_om_node, "key", NULL, &text_om_node); attri1 = axiom_attribute_create(env, "type", "xsd:string", ns2); axiom_element_add_attribute(text_om_ele, env, attri1, text_om_node); axiom_element_set_text(text_om_ele, env, google_key, text_om_node); text_om_ele = axiom_element_create(env, google_om_node, "phrase", NULL, &text_om_node); axiom_element_add_attribute(text_om_ele, env, attri1, text_om_node); axiom_element_set_text(text_om_ele, env, word_to_spell, text_om_node); buffer = axiom_node_to_string(google_om_node, env); printf("%s\n", buffer); AXIS2_FREE (env->allocator, buffer); return google_om_node; }
axiom_node_t * axis2_listener_notify(const axutil_env_t *env, axiom_node_t *node) { axiom_node_t *pres_node = NULL; axiom_node_t *status_node = NULL; axiom_element_t *body_elem = NULL; axiom_element_t *pres_elem = NULL; axiom_element_t *status_elem = NULL; axiom_attribute_t *attr_from = NULL; axutil_qname_t *qname= NULL; axis2_char_t *str = NULL; axis2_char_t *from = NULL; axis2_char_t *status = NULL; AXIS2_ENV_CHECK(env, NULL); str = axiom_node_to_string(node, env); body_elem = axiom_node_get_data_element(node, env); qname = axutil_qname_create(env, "presence", NULL, NULL); pres_elem = axiom_element_get_first_child_with_qname(body_elem, env, qname, node, &pres_node); axutil_qname_free(qname, env); if (pres_elem) { qname = axutil_qname_create(env, "from", NULL, NULL); attr_from = axiom_element_get_attribute(pres_elem, env, qname); axutil_qname_free(qname, env); if (attr_from) { from = axiom_attribute_get_value(attr_from, env); } qname = axutil_qname_create(env, "status", NULL, NULL); status_elem = axiom_element_get_first_child_with_qname(pres_elem, env, qname, pres_node, &status_node); axutil_qname_free(qname, env); if (status_elem) { status = axiom_element_get_text(status_elem, env, status_node); } } printf("\n************************************************************\n"); printf("Received presence notification:\n\n"); printf("From: %s\n", from); printf("Status: %s\n", status); printf("\nFull notification:\n%s\n\n", str); return NULL; }
axis2_status_t AXIS2_CALL echo_process_response_envelope( struct axis2_callback * callback, const axutil_env_t * env) { /** SOAP response has arrived here; get the soap envelope from the callback object and do whatever you want to do with it */ axiom_soap_envelope_t *soap_envelope = NULL; axiom_node_t *ret_node = NULL; axis2_status_t status = AXIS2_SUCCESS; soap_envelope = axis2_callback_get_envelope(callback, env); if (!soap_envelope) { 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("echo stub invoke FAILED!\n"); status = AXIS2_FAILURE; } else { ret_node = axiom_soap_envelope_get_base_node(soap_envelope, env); if (!ret_node) { 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("echo stub invoke FAILED!\n"); status = AXIS2_FAILURE; } else { axis2_char_t *om_str = NULL; om_str = axiom_node_to_string(ret_node, env); if (om_str) { printf("\nReceived OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); } printf("\necho client invoke SUCCESSFUL!\n"); } } return status; }
/* build SOAP request message content using OM */ axiom_node_t * build_om_programatically_mtom( const axutil_env_t * env) { axiom_node_t *mtom_om_node = NULL; axiom_element_t *mtom_om_ele = NULL; axiom_node_t *image_om_node = NULL; axiom_element_t *image_om_ele = NULL; axiom_node_t *file_om_node = NULL; axiom_element_t *file_om_ele = NULL; axiom_node_t *data_om_node = NULL; axiom_text_t *data_text = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *om_str = NULL; const axis2_char_t *image_name = "E:/src/C/Axis2C/build/deploy/samples/bin/resources/axis2.jpg"; const axis2_char_t *to_save_name = "test.jpg"; axis2_bool_t optimized = AXIS2_TRUE; axiom_data_handler_t *data_handler = NULL; ns1 = axiom_namespace_create(env, "http://ws.apache.org/axis2/c/samples/mtom", "ns1"); mtom_om_ele = axiom_element_create(env, NULL, "mtomSample", ns1, &mtom_om_node); file_om_ele = axiom_element_create(env, mtom_om_node, "fileName", ns1, &file_om_node); axiom_element_set_text(file_om_ele, env, to_save_name, file_om_node); image_om_ele = axiom_element_create(env, mtom_om_node, "image", ns1, &image_om_node); /* This is when we directly give file name */ data_handler = axiom_data_handler_create(env, image_name, "image/jpeg"); /* Uncomment following to set a callback instead of a file */ /*data_handler = axiom_data_handler_create(env, NULL, "image/jpeg"); axiom_data_handler_set_data_handler_type(data_handler, env, AXIOM_DATA_HANDLER_TYPE_CALLBACK); axiom_data_handler_set_user_param(data_handler, env, (void *)image_name);*/ data_text = axiom_text_create_with_data_handler(env, image_om_node, data_handler, &data_om_node); axiom_text_set_optimize(data_text, env, optimized); /*axiom_text_set_is_swa(data_text, env, AXIS2_TRUE);*/ om_str = axiom_node_to_string(mtom_om_node, env); if(om_str) { printf("%s", om_str); AXIS2_FREE(env->allocator, om_str); } return mtom_om_node; }
axiom_node_t * axis2_listener_notify(const axutil_env_t *env, axiom_node_t *node) { axis2_char_t *str = NULL; AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Start:axis2_listener_notify"); AXIS2_ENV_CHECK(env, NULL); str = axiom_node_to_string(node, env); if (str) printf("\nReceived : %s\n", str); AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "End:axis2_listener_notify"); return NULL; }
int main( int argc, char **argv) { axis2_status_t status = AXIS2_FAILURE; int i = 0; axutil_array_list_t *policy_list = NULL; axutil_array_list_t *policy_node_list = NULL; neethi_policy_t *resultant = NULL; axutil_allocator_t *allocator = axutil_allocator_init(NULL); axutil_error_t *error = axutil_error_create(allocator); const axutil_env_t *env = axutil_env_create_with_error(allocator, error); policy_list = axutil_array_list_create(env, 0); policy_node_list = axutil_array_list_create(env, 0); get_all_policy(argv[1], env, policy_node_list, argv[2]); for (i = 0; i < axutil_array_list_size(policy_node_list, env); i++) { axiom_node_t *node = NULL; node = (axiom_node_t *) axutil_array_list_get(policy_node_list, env, i); status = load_policy_array(policy_list, node, env); } resultant = merge_policylist(policy_list, env); if (!resultant) { printf("Error Merging\n"); return 0; } else { axiom_node_t *s_node = NULL; axis2_char_t *buff = NULL; s_node = neethi_engine_serialize(resultant, env); if (!s_node) { printf("Serializing failed\n"); return 0; } buff = axiom_node_to_string(s_node, env); printf("\n%s", buff); } printf("Successful\n"); return 0; }
AXIS2_EXTERN axis2_bool_t AXIS2_CALL savan_xpath_filter_mod_apply( savan_filter_mod_t *filtermod, const axutil_env_t *env, savan_subscriber_t *subscriber, axiom_node_t *payload) { axis2_char_t *payload_string = NULL; xmlDocPtr payload_doc = NULL; xsltStylesheetPtr xslt_template_filter = NULL; xmlChar *xfilter = NULL; xmlDocPtr result_doc; savan_xpath_filter_mod_t *filtermodimpl = NULL; filtermodimpl = SAVAN_INTF_TO_IMPL(filtermod); AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[savan] Entry:savan_xpath_filter_mod_apply"); xfilter = (xmlChar *) savan_subscriber_get_filter(subscriber, env); if(!xfilter) { return AXIS2_FALSE; } payload_string = axiom_node_to_string(payload, env); AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[savan] payload_string before applying filter %s:%s", xfilter, payload_string); payload_doc = (xmlDocPtr)xmlParseDoc((xmlChar*)payload_string); xslt_template_filter = (xsltStylesheetPtr) savan_xpath_filter_mod_get_filter_template(env, filtermodimpl->filter_template_path, xfilter); result_doc = (xmlDocPtr)xsltApplyStylesheet(xslt_template_filter, payload_doc, NULL); if(result_doc) { /*free(payload_string);*/ /* In apache freeing this give seg fault:damitha */ xmlFreeDoc(result_doc); return AXIS2_TRUE; } AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[savan] Exit:savan_xpath_filter_mod_apply"); return AXIS2_FALSE; }
/* build SOAP request message content using OM */ axiom_node_t * build_om_programatically( const axutil_env_t * env, const axis2_char_t * attachment_name) { axiom_node_t *mtom_om_node = NULL; axiom_element_t *mtom_om_ele = NULL; axiom_node_t *attachment_om_node = NULL; axiom_element_t *attachment_om_ele = NULL; axiom_node_t *data_om_node = NULL; axiom_text_t *data_text = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *om_str = NULL; axiom_data_handler_t *data_handler = NULL; ns1 = axiom_namespace_create(env, "http://ws.apache.org/axis2/c/samples/mtom", "ns1"); mtom_om_ele = axiom_element_create(env, NULL, "mtomSample", ns1, &mtom_om_node); attachment_om_ele = axiom_element_create(env, mtom_om_node, "attachment", ns1, &attachment_om_node); /* The attachment is loaded using the callback. The callback should be * specified in the axis2.xml */ data_handler = axiom_data_handler_create(env, NULL, "image/jpeg"); axiom_data_handler_set_data_handler_type(data_handler, env, AXIOM_DATA_HANDLER_TYPE_CALLBACK); axiom_data_handler_set_user_param(data_handler, env, (void *)attachment_name); data_text = axiom_text_create_with_data_handler(env, attachment_om_node, data_handler, &data_om_node); axiom_text_set_optimize(data_text, env, AXIS2_TRUE); om_str = axiom_node_to_string(mtom_om_node, env); if (om_str) { printf("%s", om_str); AXIS2_FREE(env->allocator, om_str); } return mtom_om_node; }
axis2_char_t* wsdl_util_create_request_envelope( const axutil_env_t *env, axiom_node_t *payload, int soap_version) { axiom_soap_envelope_t* envelope = NULL; axiom_soap_header_t* header = NULL; axiom_soap_body_t* body = NULL; axiom_node_t* envelope_node = NULL; if ((soap_version == AXIOM_SOAP11) || (soap_version == AXIOM_SOAP12)) { envelope = axiom_soap_envelope_create_with_soap_version_prefix(env, soap_version, AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX); } else { AXIS2_LOG_DEBUG_MSG(env->log, "Unknown SOAP version"); } header = axiom_soap_header_create_with_parent(env, envelope); if (!header) { return NULL; } body = axiom_soap_body_create_with_parent(env, envelope); if (!body) { return NULL; } if (payload) { axiom_soap_body_add_child(body, env, payload); } envelope_node = axiom_soap_envelope_get_base_node(envelope, env); return axiom_node_to_string(envelope_node, env); }
axiom_node_t * AXIS2_CALL create_key_info(const axutil_env_t *env, rampart_saml_token_t *saml) { axiom_node_t *key_info = NULL; oxs_key_t *session_key = NULL; axis2_status_t status = AXIS2_FAILURE; oxs_asym_ctx_t * asym_ctx = NULL; axis2_char_t *key_info_str = NULL; oxs_x509_cert_t *cert = NULL; /* Set the receiver certificate file. This public key will be used to encrypt the session key.*/ axis2_char_t *certificate_file = axutil_stracat(env, axis2c_home, RECEIVER_CERTIFICATE_FILE); session_key = oxs_key_create(env); status = oxs_key_for_algo(session_key, env, NULL); key_info = oxs_token_build_key_info_element(env, NULL); /* Create the asym_ctx_t and populate it.*/ asym_ctx = oxs_asym_ctx_create(env); oxs_asym_ctx_set_algorithm(asym_ctx, env, OXS_HREF_RSA_PKCS1); oxs_asym_ctx_set_operation(asym_ctx, env, OXS_ASYM_CTX_OPERATION_PUB_ENCRYPT); cert = oxs_key_mgr_load_x509_cert_from_pem_file(env, certificate_file); if (!cert) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Certificate cannot be loaded"); return NULL; } oxs_asym_ctx_set_certificate(asym_ctx, env, cert); status = oxs_xml_enc_encrypt_key(env, asym_ctx, key_info, session_key, NULL); rampart_saml_token_set_session_key(saml, env, session_key); key_info_str = axiom_node_to_string(key_info, env); return key_info; }
axis2_char_t * wsf_util_get_soap_msg_from_op_client ( axis2_op_client_t * op_client, axutil_env_t * env, axis2_wsdl_msg_labels_t msg_label) { if (op_client) { axiom_soap_envelope_t *soap_env = NULL; const axis2_msg_ctx_t *msg_ctx = NULL; axiom_node_t *node = NULL; msg_ctx = axis2_op_client_get_msg_ctx (op_client, env, msg_label); if (!msg_ctx) return NULL; soap_env = axis2_msg_ctx_get_soap_envelope (msg_ctx, env); if (!soap_env) return NULL; node = axiom_soap_envelope_get_base_node (soap_env, env); return axiom_node_to_string (node, env); } return NULL; }
/* build SOAP request message content using OM (for java interop)*/ axiom_node_t * build_om_payload_for_echo_svc_interop( const axutil_env_t *env) { axiom_node_t *ping_request_om_node = NULL; axiom_element_t* ping_request_om_ele = NULL; axiom_node_t *ping_om_node = NULL; axiom_element_t* ping_om_ele = NULL; axiom_node_t* text_om_node = NULL; axiom_element_t * text_om_ele = NULL; axiom_namespace_t *ns1 = NULL; axiom_namespace_t *ns0 = NULL; axis2_char_t *om_str = NULL; ns0 = axiom_namespace_create(env, "http://InteropBaseAddress/interop", "ns0"); ns1 = axiom_namespace_create(env, "http://xmlsoap.org/Ping", "ns1"); ping_request_om_ele = axiom_element_create(env, NULL, "PingRequest", ns0, &ping_request_om_node); ping_om_ele = axiom_element_create(env, ping_request_om_node, "Ping", ns1, &ping_om_node); text_om_ele = axiom_element_create(env, ping_om_node, "scenario", ns1, &text_om_node); axiom_element_set_text(text_om_ele, env, "scenario", text_om_node); text_om_node = NULL; text_om_ele = axiom_element_create(env, ping_om_node, "origin", ns1, &text_om_node); axiom_element_set_text(text_om_ele, env, "origin", text_om_node); text_om_node = NULL; text_om_ele = axiom_element_create(env, ping_om_node, "text", ns1, &text_om_node); axiom_element_set_text(text_om_ele, env, "text", text_om_node); om_str = axiom_node_to_string(ping_request_om_node, env); if(om_str) { printf("\nSending OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); om_str = NULL; } return ping_request_om_node; }
/* build SOAP request message content using OM */ axiom_node_t * build_om_payload_for_echo_svc(const axutil_env_t *env) { axiom_node_t *echo_om_node = NULL; axiom_element_t* echo_om_ele = NULL; axiom_node_t* text_om_node = NULL; axiom_element_t * text_om_ele = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *om_str = NULL; ns1 = axiom_namespace_create(env, "http://ws.apache.org/axis2/c/samples", "ns1"); echo_om_ele = axiom_element_create(env, NULL, "echoString", ns1, &echo_om_node); text_om_ele = axiom_element_create(env, echo_om_node, "text", NULL, &text_om_node); axiom_element_set_text(text_om_ele, env, "echo5", text_om_node); om_str = axiom_node_to_string(echo_om_node, env); if (om_str) { AXIS2_FREE(env->allocator, om_str); om_str = NULL; } return echo_om_node; }
/* build SOAP request message content using OM */ axiom_node_t * build_om_programatically( const axutil_env_t * env) { axiom_node_t *notify_om_node = NULL; axiom_element_t *notify_om_ele = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *buffer = NULL; ns1 = axiom_namespace_create(env, "http://example.org/notify", "m"); notify_om_ele = axiom_element_create(env, NULL, "notify", ns1, ¬ify_om_node); axiom_element_set_text(notify_om_ele, env, "notify5", notify_om_node); buffer = axiom_node_to_string(notify_om_node, env); if (buffer) { printf("\nSending OM node in XML : %s \n", buffer); AXIS2_FREE(env->allocator, buffer); } return notify_om_node; }
WSF_WSDL_EXTERN axis2_bool_t WSF_WSDL_CALL wsf_wsdl_request( const axutil_env_t* env, axis2_char_t* wsdl_file_name, const axis2_char_t* operation_name, wsf_wsdl_data_t* parameters, axis2_char_t* script_binding_home, axis2_svc_client_t* svc_client, axutil_hash_t* svc_client_user_options, axis2_char_t* service_name, axis2_char_t* port_name, wsf_wsdl_data_t** response) { int soap_version = 2; int has_fault = AXIS2_FALSE; int binding_style = WSDL_BINDING_STYLE_DOC_LIT_W; axis2_char_t* payload = NULL; axiom_node_t* payload_node = NULL; axis2_char_t* request_buffer = NULL; axiom_node_t* type_map = NULL; axis2_char_t *res_text = NULL; axiom_node_t* sig_axiom = NULL; axiom_node_t *fault_node = NULL; axiom_node_t* wsdl_axiom = NULL; axiom_node_t* params_node = NULL; axiom_node_t* returns_node = NULL; axiom_soap_body_t *soap_body = NULL; axiom_node_t *body_base_node = NULL; /*axis2_char_t *wrapper_element = NULL;*/ axiom_node_t* operation_axiom = NULL; axiom_soap_fault_t *soap_fault = NULL; axis2_options_t *client_options = NULL; /*axis2_char_t *wrapper_element_ns = NULL;*/ /*axiom_node_t *axiom_soap_base_node = NULL; */ axiom_soap_envelope_t *response_envelope = NULL; wsf_wsdl_data_template_t* input_template = NULL; wsf_wsdl_data_template_t* output_template = NULL; axis2_bool_t is_version1_wsdl = AXIS2_FALSE; axis2_char_t* xslt_location = NULL; axis2_char_t* type_map_file = NULL; AXIS2_LOG_TRACE_MSG(env->log, "Starting execution of wsf_wsdl_request..."); xslt_location = axutil_strcat(env, script_binding_home, WSF_WSDL_XSLT_LOCATION_POSTFIX, NULL); type_map_file = axutil_strcat(env, script_binding_home, WSF_WSDL_TYPE_MAP_POSTFIX, NULL); client_options = (axis2_options_t *)axis2_svc_client_get_options(svc_client, env); axis2_options_set_xml_parser_reset(client_options, env, AXIS2_FALSE); if (!wsf_wsdl_parser_load_wsdl(env, wsdl_file_name, xslt_location, &wsdl_axiom, &sig_axiom, &is_version1_wsdl, AXIS2_FALSE)) return AXIS2_FALSE; wsdl_util_create_type_map(env, type_map_file, &type_map); wsdl_util_manage_client_options(env, svc_client, svc_client_user_options, client_options, operation_name, wsdl_axiom, is_version1_wsdl, sig_axiom, service_name, port_name, &operation_axiom, &soap_version); wsdl_util_identify_binding_style(env, operation_axiom, &binding_style); if (!operation_axiom) { AXIS2_LOG_ERROR_MSG(env->log, "Operation axiom is NULL"); if (wsdl_axiom) axiom_node_free_tree(wsdl_axiom, env); if (sig_axiom) axiom_node_free_tree(sig_axiom, env); if (type_map) axiom_node_free_tree(type_map, env); return AXIS2_FALSE; } wsdl_util_get_params_node(env, operation_axiom, ¶ms_node); wsdl_util_get_returns_node(env, operation_axiom, &returns_node); wsdl_data_util_axiom_to_template(env, params_node, &input_template); wsdl_data_util_axiom_to_template(env, returns_node, &output_template); #ifdef WSDL_DEBUG_MODE { axis2_char_t* buffer = NULL; wsdl_data_util_serialize_data(env, parameters, &buffer); AXIS2_LOG_DEBUG_MSG(env->log, buffer); AXIS2_FREE(env->allocator, buffer); wsdl_data_util_serialize_template(env, input_template, &buffer); AXIS2_LOG_DEBUG_MSG(env->log, buffer); AXIS2_FREE(env->allocator, buffer); buffer = NULL; } #endif if (wsdl_data_util_validate_data(env, type_map, input_template, parameters, VALIDATION_CRITERIA_REQUEST_MODE_TYPE) == AXIS2_TRUE) { payload_node = wsdl_data_util_create_payload(env, parameters, binding_style); payload = payload_node? axiom_node_to_string(payload_node, env) : NULL; // axiom_node_free_tree(payload_node, env); } else { AXIS2_LOG_ERROR_MSG(env->log, "User data is not valid or not in proper format"); if (input_template) wsdl_data_template_free(env, input_template); if (output_template) wsdl_data_template_free(env, output_template); if (wsdl_axiom) axiom_node_free_tree(wsdl_axiom, env); if (sig_axiom) axiom_node_free_tree(sig_axiom, env); if (type_map) axiom_node_free_tree(type_map, env); return AXIS2_FALSE; } if (!payload_node) { AXIS2_LOG_ERROR_MSG(env->log, "Request payload is not found"); if (input_template) wsdl_data_template_free(env, input_template); if (output_template) wsdl_data_template_free(env, output_template); if (wsdl_axiom) axiom_node_free_tree(wsdl_axiom, env); if (sig_axiom) axiom_node_free_tree(sig_axiom, env); if (type_map) axiom_node_free_tree(type_map, env); return AXIS2_FALSE; } request_buffer = (axis2_char_t*)wsdl_util_create_request_envelope(env, payload_node, soap_version); if (!request_buffer) { AXIS2_LOG_ERROR_MSG(env->log, "Error in creating request payload dom"); if (input_template) wsdl_data_template_free(env, input_template); if (output_template) wsdl_data_template_free(env, output_template); if (wsdl_axiom) axiom_node_free_tree(wsdl_axiom, env); if (sig_axiom) axiom_node_free_tree(sig_axiom, env); if (type_map) axiom_node_free_tree(type_map, env); return AXIS2_FALSE; } response_envelope = (axiom_soap_envelope_t*)wsdl_util_send_receive_soap_envelope_with_op_client(env, svc_client, client_options, request_buffer); if (response_envelope) { has_fault = AXIS2_TRUE; soap_body = axiom_soap_envelope_get_body (response_envelope, env); if (soap_body) { soap_fault = axiom_soap_body_get_fault (soap_body, env); } if (soap_fault) { soap_version = axis2_options_get_soap_version(client_options, env); fault_node = axiom_soap_fault_get_base_node(soap_fault, env); if (fault_node) { res_text = axiom_node_to_string(fault_node, env); AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "Fault payload is %s", res_text); if (input_template) wsdl_data_template_free(env, input_template); if (output_template) wsdl_data_template_free(env, output_template); if (wsdl_axiom) axiom_node_free_tree(wsdl_axiom, env); if (sig_axiom) axiom_node_free_tree(sig_axiom, env); if (type_map) axiom_node_free_tree(type_map, env); return AXIS2_FALSE; } } if (soap_body) { body_base_node = axiom_soap_body_get_base_node(soap_body, env); } if (body_base_node && !soap_fault) { axis2_char_t *response_buffer = NULL; wsf_wsdl_data_t *response_data = NULL; response_buffer = axiom_node_to_string(body_base_node, env); AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "Response buffer is %s", response_buffer); AXIS2_FREE(env->allocator, response_buffer); wsdl_data_util_axiom_to_data(env, body_base_node, &response_data); #ifdef WSDL_DEBUG_MODE { axis2_char_t* buffer = NULL; wsdl_data_util_serialize_data(env, response_data, &buffer); AXIS2_LOG_DEBUG_MSG(env->log, buffer); AXIS2_FREE(env->allocator, buffer); wsdl_data_util_serialize_template(env, output_template, &buffer); AXIS2_LOG_DEBUG_MSG(env->log, buffer); AXIS2_FREE(env->allocator, buffer); buffer = NULL; } #endif if (wsdl_data_util_validate_data(env, type_map, output_template, response_data, VALIDATION_CRITERIA_RESPONSE_MODE) == AXIS2_TRUE) { AXIS2_LOG_DEBUG_MSG(env->log, "Valid response!!!"); *response = response_data; if (input_template) wsdl_data_template_free(env, input_template); if (output_template) wsdl_data_template_free(env, output_template); if (wsdl_axiom) axiom_node_free_tree(wsdl_axiom, env); if (sig_axiom) axiom_node_free_tree(sig_axiom, env); if (type_map) axiom_node_free_tree(type_map, env); return AXIS2_TRUE; } else { AXIS2_LOG_ERROR_MSG(env->log, "Response data is not valid or not in proper format"); if (input_template) wsdl_data_template_free(env, input_template); if (output_template) wsdl_data_template_free(env, output_template); if (wsdl_axiom) axiom_node_free_tree(wsdl_axiom, env); if (sig_axiom) axiom_node_free_tree(sig_axiom, env); if (type_map) axiom_node_free_tree(type_map, env); return AXIS2_FALSE; } } } else /* response_envelope == NULL */ { AXIS2_LOG_ERROR_MSG(env->log, "Response envelope not found"); } if (input_template) wsdl_data_template_free(env, input_template); if (output_template) wsdl_data_template_free(env, output_template); if (wsdl_axiom) axiom_node_free_tree(wsdl_axiom, env); if (sig_axiom) axiom_node_free_tree(sig_axiom, env); if (type_map) axiom_node_free_tree(type_map, env); return AXIS2_FALSE; }
axiom_node_t* AXIS2_CALL adb_TransformTypeChoice_serialize_obj( adb_TransformTypeChoice_t* _TransformTypeChoice, const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index) { axis2_char_t *string_to_stream; axiom_node_t* current_node = NULL; int tag_closed = 0; axis2_char_t* xsi_prefix = NULL; axiom_namespace_t* xsi_ns = NULL; axiom_attribute_t* xsi_type_attri = NULL; axis2_char_t* type_attrib = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *qname_uri = NULL; axis2_char_t *qname_prefix = NULL; axis2_char_t *p_prefix = NULL; axis2_bool_t ns_already_defined; axis2_char_t *text_value_1; axis2_char_t *text_value_1_temp; axis2_char_t *text_value_2; axis2_char_t *text_value_2_temp; axis2_char_t *start_input_str = NULL; axis2_char_t *end_input_str = NULL; unsigned int start_input_str_len = 0; unsigned int end_input_str_len = 0; axiom_data_source_t *data_source = NULL; axutil_stream_t *stream = NULL; AXIS2_ENV_CHECK(env, NULL); AXIS2_PARAM_CHECK(env->error, _TransformTypeChoice, NULL); current_node = parent; data_source = (axiom_data_source_t *)axiom_node_get_data_element(current_node, env); if (!data_source) return NULL; stream = axiom_data_source_get_stream(data_source, env); /* assume parent is of type data source */ if (!stream) return NULL; if(!parent_tag_closed) { if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING))) { /* it is better to stick with the standard prefix */ xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi"); axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix); if(parent_element) { axiom_namespace_t *element_ns = NULL; element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance", xsi_prefix); axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns); if(element_ns) { axiom_namespace_free(element_ns, env); } } } type_attrib = axutil_strcat(env, " ", xsi_prefix, ":type=\"TransformTypeChoice\"", NULL); axutil_stream_write(stream, env, type_attrib, axutil_strlen(type_attrib)); AXIS2_FREE(env->allocator, type_attrib); string_to_stream = ">"; axutil_stream_write(stream, env, string_to_stream, axutil_strlen(string_to_stream)); tag_closed = 1; } else { /* if the parent tag closed we would be able to declare the type directly on the parent element */ if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING))) { /* it is better to stick with the standard prefix */ xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi"); axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix); if(parent_element) { axiom_namespace_t *element_ns = NULL; element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance", xsi_prefix); axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns); if(element_ns) { axiom_namespace_free(element_ns, env); } } } } xsi_ns = axiom_namespace_create (env, "http://www.w3.org/2000/09/xmldsig#", xsi_prefix); xsi_type_attri = axiom_attribute_create (env, "type", "TransformTypeChoice", xsi_ns); axiom_element_add_attribute (parent_element, env, xsi_type_attri, parent); if(0 == axutil_strcmp(_TransformTypeChoice->current_choice, ":extraElement")) { p_prefix = NULL; if (!_TransformTypeChoice->is_valid_extraElement) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-nillable property extraElement"); return NULL; } else { start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (4 + axutil_strlen(p_prefix) + axutil_strlen("extraElement"))); /* axutil_strlen("<:>") + 1 = 4 */ end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (5 + axutil_strlen(p_prefix) + axutil_strlen("extraElement"))); /* axutil_strlen("</:>") + 1 = 5 */ /* * parsing extraElement element */ sprintf(start_input_str, "<%s%sextraElement>", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); start_input_str_len = axutil_strlen(start_input_str); sprintf(end_input_str, "</%s%sextraElement>", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); end_input_str_len = axutil_strlen(end_input_str); text_value_1 = axiom_node_to_string(_TransformTypeChoice->property_extraElement, env); axutil_stream_write(stream, env, text_value_1, axutil_strlen(text_value_1)); AXIS2_FREE(env->allocator,start_input_str); AXIS2_FREE(env->allocator,end_input_str); } } if(0 == axutil_strcmp(_TransformTypeChoice->current_choice, "http://www.w3.org/2000/09/xmldsig#:XPath")) { if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2000/09/xmldsig#", AXIS2_HASH_KEY_STRING))) { p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT); sprintf(p_prefix, "n%d", (*next_ns_index)++); axutil_hash_set(namespaces, "http://www.w3.org/2000/09/xmldsig#", AXIS2_HASH_KEY_STRING, p_prefix); axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env, "http://www.w3.org/2000/09/xmldsig#", p_prefix)); } if (!_TransformTypeChoice->is_valid_XPath) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-nillable property XPath"); return NULL; } else { start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (4 + axutil_strlen(p_prefix) + axutil_strlen("XPath"))); /* axutil_strlen("<:>") + 1 = 4 */ end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (5 + axutil_strlen(p_prefix) + axutil_strlen("XPath"))); /* axutil_strlen("</:>") + 1 = 5 */ /* * parsing XPath element */ sprintf(start_input_str, "<%s%sXPath>", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); start_input_str_len = axutil_strlen(start_input_str); sprintf(end_input_str, "</%s%sXPath>", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); end_input_str_len = axutil_strlen(end_input_str); text_value_2 = _TransformTypeChoice->property_XPath; axutil_stream_write(stream, env, start_input_str, start_input_str_len); text_value_2_temp = axutil_xml_quote_string(env, text_value_2, AXIS2_TRUE); if (text_value_2_temp) { axutil_stream_write(stream, env, text_value_2_temp, axutil_strlen(text_value_2_temp)); AXIS2_FREE(env->allocator, text_value_2_temp); } else { axutil_stream_write(stream, env, text_value_2, axutil_strlen(text_value_2)); } axutil_stream_write(stream, env, end_input_str, end_input_str_len); AXIS2_FREE(env->allocator,start_input_str); AXIS2_FREE(env->allocator,end_input_str); } } return parent; }
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) { 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; axis2_bool_t method_get = AXIS2_FALSE; axis2_bool_t method_head = AXIS2_FALSE; axis2_bool_t method_put = AXIS2_FALSE; axis2_bool_t method_delete = AXIS2_FALSE; /* Set up the environment */ env = axutil_env_create_all("echo_rest.log", AXIS2_LOG_LEVEL_TRACE); /* Set end point reference of echo service */ address = "http://localhost:9090/axis2/services/echo/echoString"; if (argc > 1) { if (0 == strncmp(argv[1], "-mGET", 5)) { method_get = AXIS2_TRUE; } else if (0 == strncmp(argv[1], "-mHEAD", 6)) { method_head = AXIS2_TRUE; } else if (0 == strncmp(argv[1], "-mPUT", 5)) { method_put = AXIS2_TRUE; } else if (0 == strncmp(argv[1], "-mDELETE",8 )) { method_delete = AXIS2_TRUE; } else if (0 == axutil_strcmp(argv[1], "-h")) { printf("Usage : %s [endpoint_url] \n", argv[0]); printf("\nNOTE: You can test for other HTTP methods by changing the"); printf(" services.xml of the echo service\n and providing the correct REST HTTP method"); printf(" and the location to be used for operation.\n"); printf(" Also note that you have to restart the server after changing the services.xml.\n"); printf(" use %s -mGET for HTTP GET\n", argv[0]); printf(" use %s -mHEAD for HTTP HEAD\n", argv[0]); printf(" use %s -mDELETE for HTTP DELETE\n", argv[0]); printf(" use %s -mPUT for HTTP PUT\n", argv[0]); printf(" use -h for help\n"); return 0; } else { address = argv[1]; } } if (argc > 2) { if (0 == strncmp(argv[2], "-mGET", 5)) { method_get = AXIS2_TRUE; } else if (0 == strncmp(argv[2], "-mHEAD", 6)) { method_head = AXIS2_TRUE; } else if (0 == strncmp(argv[2], "-mPUT", 5)) { method_put = AXIS2_TRUE; } else if (0 == strncmp(argv[2], "-mDELETE",8 )) { method_delete = AXIS2_TRUE; } else { address = argv[2]; } } printf("Using endpoint : %s\n", address); /* 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); /* Enable REST at the client side */ axis2_options_set_enable_rest(options, env, AXIS2_TRUE); if (AXIS2_TRUE == method_get) { axis2_options_set_http_method(options, env, AXIS2_HTTP_GET); } else if (AXIS2_TRUE == method_head) { axis2_options_set_http_method(options, env, AXIS2_HTTP_HEAD); } else if (AXIS2_TRUE == method_put) { axis2_options_set_http_method(options, env, AXIS2_HTTP_PUT); } else if (AXIS2_TRUE == method_delete) { axis2_options_set_http_method(options, env, AXIS2_HTTP_DELETE); } /* 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("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_om_payload_for_echo_svc(env); /* Send request */ ret_node = axis2_svc_client_send_receive(svc_client, env, payload); if (ret_node && axis2_svc_client_get_last_response_has_fault(svc_client, env)) { axis2_char_t *om_str = NULL; om_str = axiom_node_to_string(ret_node, env); if (om_str) { printf("\nReceived OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); } printf("\necho client invoke FAILED!\n"); } else if (ret_node) { axis2_char_t *om_str = NULL; om_str = axiom_node_to_string(ret_node, env); if (om_str) { printf("\nReceived OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); } printf("\necho client invoke SUCCESSFUL!\n"); } else if (method_head && axis2_svc_client_get_last_response_has_fault(svc_client, env)) { /* HEAD request should probably be removed from this file, * and be relocated to transport unit tests. */ printf("\necho client invoke FAILED!\n"); } else if (method_head) { /* HEAD request should probably be removed from this file, * and be relocated to transport unit tests. */ printf("\necho 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("echo 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; }
axiom_node_t* AXIS2_CALL adb_CanonicalizationMethodType_serialize_obj( adb_CanonicalizationMethodType_t* _CanonicalizationMethodType, const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index) { axiom_attribute_t *text_attri = NULL; axis2_char_t *string_to_stream; axiom_node_t* current_node = NULL; int tag_closed = 0; axis2_char_t* xsi_prefix = NULL; axiom_namespace_t* xsi_ns = NULL; axiom_attribute_t* xsi_type_attri = NULL; axis2_char_t* type_attrib = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *qname_uri = NULL; axis2_char_t *qname_prefix = NULL; axis2_char_t *p_prefix = NULL; axis2_bool_t ns_already_defined; int i = 0; int count = 0; void *element = NULL; axis2_char_t *text_value_1; axis2_char_t *text_value_1_temp; axis2_char_t *text_value_2; axis2_char_t *text_value_2_temp; axis2_char_t *text_value = NULL; axis2_char_t *start_input_str = NULL; axis2_char_t *end_input_str = NULL; unsigned int start_input_str_len = 0; unsigned int end_input_str_len = 0; axiom_data_source_t *data_source = NULL; axutil_stream_t *stream = NULL; AXIS2_ENV_CHECK(env, NULL); AXIS2_PARAM_CHECK(env->error, _CanonicalizationMethodType, NULL); current_node = parent; data_source = (axiom_data_source_t *)axiom_node_get_data_element(current_node, env); if (!data_source) return NULL; stream = axiom_data_source_get_stream(data_source, env); /* assume parent is of type data source */ if (!stream) return NULL; if(!parent_tag_closed) { if(_CanonicalizationMethodType->is_valid_Algorithm) { p_prefix = NULL; text_value = axutil_uri_to_string(_CanonicalizationMethodType->property_Algorithm, env, AXIS2_URI_UNP_OMITUSERINFO); string_to_stream = (axis2_char_t*) AXIS2_MALLOC (env-> allocator, sizeof (axis2_char_t) * (5 + ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT + axutil_strlen(text_value) + axutil_strlen("Algorithm"))); sprintf(string_to_stream, " %s%s%s=\"%s\"", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":"", "Algorithm", text_value); axutil_stream_write(stream, env, string_to_stream, axutil_strlen(string_to_stream)); AXIS2_FREE(env-> allocator, string_to_stream); } else { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-optional attribute Algorithm"); return NULL; } string_to_stream = ">"; axutil_stream_write(stream, env, string_to_stream, axutil_strlen(string_to_stream)); tag_closed = 1; } p_prefix = NULL; if (!_CanonicalizationMethodType->is_valid_extraElement) { /* no need to complain for minoccurs=0 element */ } else { start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (4 + axutil_strlen(p_prefix) + axutil_strlen("extraElement"))); /* axutil_strlen("<:>") + 1 = 4 */ end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (5 + axutil_strlen(p_prefix) + axutil_strlen("extraElement"))); /* axutil_strlen("</:>") + 1 = 5 */ /* * Parsing extraElement array */ if (_CanonicalizationMethodType->property_extraElement != NULL) { sprintf(start_input_str, "<%s%sextraElement>", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); start_input_str_len = axutil_strlen(start_input_str); sprintf(end_input_str, "</%s%sextraElement>", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); end_input_str_len = axutil_strlen(end_input_str); count = axutil_array_list_size(_CanonicalizationMethodType->property_extraElement, env); for(i = 0; i < count; i ++) { element = axutil_array_list_get(_CanonicalizationMethodType->property_extraElement, env, i); if(NULL == element) { continue; } /* * parsing extraElement element */ text_value_1 = axiom_node_to_string((axiom_node_t*)element, env); axutil_stream_write(stream, env, text_value_1, axutil_strlen(text_value_1)); } } AXIS2_FREE(env->allocator,start_input_str); AXIS2_FREE(env->allocator,end_input_str); } if(parent_tag_closed) { if(_CanonicalizationMethodType->is_valid_Algorithm) { p_prefix = NULL; ns1 = NULL; text_value = axutil_uri_to_string(_CanonicalizationMethodType->property_Algorithm, env, AXIS2_URI_UNP_OMITUSERINFO); text_attri = axiom_attribute_create (env, "Algorithm", text_value, ns1); axiom_element_add_attribute (parent_element, env, text_attri, parent); } else { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Nil value found in non-optional attribute Algorithm"); return NULL; } } return parent; }
axiom_node_t* AXIS2_CALL adb_Exception_serialize_obj( adb_Exception_t* _Exception, const axutil_env_t *env, axiom_node_t *parent, axiom_element_t *parent_element, int parent_tag_closed, axutil_hash_t *namespaces, int *next_ns_index) { axis2_char_t *string_to_stream; axiom_node_t* current_node = NULL; int tag_closed = 0; axis2_char_t* xsi_prefix = NULL; axis2_char_t* type_attrib = NULL; axiom_namespace_t* xsi_ns = NULL; axiom_attribute_t* xsi_type_attri = NULL; axiom_namespace_t *ns1 = NULL; axis2_char_t *qname_uri = NULL; axis2_char_t *qname_prefix = NULL; axis2_char_t *p_prefix = NULL; axis2_bool_t ns_already_defined; axis2_char_t *text_value_1; axis2_char_t *text_value_1_temp; axis2_char_t *start_input_str = NULL; axis2_char_t *end_input_str = NULL; unsigned int start_input_str_len = 0; unsigned int end_input_str_len = 0; axiom_data_source_t *data_source = NULL; axutil_stream_t *stream = NULL; AXIS2_ENV_CHECK(env, NULL); AXIS2_PARAM_CHECK(env->error, _Exception, NULL); current_node = parent; data_source = (axiom_data_source_t *)axiom_node_get_data_element(current_node, env); if (!data_source) return NULL; stream = axiom_data_source_get_stream(data_source, env); /* assume parent is of type data source */ if (!stream) return NULL; if(!parent_tag_closed) { if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING))) { /* it is better to stick with the standard prefix */ xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi"); axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix); if(parent_element) { axiom_namespace_t *element_ns = NULL; element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance", xsi_prefix); axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns); } } type_attrib = axutil_strcat(env, " ", xsi_prefix, ":type=\"Exception\"", NULL); axutil_stream_write(stream, env, type_attrib, axutil_strlen(type_attrib)); AXIS2_FREE(env->allocator, type_attrib); string_to_stream = ">"; axutil_stream_write(stream, env, string_to_stream, axutil_strlen(string_to_stream)); tag_closed = 1; } else { /* if the parent tag closed we would be able to declare the type directly on the parent element */ if(!(xsi_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING))) { /* it is better to stick with the standard prefix */ xsi_prefix = (axis2_char_t*)axutil_strdup(env, "xsi"); axutil_hash_set(namespaces, "http://www.w3.org/2001/XMLSchema-instance", AXIS2_HASH_KEY_STRING, xsi_prefix); if(parent_element) { axiom_namespace_t *element_ns = NULL; element_ns = axiom_namespace_create(env, "http://www.w3.org/2001/XMLSchema-instance", xsi_prefix); axiom_element_declare_namespace_assume_param_ownership(parent_element, env, element_ns); } } } xsi_ns = axiom_namespace_create (env, "http://services.resource.ui.mgt.registry.carbon.wso2.org", xsi_prefix); xsi_type_attri = axiom_attribute_create (env, "type", "Exception", xsi_ns); axiom_element_add_attribute (parent_element, env, xsi_type_attri, parent); if(!(p_prefix = (axis2_char_t*)axutil_hash_get(namespaces, "http://services.resource.ui.mgt.registry.carbon.wso2.org", AXIS2_HASH_KEY_STRING))) { p_prefix = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof (axis2_char_t) * ADB_DEFAULT_NAMESPACE_PREFIX_LIMIT); sprintf(p_prefix, "n%d", (*next_ns_index)++); axutil_hash_set(namespaces, "http://services.resource.ui.mgt.registry.carbon.wso2.org", AXIS2_HASH_KEY_STRING, p_prefix); axiom_element_declare_namespace_assume_param_ownership(parent_element, env, axiom_namespace_create (env, "http://services.resource.ui.mgt.registry.carbon.wso2.org", p_prefix)); } if (!_Exception->is_valid_Exception) { /* no need to complain for minoccurs=0 element */ } else { start_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (4 + axutil_strlen(p_prefix) + axutil_strlen("Exception"))); /* axutil_strlen("<:>") + 1 = 4 */ end_input_str = (axis2_char_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * (5 + axutil_strlen(p_prefix) + axutil_strlen("Exception"))); /* axutil_strlen("</:>") + 1 = 5 */ /* * parsing Exception element */ sprintf(start_input_str, "<%s%sException>", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); start_input_str_len = axutil_strlen(start_input_str); sprintf(end_input_str, "</%s%sException>", p_prefix?p_prefix:"", (p_prefix && axutil_strcmp(p_prefix, ""))?":":""); end_input_str_len = axutil_strlen(end_input_str); text_value_1 = axiom_node_to_string(_Exception->property_Exception, env); axutil_stream_write(stream, env, start_input_str, start_input_str_len); axutil_stream_write(stream, env, text_value_1, axutil_strlen(text_value_1)); axutil_stream_write(stream, env, end_input_str, end_input_str_len); AXIS2_FREE(env->allocator,start_input_str); AXIS2_FREE(env->allocator,end_input_str); } return parent; }
int main(int argc, char** argv) { const axutil_env_t *env = NULL; const axis2_char_t *address = NULL; const axis2_char_t *client_home = NULL; axis2_char_t *file_name = NULL; axis2_char_t *policy_file = NULL; 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; axis2_status_t status = AXIS2_FAILURE; neethi_policy_t *policy = NULL; rampart_config_t* client_config = NULL; axutil_property_t *property = NULL; rampart_saml_token_t *saml = NULL; axiom_node_t *assertion = NULL; /* Set up the environment */ env = axutil_env_create_all("echo.log", AXIS2_LOG_LEVEL_TRACE); /* Set end-point-reference of echo service */ address = "http://localhost:9090/axis2/services/echo"; if (argc > 2) { address = argv[1]; client_home = argv[2]; printf("Using endpoint : %s\n", address); printf("Using client_home : %s\n", client_home); } if ((axutil_strcmp(argv[1], "-h") == 0) || (axutil_strcmp(argv[1], "--help") == 0)) { printf("Usage : %s [endpoint_url] [client_home]\n", argv[0]); printf("use -h for help\n"); return 0; } /* Create end-point-reference 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_action(options, env, "http://example.com/ws/2004/09/policy/Test/EchoRequest"); /*axis2_options_set_action(options, env, "urn:echo");*/ /*If the client home is not specified, use the AXIS2C_HOME*/ if (!client_home) { client_home = AXIS2_GETENV("AXIS2C_HOME"); printf("\nNo client_home specified. Using default %s", client_home); } /* Create service client */ printf("client_home= %s", client_home); svc_client = axis2_svc_client_create(env, client_home); if (!svc_client) { printf("Error creating service client\n"); return -1; } client_config = rampart_config_create(env); if(!client_config) { printf("Cannot create rampart config\n"); return 0; } assertion = create_saml_assertion(env); saml = rampart_saml_token_create(env, assertion, RAMPART_ST_CONFIR_TYPE_SENDER_VOUCHES); rampart_saml_token_set_token_type(saml, env, RAMPART_ST_TYPE_SIGNED_SUPPORTING_TOKEN); rampart_config_add_saml_token(client_config, env, saml); property = axutil_property_create_with_args(env, AXIS2_SCOPE_REQUEST , AXIS2_TRUE, (void *)rampart_config_free, client_config); axis2_options_set_property(options, env, RAMPART_CLIENT_CONFIGURATION, property); /* Set service client options */ axis2_svc_client_set_options(svc_client, env, options); /*We need to specify the client's policy file location*/ if(client_home) { file_name = axutil_stracat(env, client_home, AXIS2_PATH_SEP_STR); policy_file = axutil_stracat(env, file_name, "policy.xml" ); AXIS2_FREE(env->allocator, file_name); file_name = NULL; }else{ printf("Client Home not Specified\n"); printf("echo client invoke FAILED!\n"); return 0; } /*Create the policy, from file*/ policy = neethi_util_create_policy_from_file(env, policy_file); if(!policy) { printf("\nPolicy creation failed from the file. %s\n", policy_file); } if(policy_file){ AXIS2_FREE(env->allocator, policy_file); policy_file = NULL; } status = axis2_svc_client_set_policy(svc_client, env, policy); if(status == AXIS2_FAILURE) { printf("Policy setting failed\n"); } /* Build the SOAP request message payload using OM API.*/ payload = build_om_payload_for_echo_svc(env); /*If not engaged in the client's axis2.xml, uncomment this line*/ axis2_svc_client_engage_module(svc_client, env, "rampart"); /* 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; 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) { printf("\nReturned SOAP fault: %s\n", axiom_node_to_string(axiom_soap_fault_get_base_node(soap_fault,env), env)); } printf("echo client invoke FAILED!\n"); return -1; } if (ret_node) { axis2_char_t *om_str = NULL; om_str = axiom_node_to_string(ret_node, env); if (om_str) { printf("\nReceived OM : %s\n", om_str); } printf("\necho client invoke SUCCESSFUL!\n"); AXIS2_FREE(env->allocator, om_str); ret_node = NULL; } else { printf("echo client invoke FAILED!\n"); return -1; } 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) { 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; /* Set up the environment */ env = axutil_env_create_all("echo_blocking_addr_amqp.log", AXIS2_LOG_LEVEL_TRACE); /* Set end point reference of echo service */ address = "amqp://localhost:5672/axis2/services/echo"; if (argc > 1) address = argv[1]; if (axutil_strcmp(address, "-h") == 0) { printf("Usage : %s [endpoint_url]\n", argv[0]); 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); /* Setup options */ options = axis2_options_create(env); axis2_options_set_to(options, env, endpoint_ref); axis2_options_set_action(options, env, "http://ws.apache.org/axis2/c/samples/echoString"); /* 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 || !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 AXIS2C_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); /* 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_payload_for_echo_svc(env); /* Send request */ ret_node = axis2_svc_client_send_receive(svc_client, env, payload); if (ret_node) { axis2_char_t *om_str = NULL; om_str = axiom_node_to_string(ret_node, env); if (om_str) { printf("\nReceived OM : %s\n", om_str); AXIS2_FREE(env->allocator, om_str); } printf("\necho 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("echo 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; }