Search in sources :

Example 26 with SOAPFault

use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.

the class SOAPFaultBuilderTest method createFault.

private static SOAPFault createFault(SOAPVersion soapVersion) throws Exception {
    SOAPFactory fac = soapVersion.getSOAPFactory();
    SOAPFault sf = fac.createFault("This is a fault.", soapVersion.faultCodeClient);
    Detail d = sf.addDetail();
    SOAPElement de = d.addChildElement(DETAIL1_QNAME);
    de.addAttribute(new QName("", "msg1"), "This is the first detail message.");
    de = d.addChildElement(DETAIL2_QNAME);
    de.addAttribute(new QName("", "msg2"), "This is the second detail message.");
    return sf;
}
Also used : QName(javax.xml.namespace.QName) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPFactory(jakarta.xml.soap.SOAPFactory) Detail(jakarta.xml.soap.Detail)

Example 27 with SOAPFault

use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.

the class jaxws413Test method test2.

public void test2() throws SOAPException, IOException {
    SOAPFault fault = SOAPVersion.SOAP_12.getSOAPFactory().createFault();
    fault.setFaultCode(new QName("http://www.w3.org/2003/05/soap-envelope", "Sender", "myprefix"));
    fault.setFaultString("Some exception");
    Detail detail = fault.addDetail();
    detail.addDetailEntry(new QName("http://foo/bar", "soap12detail"));
    Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_12, fault);
    SOAPMessage sm = faultMsg.readAsSOAPMessage();
    Detail det = sm.getSOAPBody().getFault().getDetail();
    Iterator iter = det.getDetailEntries();
    assertTrue(iter.hasNext());
    Element item = (Element) iter.next();
    assertEquals(item.getNamespaceURI(), "http://foo/bar");
    assertEquals(item.getLocalName(), "soap12detail");
}
Also used : Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPMessage(jakarta.xml.soap.SOAPMessage) Detail(jakarta.xml.soap.Detail)

Example 28 with SOAPFault

use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.

the class SOAP11Fault method getProtocolException.

protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if (detail != null) {
            Detail d = fault.addDetail();
            for (Element det : detail.getDetails()) {
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) SOAPException(jakarta.xml.soap.SOAPException) SOAPFault(jakarta.xml.soap.SOAPFault) Detail(jakarta.xml.soap.Detail)

Example 29 with SOAPFault

use of jakarta.xml.soap.SOAPFault 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)

Example 30 with SOAPFault

use of jakarta.xml.soap.SOAPFault in project metro-jax-ws by eclipse-ee4j.

the class HandleFaultTester method testServerException3.

/*
     * Same as testServerException2 except that a logical
     * handler throws the first protocol exception, then
     * a soap handler throws the second one from the handleFault
     * method. See testServerException2 description for more detail.
     */
public void testServerException3() throws Exception {
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    reportStub.clearHandlerTracker();
    for (int i = 0; i < numTotalServerHandlers; i++) {
        reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    reportStub.setInstruction(SERVER_PREFIX + 1, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
    reportStub.setInstruction(SERVER_PREFIX + 2, HF_THROW_PROTOCOL_EXCEPTION);
    tracker.clearAll();
    try {
        testStub.testInt(42);
        fail("did not receive exception");
    } catch (SOAPFaultException sfe) {
        // check which exception came back
        SOAPFault fault = sfe.getFault();
        assertNotNull("did not receive fault in exception", fault);
        String handlerMsg = fault.getFaultString();
        assertNotNull("null message in exception", handlerMsg);
        assertTrue("did not receive the expected exception, received: " + handlerMsg, handlerMsg.startsWith(SERVER_PREFIX + 2));
        assertTrue("did not get proper message, got: " + handlerMsg, handlerMsg.indexOf("from handleFault") != -1);
    }
    // check called handlers on server side
    String[] called = { "4", "2", "1", "2_FAULT" };
    List<String> calledHandlers = reportStub.getReport(REPORT_CALLED_HANDLERS);
    assertEquals("Did not get proper number of called handlers", called.length, calledHandlers.size());
    for (int i = 0; i < called.length; i++) {
        assertEquals("did not find expected handler", SERVER_PREFIX + called[i], calledHandlers.get(i));
    }
}
Also used : HandlerTracker(fromwsdl.handler.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Aggregations

SOAPFault (jakarta.xml.soap.SOAPFault)45 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)21 QName (javax.xml.namespace.QName)16 SOAPException (jakarta.xml.soap.SOAPException)12 WebServiceException (jakarta.xml.ws.WebServiceException)11 SOAPMessage (jakarta.xml.soap.SOAPMessage)9 HandlerTracker (fromwsdl.handler.common.HandlerTracker)8 HandlerTracker (handler.handler_processing.common.HandlerTracker)8 Detail (jakarta.xml.soap.Detail)7 Message (com.sun.xml.ws.api.message.Message)5 SOAPBody (jakarta.xml.soap.SOAPBody)5 SOAPFactory (jakarta.xml.soap.SOAPFactory)5 Element (org.w3c.dom.Element)5 SOAPElement (jakarta.xml.soap.SOAPElement)3 InvalidAddressingHeaderException (com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException)2 WSService (com.sun.xml.ws.api.WSService)2 OneWayFeature (com.sun.xml.ws.api.addressing.OneWayFeature)2 MemberSubmissionAddressingFeature (com.sun.xml.ws.developer.MemberSubmissionAddressingFeature)2 FaultDetailHeader (com.sun.xml.ws.message.FaultDetailHeader)2 Iterator (java.util.Iterator)2