background image

The SOAP 1.2 code

<< Creating and Populating a SOAPFault Object | Retrieving Fault Information >>
<< Creating and Populating a SOAPFault Object | Retrieving Fault Information >>
148
SOAP
WITH
A
TTACHMENTS
API
FOR
J
AVA
node with the value
"SOAP-ENV:Server"
by specifying a default prefix and the
namespace URI for a SOAP envelope.
QName faultName =
new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Server");
fault.setFaultCode(faultName);
fault.setFaultActor("http://gizmos.com/orders");
fault.setFaultString("Server not responding");
The SOAP 1.2 code would look like this:
QName faultName =
new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE,
"Receiver");
fault.setFaultCode(faultName);
fault.setFaultRole("http://gizmos.com/order");
fault.addFaultReasonText("Server not responding", Locale.US);
To add one or more subcodes to the fault code, call the method
fault.append-
FaultSubcode
, which takes a
QName
argument.
The
SOAPFault
object
fault
, created in the preceding lines of code, indicates
that the cause of the problem is an unavailable server and that the actor at
http:/
/gizmos.com/orders
is having the problem. If the message were being routed
only to its ultimate destination, there would have been no need to set a fault
actor. Also note that
fault
does not have a
Detail
object because it does not
relate to the
SOAPBody
object. (If you use SOAP 1.2, you can use the
setFault-
Role
method instead of
setFaultActor
.)
The following SOAP 1.1 code fragment creates a
SOAPFault
object that includes
a
Detail
object. Note that a
SOAPFault
object can have only one
Detail
object,
which is simply a container for
DetailEntry
objects, but the
Detail
object can
have multiple
DetailEntry
objects. The
Detail
object in the following lines of
code has two
DetailEntry
objects added to it.
SOAPFault fault = body.addFault();
QName faultName =
new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Client");
fault.setFaultCode(faultName);
fault.setFaultString("Message does not have necessary info");
Detail detail = fault.addDetail();
QName entryName =
new QName("http://gizmos.com/orders/", "order", "PO");