Search in sources :

Example 41 with SOAPFault

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

the class HandleFaultTest 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(handler.handler_processing.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 42 with SOAPFault

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

the class TestApp method testHandlerException1.

/**
 * Have a handler throw a protocol exception and make sure
 * the proper values are in the soap fault. Test for 6353191.
 */
public void testHandlerException1() throws Exception {
    // the expected fault code local part
    String code = "Sender";
    try {
        // clear handlers (should be none) and add helper handler
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
        ExceptionThrowingHandler handler = new ExceptionThrowingHandler("ProtocolException");
        ClientServerTestUtil.addHandlerToBinding(handler, (BindingProvider) stub);
        // make the call
        try {
            stub.echo("have a nice day");
            fail("did not receive any exception");
        } catch (SOAPFaultException e) {
            SOAPFault fault = e.getFault();
            String faultCode = fault.getFaultCode();
            assertTrue("fault code should end with \"" + code + "\": " + faultCode, faultCode.endsWith(code));
        } catch (Exception e) {
            fail("did not receive soap fault exception. received " + e.toString());
        }
    } finally {
        // always clear the handlers
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
    }
}
Also used : SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault) ExceptionThrowingHandler(fromwsdl.soap12.fault.client.handlers.ExceptionThrowingHandler) ProtocolException(jakarta.xml.ws.ProtocolException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

Example 43 with SOAPFault

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

the class EchoClientTest method test1193.

public void test1193() throws Exception {
    try {
        SOAPMessage response = invoke12(createDispatchWithWSDLWithoutAddressing(), MESSAGES.getReplyToRefpsEchoMessage(), S12_NS, getAddress(), ECHO_IN_ACTION, "test1193");
        fail("SOAPFaultException must be thrown");
    } catch (SOAPFaultException e) {
        assertNotNull(e.getFault());
        SOAPFault f = e.getFault();
        assertEquals(new QName("http://schemas.xmlsoap.org/soap/envelope/", "VersionMismatch"), f.getFaultCodeAsQName());
    }
}
Also used : QName(javax.xml.namespace.QName) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 44 with SOAPFault

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

the class AllResponsesTest method testNonAnonymousFaultTo2.

/**
 * Fault response case
 * @throws Exception
 */
public void testNonAnonymousFaultTo2() throws Exception {
    invokeAsync(createDispatchWithoutAddressing(), TestMessages.NON_ANONYMOUS_FAULT_TO_COMPLETE_FAULTY_MESSAGE, S11_NS, nonAnonAddress, action, endpointAddress, "testNonAnonymousReplyTo");
    // Lets see we get a response in 60 s
    SOAPMessage m = respMsgExchanger.exchange(null, TestMessages.CLIENT_MAX_TIMEOUT, TimeUnit.SECONDS);
    // System.out.println("****************************");
    // m.writeTo(System.out);
    // System.out.println("\n****************************");
    SOAPBody sb = m.getSOAPBody();
    assertTrue(sb.hasFault());
    SOAPFault fault = sb.getFault();
    assertEquals(fault.getFaultString(), "Negative numbers can't be added!");
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 45 with SOAPFault

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

the class TestEndpoint method createSFE.

private SOAPFaultException createSFE() {
    try {
        SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SOAPFault sf = fac.createFault("Some error message.", new QName("http://www.w3.org/2003/05/soap-envelope", "Receiver"));
        sf.setFaultNode("http://testNode");
        return new SOAPFaultException(sf);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) SOAPException(jakarta.xml.soap.SOAPException) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFactory(jakarta.xml.soap.SOAPFactory)

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