axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Trent Bartlem (JIRA)" <>
Subject [jira] Created: (AXIS2-4252) Axis2-xmlbean stub doesn't set exception.message on custom soap faults
Date Wed, 25 Feb 2009 02:33:01 GMT
Axis2-xmlbean stub doesn't set exception.message on custom soap faults

                 Key: AXIS2-4252
             Project: Axis 2.0 (Axis2)
          Issue Type: Improvement
          Components: client-api, codegen, databinding
    Affects Versions: 1.4.1
         Environment: Linux
            Reporter: Trent Bartlem
            Priority: Minor

Axis2 provides implementation subclasses of org.apache.axis2.client.Stub when it generates
from WSDL.

An example WSDL snippet would be:
    <wsdl:operation name="quote" parameterOrder="booking">
      <wsdl:input name="quoteRequest" message="impl:quoteRequest" />
      <wsdl:output name="quoteResponse" message="impl:quoteResponse" />
      <wsdl:fault name="ValidationException" message="impl:ValidationException" />

When the server-side code is called and fails validation, it returns this soap message, which
conforms to the above operation. (the ValidationMessage element is specified in the WSDL as
a return element, but its structure isn't important)

<soapenv:Envelope xmlns:soapenv="">
         <faultstring>Missing field: Address line1</faultstring>
            <ValidationMessage xmlns="">You are missing a required

However, the unmarshalled org.example.custom.ValidationException() that is thrown from the
axis2 client does not have the exception message set.

The section of the client stub that's responsible for unmarshalling the exception looks like
try {
        // snip
        //execute the operation client
        // snip
}catch(org.apache.axis2.AxisFault f){

   faultElt = f.getDetail();
            if (faultElt!=null){
                if (faultExceptionNameMap.containsKey(faultElt.getQName())){
                    //make the fault by reflection
                        java.lang.String exceptionClassName = (java.lang.String)faultExceptionClassNameMap.get(faultElt.getQName());
                        java.lang.Class exceptionClass = java.lang.Class.forName(exceptionClassName);
                        java.lang.Exception ex=
                                (java.lang.Exception) exceptionClass.newInstance();
                        //message class
                        java.lang.String messageClassName = (java.lang.String)faultMessageMap.get(faultElt.getQName());
                        java.lang.Class messageClass = java.lang.Class.forName(messageClassName);
                        java.lang.Object messageObject = fromOM(faultElt,messageClass,null);
                        java.lang.reflect.Method m = exceptionClass.getMethod("setFaultMessage",
                                   new java.lang.Class[]{messageClass});
                        m.invoke(ex,new java.lang.Object[]{messageObject});
                        if (ex instanceof org.example.custom.ValidationException){
                          throw (org.example.custom.ValidationException)ex;
                        // snip rest of method

The problem is due to the generated line :

                        java.lang.Exception ex=
                                (java.lang.Exception) exceptionClass.newInstance();

This doesn't set the exception message.

Perhaps the code generation could be changed to output

                        java.lang.Exception ex=
                                (java.lang.Exception) exceptionClass.getConstructor(String.class).newInstance(f.getMessage());


This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message