Search in sources :

Example 1 with TestProtocolException

use of handler.handler_processing.common.TestProtocolException in project metro-jax-ws by eclipse-ee4j.

the class HandleFaultTest method testClientException3.

/*
     * Same as testClientException21 except that a
     * test-specific protocol exception is used, and
     * the test checks to make sure the exact exception
     * is wrapped in the web service exception.
     * ProtocolExceptions are not rewrapped in WebServiceException
     */
public void testClientException3() 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 + 4, HF_THROW_TEST_PROTOCOL_EXCEPTION);
    tracker.setHandlerAction(CLIENT_PREFIX + 5, HA_THROW_PROTOCOL_EXCEPTION_OUTBOUND);
    try {
        testStub.testInt(42);
        fail("did not receive any exception");
    } catch (ProtocolException pe) {
        String msg = pe.getMessage();
        assertTrue("did not receive proper cause of exception. should " + "be TestProtocolException, not " + pe.getClass().toString(), pe instanceof TestProtocolException);
        assertTrue("received exception from wrong handler", msg.startsWith(CLIENT_PREFIX + 4));
        assertTrue("did not get proper message in exception: " + msg, msg.indexOf("handleFault") != -1);
    } catch (WebServiceException wse) {
        fail("did not receive ProtocolException. received: " + wse);
    } catch (Exception oops) {
        fail("did not receive ProtocolException. received: " + oops);
    }
    // check called handlers
    String[] called = { "0", "1", "3", "4", "5", "4_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();
    assertTrue("should be no handlers destroyed", destroyedHandlers.isEmpty());
}
Also used : TestProtocolException(handler.handler_processing.common.TestProtocolException) ProtocolException(jakarta.xml.ws.ProtocolException) TestProtocolException(handler.handler_processing.common.TestProtocolException) WebServiceException(jakarta.xml.ws.WebServiceException) HandlerTracker(handler.handler_processing.common.HandlerTracker) ProtocolException(jakarta.xml.ws.ProtocolException) TestProtocolException(handler.handler_processing.common.TestProtocolException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) WebServiceException(jakarta.xml.ws.WebServiceException)

Aggregations

HandlerTracker (handler.handler_processing.common.HandlerTracker)1 TestProtocolException (handler.handler_processing.common.TestProtocolException)1 ProtocolException (jakarta.xml.ws.ProtocolException)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)1