MessageFactory.newInstance();
SOAPMessage msg = msgFactory.createMessage();
SOAPEnvelope envelope =
msg.getSOAPPart().getEnvelope();
SOAPBody body = envelope.getBody();
SOAPFault fault = body.addFault();
fault.setFaultCode("Client");
fault.setFaultString(
"Message does not have necessary info");
fault.setFaultActor("http://gizmos.com/order");
Detail detail = fault.addDetail();
Name entryName = envelope.createName("order", "PO",
"http://gizmos.com/orders/");
DetailEntry entry = detail.addDetailEntry(entryName);
entry.addTextNode(
"quantity element does not have a value");
Name entryName2 = envelope.createName("confirmation",
"PO", "http://gizmos.com/confirm");
DetailEntry entry2 = detail.addDetailEntry(entryName2);
entry2.addTextNode("Incomplete address: no zip code");
msg.saveChanges();
// Now retrieve the SOAPFault object and its contents
//after checking to see that there is one
if (body.hasFault()) {
fault = body.getFault();
String code = fault.getFaultCode();
String string = fault.getFaultString();
String actor = fault.getFaultActor();
System.out.println("SOAP fault contains: ");
System.out.println(" fault code = " + code);
System.out.println(" fault string = " + string);
if (actor != null) {
System.out.println(" fault actor = " + actor);
}
detail = fault.getDetail();
if (detail != null) {
Iterator it = detail.getDetailEntries();
while (it.hasNext()) {
entry = (DetailEntry) it.next();
String value = entry.getValue();