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);
}
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;
}
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());
}
}
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");
}
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());
}
Aggregations