0

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

user2040528
  • 11
  • 1
  • 6

1 Answers1

1

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, e.g. 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.

Clemens Klein-Robbenhaar
  • 3,457
  • 1
  • 18
  • 27
  • Thanks for quick reply, per your suggestion i tried this: 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(axFault.getFaultReason()); } But only thing i am getting is: "The File could not be created" Not able to get faultstring i.e. "File already exists" – user2040528 Feb 04 '13 at 18:54
  • Arf, I have been pretty ignorant of the fact that Axis returns their errors as DOM-elements. If you want to extract the text of the child nodes of the element containing the error message, maybe somethign like that helper over there is useful: [Extract all text children of an element](http://www.java2s.com/Code/Java/XML/Extractalltextchildrenofanelement.htm) ... if necessary, rewrite it to be recursive ... – Clemens Klein-Robbenhaar Feb 05 '13 at 11:19