I want to create a custom SOAP Fault filling the FaultCode,FaultString and detail myself.
But it seems the Axis SOAPFault implementation forces me to use the AxisFault, to create SoapFault.
which is not a clean way of doing the creation.
See the code snippet
<Snippet>
public void testquick() throws Exception {
MessageFactory msgfactory = MessageFactory.newInstance();
SOAPFactory factory = SOAPFactory.newInstance(); SOAPMessage outputmsg = msgfactory.createMessage();
String valueCode = "faultcode";
String valueString = "faultString"; SOAPFault fault =
outputmsg.getSOAPPart().getEnvelope().getBody().addFault();
fault.setFaultCode(valueCode);
fault.setFaultString(valueString);Detail d;
d = fault.addDetail();
d.addDetailEntry(factory.createName("Hello"));
if (outputmsg != null) {
if (outputmsg.saveRequired()) {
outputmsg.saveChanges();
}
outputmsg.writeTo(System.out);
}
}
</Snippet><output>
.<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:faultcode</faultcode>
<faultstring>faultString</faultstring>
<faultactor></faultactor>
<detail/> <-------------------------------Detail Missing. , added a Hello element.
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
</output>
I think this is because of the serialization code, which only uses AxisFault.
No reference to current detail
<codesnippet>
public void outputImpl(SerializationContext context)
throws IOException
{
SOAPConstants soapConstants = context.getMessageContext() == null ?
SOAPConstants.SOAP11_CONSTANTS :
context.getMessageContext().getSOAPConstants();
namespaceURI = soapConstants.getEnvelopeURI();
name = Constants.ELEM_FAULT;context.registerPrefixForURI(prefix, soapConstants.getEnvelopeURI());
context.startElement(new QName(this.getNamespaceURI(),
this.getName()),
attributes);
// XXX - Can fault be anything but an AxisFault here?
if (fault instanceof AxisFault) {</codesnippet>
Is it a Bug and violation of SAAJ Spec.
saurabh arora
_________________________________________________________________
It's magic. It's a whole new world. http://server1.msn.co.in/sp03/hclbeanstalktour/amazing_winxp.html It's the Windows XP experience.
