Example usage for javax.xml.soap SOAPFault getFaultCodeAsQName

List of usage examples for javax.xml.soap SOAPFault getFaultCodeAsQName

Introduction

In this page you can find the example usage for javax.xml.soap SOAPFault getFaultCodeAsQName.

Prototype

public QName getFaultCodeAsQName();

Source Link

Document

Gets the fault code for this SOAPFault object as a QName object.

Usage

From source file:com.palominolabs.crm.sf.soap.MetadataConnectionImplTest.java

License:asdf

private static void assertInvalidSession(ApiException e) {
    assertEquals("Call failed", e.getMessage());
    Throwable cause = e.getCause();
    assertTrue(cause instanceof SOAPFaultException);
    SOAPFaultException soapFaultException = (SOAPFaultException) cause;

    String expectedMsg = "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: ";

    String actualMsg = soapFaultException.getMessage();
    assertEquals(expectedMsg, truncateSessionId(actualMsg));

    SOAPFault fault = soapFaultException.getFault();

    QName codeQname = fault.getFaultCodeAsQName();
    assertEquals("INVALID_SESSION_ID", codeQname.getLocalPart());

    String faultMsg = fault.getFaultString();
    assertEquals(expectedMsg, truncateSessionId(faultMsg));
}

From source file:com.legstar.proxy.invoke.jaxws.WebServiceInvoker.java

/**
 * Try to extract something meaningful from a SOAP Fault.
 * /*w  ww. ja v  a2 s.c  o  m*/
 * @param e the SOAP Fault exception
 * @return a fault description
 */
@SuppressWarnings("rawtypes")
public String getFaultReasonText(final SOAPFaultException e) {
    if (_log.isDebugEnabled()) {
        SOAPFault fault = e.getFault();
        if (fault != null) {
            QName code = fault.getFaultCodeAsQName();
            String string = fault.getFaultString();
            String actor = fault.getFaultActor();
            _log.debug("SOAP fault contains: ");
            _log.debug("  Fault code = " + code.toString());
            _log.debug("  Local name = " + code.getLocalPart());
            _log.debug("  Namespace prefix = " + code.getPrefix() + ", bound to " + code.getNamespaceURI());
            _log.debug("  Fault string = " + string);
            if (actor != null) {
                _log.debug("  Fault actor = " + actor);
            }
            Detail detail = fault.getDetail();
            if (detail != null) {
                Iterator entries = detail.getDetailEntries();
                while (entries.hasNext()) {
                    DetailEntry newEntry = (DetailEntry) entries.next();
                    String value = newEntry.getValue();
                    _log.debug("  Detail entry = " + value);
                }
            }
        } else {
            _log.debug(e);
        }
    }
    SOAPFault fault = e.getFault();
    if (fault != null) {
        StringBuffer faultMessage = new StringBuffer(e.getFault().getFaultString());
        Detail detail = fault.getDetail();
        if (detail != null) {
            Iterator entries = detail.getDetailEntries();
            while (entries.hasNext()) {
                DetailEntry newEntry = (DetailEntry) entries.next();
                faultMessage.append(" [" + newEntry.getValue() + "]");
            }
        }
        return faultMessage.toString();
    } else {
        return e.getMessage();
    }

}

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

@Validated
@Test/*from   w  w w  . j a va 2s. c om*/
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 {//from  w  ww.j a v  a2s .c o  m
        //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);
    }
}