Hey,
The following program will crash when the second thread starts up
[ _beginthread() in main() ]. A unhandled exception error is reported
and program crashes when 2nd thread starts to run ( 1st thread ends
already). This test program is just a multi-threaded version from Math
sample webservice client code of AXIS2. I just excute Math WS client
twice in different thread. But I don't have this problem if Math WS
Client is run in the same thread for two times. Any idea about this. I
checked out the newest AXIS2C code from SVN. Same problem happened.
Platform: WinXP
Compilor: Visual Studio 2005 Professional
// MathWSClient.cpp : Defines the entry point for the console
application.
//
#include
"axis2_math_stub.h"
#include
<stdio.h>
#include
<axiom.h>
#include
<axis2_util.h>
#include
<axiom_soap.h>
#include
<axis2_client.h>
#include
<iostream>
using
namespace std;
axiom_node_t *
build_om_programatically(
const axutil_env_t *env,
const axis2_char_t *operation,
const axis2_char_t *param1,
const axis2_char_t *param2);
void
run(void* param)
{
axis2_stub_t *stub = NULL;
axiom_node_t *node = NULL;
axis2_status_t status = AXIS2_FAILURE;
const axutil_env_t *env = NULL;
const axis2_char_t *address = NULL;
const axis2_char_t *client_home = NULL;
axiom_node_t *ret_node = NULL;
const axis2_char_t *operation = "add";
const axis2_char_t *param1 = "40";
const axis2_char_t *param2 = "8";
env = axutil_env_create_all(
"math_blocking.log", AXIS2_LOG_LEVEL_TRACE);
client_home = AXIS2_GETENV(
"AXIS2C_HOME");
if (!client_home || !strcmp (client_home, ""))
client_home =
"../..";
address =
"http://localhost:9090/axis2/services/math";
printf(
"Using endpoint : %s\n", address);
printf(
"\nInvoking operation %s with params %s and %s\n", operation, param1,
param2);
node = build_om_programatically(env, operation, param1, param2);
stub =
axis2_math_stub_create_with_endpoint_uri_and_client_home(env, address,
client_home);
/* create node and invoke math */
if (stub)
{
ret_node = axis2_math_stub_add(stub, env, node);
}
if (ret_node)
{
if (axiom_node_get_node_type(ret_node, env) == AXIOM_ELEMENT)
{
axis2_char_t *result = NULL;
axiom_element_t *result_ele =
(axiom_element_t*)axiom_node_get_data_element(ret_node, env);
result = axiom_element_get_text(result_ele, env, ret_node);
printf(
"\nResult = %s\n", result);
}
else
{
axiom_xml_writer_t *writer = NULL;
axiom_output_t *om_output = NULL;
axis2_char_t *buffer = NULL;
writer = axiom_xml_writer_create_for_memory(env, NULL, AXIS2_TRUE, 0,
AXIS2_XML_PARSER_TYPE_BUFFER);
om_output = axiom_output_create(env, writer);
axiom_node_serialize(ret_node, env, om_output);
buffer = (axis2_char_t*)axiom_xml_writer_get_xml(writer, env);
printf(
"\nReceived invalid OM as result : %s\n", buffer);
if (buffer)
{
AXIS2_FREE(env->allocator, buffer);
buffer = NULL;
}
if (om_output)
{
axiom_output_free(om_output, env);
om_output = NULL;
}
axiom_xml_writer_free(writer, env);
}
}
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(
"math stub invoke FAILED!\n");
}
if (stub)
{
axis2_stub_free(stub, env);
}
if (env)
{
axutil_env_free((axutil_env_t *) env);
env = NULL;
}
_endthread();
}
int
main(int argc, char* argv[])
{
_beginthread(run, 0, NULL);
Sleep(5000);
_beginthread(run, 0, NULL);
Sleep(5000);
return 0;
}
axiom_node_t *
build_om_programatically(
const axutil_env_t *env,
const axis2_char_t *operation,
const axis2_char_t *param1,
const axis2_char_t *param2)
{
axiom_node_t *math_om_node = NULL;
axiom_element_t* math_om_ele = NULL;
axiom_node_t* text_om_node = NULL;
axiom_element_t * text_om_ele = NULL;
axiom_namespace_t *ns1 = NULL;
axiom_xml_writer_t *xml_writer = NULL;
axiom_output_t *om_output = NULL;
axis2_char_t *buffer = NULL;
ns1 = axiom_namespace_create(env,
"http://ws.apache.org/axis2/services/math", "ns1");
math_om_ele = axiom_element_create(env, NULL, operation, ns1,
&math_om_node);
text_om_ele = axiom_element_create(env, math_om_node,
"param1", NULL, &text_om_node);
axiom_element_set_text(text_om_ele, env, param1, text_om_node);
text_om_ele = axiom_element_create(env, math_om_node,
"param2", NULL, &text_om_node);
axiom_element_set_text(text_om_ele, env, param2, text_om_node);
xml_writer = axiom_xml_writer_create_for_memory(env, NULL,
AXIS2_FALSE, AXIS2_FALSE,
AXIS2_XML_PARSER_TYPE_BUFFER);
om_output = axiom_output_create(env, xml_writer);
axiom_node_serialize(math_om_node, env, om_output);
buffer = (axis2_char_t*)axiom_xml_writer_get_xml(xml_writer, env);
AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
"\nSending OM node in XML : %s \n", buffer);
if (om_output)
{
axiom_output_free(om_output, env);
om_output = NULL;
}
return math_om_node;
}