Search in sources :

Example 26 with HandlerTracker

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

the class HandleFaultTest method testClientException1.

/*
     * Have one of the client handlers throw a protocol exception
     * and another handler throw a new exception during the
     * handleFault method. Handler 5 throws protocol, handler 4
     * throws new exception. Should receive the new exception and
     * have proper handlers called.
     *
     * The new exception will be wrapped by the client runtime
     * in a web service exception.
     */
public void testClientException1() 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_RUNTIME_EXCEPTION);
    tracker.setHandlerAction(CLIENT_PREFIX + 5, HA_THROW_PROTOCOL_EXCEPTION_OUTBOUND);
    try {
        testStub.testInt(42);
        fail("did not receive any exception");
    } catch (ProtocolException pe) {
        fail("should not have received original (protocol) exception");
    } catch (WebServiceException wse) {
        Throwable t = wse.getCause();
        assertNotNull("did not receive cause of exception", t);
        assertTrue("did not receive proper cause of exception", t instanceof RuntimeException);
        String msg = t.getMessage();
        assertTrue("received exception from wrong handler", msg.startsWith(CLIENT_PREFIX + 4));
        assertTrue("did not get proper message in exception: " + msg, msg.indexOf("handleFault") != -1);
    }
    // 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 only no handlers destroyed", destroyedHandlers.isEmpty());
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) TestProtocolException(handler.handler_processing.common.TestProtocolException) WebServiceException(jakarta.xml.ws.WebServiceException) HandlerTracker(handler.handler_processing.common.HandlerTracker)

Example 27 with HandlerTracker

use of handler.handler_processing.common.HandlerTracker 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)

Example 28 with HandlerTracker

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

the class HandleFaultTest method testClientException2.

/*
     * Same as testClientException1 except that a protocol
     * exception is thrown from handleFault instead of
     * a generic runtime exception.
     * ProtocolExceptions are not rewrapped in WebServiceException
     */
public void testClientException2() 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_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("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 : 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)

Example 29 with HandlerTracker

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

the class SimpleHelloTest method testHello.

/*
     * Simple end to end test (mostly for debug work)
     */
public void testHello() throws Exception {
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    tracker.clearAll();
    TestService_Service service = getService();
    TestService test = getTestStub(service);
    ReportService report = getReportStub(service);
    report.clearHandlerTracker();
    int foo = -1;
    int bar = test.testInt(foo);
    assertTrue(foo == bar);
    System.out.println("ok");
    List<String> closedHandlers = report.getReport(TestConstants.REPORT_CLOSED_HANDLERS);
    List<String> handlers = report.getReport(TestConstants.REPORT_CALLED_HANDLERS);
    assertNotNull("received null list back from server", handlers);
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker)

Example 30 with HandlerTracker

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

the class SimpleHelloTest method testHelloOneWay.

/*
     * Simple end to end test (mostly for debug work)
     */
public void testHelloOneWay() throws Exception {
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    tracker.clearAll();
    TestService_Service service = getService();
    TestService test = getTestStub(service);
    ReportService report = getReportStub(service);
    report.clearHandlerTracker();
    test.testIntOneWay(0);
    // make normal call after
    assertEquals("did not get expected response", 4, test.testInt(4));
    System.out.println("ok");
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker)

Aggregations

HandlerTracker (handler.handler_processing.common.HandlerTracker)62 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 (handler.handler_processing.common.TestProtocolException)5 Map (java.util.Map)4 BindingProvider (jakarta.xml.ws.BindingProvider)3 Binding (jakarta.xml.ws.Binding)1 Handler (jakarta.xml.ws.handler.Handler)1 SOAPBinding (jakarta.xml.ws.soap.SOAPBinding)1 QName (javax.xml.namespace.QName)1