Web Service throwing exception using Axis2 Java

China☆狼群 提交于 2019-12-04 18:06:11

I don't really think there is a problem. Your Client calls a method on the server. That method results in an exception. Axis transforms this exception to something which can be send to the client to indicate the error.

All exceptions, as far as I know, are wrapped into an AxisFault which is then transmitted to the client as, I believe, a SoapFault message with as description the exception message.

In other words, the client should only see AxisFaults as the exception (exception class) is not serialized and send. Server exceptions should become AxisFaults at the client side.

Have you tried using Axis2 with Lady4j, it solved this issue for us.

If your WSDL specifies that your service throws a custom error your client should expect to handle these errors as well as the generic remote exceptions thrown by the operation of Axis2.

When your stub recieves an AxisFault from the server, it attempts to consturct a custom exception if this is specified in your WSDL. If this fails it will simply pass out the AxisFault instead.

The stub will attempt to call f.getDetail(). If this is null it will not try to construct a custom exception and will pass out the AxisFault. With Axis2 1.5, the autogenerated MessageInOutReciver on the serverside does not set this value by default.

You can set it manually on the serverside like this (assuming you have autogenerated MyFaultException and MyFault classes):

        MyFaultException ex = new MyFaultException("My Exception Message");
        MyFault fault = new MyFault();
        fault.setMyFault("My Fault Message");
        ex.setFaultMessage(fault);
        throw ex; 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!