Search in sources :

Example 11 with ClientFactoryBean

use of org.apache.cxf.frontend.ClientFactoryBean 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 12 with ClientFactoryBean

use of org.apache.cxf.frontend.ClientFactoryBean 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 13 with ClientFactoryBean

use of org.apache.cxf.frontend.ClientFactoryBean 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 14 with ClientFactoryBean

use of org.apache.cxf.frontend.ClientFactoryBean 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 15 with ClientFactoryBean

use of org.apache.cxf.frontend.ClientFactoryBean 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

ClientFactoryBean (org.apache.cxf.frontend.ClientFactoryBean)19 ClientProxyFactoryBean (org.apache.cxf.frontend.ClientProxyFactoryBean)11 Test (org.junit.Test)10 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)6 URL (java.net.URL)2 Holder (javax.xml.ws.Holder)2 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)2 Client (org.apache.cxf.endpoint.Client)2 IOException (java.io.IOException)1 QName (javax.xml.namespace.QName)1 CreditAgencyWS (org.apache.camel.loanbroker.credit.CreditAgencyWS)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 Greeter (org.apache.cxf.greeter_control.Greeter)1 PingMeFault (org.apache.cxf.greeter_control.PingMeFault)1 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)1 JaxWsClientFactoryBean (org.apache.cxf.jaxws.JaxWsClientFactoryBean)1 Greeter (org.apache.hello_world_soap_http.Greeter)1