Getting out the message from SOAP on error.
Remus Stratulat 2004-08-30
I get from call.invoke() SOAPException - Parsing error. The message
received was not a SOAP envelope so SAX throws an error reported
through SOAPException. I want to get my hands on that message. I really
needed because is an error from PHP reported as html.
To get the message out you can do something like this:
SOAPHTTPConnection shc = new SOAPHTTPConnection();
Call call = new Call();
call.setSOAPTransport(shc);
try {
resp = call.invoke(url, "");
} catch (SOAPException e) {
StringBuffer sb = new StringBuffer();
SOAPContext sc = shc.getResponseSOAPContext();
try {
for(int i=0; i<sc.getCount(); i++) {
MimeBodyPart mbp = sc.getBodyPart(i);
sb.append(mbp.getContent());
}
} catch (Exception ex) {}
}
This is not 100% rigorous because type checking for each MimeBodyPart must be done. But you get the point.