Search in sources :

Example 6 with ProtocolException

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

the class HandleFaultTest 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(handler.handler_processing.common.TestProtocolException) 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 7 with ProtocolException

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

the class HandleFaultTest method testClientFaultAndProtocolException1.

/*
     * Have one of the client handlers insert a fault message
     * with fault string msg1 and throw a protocol
     * exception with message msg2. Another handler should
     * get a message in the handleFault method containing
     * a fault with the msg1 fault string.
     *
     * This tests that the runtime doesn't replace a fault if
     * one is already there.
     *
     * Also checks exception received to make sure the right
     * message is there. Check for bug 6232841.
     */
public void testClientFaultAndProtocolException1() 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.setHandlerAction(CLIENT_PREFIX + 7, HA_INSERT_FAULT_AND_THROW_PE_OUTBOUND);
    tracker.setHandleFaultAction(CLIENT_PREFIX + 4, HF_CHECK_FAULT_MESSAGE_STRING);
    try {
        testStub.testInt(42);
        fail("did not receive an exception");
    } catch (ProtocolException e) {
        assertTrue("did not get correct message", e.getMessage().contains(MESSAGE_IN_FAULT));
    } catch (Exception oops) {
        fail("did not receive WebServiceException. received: " + oops);
    }
    // check called handlers
    String[] called = { "0", "1", "3", "4", "5", "7", "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();
    assertEquals("should be no handlers destroyed", 0, destroyedHandlers.size());
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) TestProtocolException(handler.handler_processing.common.TestProtocolException) 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 8 with ProtocolException

use of jakarta.xml.ws.ProtocolException 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 9 with ProtocolException

use of jakarta.xml.ws.ProtocolException 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 10 with ProtocolException

use of jakarta.xml.ws.ProtocolException 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)

Aggregations

ProtocolException (jakarta.xml.ws.ProtocolException)36 WebServiceException (jakarta.xml.ws.WebServiceException)14 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)13 HandlerTracker (fromwsdl.handler.common.HandlerTracker)11 HandlerTracker (handler.handler_processing.common.HandlerTracker)11 TestProtocolException (fromwsdl.handler.common.TestProtocolException)5 TestProtocolException (handler.handler_processing.common.TestProtocolException)5 QName (javax.xml.namespace.QName)4 Message (com.sun.xml.ws.api.message.Message)2 MUHelperHandler (fromwsdl.soap12.fault.client.handlers.MUHelperHandler)2 SOAPBody (jakarta.xml.soap.SOAPBody)2 SOAPElement (jakarta.xml.soap.SOAPElement)2 SOAPException (jakarta.xml.soap.SOAPException)2 SOAPMessage (jakarta.xml.soap.SOAPMessage)2 Node (org.w3c.dom.Node)2 SerializationException (com.sun.xml.ws.encoding.soap.SerializationException)1 JAXBMessage (com.sun.xml.ws.message.jaxb.JAXBMessage)1 CheckedExceptionImpl (com.sun.xml.ws.model.CheckedExceptionImpl)1 DispatchException (com.sun.xml.ws.wsdl.DispatchException)1 ExceptionThrowingHandler (fromwsdl.soap12.fault.client.handlers.ExceptionThrowingHandler)1