Search in sources :

Example 41 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService 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) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) 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 42 with SOAPService

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

the class BusShutdownTest method doWork.

private void doWork(URL wsdlUrl, String address) {
    SOAPService service = new SOAPService(wsdlUrl);
    assertNotNull(service);
    Greeter greeter = service.getSoapPort();
    // overwrite client address
    InvocationHandler handler = Proxy.getInvocationHandler(greeter);
    BindingProvider bp = (BindingProvider) handler;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
    Client client = ClientProxy.getClient(greeter);
    HTTPConduit c = (HTTPConduit) client.getConduit();
    c.setClient(new HTTPClientPolicy());
    c.getClient().setConnection(ConnectionType.CLOSE);
    // invoke twoway call
    greeter.sayHi();
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Greeter(org.apache.hello_world_soap_http.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) BindingProvider(javax.xml.ws.BindingProvider) Client(org.apache.cxf.endpoint.Client) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 43 with SOAPService

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

the class SSLNettyServerTest method start.

@BeforeClass
public static void start() throws Exception {
    Bus b = createStaticBus("/org/apache/cxf/transport/http/netty/server/integration/ServerConfig.xml");
    // setup the ssl interceptor
    MySSLInterceptor myInterceptor = new MySSLInterceptor();
    b.getInInterceptors().add(myInterceptor);
    BusFactory.setThreadDefaultBus(b);
    address = "https://localhost:" + PORT + "/SoapContext/SoapPort";
    ep = Endpoint.publish(address, new org.apache.hello_world_soap_http.GreeterImpl());
    URL wsdl = NettyServerTest.class.getResource("/wsdl/hello_world.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService(wsdl);
    assertNotNull("Service is null", service);
    g = service.getSoapPort();
    assertNotNull("Port is null", g);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Bus(org.apache.cxf.Bus) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 44 with SOAPService

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

the class CxfSoapMessageProviderTest method testSOAPMessageModeDocLit.

@Test
public void testSOAPMessageModeDocLit() throws Exception {
    JaxwsTestHandler fromHandler = getMandatoryBean(JaxwsTestHandler.class, "fromEndpointJaxwsHandler");
    fromHandler.reset();
    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);
        ((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port + "/CxfSoapMessageProviderTest/SoapContext/SoapProviderPort");
        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);
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
    assertEquals("Can't get the right message count", fromHandler.getMessageCount(), 8);
    assertEquals("Can't get the right fault count", fromHandler.getFaultCount(), 0);
//From CXF 2.2.7 the soap handler's getHeader() method will not be called if the SOAP message don't have headers
//assertEquals("Can't get the right headers count", fromHandler.getGetHeadersCount(), 4);
}
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) JaxwsTestHandler(org.apache.camel.wsdl_first.JaxwsTestHandler) URL(java.net.URL) Test(org.junit.Test)

Example 45 with SOAPService

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

the class DispatchClientServerWithHugeResponseTest method testThresholdfForSOAPMessageWithHugeResponse.

@Test
public void testThresholdfForSOAPMessageWithHugeResponse() throws Exception {
    HugeResponseInterceptor hugeResponseInterceptor = new HugeResponseInterceptor(ResponseInterceptorType.ElementLevelThreshold);
    getBus().getInInterceptors().add(hugeResponseInterceptor);
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);
    Dispatch<SOAPMessage> disp = service.createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
    StaxUtils.setInnerElementCountThreshold(12);
    StaxUtils.setInnerElementLevelThreshold(12);
    InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
    SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
    assertNotNull(soapReqMsg3);
    Response<SOAPMessage> response = disp.invokeAsync(soapReqMsg3);
    try {
        response.get(300, TimeUnit.SECONDS);
    } catch (TimeoutException te) {
        fail("We should not have encountered a timeout, " + "should get some exception tell me stackoverflow");
    } catch (Throwable e) {
        if (e.getCause() == null) {
            throw e;
        }
        Throwable t = e.getCause();
        if (t instanceof SoapFault) {
            SoapFault sf = (SoapFault) e.getCause();
            if (sf.getCause() == null) {
                throw e;
            }
            t = sf.getCause();
        }
        if (t.getMessage() == null) {
            throw e;
        }
        String msg = t.getMessage();
        assertTrue(msg, msg.startsWith("reach the innerElementLevelThreshold") || msg.contains("Maximum Element Depth limit"));
    } finally {
        getBus().getInInterceptors().remove(hugeResponseInterceptor);
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) SoapFault(org.apache.cxf.binding.soap.SoapFault) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) TimeoutException(java.util.concurrent.TimeoutException) 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