Search in sources :

Example 11 with ClientProxyFactoryBean

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

the class LoggingInterceptorInMessageModeTest method testInvokingServiceFromCXFClient.

@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    LoggingOutInterceptor logInterceptor = null;
    for (Interceptor<?> interceptor : context.getEndpoint("cxf:bean:serviceEndpoint", CxfSpringEndpoint.class).getOutInterceptors()) {
        if (interceptor instanceof LoggingOutInterceptor) {
            logInterceptor = LoggingOutInterceptor.class.cast(interceptor);
            break;
        }
    }
    assertNotNull(logInterceptor);
    // StringPrintWriter writer = new StringPrintWriter();
    // Unfortunately, LoggingOutInterceptor does not have a setter for writer so
    // we can't capture the output to verify.
    // logInterceptor.setPrintWriter(writer);
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(ROUTER_ADDRESS);
    clientBean.setServiceClass(HelloService.class);
    HelloService client = (HelloService) proxyFactory.create();
    String result = client.echo("hello world");
    assertEquals("we should get the right answer from router", result, "echo hello world");
//assertTrue(writer.getString().indexOf("hello world") > 0);
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) Test(org.junit.Test)

Example 12 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 13 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 14 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 15 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)

Aggregations

ClientProxyFactoryBean (org.apache.cxf.frontend.ClientProxyFactoryBean)17 ClientFactoryBean (org.apache.cxf.frontend.ClientFactoryBean)11 Test (org.junit.Test)6 IOException (java.io.IOException)1 IncidentService (org.apache.camel.example.cxf.incident.IncidentService)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 Client (org.apache.cxf.endpoint.Client)1 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)1 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)1 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)1