use of org.apache.cxf.service.factory.HelloService in project cxf by apache.
the class ClientServerTest method testClientServer.
@Test
public void testClientServer() {
ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/frontend/spring/rountrip.xml" });
HelloService greeter = (HelloService) ctx.getBean("client");
assertNotNull(greeter);
String result = greeter.sayHello();
assertEquals("We get the wrong sayHello result", "hello", result);
Client c = ClientProxy.getClient(greeter);
TestInterceptor out = new TestInterceptor();
TestInterceptor in = new TestInterceptor();
c.getRequestContext().put(Message.OUT_INTERCEPTORS, Arrays.asList(new Interceptor[] { out }));
result = greeter.sayHello();
assertTrue(out.wasCalled());
out.reset();
c.getRequestContext().put(Message.IN_INTERCEPTORS, Arrays.asList(new Interceptor[] { in }));
result = greeter.sayHello();
assertTrue(out.wasCalled());
assertTrue(in.wasCalled());
ctx.close();
BusFactory.setDefaultBus(null);
}
use of org.apache.cxf.service.factory.HelloService in project cxf by apache.
the class SpringBeansTest method testClients.
@Test
public void testClients() throws Exception {
AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/frontend/spring/clients.xml" });
Object bean = ctx.getBean("client1.proxyFactory");
assertNotNull(bean);
ClientProxyFactoryBean cpfbean = (ClientProxyFactoryBean) bean;
BindingConfiguration bc = cpfbean.getBindingConfig();
assertTrue(bc instanceof SoapBindingConfiguration);
SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
assertTrue(sbc.getVersion() instanceof Soap12);
HelloService greeter = (HelloService) ctx.getBean("client1");
assertNotNull(greeter);
Client client = ClientProxy.getClient(greeter);
assertNotNull("expected ConduitSelector", client.getConduitSelector());
assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
List<Interceptor<? extends Message>> inInterceptors = client.getInInterceptors();
boolean saaj = false;
boolean logging = false;
for (Interceptor<? extends Message> i : inInterceptors) {
if (i instanceof SAAJInInterceptor) {
saaj = true;
} else if (i instanceof LoggingInInterceptor) {
logging = true;
}
}
assertTrue(saaj);
assertTrue(logging);
saaj = false;
logging = false;
for (Interceptor<?> i : client.getOutInterceptors()) {
if (i instanceof SAAJOutInterceptor) {
saaj = true;
} else if (i instanceof LoggingOutInterceptor) {
logging = true;
}
}
assertTrue(saaj);
assertTrue(logging);
ClientProxyFactoryBean clientProxyFactoryBean = (ClientProxyFactoryBean) ctx.getBean("client2.proxyFactory");
assertNotNull(clientProxyFactoryBean);
assertEquals("get the wrong transportId", clientProxyFactoryBean.getTransportId(), "http://cxf.apache.org/transports/local");
assertEquals("get the wrong bindingId", clientProxyFactoryBean.getBindingId(), "http://cxf.apache.org/bindings/xformat");
greeter = (HelloService) ctx.getBean("client2");
assertNotNull(greeter);
greeter = (HelloService) ctx.getBean("client3");
assertNotNull(greeter);
client = ClientProxy.getClient(greeter);
EndpointInfo epi = client.getEndpoint().getEndpointInfo();
AuthorizationPolicy ap = epi.getExtensor(AuthorizationPolicy.class);
assertNotNull("The AuthorizationPolicy instance should not be null", ap);
assertEquals("Get the wrong username", ap.getUserName(), "testUser");
assertEquals("Get the wrong password", ap.getPassword(), "password");
}
Aggregations