File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes web service exception handling.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "web service exception handling.." Watch "web service exception handling.." New topic

web service exception handling..

alex ho kwong yiu

Joined: Jun 06, 2006
Posts: 3
hi all,

i am using the axis ver 1.4 to call web service, the calling is fine in normal case. say i send out a request and get a response.

but when there is error return. the error message seem include in response message without throw any exceptions. i do set up catch (Exception e){} but without hitting it.

<soapenv:Envelope xmlns:soapenv="" xmlns:xsd="" xmlns:xsi="">
<faultstring> Connection timed out: connect</faultstring>
<ns1:stackTrace xmlns:ns1=""> Connection timed out: connect
at InstantCashTester.main(
<ns2:hostname xmlns:ns2="">pc-host</ns2:hostname>

i would like to ask how to catch the web service exception (such as the connection timed out exception) or should i parse the response xml and detect it the fault value by self??
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
As far as I know, different web service stacks handle faults differently.
If your web service stack is JAX-WS compliant, then have a look at section 3.7 in the JAX-WS Specifications 2.1 for details.
JAX-WS translates service-specific exceptions to faults, which at the client side are again translated to exceptions.
In your case, there seem to be no translation at the client side, so you will most likely have to examine the incoming responses for faults. This can be done in a handler.
Best wishes!

My free books and tutorials:
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
As per my understanding whenever there is fault response axis client throws fault exception, so it should not be a problem. I did further research and could find out a flag in axis2 which decides client behaviour in case of soap fault.

public class Options implements Externalizable {
* If there is a SOAP Fault in the body of the incoming SOAP Message, system
* can be configured to throw an exception with the details extracted from
* the information from the fault message. This boolean variable will enable
* that facility. If this is false, the response message will just be
* returned to the application, irrespective of whether it has a Fault or
* not.
* @param exceptionToBeThrownOnSOAPFault
public void setExceptionToBeThrownOnSOAPFault(
boolean exceptionToBeThrownOnSOAPFault) {
isExceptionToBeThrownOnSOAPFault = Boolean

SCJP 1.5(97%) My Blog
I agree. Here's the link:
subject: web service exception handling..
It's not a secret anymore!