private void writeSoap12Fault(XMLStreamWriter writer) throws Exception {
QName envelope = getEnvelopeName();
String soapUri = envelope.getNamespaceURI();
String soapPrefix = envelope.getPrefix();
writer.setPrefix(soapPrefix, soapUri);
SoapFault fault = message.getFault();
fault.translateCodeTo12();
writer.writeStartElement(soapPrefix, SoapMarshaler.FAULT, soapUri);
QName code = fault.getCode();
if (code != null) {
XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTCODE);
XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTVALUE);
XMLStreamHelper.writeTextQName(writer, code);
writer.writeEndElement();
QName subcode = fault.getSubcode();
if (subcode != null) {
XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTSUBCODE);
XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTVALUE);
XMLStreamHelper.writeTextQName(writer, subcode);
writer.writeEndElement();
writer.writeEndElement();
}
writer.writeEndElement();
}
String reason = fault.getReason();
if (reason == null && fault.getCause() != null) {
reason = fault.getCause().toString();
}
XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTREASON);
XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTTEXT);
writer.writeAttribute(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI, "lang", "en");
if (reason != null) {
writer.writeCharacters(reason);
}
writer.writeEndElement();
writer.writeEndElement();
URI node = fault.getNode();
if (node != null) {
XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTNODE);
writer.writeCharacters(node.toString());
writer.writeEndElement();
}
URI role = fault.getRole();
if (role != null) {
XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTROLE);
writer.writeCharacters(role.toString());
writer.writeEndElement();
}
Source details = fault.getDetails();
if (details != null) {
XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTDETAIL);
writeDetails(writer, details);
writer.writeEndElement();
}