Search in sources :

Example 56 with HandlerTracker

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

the class EndToEndTest method testAllRoles.

/*
     * Test the allRoles boolean argument of getHeaders()
     * method in SOAPMessageContext.
     */
public void testAllRoles() 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();
    reportStub.setInstruction(SERVER_PREFIX + 4, HA_ADD_HEADER_OUTBOUND_CLIENT_ROLE1);
    // so we clear out the client handlers afterwards
    tracker.clearAll();
    tracker.setHandlerAction(CLIENT_PREFIX + 7, HA_CHECK_SMC_ALL_ROLES);
    // first check with the client1 role
    int result = testStub.testInt(5);
    // now check without the known role (should get no headers in handler)
    SOAPBinding sBinding = (SOAPBinding) ((BindingProvider) testStub).getBinding();
    sBinding.setRoles(new HashSet<String>());
    result = testStub.testInt(5);
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker) SOAPBinding(jakarta.xml.ws.soap.SOAPBinding)

Example 57 with HandlerTracker

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

the class EndToEndTest method testClientRequestAndResponseProperties.

/*
     * Verifies that properties exist in request and response. Also
     * combines some of the above request and response tests.
     */
public void testClientRequestAndResponseProperties() throws Exception {
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    TestService stub = getTestStub(getService());
    ((BindingProvider) stub).getRequestContext().put(USER_CLIENT_PROPERTY_NAME, USER_PROPERTY_CLIENT_SET);
    tracker.clearAll();
    // handler looks for client prop in request
    tracker.setHandlerAction(CLIENT_PREFIX + 5, HA_CHECK_FOR_USER_PROPERTY_OUTBOUND);
    // handler adds another prop during request
    tracker.setHandlerAction(CLIENT_PREFIX + 7, HA_ADD_USER_PROPERTY_OUTBOUND);
    // handler checks for both props and adds third
    tracker.setHandlerAction(CLIENT_PREFIX + 3, HA_ADD_AND_CHECK_PROPS_INBOUND);
    stub.testInt(1);
    Map context = ((BindingProvider) stub).getResponseContext();
    Object testValue = context.get(USER_HANDLER_PROPERTY_NAME);
    assertNotNull("did not receive first handler property in response context", testValue);
    assertEquals("property value incorrect", USER_PROPERTY_HANDLER_SET, (String) testValue);
    // this is the last property added
    testValue = context.get(USER_HANDLER_PROPERTY_NAME + INBOUND);
    assertNotNull("did not receive second handler property in response context", testValue);
    assertEquals("property value incorrect", USER_PROPERTY_HANDLER_SET + INBOUND, (String) testValue);
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker) BindingProvider(jakarta.xml.ws.BindingProvider) Map(java.util.Map)

Example 58 with HandlerTracker

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

the class EndToEndTest method testClientHandlers2.

/*
     * Make sure the right number of client side handlers are
     * in place for a one-way call.
     */
public void testClientHandlers2() throws Exception {
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    TestService_Service service = getService();
    TestService stub = getTestStub(service);
    tracker.clearAll();
    for (int i = 0; i < numTotalHandlers; i++) {
        // just set them all
        tracker.setHandlerAction(CLIENT_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    stub.testIntOneWay(0);
    List<String> calledHandlers = tracker.getCalledHandlers();
    assertEquals("did not get the right number of called handlers", numTestHandlers, calledHandlers.size());
    int[] calledNames = { 0, 1, 3, 4, 5, 7 };
    for (int i = 0; i < calledNames.length; i++) {
        assertEquals("did not get expected handler name", CLIENT_PREFIX + calledNames[i], calledHandlers.get(i));
    }
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker)

Example 59 with HandlerTracker

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

the class HandleFaultTest method testServerException5.

/*
     * Same as testServerException4 except with different
     * handlers throwing the exceptions. This one uses
     * two logical handlers.
     */
public void testServerException5() throws Exception {
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    reportStub.clearHandlerTracker();
    for (int i = 0; i < numTotalServerHandlers; i++) {
        reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    reportStub.setInstruction(SERVER_PREFIX + 0, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
    reportStub.setInstruction(SERVER_PREFIX + 1, HF_THROW_PROTOCOL_EXCEPTION);
    tracker.clearAll();
    try {
        testStub.testInt(42);
        fail("did not receive exception");
    } catch (SOAPFaultException sfe) {
        // check which exception came back
        SOAPFault fault = sfe.getFault();
        assertNotNull("did not receive fault in exception", fault);
        String handlerMsg = fault.getFaultString();
        assertNotNull("null message in exception", handlerMsg);
        assertTrue("did not receive the expected exception, received: " + handlerMsg, handlerMsg.startsWith(SERVER_PREFIX + 1));
        assertTrue("did not get proper message, got: " + handlerMsg, handlerMsg.indexOf("from handleFault") != -1);
    }
    // check called handlers on server side
    String[] called = { "4", "2", "1", "0", "1_FAULT" };
    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));
    }
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 60 with HandlerTracker

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

the class HandleFaultTest method testServerException4.

/*
     * Same as testServerException3 except with different
     * handlers throwing the exceptions.
     */
public void testServerException4() throws Exception {
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    reportStub.clearHandlerTracker();
    for (int i = 0; i < numTotalServerHandlers; i++) {
        reportStub.setInstruction(SERVER_PREFIX + i, HA_REGISTER_HANDLE_XYZ);
    }
    reportStub.setInstruction(SERVER_PREFIX + 0, HA_THROW_PROTOCOL_EXCEPTION_INBOUND);
    reportStub.setInstruction(SERVER_PREFIX + 2, HF_THROW_PROTOCOL_EXCEPTION);
    tracker.clearAll();
    try {
        testStub.testInt(42);
        fail("did not receive exception");
    } catch (SOAPFaultException sfe) {
        // check which exception came back
        SOAPFault fault = sfe.getFault();
        assertNotNull("did not receive fault in exception", fault);
        String handlerMsg = fault.getFaultString();
        assertNotNull("null message in exception", handlerMsg);
        assertTrue("did not receive the expected exception, received: " + handlerMsg, handlerMsg.startsWith(SERVER_PREFIX + 2));
        assertTrue("did not get proper message, got: " + handlerMsg, handlerMsg.indexOf("from handleFault") != -1);
    }
    // check called handlers on server side
    String[] called = { "4", "2", "1", "0", "1_FAULT", "2_FAULT" };
    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));
    }
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPFault(jakarta.xml.soap.SOAPFault)

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