Search in sources :

Example 46 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class ClientServerTest method testAsyncSynchronousPolling.

@Test
public void testAsyncSynchronousPolling() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    final String expectedString = new String("Hello, finally!");
    class Poller extends Thread {

        Response<GreetMeLaterResponse> response;

        int tid;

        Poller(Response<GreetMeLaterResponse> r, int t) {
            response = r;
            tid = t;
        }

        public void run() {
            if (tid % 2 > 0) {
                while (!response.isDone()) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                    // ignore
                    }
                }
            }
            GreetMeLaterResponse reply = null;
            try {
                reply = response.get();
            } catch (Exception ex) {
                fail("Poller " + tid + " failed with " + ex);
            }
            assertNotNull("Poller " + tid + ": no response received from service", reply);
            String s = reply.getResponseType();
            assertEquals(expectedString, s);
        }
    }
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    long before = System.currentTimeMillis();
    long delay = 3000;
    Response<GreetMeLaterResponse> response = greeter.greetMeLaterAsync(delay);
    long after = System.currentTimeMillis();
    assertTrue("Duration of calls exceeded " + delay + " ms", after - before < delay);
    // first time round, responses should not be available yet
    assertFalse("Response already available.", response.isDone());
    Poller[] pollers = new Poller[4];
    for (int i = 0; i < pollers.length; i++) {
        pollers[i] = new Poller(response, i);
    }
    for (Poller p : pollers) {
        p.start();
    }
    for (Poller p : pollers) {
        p.join();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) URL(java.net.URL) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExecutionException(java.util.concurrent.ExecutionException) WebServiceException(javax.xml.ws.WebServiceException) Endpoint(javax.xml.ws.Endpoint) BareDocumentResponse(org.apache.hello_world_soap_http.types.BareDocumentResponse) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) Response(javax.xml.ws.Response) Greeter(org.apache.hello_world_soap_http.Greeter) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Example 47 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class ClientServerTest method testAsyncCallWithHandler.

@Test
public void testAsyncCallWithHandler() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    MyHandler h = new MyHandler();
    MyHandler.invocationCount = 0;
    String expectedString = new String("Hello, finally!");
    try {
        Greeter greeter = service.getPort(portName, Greeter.class);
        updateAddressPort(greeter, PORT);
        long before = System.currentTimeMillis();
        long delay = 3000;
        Future<?> f = greeter.greetMeLaterAsync(delay, h);
        long after = System.currentTimeMillis();
        assertTrue("Duration of calls exceeded " + delay + " ms", after - before < delay);
        // first time round, responses should not be available yet
        assertFalse("Response already available.", f.isDone());
        int i = 0;
        while (!f.isDone() && i < 50) {
            Thread.sleep(100);
            i++;
        }
        assertEquals("callback was not executed or did not return the expected result", expectedString, h.getReplyBuffer());
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
    assertEquals(1, MyHandler.invocationCount);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Greeter(org.apache.hello_world_soap_http.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) URL(java.net.URL) Endpoint(javax.xml.ws.Endpoint) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Example 48 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class ClientServerTest method testAsyncCallWithHandlerAndMultipleClients.

@Test
public void testAsyncCallWithHandlerAndMultipleClients() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    final MyHandler h = new MyHandler();
    MyHandler.invocationCount = 0;
    final String expectedString = new String("Hello, finally!");
    class Poller extends Thread {

        Future<?> future;

        int tid;

        Poller(Future<?> f, int t) {
            future = f;
            tid = t;
        }

        public void run() {
            if (tid % 2 > 0) {
                while (!future.isDone()) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                        // ignore
                        ex.printStackTrace();
                    }
                }
            }
            try {
                future.get();
            } catch (Exception ex) {
                fail("Poller " + tid + " failed with " + ex);
            }
            assertEquals("callback was not executed or did not return the expected result", expectedString, h.getReplyBuffer());
        }
    }
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    long before = System.currentTimeMillis();
    long delay = 3000;
    Future<?> f = greeter.greetMeLaterAsync(delay, h);
    long after = System.currentTimeMillis();
    assertTrue("Duration of calls exceeded " + delay + " ms", after - before < delay);
    // first time round, responses should not be available yet
    assertFalse("Response already available.", f.isDone());
    Poller[] pollers = new Poller[4];
    for (int i = 0; i < pollers.length; i++) {
        pollers[i] = new Poller(f, i);
    }
    for (Poller p : pollers) {
        p.start();
    }
    for (Poller p : pollers) {
        p.join();
    }
    assertEquals(1, MyHandler.invocationCount);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) URL(java.net.URL) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExecutionException(java.util.concurrent.ExecutionException) WebServiceException(javax.xml.ws.WebServiceException) Endpoint(javax.xml.ws.Endpoint) Greeter(org.apache.hello_world_soap_http.Greeter) Future(java.util.concurrent.Future) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Example 49 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class ClientServerTest method testBogusAddress.

@Test
public void testBogusAddress() throws Exception {
    String realAddress = "http://localhost:" + BOGUS_REAL_PORT + "/SoapContext/SoapPort";
    SOAPServiceBogusAddressTest service = new SOAPServiceBogusAddressTest();
    Greeter greeter = service.getSoapPort();
    try {
        greeter.greetMe("test");
        fail("Should fail");
    } catch (WebServiceException f) {
    // expected
    }
    BindingProvider bp = (BindingProvider) greeter;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, realAddress);
    greeter.greetMe("test");
    // should persist
    greeter.greetMe("test");
    bp.getRequestContext().remove(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
    try {
        greeter.greetMe("test");
        fail("Should fail");
    } catch (WebServiceException f) {
    // expected
    }
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, realAddress);
    String reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals("Bonjour", reply);
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Greeter(org.apache.hello_world_soap_http.Greeter) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) BindingProvider(javax.xml.ws.BindingProvider) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Example 50 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class ClientServerTest method testBasicConnectionAndOneway.

@Test
public void testBasicConnectionAndOneway() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    String response1 = new String("Hello Milestone-");
    String response2 = new String("Bonjour");
    try {
        for (int idx = 0; idx < 1; idx++) {
            String greeting = greeter.greetMe("Milestone-" + idx);
            assertNotNull("no response received from service", greeting);
            String exResponse = response1 + idx;
            assertEquals(exResponse, greeting);
            String reply = greeter.sayHi();
            assertNotNull("no response received from service", reply);
            assertEquals(response2, reply);
            greeter.greetMeOneWay("Milestone-" + idx);
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Greeter(org.apache.hello_world_soap_http.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) URL(java.net.URL) Endpoint(javax.xml.ws.Endpoint) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Aggregations

Greeter (org.apache.hello_world_soap_http.Greeter)104 Test (org.junit.Test)78 SOAPService (org.apache.hello_world_soap_http.SOAPService)55 URL (java.net.URL)47 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)24 BindingProvider (javax.xml.ws.BindingProvider)23 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)21 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)21 Service (javax.xml.ws.Service)19 Client (org.apache.cxf.endpoint.Client)17 Endpoint (javax.xml.ws.Endpoint)13 QName (javax.xml.namespace.QName)10 Bus (org.apache.cxf.Bus)10 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)10 ExecutorService (java.util.concurrent.ExecutorService)9 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)7 File (java.io.File)6 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)6 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)6 InvocationHandler (java.lang.reflect.InvocationHandler)5