The simple answer is: you cannot. Expressing the HttpSOAPConnection code, the local instance of the HttpURLConnection object is used to actually communicate with the target service. This does the httpResponse code, but it more or less completely hides it from the caller. All you conclude is that if you don't get an exception, but the returned SOAPMessage contains SOAPFault, then the return code was HttpURLConnection.HTTP_INTERNAL_ERROR (i.e. 500). No exception and SOAPFault does not mean that the return code ranged from 200 to 206, all of which are "SUCCESS" - unfortunately, the status record from the HTTP headers in the HttpURLConnection object is not explicitly copied to the MIMEHeaders in the returned SOAPMessage ...
Everything else will throw an exception, and the code will start after the open parenthesis in the exception message field and will probably be three-digit, it is difficult to be precise, because someone forgot the closed parenthesis or any other delimiter before the message ...
throw new SOAPExceptionImpl( "Bad response: (" + responseCode + httpConnection.getResponseMessage());
For instance:
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (502internal error - server connection terminated
It terribly relies on formatting the text message in the exception, but the response code no longer displays.
source share