I am using JAX-WS 2.2.5 framework for calling WebServices. I want to identify the special case when the call fails because the Web Service is down or not accessible.
In some calls, i get a WebServiceException.
    catch(javax.xml.ws.WebServiceException e)
    {
        if(e.getCause() instanceof IOException)
            if(e.getCause().getCause() instanceof ConnectException)
                 // Will reach here because the Web Service was down or not accessible
In other places, I get ClientTransportException (class derived from WebServiceException)
    catch(com.sun.xml.ws.client.ClientTransportException ce)
    {
         if(ce.getCause() instanceof ConnectException)
              // Will reach here because the Web Service was down or not accessible
What's a good way to trap this error?
Should I use something like
    catch(javax.xml.ws.WebServiceException e)
    {
        if((e.getCause() instanceof ConnectException) || (e.getCause().getCause() instanceof ConnectException))
         {
                   // Webservice is down or inaccessible
or is there a better way of doing this?
Maybe you'll want to treat UnknownHostException also!
        Throwable cause = e.getCause();
        while (cause != null)
        {
            if (cause instanceof UnknownHostException)
            {
                //TODO some thing
                break;
            }
            else if (cause instanceof ConnectException)
            {
                //TODO some thing
                break;
            }
            cause = cause.getCause();
        }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With