从InvocationTargetException检索AxisFault的示例java代码

从InvocationTargetException检索AxisFault的示例java代码,java,invocationtargetexception,Java,Invocationtargetexception,我的InvocationTargetException打印以下内容printStackTrace是何时进行的: AxisFault faultCode: file.could.not.be.created faultSubcode: faultString: The File could not be created faultActor: faultNode: faultDetail: {http://schemas.xmlsoap.org/soap/envelop

我的InvocationTargetException打印以下内容printStackTrace是何时进行的:

AxisFault faultCode: file.could.not.be.created faultSubcode: faultString: The File could not be created faultActor: faultNode: faultDetail: {http://schemas.xmlsoap.org/soap/envelope/}Fault:file.already.existsFile already exists The File could not be created at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222) at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129) at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) 轴断层 故障代码:file.can.not.be.created 故障子代码: faultString:无法创建文件 故障因素: 故障节点: 故障详情: {http://schemas.xmlsoap.org/soap/envelope/}错误:file.ready.existsFile已存在 无法创建该文件 位于org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222) 位于org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129) 位于org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087) 位于org.apache.xerces.parsers.AbstractSAXParser.endElement(未知源) 我想从InvocationTargetException检索faultcode和faultString: 文件已存在 文件已存在


我如何做到这一点???

我不确定stacktrace为什么看起来像这样,并且不包含实际InvocationFailureException的跟踪,但我假设AxisFault直接包装在InvocationFailureException中,然后将其展开可能会有所帮助,例如:

    try {
         // here code which throws InvocationFailureException
    } catch (InvocationFailureException e) {
        Throwable rootCause = e.getRootCause();
        if (rootCause instanceof AxisFault) {
            AxisFault axFault = (AxisFault)rootCause;
            // now extract information, e.g. 
            axFault.getFaultDetails();
        }
    }

如果不直接包装根本原因,可能您甚至需要递归获取它。

感谢您的快速回复,根据您的建议,我尝试了以下方法:Throwable rootCause=ex.getCause();if(rootCause instanceof org.apache.axis.AxisFault){AxisFault axFault=(AxisFault)rootCause;Element[]eleArray=axFault.getFaultDetails();for(Element ele:eleArray){SOP(“ele:+ele”);SOP(ele.getChildNodes();}SOP(axFault.getFaultString());SOP(axFault.getFaultCode());SOP(axfaultreason.getFaultReason())}但我得到的唯一信息是:“无法创建文件”无法获取faultstring,即“文件已存在”Arf,我一直不知道Axis将其错误作为DOM元素返回。如果您想提取包含错误消息的元素的子节点的文本,可能像那边的助手这样的东西很有用:。。。如有必要,将其重写为递归。。。