Hi all,
Again multithreading. That's my last effort to solve the problem, then I
give up. Please have a look to the attached file, that can be compiled
and run using VS6 on Windows. The file is easy to understand and can be
run just tuning the #defines at the beginning.
May you help me testing client multithreading on Windows?
Thanks.
Stefano
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
------------------------------------------------------------------------
#define N_THREADS 40
#define N_CLIENTS 1
#define N_CALLS 1
#define SOAP_ENDPOINT "http://localhost:9090/axis2/services/echo"
#define SOAP_ACTION "echoString"
#define XML_REQUEST "<echoString><text>Hello</text></echoString>"
#define AXIS2_PATH "D:\\manjula\\axis2\\build\\deploy"
#include <iostream>
#include <axiom.h>
#include <axiom_soap.h>
#include <axiom_xml_reader.h>
#include <axiom_xml_writer.h>
#include <axutil_allocator.h>
#include <axutil_error.h>
#include <axutil_error_default.h>
#include <axutil_log.h>
#include <axutil_log_default.h>
#include <axis2_util.h>
#include <axis2_client.h>
using namespace std;
DWORD WINAPI threadProc(LPVOID pParam)
{
const int N = N_CLIENTS; // Number of clients per thread
const int M = N_CALLS; // Calls per client
const int id = (int) pParam;
int i;
int j;
axutil_error_t* error;
axutil_allocator_t* alloc;
axutil_log_t* log;
axutil_env_t *env = NULL;
axis2_endpoint_ref_t* endpoint[N];
axis2_options_t* options[N];
axis2_svc_client_t* svc_client[N];
axiom_node_t* out_node = NULL;
axiom_node_t* in_node = NULL;
axiom_namespace_t* ns = NULL;
// Environment
/*alloc = axutil_allocator_init(NULL);
error = axutil_error_create(alloc);
log = axutil_log_create_default(alloc);
env = axutil_env_create_with_error_log(alloc, error, log);*/
env = axutil_env_create_all("test.log", AXIS2_LOG_LEVEL_DEBUG);
// Source document
string xml = XML_REQUEST;
axiom_xml_reader_t* reader = axiom_xml_reader_create_for_memory(env,
(void*) xml.c_str(), xml.length(), AXIS2_DEFAULT_CHAR_SET_ENCODING,
AXIS2_XML_PARSER_TYPE_BUFFER);
axiom_stax_builder_t* builder = axiom_stax_builder_create(env, reader);
axiom_document_t* document = axiom_stax_builder_get_document(builder,
env);
in_node = axiom_document_get_root_element(document, env);
if (!in_node)
{
cout << AXIS2_ERROR_GET_MESSAGE(env->error) << endl;
return -1;
}
// Options
for (i=0; i<N; i++)
{
options[i] = axis2_options_create(env);
endpoint[i] = axis2_endpoint_ref_create(env, SOAP_ENDPOINT);
axis2_options_set_to(options[i], env, endpoint[i]);
//axis2_options_set_soap_version(options[i], env,
AXIOM_SOAP_12);
axis2_options_set_soap_action(options[i], env,
axutil_string_create(env, SOAP_ACTION));
axis2_options_set_xml_parser_reset(options[i], env,
AXIS2_FALSE);
}
// Clients
for (i=0; i<N; i++)
{
svc_client[i] = axis2_svc_client_create(env, AXIS2_PATH);
//svc_client[i] = axis2_svc_client_create(env,
AXIS2_GETENV("AXIS2C_HOME"));
if (!svc_client[i])
{
cout << "counld not create svc client\n";
return -2;
}
axis2_svc_client_set_options(svc_client[i], env, options[i]);
}
// SOAP call
for (j=0; j<M; j++)
for (i=0; i<N; i++)
{
out_node = axis2_svc_client_send_receive(svc_client[i],
env, in_node);
if (out_node)
{
if
(axis2_svc_client_get_last_response_has_fault(svc_client[i], env))
{
axiom_soap_envelope_t* envelope;
axiom_soap_body_t* body;
axiom_soap_fault_t* fault;
axiom_soap_fault_code_t* code;
axiom_soap_fault_reason_t* reason;
envelope =
axis2_svc_client_get_last_response_soap_envelope(svc_client[i], env);
body =
axiom_soap_envelope_get_body(envelope, env);
fault = axiom_soap_body_get_fault(body,
env);
code = axiom_soap_fault_get_code(fault,
env);
reason =
axiom_soap_fault_get_reason(fault, env);
cout << "Returned SOAP error:" << endl;
if (code)
{
axiom_node_t* node =
axiom_soap_fault_code_get_base_node(code, env);
axiom_element_t* element =
(axiom_element_t*) axiom_node_get_data_element(node, env);
cout << "SOAP fault code: " <<
axiom_element_get_text(element, env, node) << endl;
}
if (reason)
{
axiom_node_t* node =
axiom_soap_fault_reason_get_base_node(reason, env);
axiom_element_t* element =
(axiom_element_t*) axiom_node_get_data_element(node, env);
cout << "SOAP fault reason: " <<
axiom_element_get_text(element, env, node) << endl;
}
return -3;
}
else
{
cout << "OK! Response:" << endl << endl;
axiom_xml_writer_t* writer =
axiom_xml_writer_create_for_memory(env, AXIS2_DEFAULT_CHAR_SET_ENCODING,
AXIS2_FALSE, 0, AXIS2_XML_PARSER_TYPE_BUFFER);
axiom_output_t* output =
axiom_output_create(env, writer);
axiom_document_t* document =
axiom_document_create(env, out_node, NULL);
axiom_document_serialize(document, env,
output);
string xml = (axis2_char_t*)
axiom_xml_writer_get_xml(writer, env);
cout << xml.c_str() << endl;
}
}
else
{
cout << "Returned AXIS2/NETWORK error" << endl;
cout << AXIS2_ERROR_GET_MESSAGE(env->error) <<
endl;
return -4;
}
}
for (i = 0; i<N; i++)
axis2_svc_client_free(svc_client[i], env);
axutil_env_free(env);
Sleep(10000);
cout << "Thread ID " << id << " completed" << endl;
return 0;
}
void main()
{
axiom_xml_reader_init();
for (int i = 0; i < N_THREADS; i++)
{
cout << "Creating thread " << i << endl << flush;
CreateThread(NULL, 0, &threadProc, (void*) i, 0, NULL);
}
while (true)
Sleep(10000);
}
------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]