Java Code Examples for org.apache.cxf.binding.soap.SoapFault#createFault()
The following examples show how to use
org.apache.cxf.binding.soap.SoapFault#createFault() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Soap12FaultOutInterceptor.java From cxf with Apache License 2.0 | 4 votes |
public void handleMessage(SoapMessage message) throws Fault { LOG.info(getClass() + (String) message.get(Message.CONTENT_TYPE)); XMLStreamWriter writer = message.getContent(XMLStreamWriter.class); Fault f = (Fault)message.getContent(Exception.class); message.put(org.apache.cxf.message.Message.RESPONSE_CODE, f.getStatusCode()); SoapFault fault = SoapFault.createFault(f, message.getVersion()); try { Map<String, String> namespaces = fault.getNamespaces(); for (Map.Entry<String, String> e : namespaces.entrySet()) { writer.writeNamespace(e.getKey(), e.getValue()); } String ns = message.getVersion().getNamespace(); String defaultPrefix = writer.getPrefix(ns); if (defaultPrefix == null) { defaultPrefix = StaxUtils.getUniquePrefix(writer, ns, false); writer.writeStartElement(defaultPrefix, "Fault", ns); writer.writeNamespace(defaultPrefix, ns); } else { writer.writeStartElement(defaultPrefix, "Fault", ns); } writer.writeStartElement(defaultPrefix, "Code", ns); writer.writeStartElement(defaultPrefix, "Value", ns); writer.writeCharacters(fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()), defaultPrefix)); writer.writeEndElement(); if (fault.getSubCodes() != null) { int fscCount = 0; for (QName fsc : fault.getSubCodes()) { writer.writeStartElement(defaultPrefix, "Subcode", ns); writer.writeStartElement(defaultPrefix, "Value", ns); writer.writeCharacters(getCodeString(getFaultCodePrefix(writer, fsc), defaultPrefix, fsc)); writer.writeEndElement(); fscCount++; } while (fscCount-- > 0) { writer.writeEndElement(); } } writer.writeEndElement(); writer.writeStartElement(defaultPrefix, "Reason", ns); writer.writeStartElement(defaultPrefix, "Text", ns); String lang = f.getLang(); if (StringUtils.isEmpty(lang)) { lang = getLangCode(); } writer.writeAttribute("xml", "http://www.w3.org/XML/1998/namespace", "lang", lang); writer.writeCharacters(getFaultMessage(message, fault)); writer.writeEndElement(); writer.writeEndElement(); if (fault.getRole() != null) { writer.writeStartElement(defaultPrefix, "Role", ns); writer.writeCharacters(fault.getRole()); writer.writeEndElement(); } prepareStackTrace(message, fault); if (fault.hasDetails()) { Element detail = fault.getDetail(); writer.writeStartElement(defaultPrefix, "Detail", ns); Node node = detail.getFirstChild(); while (node != null) { StaxUtils.writeNode(node, writer, true); node = node.getNextSibling(); } // Details writer.writeEndElement(); } // Fault writer.writeEndElement(); } catch (Exception xe) { LOG.log(Level.WARNING, "XML_WRITE_EXC", xe); throw f; } }
Example 2
Source File: Soap11FaultOutInterceptor.java From cxf with Apache License 2.0 | 4 votes |
public void handleMessage(SoapMessage message) throws Fault { XMLStreamWriter writer = message.getContent(XMLStreamWriter.class); Fault f = (Fault) message.getContent(Exception.class); SoapFault fault = SoapFault.createFault(f, message.getVersion()); try { Map<String, String> namespaces = fault.getNamespaces(); for (Map.Entry<String, String> e : namespaces.entrySet()) { writer.writeNamespace(e.getKey(), e.getValue()); } String ns = message.getVersion().getNamespace(); String defaultPrefix = writer.getPrefix(ns); if (defaultPrefix == null) { defaultPrefix = StaxUtils.getUniquePrefix(writer, ns, false); writer.writeStartElement(defaultPrefix, "Fault", ns); writer.writeNamespace(defaultPrefix, ns); } else { writer.writeStartElement(defaultPrefix, "Fault", ns); } writer.writeStartElement("faultcode"); String codeString = fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()), defaultPrefix); writer.writeCharacters(codeString); writer.writeEndElement(); writer.writeStartElement("faultstring"); String lang = f.getLang(); if (!StringUtils.isEmpty(lang)) { writer.writeAttribute("xml", "http://www.w3.org/XML/1998/namespace", "lang", lang); } writer.writeCharacters(getFaultMessage(message, fault)); writer.writeEndElement(); prepareStackTrace(message, fault); if (fault.getRole() != null) { writer.writeStartElement("faultactor"); writer.writeCharacters(fault.getRole()); writer.writeEndElement(); } if (fault.hasDetails()) { Element detail = fault.getDetail(); writer.writeStartElement("detail"); Node node = detail.getFirstChild(); while (node != null) { StaxUtils.writeNode(node, writer, true); node = node.getNextSibling(); } // Details writer.writeEndElement(); } // Fault writer.writeEndElement(); } catch (Exception xe) { LOG.log(Level.WARNING, "XML_WRITE_EXC", xe); throw f; } }
Example 3
Source File: SoapFaultSerializerTest.java From cxf with Apache License 2.0 | 4 votes |
private SoapFault verifyFaultToSoapFault(Fault fault, String msg, boolean sender, SoapVersion v) { SoapFault sf = SoapFault.createFault(fault, v); assertEquals(sender ? v.getSender() : v.getReceiver(), sf.getFaultCode()); assertEquals(msg, sf.getMessage()); return sf; }