Search in sources :

Example 1 with FaultMessage

use of com.sun.xml.ws.message.FaultMessage in project metro-jax-ws by eclipse-ee4j.

the class SOAPFaultBuilder method createSOAP11Fault.

private static Message createSOAP11Fault(SOAPVersion soapVersion, Throwable e, Object detail, CheckedExceptionImpl ce, QName faultCode) {
    SOAPFaultException soapFaultException = null;
    String faultString = null;
    String faultActor = null;
    Throwable cause = e.getCause();
    if (e instanceof SOAPFaultException) {
        soapFaultException = (SOAPFaultException) e;
    } else if (cause instanceof SOAPFaultException) {
        soapFaultException = (SOAPFaultException) e.getCause();
    }
    if (soapFaultException != null) {
        QName soapFaultCode = soapFaultException.getFault().getFaultCodeAsQName();
        if (soapFaultCode != null)
            faultCode = soapFaultCode;
        faultString = soapFaultException.getFault().getFaultString();
        faultActor = soapFaultException.getFault().getFaultActor();
    }
    if (faultCode == null) {
        faultCode = getDefaultFaultCode(soapVersion);
    }
    if (faultString == null) {
        faultString = e.getMessage();
        if (faultString == null) {
            faultString = e.toString();
        }
    }
    Element detailNode = null;
    QName firstEntry = null;
    if (detail == null && soapFaultException != null) {
        detailNode = soapFaultException.getFault().getDetail();
        firstEntry = getFirstDetailEntryName((Detail) detailNode);
    } else if (ce != null) {
        try {
            DOMResult dr = new DOMResult();
            ce.getBond().marshal(detail, dr);
            detailNode = (Element) dr.getNode().getFirstChild();
            firstEntry = getFirstDetailEntryName(detailNode);
        } catch (JAXBException e1) {
            // Should we throw Internal Server Error???
            faultString = e.getMessage();
            faultCode = getDefaultFaultCode(soapVersion);
        }
    }
    SOAP11Fault soap11Fault = new SOAP11Fault(faultCode, faultString, faultActor, detailNode);
    // Don't fill the stacktrace for Service specific exceptions.
    if (ce == null) {
        soap11Fault.captureStackTrace(e);
    }
    Message msg = JAXBMessage.create(JAXB_CONTEXT, soap11Fault, soapVersion);
    return new FaultMessage(msg, firstEntry);
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) FaultMessage(com.sun.xml.ws.message.FaultMessage) Message(com.sun.xml.ws.api.message.Message) JAXBMessage(com.sun.xml.ws.message.jaxb.JAXBMessage) FaultMessage(com.sun.xml.ws.message.FaultMessage) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) JAXBException(jakarta.xml.bind.JAXBException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) Detail(jakarta.xml.soap.Detail)

Example 2 with FaultMessage

use of com.sun.xml.ws.message.FaultMessage in project metro-jax-ws by eclipse-ee4j.

the class SOAPFaultBuilder method createSOAP12Fault.

private static Message createSOAP12Fault(SOAPVersion soapVersion, Throwable e, Object detail, CheckedExceptionImpl ce, QName faultCode) {
    SOAPFaultException soapFaultException = null;
    CodeType code = null;
    String faultString = null;
    String faultRole = null;
    String faultNode = null;
    Throwable cause = e.getCause();
    if (e instanceof SOAPFaultException) {
        soapFaultException = (SOAPFaultException) e;
    } else if (cause instanceof SOAPFaultException) {
        soapFaultException = (SOAPFaultException) e.getCause();
    }
    if (soapFaultException != null) {
        SOAPFault fault = soapFaultException.getFault();
        QName soapFaultCode = fault.getFaultCodeAsQName();
        if (soapFaultCode != null) {
            faultCode = soapFaultCode;
            code = new CodeType(faultCode);
            Iterator<QName> iter = fault.getFaultSubcodes();
            boolean first = true;
            SubcodeType subcode = null;
            while (iter.hasNext()) {
                QName value = iter.next();
                if (first) {
                    SubcodeType sct = new SubcodeType(value);
                    code.setSubcode(sct);
                    subcode = sct;
                    first = false;
                    continue;
                }
                subcode = fillSubcodes(subcode, value);
            }
        }
        faultString = soapFaultException.getFault().getFaultString();
        faultRole = soapFaultException.getFault().getFaultActor();
        faultNode = soapFaultException.getFault().getFaultNode();
    }
    if (faultCode == null) {
        faultCode = getDefaultFaultCode(soapVersion);
        code = new CodeType(faultCode);
    } else if (code == null) {
        code = new CodeType(faultCode);
    }
    if (faultString == null) {
        faultString = e.getMessage();
        if (faultString == null) {
            faultString = e.toString();
        }
    }
    ReasonType reason = new ReasonType(faultString);
    Element detailNode = null;
    QName firstEntry = null;
    if (detail == null && soapFaultException != null) {
        detailNode = soapFaultException.getFault().getDetail();
        firstEntry = getFirstDetailEntryName((Detail) detailNode);
    } else if (detail != null) {
        try {
            DOMResult dr = new DOMResult();
            ce.getBond().marshal(detail, dr);
            detailNode = (Element) dr.getNode().getFirstChild();
            firstEntry = getFirstDetailEntryName(detailNode);
        } catch (JAXBException e1) {
            // Should we throw Internal Server Error???
            faultString = e.getMessage();
        }
    }
    SOAP12Fault soap12Fault = new SOAP12Fault(code, reason, faultNode, faultRole, detailNode);
    // Don't fill the stacktrace for Service specific exceptions.
    if (ce == null) {
        soap12Fault.captureStackTrace(e);
    }
    Message msg = JAXBMessage.create(JAXB_CONTEXT, soap12Fault, soapVersion);
    return new FaultMessage(msg, firstEntry);
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) Message(com.sun.xml.ws.api.message.Message) JAXBMessage(com.sun.xml.ws.message.jaxb.JAXBMessage) FaultMessage(com.sun.xml.ws.message.FaultMessage) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) JAXBException(jakarta.xml.bind.JAXBException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) FaultMessage(com.sun.xml.ws.message.FaultMessage) SOAPFault(jakarta.xml.soap.SOAPFault) Detail(jakarta.xml.soap.Detail)

Aggregations

Message (com.sun.xml.ws.api.message.Message)2 FaultMessage (com.sun.xml.ws.message.FaultMessage)2 JAXBMessage (com.sun.xml.ws.message.jaxb.JAXBMessage)2 JAXBException (jakarta.xml.bind.JAXBException)2 Detail (jakarta.xml.soap.Detail)2 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)2 QName (javax.xml.namespace.QName)2 DOMResult (javax.xml.transform.dom.DOMResult)2 Element (org.w3c.dom.Element)2 SOAPFault (jakarta.xml.soap.SOAPFault)1