Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom service exceptions are being thrown as AxisFault

We have an Axis2 client reading from a SOAP web service; an issue occurred when new client stub classes were generated using WSDL2JAVA and their packages were renamed. The generation tool itself isn't causing the issue, but WSDL2JAVA isn't renaming packages for all classes, so i'm having to do this myself.

Any idea about the best way to rename packages for these classes, without having issues? Such as doing a String replacement in a smart way ?

The web service throws business exceptions in some cases, and they are caught directly by the calling code, however this is not happening anymore and instead of SPECIALException, the client now catches AxisFault.

You can see the XML response below:

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server</faultcode>
            <faultstring>Exception message, due to business error.</faultstring>
            <detail>
                <ns2:SPECIALException
                    xmlns:ns2="http://com.bla.com/common/exception/xsd/2008/08">
                    <ns2:code>7</ns2:code>
                    <ns2:message>Exception message, due to business error.</ns2:message>
                </ns2:SPECIALException>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

Checking this in more detail, the difference are probably due to method populateFaults in the generated BlaServiceStub class, where class names are set as Strings for later use through reflection.

like image 298
abdelrahman-sinno Avatar asked Apr 17 '15 14:04

abdelrahman-sinno


1 Answers

This was solved through doing a String replacement in all the generated stub classes, while not changing the entire package name, so say you have used '-p com.my.company.network.stubs in generation', then for remaining packages under 'com.bla.blo.bli', do not rename to 'com.my.company.network.stubs.bli', but do it to 'com.my.company.network.stubs.bla.blo.bli'

like image 127
abdelrahman-sinno Avatar answered Nov 10 '22 07:11

abdelrahman-sinno