Example usage for javax.xml.soap SOAPFactory createFault

List of usage examples for javax.xml.soap SOAPFactory createFault

Introduction

In this page you can find the example usage for javax.xml.soap SOAPFactory createFault.

Prototype

public abstract SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException;

Source Link

Document

Creates a new SOAPFault object initialized with the given reasonText and faultCode

Usage

From source file:be.fedict.trust.xkms2.WSSecurityServerHandler.java

public static SOAPFaultException createSOAPFaultException(String faultString, String wsseFaultCode) {

    SOAPFault soapFault;/*www  .  jav  a2 s.  c o m*/
    try {
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        soapFault = soapFactory.createFault(faultString,
                new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                        wsseFaultCode, "wsse"));
    } catch (SOAPException e) {
        throw new RuntimeException("SOAP error");
    }
    return new SOAPFaultException(soapFault);
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test/*from   www. ja va2s  .c o  m*/
public void testCreateFault() {
    try {
        SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        //SOAPFactory factory = SOAPFactory.newInstance();
        SOAPFault sf = factory.createFault("This is the fault reason.", SOAPConstants.SOAP_RECEIVER_FAULT);
        assertNotNull(sf);
        assertTrue(sf instanceof SOAPFault);
        QName fc = sf.getFaultCodeAsQName();
        //Expect FaultCode="+SOAPConstants.SOAP_RECEIVER_FAULT
        Iterator i = sf.getFaultReasonTexts();
        if (i == null) {
            log.info("Call to getFaultReasonTexts() returned null iterator");
        }
        String reason = "";
        while (i.hasNext()) {
            reason += (String) i.next();
        }
        assertNotNull(reason);
        assertTrue(reason.indexOf("This is the fault reason.") > -1);
        assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
    } catch (SOAPException e) {
        fail("Caught unexpected SOAPException");
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Test
public void testCreateFault1() {
    try {// w  ww.ja  v a  2  s .  com
        //SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SOAPFactory factory = SOAPFactory.newInstance();
        SOAPFault sf = factory.createFault("This is the fault reason.", SOAPConstants.SOAP_RECEIVER_FAULT);
        assertNotNull(sf);
        QName fc = sf.getFaultCodeAsQName();
        Iterator i = sf.getFaultReasonTexts();

        String reason = "";
        while (i.hasNext()) {
            reason += (String) i.next();
        }
        log.info("Actual ReasonText=" + reason);
        assertNotNull(reason);
        assertTrue(reason.indexOf("This is the fault reason.") > -1);
        assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
    } catch (SOAPException e) {
        //Caught expected SOAPException
    } catch (Exception e) {
        fail("Exception: " + e);
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

/** for soap 1.1 */
@Validated/*from w  w w  . j  av a 2  s . c  o m*/
@Test
public void testSOAPFaultException1() {
    try {
        SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SOAPFault fault = factory.createFault("This is the fault reason.",
                new QName("http://MyNamespaceURI.org/", "My Fault Code"));
    } catch (UnsupportedOperationException e) {
        //Caught expected UnsupportedOperationException
    } catch (SOAPException e) {
        //Caught expected SOAPException
    } catch (IllegalArgumentException e) {
        //Caught expected IllegalArgumentException
    } catch (Exception e) {
        fail("Exception: " + e);
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

/** for soap 1.2 */
@Validated//  w ww.  ja  va  2 s .c  o m
@Test
public void testSOAPFaultException2() {
    try {
        SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SOAPFault sf = factory.createFault("This is the fault reason.",
                new QName("http://MyNamespaceURI.org/", "My Fault Code"));
        fail("Did not throw expected SOAPException");
    } catch (UnsupportedOperationException e) {
        //Caught expected UnsupportedOperationException
    } catch (SOAPException e) {
        //Caught expected SOAPException
    } catch (IllegalArgumentException e) {
        //Caught expected IllegalArgumentException
    } catch (Exception e) {
        fail("Exception: " + e);
    }
}