自定义服务异常作为 AxisFault 被抛出

Custom service exceptions are being thrown as AxisFault

我们有一个从 SOAP Web 服务读取的 Axis2 客户端;当使用 WSDL2JAVA 生成新的客户端存根 classes 并且它们的包被重命名时出现问题。生成工具本身不会导致问题,但 WSDL2JAVA 不会为所有 classes 重命名包,所以我必须自己做。

关于为这些 classes 重命名包的最佳方法有什么想法吗?比如以一种巧妙的方式进行字符串替换?

Web 服务在某些情况下会抛出业务异常,它们会被调用代码直接捕获,但是这种情况不会再发生了,客户端现在会捕获 AxisFault,而不是 SPECIALException。

您可以在下面看到 XML 回复:

<?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>

更详细地检查一下,差异可能是由于生成的 BlaServiceStubclass 中的方法 populateFaults 造成的,其中 class 名称设置为稍后通过反射使用的字符串。

这是通过在所有生成的存根 类 中进行字符串替换解决的,同时不更改整个包名称,假设您在生成中使用了“-p com.my.company.network.stubs”,然后对于 'com.bla.blo.bli' 下的剩余包,不要重命名为 'com.my.company.network.stubs.bli',而是重命名为 'com.my.company.network.stubs.bla.blo.bli'