Custom service exceptions are being thrown as AxisFault
Asked Answered
H

1

7

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.

Herat answered 17/4, 2015 at 14:0 Comment(3)
if it is from the server. You can check with Server side team to check what goes wrong in your request processing. Do not forget to share the request and response XML files with them.Cohosh
It is not from the server, it turns out: if I generate new code using WSDL2JAVA, things work out. But I need to rename the package, using -p 'packageName' renames only some of the class, and renaming the packages for more classes is causing the exception to become AxisFault again.Herat
I don't know deeply Axis2, but in Axis 1 when you generated classes from wsdl it generated also wsdd files; in these files you could find also package definition; did you check if there are some files after code generation? did you check the file content? In any case I think that the simplest way to generate classes is to use the Ant task provided by AxisHalley
H
1

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'

Herat answered 25/4, 2015 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.