Search in sources :

Example 26 with SOAPFaultException

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

the class EndToEndErrorTest method testServerInboundSoapFaultException1.

/*
     * Have one of the server handlers throw a soap fault
     * exception and check that the proper methods are called.
     */
public void testServerInboundSoapFaultException1() throws Exception {
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    // these lines make calls to the server
    reportStub.clearHandlerTracker();
    for (int i = 0; i < numTotalHandlers; i++) {
        reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    reportStub.setInstruction(SERVER_PREFIX + 2, HA_THROW_SOAP_FAULT_EXCEPTION_INBOUND);
    // so we clear out the client handlers afterwards
    tracker.clearAll();
    try {
        testStub.testInt(3);
        fail("did not receive any exception");
    } catch (SOAPFaultException e) {
        // check some details
        SOAPFault fault = e.getFault();
        assertEquals("did not get proper fault actor", "faultActor", fault.getFaultActor());
        assertEquals("did not get proper fault string", "fault", fault.getFaultString());
        assertEquals("did not get proper fault code", new QName("uri", "local", "prefix"), fault.getFaultCodeAsQName());
    }
    // check result
    String[] called = { "4", "2", "4_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));
    }
    // should be no destroyed handlers
    List<String> destroyedHandlers = reportStub.getReport(REPORT_DESTROYED_HANDLERS);
    assertTrue("Should be 0 destroyed handlers", destroyedHandlers.isEmpty());
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker) QName(javax.xml.namespace.QName) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 27 with SOAPFaultException

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

the class HandleFaultTest method testServerException1.

/*
     * Have one of the server handlers throw a protocol exception
     * and another handler throw a different exception during the
     * handleFault method. Handler 2 throws first exception, then
     * handler 4. Should receive the new exception.
     */
public void testServerException1() throws Exception {
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    reportStub.clearHandlerTracker();
    // tell the server handlers to register themselves
    for (int i = 0; i < numTotalServerHandlers; i++) {
        reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    // this handler will register being called before throwing PE
    reportStub.setInstruction(SERVER_PREFIX + 2, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
    // the HF_ action does not override the HA_ action
    reportStub.setInstruction(SERVER_PREFIX + 4, HF_THROW_RUNTIME_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 + 4));
    }
    // check called handlers on server side
    String[] called = { "4", "2", "4_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 28 with SOAPFaultException

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

the class AddNumbersTest method testClientValidationFailure.

public void testClientValidationFailure() {
    SchemaValidationFeature feature = new SchemaValidationFeature();
    AddNumbersPortType port = service.getAddNumbersPort(feature);
    // more than 4 digits, so doesn't pass validation
    int number1 = 10001;
    int number2 = 20;
    try {
        port.addNumbers(number1, number2);
        fail("Client Schema Validation didn't work");
    } catch (SOAPFaultException se) {
        fail("Client Schema Validation didn't work");
    } catch (WebServiceException se) {
    // Expected exception - Client side validation failed as expected
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SchemaValidationFeature(com.sun.xml.ws.developer.SchemaValidationFeature)

Example 29 with SOAPFaultException

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

the class HandlerClientTest method testServerRtException2.

public void testServerRtException2() throws Exception {
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    tracker.clearAll();
    Hello12 stub = create12Stub();
    ReportService report = createReportStub();
    report.clearHandlerTracker();
    try {
        int bar = stub.hello12(handler.single_handlertube.common.TestConstants.SERVER_THROW_RUNTIME_EXCEPTION);
        assert (false);
    } catch (SOAPFaultException e) {
        // as expected.
        System.out.println("ok");
    }
    List<String> expClientCalled = Arrays.asList(new String[] { "client2", "client2_FAULT" });
    List<String> gotClientCalled = tracker.getCalledHandlers();
    Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_CLIENT_CALLED_HANDLERS, checkEqual(expClientCalled, gotClientCalled));
    List<String> expServerCalled = Arrays.asList(new String[] { "server1", "server1_FAULT" });
    List<String> gotServerCalled = report.getReport(handler.single_handlertube.common.TestConstants.REPORT_CALLED_HANDLERS);
    Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_SERVER_CALLED_HANDLERS, checkEqual(expServerCalled, gotServerCalled));
    List<String> expClientClosed = Arrays.asList(new String[] { "client2" });
    List<String> gotClientClosed = tracker.getClosedHandlers();
    Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_CLIENT_CLOSED_HANDLERS, checkEqual(expClientClosed, gotClientClosed));
    List<String> expServerClosed = Arrays.asList(new String[] { "server1" });
    List<String> gotServerClosed = report.getReport(handler.single_handlertube.common.TestConstants.REPORT_CLOSED_HANDLERS);
    Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_SERVER_CLOSED_HANDLERS, checkEqual(expServerClosed, gotServerClosed));
}
Also used : HandlerTracker(handler.single_handlertube.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

Example 30 with SOAPFaultException

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

the class HandlerClientTest method testServerRtException1.

public void testServerRtException1() throws Exception {
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    tracker.clearAll();
    Hello stub = createStub();
    ReportService report = createReportStub();
    report.clearHandlerTracker();
    try {
        int bar = stub.hello(handler.single_handlertube.common.TestConstants.SERVER_THROW_RUNTIME_EXCEPTION);
        assert (false);
    } catch (SOAPFaultException e) {
        // as expected.
        System.out.println("ok");
    }
    List<String> expClientCalled = Arrays.asList(new String[] { "client1", "client1_FAULT" });
    List<String> gotClientCalled = tracker.getCalledHandlers();
    Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_CLIENT_CALLED_HANDLERS, checkEqual(expClientCalled, gotClientCalled));
    List<String> expServerCalled = Arrays.asList(new String[] { "server2", "server2_FAULT" });
    List<String> gotServerCalled = report.getReport(handler.single_handlertube.common.TestConstants.REPORT_CALLED_HANDLERS);
    Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_SERVER_CALLED_HANDLERS, checkEqual(expServerCalled, gotServerCalled));
    List<String> expClientClosed = Arrays.asList(new String[] { "client1" });
    List<String> gotClientClosed = tracker.getClosedHandlers();
    Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_CLIENT_CLOSED_HANDLERS, checkEqual(expClientClosed, gotClientClosed));
    List<String> expServerClosed = Arrays.asList(new String[] { "server2" });
    List<String> gotServerClosed = report.getReport(handler.single_handlertube.common.TestConstants.REPORT_CLOSED_HANDLERS);
    Assert.assertTrue(handler.single_handlertube.common.TestConstants.ERR_SERVER_CLOSED_HANDLERS, checkEqual(expServerClosed, gotServerClosed));
}
Also used : HandlerTracker(handler.single_handlertube.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

Aggregations

SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)105 QName (javax.xml.namespace.QName)28 WebServiceException (jakarta.xml.ws.WebServiceException)27 SOAPFault (jakarta.xml.soap.SOAPFault)21 JAXBException (jakarta.xml.bind.JAXBException)16 Dispatch (jakarta.xml.ws.Dispatch)16 MemberSubmissionAddressingFeature (com.sun.xml.ws.developer.MemberSubmissionAddressingFeature)14 MemberSubmissionEndpointReference (com.sun.xml.ws.developer.MemberSubmissionEndpointReference)12 W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)12 MalformedURLException (java.net.MalformedURLException)12 Source (javax.xml.transform.Source)12 HandlerTracker (fromwsdl.handler.common.HandlerTracker)11 HandlerTracker (handler.handler_processing.common.HandlerTracker)11 AddressingFeature (jakarta.xml.ws.soap.AddressingFeature)10 Message (com.sun.xml.ws.api.message.Message)9 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)9 ProtocolException (jakarta.xml.ws.ProtocolException)9 IOException (java.io.IOException)7 SOAPMessage (jakarta.xml.soap.SOAPMessage)6 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)5