Search in sources :

Example 1 with SOAPTestHandler

use of async.wsdl_hello_lit.client.handlers.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.

the class Hello1CallbackHandler method testHello0AsyncPollHandler.

/*
     * Adds handler to increment value of request and response.
     */
public void testHello0AsyncPollHandler() throws Exception {
    try {
        // should be no handlers, but to be safe
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
        // add handler
        ClientServerTestUtil.addHandlerToBinding(new SOAPTestHandler(), (BindingProvider) stub);
        int orig = 1;
        // 1 per handler invocation
        int diff = 2;
        Response<Integer> response = stub.hello0Async(orig);
        Integer output = response.get(15, TimeUnit.SECONDS);
        assertEquals("Handlers were not invoked properly", orig + diff, output.intValue());
    } finally {
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
    }
}
Also used : SOAPTestHandler(async.wsdl_hello_lit.client.handlers.SOAPTestHandler)

Example 2 with SOAPTestHandler

use of async.wsdl_hello_lit.client.handlers.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.

the class Hello1CallbackHandler method testHelloAsyncCallback0Handler.

/*
     * Adds handler to increment value of request and response.
     */
public void testHelloAsyncCallback0Handler() throws Exception {
    try {
        // should be no handlers, but to be safe
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
        // test with no handler first
        int orig = 1;
        final IntHolder intHolder = new IntHolder();
        Future<?> response = stub.hello0Async(orig, new AsyncHandler<Integer>() {

            public void handleResponse(Response<Integer> resp) {
                try {
                    // add 10 to make sure this was called
                    intHolder.setValue(resp.get().intValue() + 10);
                } catch (Exception e) {
                    e.printStackTrace();
                    // will cause failure
                    intHolder.setValue(-100);
                }
            }
        });
        // wait, but only up to 15 seconds. if it takes more,
        // it's considered a hangup
        response.get(15, TimeUnit.SECONDS);
        assertEquals("did not get expected value back in response", orig + 10, intHolder.getValue());
        // add handler
        ClientServerTestUtil.addHandlerToBinding(new SOAPTestHandler(), (BindingProvider) stub);
        // 1 per handler invocation
        int diff = 2;
        response = stub.hello0Async(orig, new AsyncHandler<Integer>() {

            public void handleResponse(Response<Integer> resp) {
                try {
                    intHolder.setValue(resp.get().intValue());
                } catch (Exception e) {
                    e.printStackTrace();
                    // will cause failure
                    intHolder.setValue(-100);
                }
            }
        });
        response.get(15, TimeUnit.SECONDS);
        assertEquals("handlers did not execute successfully", orig + diff, intHolder.getValue());
    } finally {
        ClientServerTestUtil.clearHandlers((BindingProvider) stub);
    }
}
Also used : Response(jakarta.xml.ws.Response) AsyncHandler(jakarta.xml.ws.AsyncHandler) SOAPTestHandler(async.wsdl_hello_lit.client.handlers.SOAPTestHandler) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

SOAPTestHandler (async.wsdl_hello_lit.client.handlers.SOAPTestHandler)2 AsyncHandler (jakarta.xml.ws.AsyncHandler)1 Response (jakarta.xml.ws.Response)1 ExecutionException (java.util.concurrent.ExecutionException)1