Search in sources :

Example 41 with Greeter

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

the class ProviderClientServerTest method testSOAPMessageModeDocLitWithSchemaValidation.

@Test
public void testSOAPMessageModeDocLitWithSchemaValidation() throws Exception {
    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
    QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    try {
        Greeter greeter = service.getPort(portName, Greeter.class);
        setAddress(greeter, ADDRESS);
        try {
            greeter.greetMe("this is a greetMe message which length is more " + "than 30 so that I wanna a schema validation error");
            fail("Should have thrown an exception");
        } catch (Exception ex) {
            // expected
            assertTrue(ex.getMessage().contains("the length of the value is 96, but the required maximum is 30"));
        }
        try {
            greeter.greetMe("exceed maxLength");
            fail("Should have thrown an exception");
        } catch (Exception ex) {
            // expected
            assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) QName(javax.xml.namespace.QName) Greeter(org.apache.hello_world_soap_http.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) URL(java.net.URL) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 42 with Greeter

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

the class ProviderClientServerTest method testSOAPMessageModeDocLit.

@Test
public void testSOAPMessageModeDocLit() throws Exception {
    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
    QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    String response1 = new String("TestSOAPOutputPMessage");
    String response2 = new String("Bonjour");
    try {
        Greeter greeter = service.getPort(portName, Greeter.class);
        setAddress(greeter, ADDRESS);
        try {
            greeter.greetMe("Return sayHi");
            fail("Should have thrown an exception");
        } catch (Exception ex) {
            // expected
            assertTrue(ex.getMessage().contains("sayHiResponse"));
        }
        for (int idx = 0; idx < 2; idx++) {
            String greeting = greeter.greetMe("Milestone-" + idx);
            assertNotNull("no response received from service", greeting);
            assertEquals(response1, greeting);
            String reply = greeter.sayHi();
            assertNotNull("no response received from service", reply);
            assertEquals(response2, reply);
        }
        try {
            greeter.greetMe("throwFault");
            fail("Expected a fault");
        } catch (SOAPFaultException ex) {
            assertTrue(ex.getMessage().contains("Test Fault String"));
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) QName(javax.xml.namespace.QName) Greeter(org.apache.hello_world_soap_http.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) URL(java.net.URL) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Endpoint(javax.xml.ws.Endpoint) Test(org.junit.Test)

Example 43 with Greeter

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

the class ThreadPoolTest method setUp.

@Before
public void setUp() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class);
    BindingProvider bp = (BindingProvider) greeter;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Greeter(org.apache.hello_world_soap_http.Greeter) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Before(org.junit.Before)

Example 44 with Greeter

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

the class ClientServerTest method testBasicConnection2.

@Test
public void testBasicConnection2() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    // getPort only passing in SEI
    Greeter greeter = service.getPort(Greeter.class);
    ((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/SoapContext/SoapPort");
    String response1 = new String("Hello Milestone-");
    String response2 = new String("Bonjour");
    try {
        for (int idx = 0; idx < 5; 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)

Example 45 with Greeter

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

the class ClientServerTest method testAsyncPollingCall.

@Test
public void testAsyncPollingCall() 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);
    assertNotNull(service);
    updateAddressPort(greeter, PORT);
    long before = System.currentTimeMillis();
    long delay = 3000;
    Response<GreetMeLaterResponse> r1 = greeter.greetMeLaterAsync(delay);
    Response<GreetMeLaterResponse> r2 = greeter.greetMeLaterAsync(delay);
    long after = System.currentTimeMillis();
    assertTrue("Duration of calls exceeded " + (2 * delay) + " ms", after - before < (2 * delay));
    // first time round, responses should not be available yet
    assertFalse("Response already available.", r1.isDone());
    assertFalse("Response already available.", r2.isDone());
    // after three seconds responses should be available
    long waited = 0;
    while (waited < (delay + 1000)) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException ex) {
        // ignore
        }
        if (r1.isDone() && r2.isDone()) {
            break;
        }
        waited += 500;
    }
    assertTrue("Response is  not available.", r1.isDone());
    assertTrue("Response is  not available.", r2.isDone());
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Greeter(org.apache.hello_world_soap_http.Greeter) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) URL(java.net.URL) 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