You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by Ann-Cathrin Dykström <An...@oss.teleca.se> on 2002/10/08 13:57:31 UTC

Fault and exception handling

Hi,

I'm looking for examples of how fault and exception handling is done??
I'm writing a SOAP web service in Java.

/Annci

--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>


Re: Fault and exception handling

Posted by Scott Nichol <sn...@scottnichol.com>.
I am not certain what you mean by "fault and exception handling".  You
say you are writing a service.  The service does not need to have
anything specific to SOAP.  You can handle exceptions the way you always
would, both catching exceptions you don't want propagating to the client
and throwing exceptions.  The Apache SOAP code will ultimately return a
SOAP fault to the client when your service throws an exception.  If you
want your faults to contain some specific information, you can write a
custom fault handler.  See
http://xml.apache.org/soap/docs/guide/errors.html.

The "standard" client code is something like this code from the
addressbook sample:

    // Invoke the call.
    Response resp;

    try
    {
      resp = call.invoke(url, "");
    }
    catch (SOAPException e)
    {
      System.err.println("Caught SOAPException (" +
                         e.getFaultCode() + "): " +
                         e.getMessage());
      return;
    }

    // Check the response.
    if (!resp.generatedFault())
    {
      Parameter ret = resp.getReturnValue();
      Object value = ret.getValue();

      System.out.println(value != null ? "\n" + value : "I don't
know.");
    }
    else
    {
      Fault fault = resp.getFault();

      System.err.println("Generated fault: " + fault);
    }

Scott Nichol

----- Original Message -----
From: "Ann-Cathrin Dykström" <An...@oss.teleca.se>
To: <so...@xml.apache.org>
Sent: Tuesday, October 08, 2002 7:57 AM
Subject: Fault and exception handling


> Hi,
>
> I'm looking for examples of how fault and exception handling is done??
> I'm writing a SOAP web service in Java.
>
> /Annci
>
> --
> To unsubscribe, e-mail:   <ma...@xml.apache.org>
> For additional commands, e-mail: <ma...@xml.apache.org>
>
>


Re: Fault and exception handling

Posted by Scott Nichol <sn...@scottnichol.com>.
I am not certain what you mean by "fault and exception handling".  You
say you are writing a service.  The service does not need to have
anything specific to SOAP.  You can handle exceptions the way you always
would, both catching exceptions you don't want propagating to the client
and throwing exceptions.  The Apache SOAP code will ultimately return a
SOAP fault to the client when your service throws an exception.  If you
want your faults to contain some specific information, you can write a
custom fault handler.  See
http://xml.apache.org/soap/docs/guide/errors.html.

The "standard" client code is something like this code from the
addressbook sample:

    // Invoke the call.
    Response resp;

    try
    {
      resp = call.invoke(url, "");
    }
    catch (SOAPException e)
    {
      System.err.println("Caught SOAPException (" +
                         e.getFaultCode() + "): " +
                         e.getMessage());
      return;
    }

    // Check the response.
    if (!resp.generatedFault())
    {
      Parameter ret = resp.getReturnValue();
      Object value = ret.getValue();

      System.out.println(value != null ? "\n" + value : "I don't
know.");
    }
    else
    {
      Fault fault = resp.getFault();

      System.err.println("Generated fault: " + fault);
    }

Scott Nichol

----- Original Message -----
From: "Ann-Cathrin Dykström" <An...@oss.teleca.se>
To: <so...@xml.apache.org>
Sent: Tuesday, October 08, 2002 7:57 AM
Subject: Fault and exception handling


> Hi,
>
> I'm looking for examples of how fault and exception handling is done??
> I'm writing a SOAP web service in Java.
>
> /Annci
>
> --
> To unsubscribe, e-mail:   <ma...@xml.apache.org>
> For additional commands, e-mail: <ma...@xml.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>