Java Code Examples for org.apache.cxf.interceptor.Fault#setDetail()

The following examples show how to use org.apache.cxf.interceptor.Fault#setDetail() . 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: SonosFaultInterceptor.java    From airsonic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handleMessage(SoapMessage message) throws Fault {
    Fault fault = (Fault) message.getContent(Exception.class);
    LOG.warn("Error: " + fault, fault);

    if (fault.getCause() instanceof SonosSoapFault) {
        SonosSoapFault cause = (SonosSoapFault) fault.getCause();
        fault.setFaultCode(new QName(cause.getFaultCode()));
        fault.setMessage(cause.getFaultCode());

        Document document = DOMUtils.createDocument();
        Element details = document.createElement("detail");
        fault.setDetail(details);

        details.appendChild(document.createElement("ExceptionInfo"));

        Element sonosError = document.createElement("SonosError");
        sonosError.setTextContent(String.valueOf(cause.getSonosError()));
        details.appendChild(sonosError);
    }
}
 
Example 2
Source File: SonosFaultInterceptor.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handleMessage(SoapMessage message) throws Fault {
    Fault fault = (Fault) message.getContent(Exception.class);
    LOG.warn("Error: " + fault, fault);

    if (fault.getCause() instanceof SonosSoapFault) {
        SonosSoapFault cause = (SonosSoapFault) fault.getCause();
        fault.setFaultCode(new QName(cause.getFaultCode()));
        fault.setMessage(cause.getFaultCode());

        Document document = DOMUtils.createDocument();
        Element details = document.createElement("detail");
        fault.setDetail(details);

        details.appendChild(document.createElement("ExceptionInfo"));

        Element sonosError = document.createElement("SonosError");
        sonosError.setTextContent(String.valueOf(cause.getSonosError()));
        details.appendChild(sonosError);
    }
}
 
Example 3
Source File: CorbaStreamFaultInInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void createFaultDetail(Document faultData, FaultInfo faultInfo, Fault faultEx) {
    MessagePartInfo partInfo = faultInfo.getMessageParts().get(0);
    QName partInfoName = partInfo.getElementQName();
    Document faultDoc = DOMUtils.getEmptyDocument();
    Element faultElement = faultDoc.createElement("detail");
    Element partElement =
        faultDoc.createElementNS(partInfoName.getNamespaceURI(), partInfoName.getLocalPart());

    Element faultDataElement = (Element) faultData.getFirstChild();
    Node node = faultDataElement.getFirstChild();
    while (node != null) {
        Node importedFaultData = faultDoc.importNode(node, true);
        partElement.appendChild(importedFaultData);
        node = node.getNextSibling();
    }
    faultElement.appendChild(partElement);
    faultEx.setDetail(faultElement);
}
 
Example 4
Source File: XMLFaultInInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(Message message) throws Fault {

        XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
        DepthXMLStreamReader reader = new DepthXMLStreamReader(xsr);

        try {
            reader.nextTag();
            if (!StaxUtils.toNextElement(reader)) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("ILLEGAL_XMLFAULT_FORMAT", BUNDLE));
            }
            String exMessage = reader.getElementText();
            Fault fault = new XMLFault(exMessage);
            reader.nextTag();
            if (StaxUtils.toNextElement(reader)) {
                // handling detail
                Element detail = StaxUtils.read(new FragmentStreamReader(reader)).getDocumentElement();
                fault.setDetail(detail);
            }
            message.setContent(Exception.class, fault);
        } catch (XMLStreamException xse) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", BUNDLE));
        }

    }
 
Example 5
Source File: SonosFaultInterceptor.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleMessage(SoapMessage message) throws Fault {
    Fault fault = (Fault) message.getContent(Exception.class);
    LOG.warn("Error with Soap message", fault);

    if (fault.getCause() instanceof SonosSoapFault) {
        SonosSoapFault cause = (SonosSoapFault) fault.getCause();
        fault.setFaultCode(new QName(cause.getFaultCode()));
        fault.setMessage(cause.getFaultCode());

        Document document = DOMUtils.createDocument();
        Element details = document.createElement("detail");
        fault.setDetail(details);

        if (cause instanceof TokenRefreshRequired) {
            try {
                marshaller.marshal(((TokenRefreshRequired) cause).getRefreshTokens(), details);
            } catch (JAXBException e) {
                LOG.warn("Could not marshal Sonos refresh tokens", e);
            }
        } else {
            details.appendChild(document.createElement("ExceptionInfo"));

            Element sonosError = document.createElement("SonosError");
            sonosError.setTextContent(String.valueOf(cause.getSonosError()));
            details.appendChild(sonosError);
        }
    }
}
 
Example 6
Source File: WeatherSoapFaultHelper.java    From tutorial-soap-spring-boot-cxf with MIT License 5 votes vote down vote up
public static void buildWeatherFaultAndSet2SoapMessage(SoapMessage message, FaultConst faultContent) {
	Fault exceptionFault = (Fault) message.getContent(Exception.class);
	String originalFaultMessage = exceptionFault.getMessage();
	exceptionFault.setMessage(faultContent.getMessage());
	exceptionFault.setDetail(createFaultDetailWithWeatherException(originalFaultMessage, faultContent));
	message.setContent(Exception.class, exceptionFault);
}