Search in sources :

Example 31 with ProtocolException

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

the class EndToEndErrorTest method testServerInboundRuntimeException1.

/*
     * Have one of the server handlers throw a runtime
     * exception and check that the proper methods are called.
     * This test uses a logical handler.
     */
public void testServerInboundRuntimeException1() throws Exception {
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    // these lines make calls to the server
    reportStub.clearHandlerTracker();
    for (int i = 0; i < numTotalHandlers; i++) {
        reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    reportStub.setInstruction(SERVER_PREFIX + 1, HA_THROW_RUNTIME_EXCEPTION_INBOUND);
    // so we clear out the client handlers afterwards
    tracker.clearAll();
    try {
        testStub.testInt(3);
        fail("did not receive exception");
    } catch (ProtocolException e) {
    // pass
    }
    // check result
    String[] called = { "4", "2", "1" };
    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));
    }
    // should be no destroyed handlers
    List<String> destroyedHandlers = reportStub.getReport(REPORT_DESTROYED_HANDLERS);
    assertTrue("Should be no destroyed handlers", destroyedHandlers.isEmpty());
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) HandlerTracker(handler.handler_processing.common.HandlerTracker)

Example 32 with ProtocolException

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

the class EndToEndErrorTest method testServerOutboundSOAPFault1.

/*
     * Have one of the server handlers throw a soap protocol
     * exception and check that the proper methods are called.
     */
public void testServerOutboundSOAPFault1() throws Exception {
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    // these lines make calls to the server
    reportStub.clearHandlerTracker();
    for (int i = 0; i < numTotalHandlers; i++) {
        reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    reportStub.setInstruction(SERVER_PREFIX + 2, HA_THROW_SOAP_FAULT_EXCEPTION_OUTBOUND);
    // clear out the client handlers afterwards and set instructions
    tracker.clearAll();
    for (int i = 0; i < numTotalHandlers; i++) {
        tracker.setHandlerAction(CLIENT_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    try {
        testStub.testInt(3);
        fail("did not receive exception");
    } catch (ProtocolException e) {
    // ok
    }
    // check result
    List<String> clientCalledHandlers = tracker.getCalledHandlers();
    List<String> clientClosedHandlers = tracker.getClosedHandlers();
    // check client handlers
    String[] clientCalled = { "0", "1", "3", "4", "5", "7", "7_FAULT", "5_FAULT", "4_FAULT", "3_FAULT", "1_FAULT", "0_FAULT" };
    int[] clientClosed = { 7, 5, 4, 3, 1, 0 };
    assertEquals("Did not get proper number of called handlers", clientCalled.length, clientCalledHandlers.size());
    for (int i = 0; i < clientCalled.length; i++) {
        assertEquals("did not find expected handler", CLIENT_PREFIX + clientCalled[i], clientCalledHandlers.get(i));
    }
    assertEquals("Did not get proper number of closed handlers", clientClosed.length, clientClosedHandlers.size());
    for (int i = 0; i < clientClosed.length; i++) {
        assertEquals("did not find expected handler", CLIENT_PREFIX + clientClosed[i], clientClosedHandlers.get(i));
    }
    // check server after client because it makes calls through the handlers
    String[] serverCalled = { "4", "2", "1", "0", "0", "1", "2" };
    List<String> serverCalledHandlers = reportStub.getReport(REPORT_CALLED_HANDLERS);
    assertEquals("Did not get proper number of called handlers", serverCalled.length, serverCalledHandlers.size());
    for (int i = 0; i < serverCalled.length; i++) {
        assertEquals("did not find expected handler", SERVER_PREFIX + serverCalled[i], serverCalledHandlers.get(i));
    }
    // too many closes on server to check them all
    // should be no destroyed handlers
    List<String> destroyedHandlers = reportStub.getReport(REPORT_DESTROYED_HANDLERS);
    assertEquals("Should be 0 destroyed handlers", 0, destroyedHandlers.size());
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) HandlerTracker(handler.handler_processing.common.HandlerTracker)

Example 33 with ProtocolException

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

the class EndToEndErrorTest method testClientInboundProtocolException1.

/*
     * Have one of the client handlers throw a proper exception
     * and check that the proper methods are called. This test
     * is on inbound message. Testing with soap handler.
     */
public void testClientInboundProtocolException1() throws Exception {
    int badHandler = 5;
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    reportStub.clearHandlerTracker();
    tracker.clearAll();
    for (int i = 0; i < numTotalHandlers; i++) {
        tracker.setHandlerAction(CLIENT_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    tracker.setHandlerAction(CLIENT_PREFIX + badHandler, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
    try {
        testStub.testInt(42);
        fail("should have received a web service exception");
    } catch (ProtocolException e) {
        assertTrue("ProtocolException message not as expected, but got:" + e.getMessage(), e.getMessage().contains(CLIENT_PREFIX + badHandler));
    }
    // check called handlers
    int[] called = { 0, 1, 3, 4, 5, 7, 7, 5 };
    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 -- none in jaxws 2.0
    List<String> destroyedHandlers = tracker.getDestroyedHandlers();
    assertTrue("destroyed handler list should be empty", destroyedHandlers.isEmpty());
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) HandlerTracker(handler.handler_processing.common.HandlerTracker)

Example 34 with ProtocolException

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

the class TestApp method testMustUnderstand1.

/*
     * MU test here for soap 1.2. Test uses a simple handler
     * on client side to test service with no handlers.
     */
public void testMustUnderstand1() throws Exception {
    String next_1_2 = "http://www.w3.org/2003/05/soap-envelope/role/next";
    try {
        // clear handlers (should be none) and add helper handler
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
        MUHelperHandler handler = new MUHelperHandler();
        ClientServerTestUtil.addHandlerToBinding(handler, (BindingProvider) stub);
        // have handler set header that is ignored
        handler.setMUHeader(new QName("urn:mutest", "someheader"), "notarealactor");
        // make the call
        String arg = "echo";
        assertEquals(arg, stub.echo(arg));
        // add header that should result in soap fault
        handler.setMUHeader(new QName("urn:mutest", "someheader"), next_1_2);
        // make the call
        try {
            stub.echo(arg);
            fail("did not receive any exception");
        } catch (ProtocolException e) {
            if (e instanceof SOAPFaultException) {
            // pass
            } else {
                fail("did not receive soap fault, received: " + e.toString());
            }
        } catch (Exception e) {
            fail("did not receive protocol exception. received " + e.toString());
        }
    } finally {
        // always clear the handlers
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
    }
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) QName(javax.xml.namespace.QName) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) MUHelperHandler(fromwsdl.soap12.fault.client.handlers.MUHelperHandler) ProtocolException(jakarta.xml.ws.ProtocolException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

Example 35 with ProtocolException

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

the class TestApp method testHandlerException1.

/**
 * Have a handler throw a protocol exception and make sure
 * the proper values are in the soap fault. Test for 6353191.
 */
public void testHandlerException1() throws Exception {
    // the expected fault code local part
    String code = "Sender";
    try {
        // clear handlers (should be none) and add helper handler
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
        ExceptionThrowingHandler handler = new ExceptionThrowingHandler("ProtocolException");
        ClientServerTestUtil.addHandlerToBinding(handler, (BindingProvider) stub);
        // make the call
        try {
            stub.echo("have a nice day");
            fail("did not receive any exception");
        } catch (SOAPFaultException e) {
            SOAPFault fault = e.getFault();
            String faultCode = fault.getFaultCode();
            assertTrue("fault code should end with \"" + code + "\": " + faultCode, faultCode.endsWith(code));
        } catch (Exception e) {
            fail("did not receive soap fault exception. received " + e.toString());
        }
    } finally {
        // always clear the handlers
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
    }
}
Also used : SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault) ExceptionThrowingHandler(fromwsdl.soap12.fault.client.handlers.ExceptionThrowingHandler) ProtocolException(jakarta.xml.ws.ProtocolException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

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