Search in sources :

Example 26 with HandlerTracker

use of fromwsdl.handler.common.HandlerTracker in project metro-jax-ws by eclipse-ee4j.

the class EndToEndTester method testRequestProperty.

/*
     * Sets a property on the request context with a static stub
     * and verifies that the property exists in the handler.
     */
public void testRequestProperty() throws Exception {
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    TestService stub = getTestStub(getService());
    ((BindingProvider) stub).getRequestContext().put(USER_CLIENT_PROPERTY_NAME, USER_PROPERTY_CLIENT_SET);
    tracker.clearAll();
    tracker.setHandlerAction(CLIENT_PREFIX + 5, HA_CHECK_FOR_USER_PROPERTY_OUTBOUND);
    stub.testInt(1);
}
Also used : HandlerTracker(fromwsdl.handler.common.HandlerTracker)

Example 27 with HandlerTracker

use of fromwsdl.handler.common.HandlerTracker in project metro-jax-ws by eclipse-ee4j.

the class HandleFaultTester method testServerException5.

/*
     * Same as testServerException4 except with different
     * handlers throwing the exceptions. This one uses
     * two logical handlers.
     */
public void testServerException5() 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 + 0, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
    reportStub.setInstruction(SERVER_PREFIX + 1, 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 + 1));
        assertTrue("did not get proper message, got: " + handlerMsg, handlerMsg.indexOf("from handleFault") != -1);
    }
    // check called handlers on server side
    String[] called = { "4", "2", "1", "0", "1_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)

Example 28 with HandlerTracker

use of fromwsdl.handler.common.HandlerTracker in project metro-jax-ws by eclipse-ee4j.

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

Example 29 with HandlerTracker

use of fromwsdl.handler.common.HandlerTracker in project metro-jax-ws by eclipse-ee4j.

the class HandleFaultTester method testClientReturnFalse1.

/*
     * Have one of the client handlers throw a protocol exception
     * and another handler return false during the handleFault
     * method. Handler 5 throws protocol, handler 1 returns
     * false.
     */
public void testClientReturnFalse1() throws Exception {
    TestService testStub = getTestStub(getService());
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    tracker.clearAll();
    for (int i = 0; i < numTotalHandlers; i++) {
        tracker.setHandlerAction(CLIENT_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    tracker.setHandleFaultAction(CLIENT_PREFIX + 1, HF_RETURN_FALSE);
    tracker.setHandlerAction(CLIENT_PREFIX + 5, HA_THROW_PROTOCOL_EXCEPTION_OUTBOUND);
    try {
        testStub.testInt(42);
        fail("did not receive an exception");
    } catch (ProtocolException pe) {
    // ok
    } catch (Exception oops) {
        fail("did not receive WebServiceException. received: " + oops);
    }
    // check called handlers
    String[] called = { "0", "1", "3", "4", "5", "4_FAULT", "3_FAULT", "1_FAULT" };
    int[] closed = { 5, 4, 3, 1, 0 };
    List<String> calledHandlers = tracker.getCalledHandlers();
    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", CLIENT_PREFIX + called[i], calledHandlers.get(i));
    }
    // check closed handlers
    List<String> closedHandlers = tracker.getClosedHandlers();
    assertEquals("Did not get proper number of closed handlers", closed.length, closedHandlers.size());
    for (int i = 0; i < closed.length; i++) {
        assertEquals("did not find expected handler", CLIENT_PREFIX + closed[i], closedHandlers.get(i));
    }
    // check destroyed handlers
    List<String> destroyedHandlers = tracker.getDestroyedHandlers();
    assertEquals("should be no handlers destroyed", 0, destroyedHandlers.size());
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) TestProtocolException(fromwsdl.handler.common.TestProtocolException) HandlerTracker(fromwsdl.handler.common.HandlerTracker) ProtocolException(jakarta.xml.ws.ProtocolException) TestProtocolException(fromwsdl.handler.common.TestProtocolException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) WebServiceException(jakarta.xml.ws.WebServiceException)

Example 30 with HandlerTracker

use of fromwsdl.handler.common.HandlerTracker in project metro-jax-ws by eclipse-ee4j.

the class HandleFaultTester method testServerException2.

/*
     * 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.
     *
     * Same as testServerException1 except that the handleFault
     * method throws a ProtocolException rather than a generic
     * runtime exception. This is because the SOAPMessageDispatcher
     * assumes that the message already has the proper fault information
     * in it when the exception it catches is a protocol exception.
     */
public void testServerException2() throws Exception {
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    reportStub.clearHandlerTracker();
    reportStub.setInstruction(SERVER_PREFIX + 2, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
    reportStub.setInstruction(SERVER_PREFIX + 4, HF_THROW_PROTOCOL_EXCEPTION);
    tracker.clearAll();
    for (int i = 0; i < numTotalHandlers; i++) {
        tracker.setHandlerAction(CLIENT_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    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));
        assertTrue("did not get proper message, got: " + handlerMsg, handlerMsg.indexOf("from handleFault") != -1);
    }
    // check called handlers on client side
    String[] called = { "0", "1", "3", "4", "5", "7", "7_FAULT", "5_FAULT", "4_FAULT", "3_FAULT", "1_FAULT", "0_FAULT" };
    int[] closed = { 7, 5, 4, 3, 1, 0 };
    List<String> calledHandlers = tracker.getCalledHandlers();
    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", CLIENT_PREFIX + called[i], calledHandlers.get(i));
    }
    // check closed handlers
    List<String> closedHandlers = tracker.getClosedHandlers();
    assertEquals("Did not get proper number of closed handlers", closed.length, closedHandlers.size());
    for (int i = 0; i < closed.length; i++) {
        assertEquals("did not find expected handler", CLIENT_PREFIX + closed[i], closedHandlers.get(i));
    }
    // check destroyed handlers
    List<String> destroyedHandlers = tracker.getDestroyedHandlers();
    assertTrue("should be no handler destroyed", destroyedHandlers.isEmpty());
}
Also used : HandlerTracker(fromwsdl.handler.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Aggregations

HandlerTracker (fromwsdl.handler.common.HandlerTracker)64 WebServiceException (jakarta.xml.ws.WebServiceException)16 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)16 ProtocolException (jakarta.xml.ws.ProtocolException)13 SOAPFault (jakarta.xml.soap.SOAPFault)8 TestProtocolException (fromwsdl.handler.common.TestProtocolException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 BindingProvider (jakarta.xml.ws.BindingProvider)3 Handler (jakarta.xml.ws.handler.Handler)3 BaseSOAPHandler (fromwsdl.handler.common.BaseSOAPHandler)2 AsyncHandler (jakarta.xml.ws.AsyncHandler)2 ArrayList (java.util.ArrayList)2 Binding (jakarta.xml.ws.Binding)1 SOAPBinding (jakarta.xml.ws.soap.SOAPBinding)1 QName (javax.xml.namespace.QName)1