Example usage for javax.xml.soap SOAPBody addFault

List of usage examples for javax.xml.soap SOAPBody addFault

Introduction

In this page you can find the example usage for javax.xml.soap SOAPBody addFault.

Prototype

public SOAPFault addFault(QName faultCode, String faultString) throws SOAPException;

Source Link

Document

Creates a new SOAPFault object and adds it to this SOAPBody object.

Usage

From source file:net.bpelunit.framework.control.util.BPELUnitUtil.java

/**
 * Creates a new, generic SOAP fault to be used when something goes wrong in a partner track and
 * other tracks must be notified./*from w w  w . ja v  a 2s.  co  m*/
 * 
 * @return
 */
public static SOAPMessage generateGenericSOAPFault() {

    try {
        MessageFactory mFactory = MessageFactory.newInstance();
        SOAPMessage message = mFactory.createMessage();
        SOAPBody body = message.getSOAPBody();
        SOAPFault fault = body.addFault(BPELUnitConstants.SOAP_FAULT_CODE_CLIENT,
                BPELUnitConstants.SOAP_FAULT_DESCRIPTION);

        Detail detail = fault.addDetail();
        DetailEntry entry = detail
                .addDetailEntry(new QName("http://www.bpelunit.org/framework/error", "BPELUnitFault"));
        entry.addTextNode(
                "The BPELUnit test framework has detected a test failure or error. This test case is aborted.");

        return message;

    } catch (Exception e) {
        return null;
    }
}

From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java

/**
 * Allow version specific factory passed in to support SOAP 1.1 and 1.2
 * <b>Important</b> Faults are treated differently for 1.1 and 1.2 For 1.2
 * you can't use the elementName otherwise it throws an exception
 *
 * @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html
 *
 * @param factory/*ww  w. j a  va2s  .  co m*/
 * @param code
 * @param message
 * @return Xml fault string
 * @throws SOAPException
 * @throws TransformerException
 */
protected String createSoapFaultResponse(String soapVersion, String code, String message)
        throws SOAPException, TransformerException {

    SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage();
    SOAPBody soapBody = soapMessage.getSOAPBody();
    /**
     * Faults are treated differently for 1.1 and 1.2 For 1.2 you can't use
     * the elementName otherwise it throws an exception
     *
     * @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html
     */
    SOAPFault fault = null;
    if (soapVersion.equals(SOAPConstants.SOAP_1_1_PROTOCOL)) {
        // existing 1.1 functionality
        fault = soapBody.addFault(soapMessage.getSOAPHeader().getElementName(), message);
        if (code != null)
            fault.setFaultCode(code);
    } else if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) {
        /**
         * For 1.2 there are only a set number of allowed codes, so we can't
         * just use any one like what we did in 1.1. The recommended one to
         * use is SOAPConstants.SOAP_RECEIVER_FAULT
         */
        fault = soapBody.addFault(SOAPConstants.SOAP_RECEIVER_FAULT,
                code == null ? message : code + " : " + message);

    }
    return DomHelper.toXml(soapMessage.getSOAPPart().getDocumentElement());

}