Axis2 schema validation using ADB - how to report a meaningful error message in Soap Fault

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Axis2 schema validation using ADB - how to report a meaningful error message in Soap Fault

googley
I am using Axis 1.6.2 to generate Java from WSDL using ADB for serialisation. I have many elements in the WSDL that uses restriction and a pattern e.g. element ABC:

    <simpleType name="ABC">
        <restriction base="string">
            <maxLength value="10"/>
            <minLength value="10"/>
            <pattern value="[1-9][0-9]{9}"/>
        </restriction>
    </simpleType>

The code generated is:

public void setABC(java.lang.String param){

    if (org.apache.axis2.databinding.utils.ConverterUtil.convertToString(param).matches("[1-9][0-9]{9}")) {
        this.localABC=param;
    }
    else {
        throw new java.lang.RuntimeException();
    }
}

The problem is when I send a request with an invalid ABC element (e.g. 'AAA') in SoapUI I get the above runtime exception thrown and displayed as the message detail in the SoapFault in a big stack trace in the response. This occurs early on in the in bound message flow before it hits my business logic implementation class.

What I would like is to report a meaningful error message wrt element  ABC e.g. 'Invalid ABC format'. 

Is there a way to do this in Axis2 using ADB (bearing in mind that I have many elements similar to ABC)?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Axis2 schema validation using ADB - how to report a meaningful error message in Soap Fault

googley
This is post to answer my own question in case it may help someone else.

Basically yo have to use schema validation further up the message pipeline. The following article proved very helpful for understanding the extension points available in Axis2 here

The solution I chose was the created a custom MessageReceiver so I could get access to the MessageContext. Once you have a MessageContext you can follow the schema validation code  posted here