0
檢索AxisFault做的printStackTrace當以下
我的InvocationTargetException打印:樣本Java代碼來的InvocationTargetException
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)
我想找回的faultcode &從的InvocationTargetException faultString: file.already.exists 文件已經存在
我該怎麼做?
感謝您的快速回復,根據您的建議我試過這個: Throwable rootCause = ex.getCause();如果(rootCause instanceof org.apache.axis.AxisFault){ AxisFault axFault =(AxisFault)rootCause; Element [] eleArray = axFault.getFaultDetails(); (元素ele:eleArray){SOP(「ele:」+ ele); SOP(ele.getChildNodes()); } SOP(axFault.getFaultString()); SOP(axFault.getFaultCode()); SOP(axFault.getFaultReason()); } 但只有我得到的是:「該文件無法創建」 無法獲得故障字符串,即「文件已存在」 – user2040528
Arf,我一直都很無知的事實,軸返回他們的錯誤爲DOM -elements。如果要提取包含錯誤消息的元素的子節點的文本,可能像那個幫助器那樣有用:[提取元素的所有文本子元素](http://www.java2s.com/Code /Java/XML/Extractalltextchildrenofanelement.htm)...如果有必要,將其重寫爲遞歸... –