Search in sources :

Example 31 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 32 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 33 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 34 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)

Example 35 with SOAPFaultException

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

the class HandlerUtil method throwSOAPFaultException.

boolean throwSOAPFaultException(MessageContext context, String name, String direction) {
    Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if ((outbound == Boolean.TRUE && direction.equals(INBOUND)) || (outbound == Boolean.FALSE && direction.equals(OUTBOUND))) {
        // not the direction we want
        return true;
    }
    // random info in soap fault
    try {
        QName faultCode = new QName("uri", "local", "prefix");
        String faultString = "fault";
        String faultActor = "faultActor";
        SOAPFault sf = SOAPFactory.newInstance().createFault(faultString, faultCode);
        sf.setFaultActor(faultActor);
        Detail detail = sf.addDetail();
        Name entryName = SOAPFactory.newInstance().createName("someFaultEntry");
        detail.addDetailEntry(entryName);
        throw new SOAPFaultException(sf);
    } catch (SOAPException e) {
        throw new RuntimeException("Couldn't create SOAPFaultException " + e);
    }
}
Also used : QName(javax.xml.namespace.QName) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) QName(javax.xml.namespace.QName)

Aggregations

SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)113 QName (javax.xml.namespace.QName)31 WebServiceException (jakarta.xml.ws.WebServiceException)28 SOAPFault (jakarta.xml.soap.SOAPFault)22 JAXBException (jakarta.xml.bind.JAXBException)17 Dispatch (jakarta.xml.ws.Dispatch)16 MemberSubmissionAddressingFeature (com.sun.xml.ws.developer.MemberSubmissionAddressingFeature)14 Source (javax.xml.transform.Source)14 MemberSubmissionEndpointReference (com.sun.xml.ws.developer.MemberSubmissionEndpointReference)12 SOAPMessage (jakarta.xml.soap.SOAPMessage)12 W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)12 MalformedURLException (java.net.MalformedURLException)12 HandlerTracker (fromwsdl.handler.common.HandlerTracker)11 HandlerTracker (handler.handler_processing.common.HandlerTracker)11 AddressingFeature (jakarta.xml.ws.soap.AddressingFeature)10 IOException (java.io.IOException)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 Test (org.junit.Test)7