Java Code Examples for org.apache.cxf.binding.soap.SoapFault#getRole()

The following examples show how to use org.apache.cxf.binding.soap.SoapFault#getRole() . 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: Soap12FaultSoapPayloadConverter.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleFault(XMLStreamWriter writer, SoapFault soapFault, SoapVersion soapVersion) {
    try {
        Map<String, String> namespaces = soapFault.getNamespaces();
        for (Map.Entry<String, String> e : namespaces.entrySet()) {
            writer.writeNamespace(e.getKey(), e.getValue());
        }

        String ns = soapVersion.getNamespace();
        writer.writeStartElement(SOAP_PREFIX, "Fault", ns);

        writer.writeStartElement(SOAP_PREFIX, "Code", ns);
        writer.writeStartElement(SOAP_PREFIX, "Value", ns);

        writer.writeCharacters(soapFault.getCodeString(getFaultCodePrefix(writer, soapFault.getFaultCode()), SOAP_PREFIX));
        writer.writeEndElement();

        if (soapFault.getSubCodes() != null) {
            int fscCount = 0;
            for (QName fsc : soapFault.getSubCodes()) {
                writer.writeStartElement(SOAP_PREFIX, "Subcode", ns);
                writer.writeStartElement(SOAP_PREFIX, "Value", ns);
                writer.writeCharacters(getCodeString(getFaultCodePrefix(writer, fsc), SOAP_PREFIX, fsc));
                writer.writeEndElement();
                fscCount++;
            }
            while (fscCount > 0) {
                writer.writeEndElement();
                fscCount--;
            }
        }
        writer.writeEndElement();

        writer.writeStartElement(SOAP_PREFIX, "Reason", ns);
        writer.writeStartElement(SOAP_PREFIX, "Text", ns);
        String lang = soapFault.getLang();
        if (StringUtils.isEmpty(lang)) {
            lang = getLangCode();
        }
        writer.writeAttribute("xml", "http://www.w3.org/XML/1998/namespace", "lang", lang);
        writer.writeCharacters(getFaultMessage(soapFault));
        writer.writeEndElement();
        writer.writeEndElement();

        if (soapFault.getRole() != null) {
            writer.writeStartElement(SOAP_PREFIX, "Role", ns);
            writer.writeCharacters(soapFault.getRole());
            writer.writeEndElement();
        }

        prepareStackTrace(ns, soapFault);

        if (soapFault.hasDetails()) {
            Element detail = soapFault.getDetail();
            writer.writeStartElement(SOAP_PREFIX, "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) {
        throw new RuntimeCamelException("XML Write Exception: " + xe.getMessage(), xe);
    }
}
 
Example 2
Source File: Soap11FaultSoapPayloadConverter.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleFault(XMLStreamWriter writer, SoapFault fault, SoapVersion soapVersion) {
    try {
        Map<String, String> namespaces = fault.getNamespaces();
        for (Map.Entry<String, String> e : namespaces.entrySet()) {
            writer.writeNamespace(e.getKey(), e.getValue());
        }

        final String soapNamespace = soapVersion.getNamespace();
        writer.writeStartElement(SOAP_PREFIX, "Fault", soapNamespace);

        writer.writeStartElement("faultcode");

        String codeString = fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()), SOAP_PREFIX);

        writer.writeCharacters(codeString);
        writer.writeEndElement();

        writer.writeStartElement("faultstring");
        String lang = fault.getLang();
        if (!StringUtils.isEmpty(lang)) {
            writer.writeAttribute("xml", "http://www.w3.org/XML/1998/namespace", "lang", lang);
        }
        writer.writeCharacters(getFaultMessage(fault));
        writer.writeEndElement();
        prepareStackTrace(soapNamespace, 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) {
        throw new RuntimeCamelException("XML write exception: " + xe.getMessage(), xe);
    }
}
 
Example 3
Source File: Soap12FaultOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
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 4
Source File: Soap11FaultOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
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;
    }
}