axis-c-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Samisa Abeysinghe <sam...@wso2.com>
Subject Re: Multithreading again
Date Tue, 10 Jul 2007 06:00:15 GMT
This attached file works with the echo service sample of Axis2/C, that 
shows that the threading works fine.

It must have been the way you created the env that caused the problems.

I tested this and works fine, tanks Manjula for the comprehensive 
working sample.

Samisa...

manjula wrote:
> Hi Stefano, 
>
> I have successfully compiled and run the sample code you have sent with
> 40 threads, after doing some minor changes to your code. I have attached
> the modified source code. There are no issues with threading. Following
> are the changes I had done.
>
> 1. Escape the '\' charactor in AXIS2_PATH constant.
> 2. change the XML_REQUEST and SOAP_ACTION as in the attached file
>
> The change 2 is done just because my services expect that soap action
> and payload.
>
> Please let us know if you have any further problems.
>
> Thanks
>
> -Manjula.
>
>
> On Mon, 2007-07-09 at 17:56 +0200, Stefano Pettini wrote:
>   
>> 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: axis-c-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-c-user-help@ws.apache.org
>>     
>> ------------------------------------------------------------------------
>>
>> #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: axis-c-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-c-user-help@ws.apache.org


-- 
Samisa Abeysinghe : http://www.wso2.org/ (WSO2 Oxygen Tank - Web Services Developers' Portal)


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-c-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-c-user-help@ws.apache.org


Mime
View raw message