Using SAAJ you can specify the value for faultcode, faultstring, and faultactor using methods of the SOAPFault object. The following code creates a SOAP fault object and sets the faultcode, faultstring, and faultactor attributes:
SOAPFault fault; reply = factory.createMessage(); envp = reply.getSOAPPart().getEnvelope(true); someBody = envp.getBody(); fault = someBody.addFault(): fault.setFaultCode("Server"); fault.setFaultString("Some Server Error"); fault.setFaultActor(http://xxx.me.com/list/endpoint.esp/) reply.saveChanges(); |
The server can return this object in its reply to an incoming SOAP message in case of a server error.
The next code sample shows how to define a detail and detail entry object. Note that you must create a name for the detail entry object.
SOAPFault fault = someBody.addFault(); fault.setFaultCode("Server"); fault.setFaultActor("http://foo.com/uri"); fault.setFaultString ("Unkown error"); Detail myDetail = fault.addDetail(); detail.addDetailEntry(envelope.createName("125detail", "m", "Someuri")).addTextNode("the message cannot contain the string //"); reply.saveChanges(); |