简体   繁体   中英

Sample java code to retrieve AxisFault from InvocationTargetException

My InvocationTargetException prints following when did 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)

I would like to retrieve faultcode & faultString from InvocationTargetException: file.already.exists File already exists

how can i do this??

I am not sure why the the stacktrace looks like this and contains no trace of the actual InvocationFailureException, but I assume the AxisFault is directly wrapped in the InvocationFailureException, and then unwrapping it might help, eg like:

    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();
        }
    }

Maybe you even need to get the root cause recursively if it is not wrapped directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM