Search in sources :

Example 11 with ProtocolException

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

the class TestHandler method incrementArgument.

private Source incrementArgument(Source source) throws TransformerException {
    Transformer xFormer = TransformerFactory.newInstance().newTransformer();
    xFormer.setOutputProperty("omit-xml-declaration", "yes");
    DOMResult dResult = new DOMResult();
    xFormer.transform(source, dResult);
    Node documentNode = dResult.getNode();
    Node envelopeNode = documentNode.getFirstChild();
    Node requestResponseNode = envelopeNode.getLastChild().getFirstChild();
    Node textNode = requestResponseNode.getFirstChild().getFirstChild();
    int orig = Integer.parseInt(textNode.getNodeValue());
    // check for error tests
    if (orig == THROW_HTTP_EXCEPTION) {
        throw new HTTPException(500);
    } else if (orig == THROW_RUNTIME_EXCEPTION) {
        throw new RuntimeException("EXPECTED EXCEPTION");
    } else if (orig == THROW_PROTOCOL_EXCEPTION) {
        throw new ProtocolException("TEST EXCEPTION FROM HANDLER");
    }
    textNode.setNodeValue(String.valueOf(++orig));
    return new DOMSource(documentNode);
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) HTTPException(jakarta.xml.ws.http.HTTPException) Node(org.w3c.dom.Node)

Example 12 with ProtocolException

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

the class EndToEndErrorTester method testServerInboundRuntimeException2.

/*
     * Have one of the server handlers throw a runtime
     * exception and check that the proper methods are called.
     * This test uses a protocol handler.
     */
public void testServerInboundRuntimeException2() 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_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) {
    // ok
    }
    // check result
    String[] called = { "4", "2" };
    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(fromwsdl.handler.common.HandlerTracker)

Example 13 with ProtocolException

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

the class EndToEndErrorTester 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(fromwsdl.handler.common.HandlerTracker)

Example 14 with ProtocolException

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

the class EndToEndErrorTester method testServerOutboundProtocolException1.

/*
     * Have one of the server handlers throw a simple protocol
     * exception and check that the proper methods are called.
     */
public void testServerOutboundProtocolException1() 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_PROTOCOL_EXCEPTION_OUTBOUND);
    // so we clear out the client handlers afterwards
    tracker.clearAll();
    try {
        testStub.testInt(3);
        fail("did not receive exception");
    } catch (ProtocolException e) {
    // ok
    }
    // check result
    String[] called = { "4", "2", "1", "0", "0", "1", "2" };
    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));
    }
    // too many closes to check them all
    // 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(fromwsdl.handler.common.HandlerTracker)

Example 15 with ProtocolException

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

the class EndToEndErrorTester method testClientInboundProtocolException2.

/*
     * 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 logical handler.
     *
     * Is this a valid test case?
     */
public void testClientInboundProtocolException2() throws Exception {
    int badHandler = 1;
    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, 4, 3, 1 };
    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(fromwsdl.handler.common.HandlerTracker)

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