Search in sources :

Example 1 with TestHandler

use of fromjava.handler_simple.common.TestHandler in project metro-jax-ws by eclipse-ee4j.

the class HandlerClient method test2.

// public void testDispatch1() throws Exception {
// int x = 1; // what we send
// int diff = 2; // 4 handler invocations
// 
// JAXBContext jxbContext = JAXBContext.newInstance(ObjectFactory.class);
// Dispatch dispatch = createDispatchForJAXB(
// new QName("urn:test", "HelloPort"), jxbContext);
// 
// Hello_Type request = objectFactory.createHello_Type();
// request.setValue(1);
// 
// // make first call with no client side handlers
// HelloResponse response = (HelloResponse) dispatch.invoke(request);
// assertNotNull("response cannot be null", response);
// 
// int y = response.getValue();
// System.out.println("sent: " + x + ", expect " + (x+diff) +
// " back. received: " + y);
// assertTrue(y == x+diff);
// 
// System.out.println("now adding handler to dispatch");
// Binding binding = dispatch.getBinding();
// assertNotNull("binding cannot be null", binding);
// int handlerChainLength = binding.getHandlerChain().size();
// assertEquals("the handler list is not empty", 0, handlerChainLength);
// 
// // add handler
// HandlerInfo hInfo = new HandlerInfo(
// handler_tests.simple_handler_test.client.handlers.ClientHandler.class,
// null, null);
// List<HandlerInfo> newHandlers = new ArrayList<HandlerInfo>();
// newHandlers.add(hInfo);
// binding.setHandlerChain(newHandlers);
// 
// // now try again
// diff = 4;
// response = (HelloResponse) dispatch.invoke(request);
// assertNotNull("response cannot be null", response);
// 
// y = response.getValue();
// System.out.println("sent: " + x + ", expect " + (x+diff) +
// " back. received: " + y);
// assertTrue(y == x+diff);
// }
/*
     * Test tries to add a handler programmatically after clearing
     * handlers out of registry in the service.
     */
public void test2() throws Exception {
    HelloService service = createService();
    service.setHandlerResolver(new HandlerResolver() {

        public List<Handler> getHandlerChain(PortInfo info) {
            return new ArrayList<Handler>();
        }
    });
    HelloPortType stub = createStub(service);
    int x = 1;
    // 2 per handler invoked
    int diff = 2;
    int y = stub.hello(x);
    System.out.println("sent: " + x + ", expect " + (x + diff) + " back. received: " + y);
    assertTrue(y == x + diff);
    // now add client handler
    service.setHandlerResolver(new HandlerResolver() {

        public List<Handler> getHandlerChain(PortInfo info) {
            List<Handler> handlers = new ArrayList<Handler>();
            handlers.add(new TestHandler());
            return handlers;
        }
    });
    stub = createStub(service);
    // test again
    diff = 4;
    y = stub.hello(x);
    System.out.println("sent: " + x + ", expect " + (x + diff) + " back. received: " + y);
    assertTrue(y == x + diff);
}
Also used : PortInfo(jakarta.xml.ws.handler.PortInfo) HandlerResolver(jakarta.xml.ws.handler.HandlerResolver) TestHandler(fromjava.handler_simple.common.TestHandler) Handler(jakarta.xml.ws.handler.Handler) TestHandler(fromjava.handler_simple.common.TestHandler) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

TestHandler (fromjava.handler_simple.common.TestHandler)1 Handler (jakarta.xml.ws.handler.Handler)1 HandlerResolver (jakarta.xml.ws.handler.HandlerResolver)1 PortInfo (jakarta.xml.ws.handler.PortInfo)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1