use of org.apache.cxf.feature.AbstractFeature in project cxf by apache.
the class LoadDistributorTest method createBean.
protected JAXRSClientFactoryBean createBean(String address, FailoverFeature feature) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
List<AbstractFeature> features = new ArrayList<>();
features.add(feature);
bean.setFeatures(features);
return bean;
}
use of org.apache.cxf.feature.AbstractFeature in project fabric8 by jboss-fuse.
the class CxfRsFailOverClientServerTest method testClientServer.
@Test
public void testClientServer() throws Exception {
assertNotNull(bus);
// The bus is load the feature
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setResourceClasses(CustomerService.class);
factory.setAddress("http://localhost:9000/fail/server");
factory.setBus(bus);
factory.create();
factory = new JAXRSServerFactoryBean();
factory.setServiceClass(CustomerService.class);
factory.setResourceClasses(CustomerService.class);
factory.setBus(bus);
factory.create();
// sleep a while to let the service be published
for (int i = 0; i < 100; i++) {
if (!feature.getLoadBalanceStrategy().getAlternateAddressList().isEmpty()) {
break;
}
Thread.sleep(100);
}
JAXRSClientFactoryBean clientFactory = new JAXRSClientFactoryBean();
clientFactory.setServiceClass(CustomerServiceResources.class);
// The address is not the actual address that the client will access
clientFactory.setAddress("http://someotherplace");
List<AbstractFeature> features = new ArrayList<>();
// add the instance of FabricLoadBalancerFeature into features list
features.add(feature);
// we need to setup the feature on the clientfactory
clientFactory.setFeatures(features);
// set this interceptor to simulate the Transport level exception
List<Interceptor<? extends Message>> outInterceptor = clientFactory.getOutInterceptors();
outInterceptor.add(new TransportFailureInterceptor());
clientFactory.setOutInterceptors(outInterceptor);
CustomerServiceResources proxy = clientFactory.create(CustomerServiceResources.class);
Customer response = proxy.getCustomer("123");
assertEquals("Get a wrong customer name", "John", response.getName());
response = proxy.getCustomer("123");
assertEquals("Get a wrong customer name", "John", response.getName());
}
use of org.apache.cxf.feature.AbstractFeature in project fabric8 by jboss-fuse.
the class LoadBalanceClientServerTest method testClientServer.
@Test
public void testClientServer() throws Exception {
assertNotNull(bus);
// The bus is load the feature
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceBean(new HelloImpl());
factory.setAddress("http://localhost:9000/simple/server");
factory.setBus(bus);
factory.create();
// sleep a while to let the service be published
for (int i = 0; i < 100; i++) {
if (!feature.getLoadBalanceStrategy().getAlternateAddressList().isEmpty()) {
break;
}
Thread.sleep(100);
}
JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
clientFactory.setServiceClass(Hello.class);
// The address is not the actual address that the client will access
clientFactory.setAddress("http://someotherplace");
List<AbstractFeature> features = new ArrayList<AbstractFeature>();
features.add(feature);
// we need to setup the feature on the clientfactory
clientFactory.setFeatures(features);
Hello hello = clientFactory.create(Hello.class);
String response = hello.sayHello();
assertEquals("Get a wrong response", "Hello", response);
response = hello.sayHello();
assertEquals("Get a wrong response", "Hello", response);
// Try to call the hello proxy which is created by Spring with setting feature on the bus
response = helloProxy.sayHello();
assertEquals("Get a wrong response", "Hello", response);
}
use of org.apache.cxf.feature.AbstractFeature in project cxf by apache.
the class JAXRSSoapBookTest method serverFaultInInterceptorTest.
private void serverFaultInInterceptorTest(String param) {
String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(baseAddress);
bean.setResourceClass(BookStoreJaxrsJaxws.class);
TestFeature testFeature = new TestFeature();
List<AbstractFeature> features = new ArrayList<>();
features.add(testFeature);
bean.setFeatures(features);
BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws) bean.create();
WebClient.getConfig(proxy).getRequestContext().put("org.apache.cxf.transport.no_io_exceptions", false);
try {
// 321 is special case - causes error code of 525
proxy.getBook(Long.valueOf(param));
fail("Method should have thrown an exception");
} catch (Exception e) {
assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
if ("322".equals(param)) {
// In interceptors not called when checked exception thrown from server
assertTrue("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
} else {
assertFalse("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
}
assertTrue("Client In Fault In Interceptor not invoked", testFeature.faultInInterceptorCalled());
}
}
Aggregations