Search in sources :

Example 1 with SOAPTestHandler

use of fromwsdl.handler_simple.common.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.

the class HandlerClient method testDispatchJAXB.

/*
     * Creates a Dispatch object with jaxb and tests that the
     * handler is called.
     */
public void testDispatchJAXB() throws Exception {
    QName portQName = new QName("urn:test", "HelloPort");
    String endpointAddress = getEndpointAddress("http://localhost:8080/jaxrpc-fromwsdl_handler_simple/hello");
    // create service with just qname -- no handlers in that case
    // Hello_Service service = createService();
    QName serviceQName = new QName("urn:test", "Hello");
    Service service = Service.create(serviceQName);
    service.addPort(portQName, SOAP11HTTP_BINDING, setTransport(endpointAddress));
    JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
    Dispatch<Object> dispatch = service.createDispatch(portQName, jaxbContext, Service.Mode.PAYLOAD);
    // ClientServerTestUtil.setTransport(dispatch, null);
    int numHandlers = 0;
    assertEquals("Should be " + numHandlers + " handler(s) on dispatch object", numHandlers, dispatch.getBinding().getHandlerChain().size());
    int x = 1;
    // 2 per handler
    int diff = 2;
    Hello_Type hello = new Hello_Type();
    hello.setIntin(x);
    HelloResponse response = (HelloResponse) dispatch.invoke(hello);
    assertEquals(x + diff, response.getIntout());
    // add handler programatically
    ClientServerTestUtil.addHandlerToBinding(new SOAPTestHandler(), dispatch);
    diff = 4;
    response = (HelloResponse) dispatch.invoke(hello);
    assertEquals(x + diff, response.getIntout());
}
Also used : QName(javax.xml.namespace.QName) SOAPTestHandler(fromwsdl.handler_simple.common.SOAPTestHandler) Service(jakarta.xml.ws.Service) JAXBContext(jakarta.xml.bind.JAXBContext)

Example 2 with SOAPTestHandler

use of fromwsdl.handler_simple.common.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.

the class HandlerClient method testDynamic2.

/*
     * Test tries to add a handler programmatically after clearing
     * handlers out of the service. Adds handler using HandlerResolver.
     * Uses a null HandlerResolver to clear the service.
     */
public void testDynamic2() throws Exception {
    Hello_Service service = createService();
    service.setHandlerResolver(null);
    Hello stub = createStub(service);
    int x = 1;
    // 2 per handler invoked
    int diff = 2;
    int y = stub.hello(x);
    assertEquals(x + diff, y);
    // now add client handler
    service.setHandlerResolver(new HandlerResolver() {

        public List<Handler> getHandlerChain(PortInfo info) {
            List list = new ArrayList<Handler>();
            list.add(new SOAPTestHandler());
            return list;
        }
    });
    stub = createStub(service);
    // test again
    diff = 4;
    y = stub.hello(x);
    assertTrue(y == x + diff);
}
Also used : PortInfo(jakarta.xml.ws.handler.PortInfo) HandlerResolver(jakarta.xml.ws.handler.HandlerResolver) SOAPTestHandler(fromwsdl.handler_simple.common.SOAPTestHandler) SOAPTestHandler(fromwsdl.handler_simple.common.SOAPTestHandler) Handler(jakarta.xml.ws.handler.Handler) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with SOAPTestHandler

use of fromwsdl.handler_simple.common.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.

the class HandlerClient method testDispatchSourceSOAPHandler.

/*
     * Creates a Dispatch object with source and tests that
     * the handler is called. Test uses a SOAP handler.
     */
public void testDispatchSourceSOAPHandler() throws Exception {
    String req = "<?xml version=\"1.0\" ?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><Hello xmlns=\"urn:test:types\"><intin>1</intin></Hello></soapenv:Body></soapenv:Envelope>";
    QName portQName = new QName("urn:test", "HelloPort");
    String endpointAddress = getEndpointAddress("http://localhost:8080/jaxrpc-fromwsdl_handler_simple/hello");
    // create service with just qname -- no handlers in that case
    QName serviceQName = new QName("urn:test", "Hello");
    Service service = Service.create(serviceQName);
    service.addPort(portQName, SOAP11HTTP_BINDING, setTransport(endpointAddress));
    Dispatch<Source> dispatch = service.createDispatch(portQName, Source.class, Service.Mode.MESSAGE);
    // ClientServerTestUtil.setTransport(dispatch, null);
    int numHandlers = 0;
    assertEquals("Should be " + numHandlers + " handler(s) on dispatch object", numHandlers, dispatch.getBinding().getHandlerChain().size());
    int x = 1;
    // 2 per handler
    int diff = 2;
    ByteArrayInputStream iStream = new ByteArrayInputStream(req.getBytes());
    Source requestSource = new StreamSource(iStream);
    Source response = dispatch.invoke(requestSource);
    int responseInt = getIntFromResponse(response);
    assertEquals(x + diff, responseInt);
    // add handler programatically
    ClientServerTestUtil.addHandlerToBinding(new SOAPTestHandler(), dispatch);
    diff = 4;
    // make new call
    iStream = new ByteArrayInputStream(req.getBytes());
    requestSource = new StreamSource(iStream);
    response = dispatch.invoke(requestSource);
    responseInt = getIntFromResponse(response);
    assertEquals(x + diff, responseInt);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) SOAPTestHandler(fromwsdl.handler_simple.common.SOAPTestHandler) StreamSource(javax.xml.transform.stream.StreamSource) Service(jakarta.xml.ws.Service) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 4 with SOAPTestHandler

use of fromwsdl.handler_simple.common.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.

the class HandlerClient method testDynamic1.

/*
     * Test tries to add a handler programmatically after clearing
     * handlers out of the service. Adds handler to binding. Uses
     * an empty handler resolver for clearing the service.
     */
public void testDynamic1() throws Exception {
    Hello_Service service = createService();
    service.setHandlerResolver(new HandlerResolver() {

        public List<Handler> getHandlerChain(PortInfo info) {
            return new ArrayList<Handler>();
        }
    });
    Hello stub = createStub(service);
    int x = 1;
    // 2 per handler invoked
    int diff = 2;
    int y = stub.hello(x);
    assertTrue(y == x + diff);
    // now add client handler
    List<Handler> handlerList = new ArrayList<Handler>();
    handlerList.add(new SOAPTestHandler());
    Binding binding = ((BindingProvider) stub).getBinding();
    binding.setHandlerChain(handlerList);
    // test again
    diff = 4;
    y = stub.hello(x);
    assertTrue(y == x + diff);
}
Also used : Binding(jakarta.xml.ws.Binding) SOAPTestHandler(fromwsdl.handler_simple.common.SOAPTestHandler) ArrayList(java.util.ArrayList) SOAPTestHandler(fromwsdl.handler_simple.common.SOAPTestHandler) Handler(jakarta.xml.ws.handler.Handler) BindingProvider(jakarta.xml.ws.BindingProvider) PortInfo(jakarta.xml.ws.handler.PortInfo) HandlerResolver(jakarta.xml.ws.handler.HandlerResolver) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SOAPTestHandler (fromwsdl.handler_simple.common.SOAPTestHandler)4 Service (jakarta.xml.ws.Service)2 Handler (jakarta.xml.ws.handler.Handler)2 HandlerResolver (jakarta.xml.ws.handler.HandlerResolver)2 PortInfo (jakarta.xml.ws.handler.PortInfo)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 QName (javax.xml.namespace.QName)2 JAXBContext (jakarta.xml.bind.JAXBContext)1 Binding (jakarta.xml.ws.Binding)1 BindingProvider (jakarta.xml.ws.BindingProvider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Source (javax.xml.transform.Source)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamSource (javax.xml.transform.stream.StreamSource)1