Search in sources :

Example 76 with SOAPService

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

the class JSClientServerTest method testJSMessageMode.

@Test
public void testJSMessageMode() throws Exception {
    QName serviceName = new QName(NS, "SOAPService");
    QName portName = new QName(NS, "SoapPort");
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    String response1 = new String("TestGreetMeResponse");
    String response2 = new String("TestSayHiResponse");
    try {
        Greeter greeter = service.getPort(portName, Greeter.class);
        updateAddressPort(greeter, JS_PORT);
        String greeting = greeter.greetMe("TestGreetMeRequest");
        assertNotNull("no response received from service", greeting);
        assertEquals(response1, greeting);
        String reply = greeter.sayHi();
        assertNotNull("no response received from service", reply);
        assertEquals(response2, reply);
    } catch (UndeclaredThrowableException ex) {
        ex.printStackTrace();
        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) Test(org.junit.Test)

Example 77 with SOAPService

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

the class ClientServerTest method testFaultStackTrace.

@Test
public void testFaultStackTrace() throws Exception {
    System.setProperty("cxf.config.file.url", getClass().getResource("fault-stack-trace.xml").toString());
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    ExecutorService ex = Executors.newFixedThreadPool(1);
    service.setExecutor(ex);
    assertNotNull(service);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    try {
        // trigger runtime exception throw of implementor method
        greeter.testDocLitFault("");
        fail("Should have thrown Runtime exception");
    } catch (WebServiceException e) {
        assertEquals("can't get back original message", "Unknown source", e.getCause().getMessage());
        assertTrue(e.getCause().getStackTrace().length > 0);
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) WebServiceException(javax.xml.ws.WebServiceException) Greeter(org.apache.hello_world_soap_http.Greeter) ExecutorService(java.util.concurrent.ExecutorService) URL(java.net.URL) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Example 78 with SOAPService

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

the class ClientServerTest method testAsyncDiscardProxy.

@Test
public void testAsyncDiscardProxy() 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);
    Response<GreetMeLaterResponse> r1 = greeter.greetMeLaterAsync(3000);
    greeter = null;
    service = null;
    System.gc();
    System.gc();
    System.gc();
    assertEquals("Hello, finally!", r1.get().getResponseType());
}
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)

Example 79 with SOAPService

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

the class ClientServerTest method testAsyncCallUseProperAssignedExecutor.

@Test
public void testAsyncCallUseProperAssignedExecutor() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    class TestExecutor implements Executor {

        private AtomicInteger count = new AtomicInteger();

        public void execute(Runnable command) {
            int c = count.incrementAndGet();
            LOG.info("asyn call time " + c);
            command.run();
        }

        public int getCount() {
            return count.get();
        }
    }
    Executor executor = new TestExecutor();
    service.setExecutor(executor);
    assertNotNull(service);
    assertSame(executor, service.getExecutor());
    assertEquals(((TestExecutor) executor).getCount(), 0);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    List<Response<GreetMeResponse>> responses = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        responses.add(greeter.greetMeAsync("asyn call" + i));
    }
    // wait for all the responses
    for (Response<GreetMeResponse> resp : responses) {
        resp.get();
    }
    assertEquals(5, ((TestExecutor) executor).getCount());
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) ArrayList(java.util.ArrayList) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) URL(java.net.URL) 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) Executor(java.util.concurrent.Executor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 80 with SOAPService

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

the class ClientServerTest method testTimeoutConfigutation.

@Test
public void testTimeoutConfigutation() throws Exception {
    SOAPService service = new SOAPService();
    assertNotNull(service);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    ((javax.xml.ws.BindingProvider) greeter).getRequestContext().put("javax.xml.ws.client.receiveTimeout", "1");
    try {
        greeter.greetMe("test");
    // remove fail() check to let this test pass in the powerful machine
    } catch (Throwable ex) {
        Object cause = null;
        if (ex.getCause() != null) {
            cause = ex.getCause();
        }
        assertTrue("Timeout cause is expected", cause instanceof java.net.SocketTimeoutException);
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) 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)

Aggregations

SOAPService (org.apache.hello_world_soap_http.SOAPService)84 URL (java.net.URL)67 Test (org.junit.Test)56 Greeter (org.apache.hello_world_soap_http.Greeter)49 InputStream (java.io.InputStream)20 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)18 SOAPMessage (javax.xml.soap.SOAPMessage)14 Bus (org.apache.cxf.Bus)14 BindingProvider (javax.xml.ws.BindingProvider)13 Endpoint (javax.xml.ws.Endpoint)13 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)13 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)13 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)12 TimeoutException (java.util.concurrent.TimeoutException)8 WebServiceException (javax.xml.ws.WebServiceException)8 File (java.io.File)7 ExecutionException (java.util.concurrent.ExecutionException)7 QName (javax.xml.namespace.QName)7 BeforeClass (org.junit.BeforeClass)7 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)6