Hi Dimuthu,
Do you have any example custom soap fault wsdl? I am not clear with this
concept I tried a new example, since you found some problems with my last
wsdl file. I have attached the wsdl file. In that, there is one
myOperationRequest which is a string, and a myOperationResponse which is
also a string. There are two custom faults here, MyFirstException and
MySecondException. With this wsdl, the service function that was generated
was as below:
adb_myOperationResponse_t* axis2_skel_MyService_myOperation (const
axutil_env_t *env ,
adb_myOperation_t* myOperation
)
{
adb_myOperationResponse_t *myResponse;
/* TODO fill this with the necessary business logic */
axis2_char_t *myInpMsg =
adb_myOperation_get_myInput(myOperation,env);
printf("My input message = %s\n",myInpMsg);
if (strcmp(myInpMsg,"Bad server")==0)
{
//What is the way to throw the exception here?
return NULL;
}
// Assuming the myResponse object is created
return myResponse;
}
You have told me to modify the axis2_svc_skel_MyService_on_fault() function
to build custom faults. Does that mean that i have to create an object of
myFirstException inside that? Should the service function just return NULL?
Suppose i call a function that has some business logic that return error
code inside axis2_skel_MyService_myOperation, and i want to throw an
exception (with an error message) based on that error code, how exactly
should i do it?
Can you help me out?
Thanks
Sathya
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="MyService"
targetNamespace="urn:myuri:1.0"
xmlns:tns="urn:myuri:1.0"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="urn:myuri:1.0"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="urn:myuri:1.0"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="urn:myuri:1.0"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<!-- fault element -->
<element name="MyFirstException">
<complexType>
<sequence>
<element name="text" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="false"/>
</sequence>
</complexType>
</element>
<!-- fault element -->
<element name="MySecondException">
<complexType>
<sequence>
<element name="number" type="xsd:int" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
</element>
<!-- operation request element -->
<element name="myOperation">
<complexType>
<sequence>
<element name="myInput" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
</sequence>
</complexType>
</element>
<!-- operation response element -->
<element name="myOperationResponse">
<complexType>
<sequence>
<element name="myOutput" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="myOperationRequest">
<part name="parameters" element="ns1:myOperation"/>
</message>
<message name="myOperationResponse">
<part name="parameters" element="ns1:myOperationResponse"/>
</message>
<message name="MySecondExceptionFault">
<part name="fault" element="ns1:MySecondException"/>
</message>
<message name="MyFirstExceptionFault">
<part name="fault" element="ns1:MyFirstException"/>
</message>
<portType name="MyType">
<operation name="myOperation">
<documentation>Service definition of function ns1__myOperation</documentation>
<input message="tns:myOperationRequest"/>
<output message="tns:myOperationResponse"/>
<fault name="MySecondException" message="tns:MySecondExceptionFault"/>
<fault name="MyFirstException" message="tns:MyFirstExceptionFault"/>
</operation>
</portType>
<binding name="MyService" type="tns:MyType">
<SOAP:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="myOperation">
<SOAP:operation soapAction="http://localhost/axis/myOperation"/>
<input>
<SOAP:body use="literal"/>
</input>
<output>
<SOAP:body use="literal"/>
</output>
<fault name="MySecondException">
<SOAP:fault name="MySecondException" use="literal"/>
</fault>
<fault name="MyFirstException">
<SOAP:fault name="MyFirstException" use="literal"/>
</fault>
</operation>
</binding>
<service name="MyService">
<documentation>gSOAP 2.7.1 generated service definition</documentation>
<port name="MyService" binding="tns:MyService">
<SOAP:address location="http://localhost:10000"/>
</port>
</service>
</definitions>
/**
* adb_MyFirstException.h
*
* This file was auto-generated from WSDL
* by the Apache Axis2/C version: 1.3 Built on : Aug 10, 2007 (04:45:58
LKT)
*
*/
#include "adb_MyFirstException.h"
/**
* implmentation of the MyFirstException|urn:myuri:1.0 element
*/
struct adb_MyFirstException
{
axutil_qname_t* qname;
axis2_char_t* attrib_text;
};
/************************* Function Implmentations
********************************/
AXIS2_EXTERN adb_MyFirstException_t* AXIS2_CALL
adb_MyFirstException_create(
const axutil_env_t *env )
{
adb_MyFirstException_t *_MyFirstException = NULL;
axutil_qname_t* qname = NULL;
AXIS2_ENV_CHECK(env, NULL);
_MyFirstException = (adb_MyFirstException_t *) AXIS2_MALLOC(env->
allocator, sizeof(adb_MyFirstException_t));
if(NULL == _MyFirstException)
{
AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY,
AXIS2_FAILURE);
return NULL;
}
qname = axutil_qname_create (env,
"MyFirstException",
"urn:myuri:1.0",
"ns1");
_MyFirstException->qname = qname;
return _MyFirstException;
}
axis2_status_t AXIS2_CALL
adb_MyFirstException_free (
adb_MyFirstException_t* _MyFirstException,
const axutil_env_t *env)
{
AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
if(_MyFirstException->qname )
{
axutil_qname_free (_MyFirstException->qname, env);
_MyFirstException->qname = NULL;
}
if(_MyFirstException)
{
AXIS2_FREE( env->allocator, _MyFirstException);
_MyFirstException = NULL;
}
return AXIS2_SUCCESS;
}
axutil_qname_t* AXIS2_CALL
adb_MyFirstException_get_qname (
adb_MyFirstException_t* _MyFirstException,
const axutil_env_t *env)
{
AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
return _MyFirstException-> qname;
}
axis2_status_t AXIS2_CALL
adb_MyFirstException_deserialize(
adb_MyFirstException_t* _MyFirstException,
const axutil_env_t *env,
axiom_node_t* parent)
{
axis2_status_t status = AXIS2_SUCCESS;
axiom_namespace_t *ns1 = NULL;
axis2_char_t* text_value = NULL;
axutil_qname_t *qname = NULL;
axiom_node_t *first_node = NULL;
axiom_node_t *current_node = NULL;
axiom_element_t *current_element = NULL;
AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
ns1 = axiom_namespace_create (env,
"urn:myuri:1.0",
"ns1");
if ( NULL == parent )
{
/** This should be checked above */
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "NULL elemenet for
MyFirstException"
" %d :: %s",
env->error->error_number,
AXIS2_ERROR_GET_MESSAGE(env->error));
return AXIS2_FAILURE;
}
current_element = axiom_node_get_data_element( parent, env);
qname = axiom_element_get_qname( current_element, env,
parent);
if ( axutil_qname_equals( qname, env, _MyFirstException->
qname ) )
{
first_node = axiom_node_get_first_child( parent, env);
}
else
{
first_node = parent;
}
/**
* building text element
*/
current_node = first_node;
if ( current_node != NULL)
{
current_element = axiom_node_get_data_element(
current_node, env);
text_value =
axiom_element_get_text(current_element, env, current_node );
status = adb_MyFirstException_set_text(
_MyFirstException, env,
text_value);
if( AXIS2_FAILURE == status)
{
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
"failed in setting the value for text "
" %d :: %s",
env->error->error_number,
AXIS2_ERROR_GET_MESSAGE(env->error));
return AXIS2_FAILURE;
}
}
else
{
/** this is not a nillable element*/
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "non
nillable or minOuccrs != 0 element text missing"
" %d :: %s",
env->error->error_number,
AXIS2_ERROR_GET_MESSAGE(env->error));
return AXIS2_FAILURE;
}
return status;
}
axiom_node_t* AXIS2_CALL
adb_MyFirstException_serialize(
adb_MyFirstException_t* _MyFirstException,
const axutil_env_t *env, axiom_node_t* parent, int has_parent)
{
axiom_namespace_t *ns1 = NULL;
axis2_char_t *text_value_1;
axiom_node_t *current_node = NULL;
axiom_element_t *current_element = NULL;
axiom_data_source_t *data_source = NULL;
axutil_stream_t *stream = 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;
AXIS2_ENV_CHECK(env, NULL);
ns1 = axiom_namespace_create (env,
"urn:myuri:1.0",
"ns1");
if( parent == NULL)
{
current_element = axiom_element_create (env, parent,
"MyFirstException", ns1 , ¤t_node);
axiom_element_set_namespace( current_element, env, ns1,
current_node);
parent = current_node;
}
if(has_parent)
{
data_source = axiom_node_get_data_element(parent, 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;
current_node = parent;
}
else
{
data_source = axiom_data_source_create(env, parent,
¤t_node);
stream = axiom_data_source_get_stream(data_source, env);
}
/**
* parsing text element
*/
start_input_str = "<ns1:text>";
start_input_str_len = axutil_strlen(start_input_str);
end_input_str = "</ns1:text>";
end_input_str_len = axutil_strlen(end_input_str);
text_value_1 = _MyFirstException->attrib_text;
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);
return parent;
}
/**
* getter for text.
*/
axis2_char_t* AXIS2_CALL
adb_MyFirstException_get_text(
adb_MyFirstException_t* _MyFirstException,
const axutil_env_t *env)
{
AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
return _MyFirstException-> attrib_text;
}
/**
* setter for text
*/
axis2_status_t AXIS2_CALL
adb_MyFirstException_set_text(
adb_MyFirstException_t* _MyFirstException,
const axutil_env_t *env,
axis2_char_t* param_text)
{
AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
if(!_MyFirstException)
{
return AXIS2_FAILURE;
}
if( NULL == param_text )
{
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "text is NULL,
but not a nullable element"
" %d :: %s",
env->error->error_number,
AXIS2_ERROR_GET_MESSAGE(env->error));
return AXIS2_FAILURE;
}
_MyFirstException-> attrib_text = param_text;
return AXIS2_SUCCESS;
}
/**
* axis2_svc_skel_MyService.c
*
* This file was auto-generated from WSDL for "MyService|urn:myuri:1.0"
service
* by the Apache Axis2 version: 1.3 Built on : Aug 10, 2007 (04:45:47
LKT)
* axis2_svc_skel_MyService
*/
#include "axis2_skel_MyService.h"
#include "adb_MyFirstException.h"
#include <axis2_svc_skeleton.h>
#include <axutil_array_list.h>
#include <stdio.h>
/**
* functions prototypes
*/
/* On fault, handle the fault */
axiom_node_t* AXIS2_CALL
axis2_svc_skel_MyService_on_fault(axis2_svc_skeleton_t *svc_skeleton,
const axutil_env_t *env, axiom_node_t *node);
/* Free the service */
int AXIS2_CALL
axis2_svc_skel_MyService_free(axis2_svc_skeleton_t *svc_skeleton,
const axutil_env_t *env);
/* This method invokes the right service method */
axiom_node_t* AXIS2_CALL
axis2_svc_skel_MyService_invoke(axis2_svc_skeleton_t *svc_skeleton,
const axutil_env_t *env,
axiom_node_t *node,
axis2_msg_ctx_t *msg_ctx);
/* Initializing the environment */
int AXIS2_CALL
axis2_svc_skel_MyService_init(axis2_svc_skeleton_t *svc_skeleton,
const axutil_env_t *env);
/* Create the service */
axis2_svc_skeleton_t* AXIS2_CALL
axis2_svc_skel_MyService_create(const axutil_env_t *env);
static const axis2_svc_skeleton_ops_t
axis2_svc_skel_MyService_svc_skeleton_ops_var = {
axis2_svc_skel_MyService_init,
axis2_svc_skel_MyService_invoke,
axis2_svc_skel_MyService_on_fault,
axis2_svc_skel_MyService_free
};
/**
* Implementations for the functions
*/
axis2_svc_skeleton_t* AXIS2_CALL
axis2_svc_skel_MyService_create(const axutil_env_t *env)
{
axis2_svc_skeleton_t *svc_skeleton = NULL;
/* Allocate memory for the structs */
svc_skeleton = AXIS2_MALLOC(env->allocator,
sizeof(axis2_svc_skeleton_t));
svc_skeleton->ops = &axis2_svc_skel_MyService_svc_skeleton_ops_var;
svc_skeleton->func_array = NULL;
return svc_skeleton;
}
int AXIS2_CALL
axis2_svc_skel_MyService_init(axis2_svc_skeleton_t *svc_skeleton,
const axutil_env_t *env)
{
svc_skeleton->func_array = axutil_array_list_create(env, 10);
axutil_array_list_add(svc_skeleton->func_array, env,
axutil_strdup(env, "myOperation"));
/* Any initialization stuff of axis2_skel_MyService goes here */
return AXIS2_SUCCESS;
}
int AXIS2_CALL
axis2_svc_skel_MyService_free(axis2_svc_skeleton_t *svc_skeleton,
const axutil_env_t *env)
{
/* Free the function array */
if (svc_skeleton->func_array)
{
axutil_array_list_free(svc_skeleton->func_array, env);
svc_skeleton->func_array = NULL;
}
/* Free the service skeleton */
if (svc_skeleton)
{
AXIS2_FREE(env->allocator, svc_skeleton);
svc_skeleton = NULL;
}
return AXIS2_SUCCESS;
}
/*
* This method invokes the right service method
*/
axiom_node_t* AXIS2_CALL
axis2_svc_skel_MyService_invoke(axis2_svc_skeleton_t *svc_skeleton,
const axutil_env_t *env,
axiom_node_t *content_node,
axis2_msg_ctx_t *msg_ctx)
{
/* depending on the function name invoke the
* corresponding method
*/
axis2_op_ctx_t *operation_ctx = NULL;
axis2_op_t *operation = NULL;
axutil_qname_t *op_qname = NULL;
axis2_char_t *op_name = NULL;
axiom_node_t *ret_node = NULL;
adb_myOperationResponse_t* ret_val1 = NULL;
adb_myOperation_t* input_val1_1;
operation_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
operation = axis2_op_ctx_get_op(operation_ctx, env);
op_qname = (axutil_qname_t *)axis2_op_get_qname(operation, env);
op_name = axutil_qname_get_localpart(op_qname, env);
if (op_name)
{
if ( axutil_strcmp(op_name, "myOperation") == 0 )
{
input_val1_1 =
adb_myOperation_create( env);
adb_myOperation_deserialize(input_val1_1, env,
content_node );
ret_val1 = axis2_skel_MyService_myOperation(env,
input_val1_1 );
if ( NULL == ret_val1 )
{
AXIS2_LOG_ERROR( env->log, AXIS2_LOG_SI, "NULL
returnted from the business logic from myOperation "
" %d :: %s", env->error->error_number,
AXIS2_ERROR_GET_MESSAGE(env->error));
return axis2_svc_skel_MyService_on_fault( svc_skeleton,
env, NULL);
}
ret_node =
adb_myOperationResponse_serialize(ret_val1, env,
NULL, AXIS2_FALSE);
adb_myOperationResponse_free(ret_val1, env);
adb_myOperation_free(input_val1_1, env);
return ret_node;
}
}
printf("axis2_svc_skel_MyService service ERROR: invalid OM parameters
in request\n");
return content_node;
}
axiom_node_t* AXIS2_CALL
axis2_svc_skel_MyService_on_fault(axis2_svc_skeleton_t *svc_skeleton,
const axutil_env_t *env, axiom_node_t *node)
{
axiom_node_t *error_node = NULL;
axiom_element_t *error_ele = NULL;
adb_MyFirstException_t* _MyFirstException;
error_ele = axiom_element_create(env, node, "fault", NULL,
&error_node);
// get the user defined fault message
_MyFirstException = adb_MyFirstException_create(env);
adb_MyFirstException_set_text(_MyFirstException,env,"Bad server
exception");
axiom_element_set_text(error_ele, env,
adb_MyFirstException_get_text(_MyFirstException,env),
error_node);
//
//axiom_element_set_text(error_ele, env, "FAULT", error_node);
return error_node;
}
/**
* Following block distinguish the exposed part of the dll.
*/
AXIS2_EXTERN int
axis2_get_instance(struct axis2_svc_skeleton **inst,
const axutil_env_t *env)
{
*inst = axis2_svc_skel_MyService_create(env);
if(!(*inst))
{
return AXIS2_FAILURE;
}
return AXIS2_SUCCESS;
}
AXIS2_EXTERN int
axis2_remove_instance(axis2_svc_skeleton_t *inst,
const axutil_env_t *env)
{
axis2_status_t status = AXIS2_FAILURE;
if (inst)
{
status = AXIS2_SVC_SKELETON_FREE(inst, env);
}
return status;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]