Search in sources :

Example 26 with ClientProxyFactoryBean

use of org.apache.cxf.frontend.ClientProxyFactoryBean in project camel by apache.

the class CxfSimpleRouterWithUnwrappedStyleTest method getCXFClient.

protected HelloService getCXFClient() throws Exception {
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(getRouterAddress());
    clientBean.setServiceClass(HelloService.class);
    clientBean.getServiceFactory().setWrapped(false);
    HelloService client = (HelloService) proxyFactory.create();
    return client;
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean)

Example 27 with ClientProxyFactoryBean

use of org.apache.cxf.frontend.ClientProxyFactoryBean in project camel by apache.

the class CxfCustomizedExceptionTest method testInvokingServiceFromCXFClient.

@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(routerAddress);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(bus);
    HelloService client = (HelloService) proxyFactory.create();
    try {
        client.echo("hello world");
        fail("Expect to get an exception here");
    } catch (Exception e) {
        assertEquals("Expect to get right exception message", EXCEPTION_MESSAGE, e.getMessage());
        assertTrue("Exception is not instance of SoapFault", e instanceof SoapFault);
        assertEquals("Expect to get right detail message", DETAIL_TEXT, ((SoapFault) e).getDetail().getTextContent());
        //In CXF 2.1.2 , the fault code is per spec , the below fault-code is for SOAP 1.1
        assertEquals("Expect to get right fault-code", "{http://schemas.xmlsoap.org/soap/envelope/}Client", ((SoapFault) e).getFaultCode().toString());
    }
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) IOException(java.io.IOException) Test(org.junit.Test)

Example 28 with ClientProxyFactoryBean

use of org.apache.cxf.frontend.ClientProxyFactoryBean in project camel by apache.

the class CxfConsumerMessageTest method testInvokingServiceFromClient.

@Test
public void testInvokingServiceFromClient() throws Exception {
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(simpleEndpointAddress);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(BusFactory.getDefaultBus());
    HelloService client = (HelloService) proxyFactory.create();
    String result = client.echo(TEST_MESSAGE);
    assertEquals("We should get the echo string result from router", result, "echo " + TEST_MESSAGE);
    Boolean bool = client.echoBoolean(Boolean.TRUE);
    assertNotNull("The result should not be null", bool);
    assertEquals("We should get the echo boolean result from router ", bool.toString(), "true");
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) Test(org.junit.Test)

Example 29 with ClientProxyFactoryBean

use of org.apache.cxf.frontend.ClientProxyFactoryBean in project camel by apache.

the class CxfConsumerPayloadXPathClientServerTest method execTest.

private void execTest(int size) throws Exception {
    buildTestMessage(size);
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(simpleEndpointAddress);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(BusFactory.getDefaultBus());
    HelloService client = (HelloService) proxyFactory.create();
    String result = client.echo(testMessage);
    assertEquals("We should get the echo string result from router", "echo Hello World!", result);
    //check received requests
    assertEquals("Lengths of testMessage and receiveMessage should be equal (conversion body to String),", testMessage.length(), receivedMessageStringApplyingXPath.length());
    assertEquals("Lengths of receivedMessageByDom and receivedMessageCxfPayloadApplyingXPath should be equal", receivedMessageCxfPayloadApplyingXPath.length(), receivedMessageByDom.length());
    assertEquals("Lengths of testMessage and receiveMessage should be equal (body is CxfPayload),", testMessage.length(), receivedMessageCxfPayloadApplyingXPath.length());
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean)

Example 30 with ClientProxyFactoryBean

use of org.apache.cxf.frontend.ClientProxyFactoryBean in project camel by apache.

the class CxfConsumerResponseTest method testInvokingServiceFromCXFClient.

// END SNIPPET: example
@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(simpleEndpointAddress);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(BusFactory.getDefaultBus());
    HelloService client = (HelloService) proxyFactory.create();
    assertNotNull(client);
    String result = client.echo(TEST_MESSAGE);
    assertEquals("We should get the echo string result from router", result, "echo " + TEST_MESSAGE);
    Boolean bool = client.echoBoolean(Boolean.TRUE);
    assertNotNull("The result should not be null", bool);
    assertEquals("We should get the echo boolean result from router ", bool.toString(), "true");
    int beforeCallingPing = pingCounter;
    client.ping();
    int afterCallingPing = pingCounter;
    assertTrue("The ping operation doesn't be called", afterCallingPing - beforeCallingPing == 1);
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) Test(org.junit.Test)

Aggregations

ClientProxyFactoryBean (org.apache.cxf.frontend.ClientProxyFactoryBean)43 Test (org.junit.Test)23 AegisDatabinding (org.apache.cxf.aegis.databinding.AegisDatabinding)12 ClientFactoryBean (org.apache.cxf.frontend.ClientFactoryBean)12 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)10 Client (org.apache.cxf.endpoint.Client)4 Server (org.apache.cxf.endpoint.Server)4 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)4 ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)3 BeanInvoker (org.apache.cxf.service.invoker.BeanInvoker)3 Before (org.junit.Before)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 Document (org.w3c.dom.Document)3 CustomerService (com.example.customerservice.CustomerService)2 HashMap (java.util.HashMap)2 QName (javax.xml.namespace.QName)2 AegisContext (org.apache.cxf.aegis.AegisContext)2 JaxbElementTest (org.apache.cxf.jaxb_element_test.JaxbElementTest)2 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)2 Service (org.apache.cxf.service.Service)2